%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% COPYRIGHT:
% Paul Harrison, Laurent Badel, Mark Wall and Magnus JE Richardson
% (2014)
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation version 3.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% See for the GNU General Public License
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ Data_gen_class,Variables ] = Generate_rEIF( N )
%GENERATEREIF Generate populations of rEIF neuron models of layer 2/3, 4,
%slender-tufted layer 5, and thick-tufted layer 5 pyramidal cells. Requires
%MATLAB Global Optimzation and Statistics toolboxes.
% Input:
% N = number of cells to generate. 4x1 vector consisting of the
% number required for each class in the order stated above. If the
% same number from each class are required just input a single
% number.
% Output:
% Data_gen_class = 4x1 cell array where each element corresponds to
% the cell classes in the order stated above (Data_gen_class{1} are
% layer 2/3 cells etc.). Each element in the cell array is an N(k)*13
% array of parameter values. Rows correspond to to model neurons and
% columns are parameters
% [C,tau,E,VT,DT,g1,taug,VT1,tauT,E_A1,tau_E1,E_A2,tau_E2]. In the
% case of cells with a mono-exponential decaying equilibrium
% potential E_A1=0 and tau_E1=10. Refractory dynamics are measured
% from 4ms after the spike peak (i.e. from after the refractory
% period).
% Variables = Cell array of variable names.
nClass=4;%Number of cell classes
if numel(N)==1
N=N*ones(nClass,1);
end
%% Non-Eref Distribution Parameters
Variables_rEIF={'C';'tau';'E';'VT';'DT';'g1';'taug';'VT1';'tauT'};
nVar=numel(Variables_rEIF);%Number of EIF parameters
DistName={'logn';'logn';'norm';'norm';'logn';'logn';'logn';'logn';'logn'};
mu=[4.87 4.86 4.86 5.61;...C
2.67 2.82 2.88 2.9;...tau
-79.3 -71.8 -69.9 -68.5;...E
-49.5 -48.7 -49.7 -52.7;...VT
.227 .213 .235 .0836;...DT
2.50 2.90 2.63 3.15;...g1
2.62 2.65 2.87 2.99;...taug
2.75 2.71 2.53 2.65;...VT1
2.49 2.61 2.65 2.44];%tauT
sig=[.258 .289 .251 .273;...C
.171 .24 .255 .229;...tau
4.27 4.2 4.18 3.98;...E
3.81 3.53 3.56 3.59;...VT
.359 .266 .361 .364;...DT
.616 .445 .528 .501;...g1
.570 .578 .694 .635;...taug
.286 .368 .296 .312;...VT1
.442 .345 .479 .432];%tauT
Rho{1}=...
[1.0000 -0.2721 0.0042 -0.5636 -0.1307 0.3344 0.1288 0.2781 -0.1811
-0.2721 1.0000 -0.1357 0.4244 -0.4509 -0.0626 -0.1978 -0.3071 -0.0952
0.0042 -0.1357 1.0000 0.4765 -0.0464 -0.1098 0.0114 0.0466 0.1897
-0.5636 0.4244 0.4765 1.0000 -0.3097 -0.1693 -0.0708 -0.2542 0.1030
-0.1307 -0.4509 -0.0464 -0.3097 1.0000 -0.1271 -0.0322 0.0376 0.5705
0.3344 -0.0626 -0.1098 -0.1693 -0.1271 1.0000 -0.7359 0.2904 -0.0036
0.1288 -0.1978 0.0114 -0.0708 -0.0322 -0.7359 1.0000 -0.2386 -0.1869
0.2781 -0.3071 0.0466 -0.2542 0.0376 0.2904 -0.2386 1.0000 -0.3623
-0.1811 -0.0952 0.1897 0.1030 0.5705 -0.0036 -0.1869 -0.3623 1.0000];
Rho{2}=...
[1.0000 0.1124 0.2056 -0.2430 -0.1318 0.2828 0.1578 0.1787 -0.0830
0.1124 1.0000 0.2773 -0.0053 -0.1034 -0.1876 0.4213 0.1560 0.0287
0.2056 0.2773 1.0000 0.3427 -0.3416 0.2254 0.2933 -0.0635 -0.0035
-0.2430 -0.0053 0.3427 1.0000 -0.4020 -0.1464 0.1829 0.1130 -0.2779
-0.1318 -0.1034 -0.3416 -0.4020 1.0000 0.1131 -0.4755 0.0372 0.2555
0.2828 -0.1876 0.2254 -0.1464 0.1131 1.0000 -0.5901 0.0257 -0.1920
0.1578 0.4213 0.2933 0.1829 -0.4755 -0.5901 1.0000 0.0336 -0.0620
0.1787 0.1560 -0.0635 0.1130 0.0372 0.0257 0.0336 1.0000 -0.5750
-0.0830 0.0287 -0.0035 -0.2779 0.2555 -0.1920 -0.0620 -0.5750 1.0000];
Rho{3}=...
[1.0000 0.3380 0.4681 -0.1710 -0.2218 0.2029 0.3500 0.0264 -0.1258
0.3380 1.0000 0.2582 -0.0344 -0.2067 0.0681 0.3596 -0.2010 0.1171
0.4681 0.2582 1.0000 0.3974 -0.4300 0.0924 0.3367 -0.1432 -0.3766
-0.1710 -0.0344 0.3974 1.0000 -0.1410 -0.0874 0.0882 0.1301 -0.2095
-0.2218 -0.2067 -0.4300 -0.1410 1.0000 -0.0274 -0.1694 0.0836 0.6912
0.2029 0.0681 0.0924 -0.0874 -0.0274 1.0000 -0.6661 -0.1429 -0.0372
0.3500 0.3596 0.3367 0.0882 -0.1694 -0.6661 1.0000 -0.0100 0.0137
0.0264 -0.2010 -0.1432 0.1301 0.0836 -0.1429 -0.0100 1.0000 -0.1519
-0.1258 0.1171 -0.3766 -0.2095 0.6912 -0.0372 0.0137 -0.1519 1.0000];
Rho{4}=...
[1.0000 0.0639 0.1435 -0.2865 -0.2151 0.1435 0.2147 -0.0737 -0.0698
0.0639 1.0000 0.0773 -0.0066 -0.2062 0.1547 0.1640 0.0313 -0.0202
0.1435 0.0773 1.0000 0.3730 0.1508 0.2822 0.2144 -0.0188 -0.0893
-0.2865 -0.0066 0.3730 1.0000 0.1949 0.2800 -0.2783 -0.1180 0.1357
-0.2151 -0.2062 0.1508 0.1949 1.0000 0.0603 -0.2176 0.1960 0.4118
0.1435 0.1547 0.2822 0.2800 0.0603 1.0000 -0.4625 0.1081 0.0126
0.2147 0.1640 0.2144 -0.2783 -0.2176 -0.4625 1.0000 0.0610 -0.2465
-0.0737 0.0313 -0.0188 -0.1180 0.1960 0.1081 0.0610 1.0000 -0.4574
-0.0698 -0.0202 -0.0893 0.1357 0.4118 0.0126 -0.2465 -0.4574 1.0000];
%% Eref Distribution Parameters
%Double exponential decay distribution parameters
DistName_dexp={'logn';'logn';'logn';'logn'};
mu_dexp=[2.70 2.24 2.15 1.83;...%Ejump
.0898 .442 .814 1.38;...%Esag
4.44 4.15 3.88 3.66;...%tsag
3.77 3.33 2.88 2.22];%t0
sig_dexp=[.396 .407 .492 .829;...%Ejump
.549 .599 .594 .493;...;%Esag
.263 .329 .471 .306;...%tsag
.360 .443 .704 .799];%t0
Rho_sag{1}=[1.0000 -0.3088 0.3989 0.5276
-0.3088 1.0000 -0.4835 -0.6705
0.3989 -0.4835 1.0000 0.9234
0.5276 -0.6705 0.9234 1.0000];
Rho_sag{2}=[1.0000 0.0558 0.3182 0.4164
0.0558 1.0000 -0.1502 -0.5196
0.3182 -0.1502 1.0000 0.8903
0.4164 -0.5196 0.8903 1.0000];
Rho_sag{3}=[1.0000 -0.0375 -0.1135 0.1634
-0.0375 1.0000 -0.7647 -0.8741
-0.1135 -0.7647 1.0000 0.9329
0.1634 -0.8741 0.9329 1.0000];
Rho_sag{4}=[1.0000 -0.3466 0.1548 0.8254
-0.3466 1.0000 -0.2784 -0.5810
0.1548 -0.2784 1.0000 0.6094
0.8254 -0.5810 0.6094 1.0000];
Rho_nosag{1}=[1.0000 -0.4993
-0.4993 1.0000];
Rho_nosag{2}=[1.0000 -0.1881
-0.1881 1.0000];
Rho_nosag{3}=[1.0000 -0.0664
-0.0664 1.0000];
Rho_nosag{4}=[1.0000 0.9983
0.9983 1.0000];
%Mono exponential decay distribution parameters (drawn from single
%distribution)
DistName_mexp={'logn';'logn'};
mu_mexp=[2.72;...A
2.67];%tau
sig_mexp=[.363;...A
.313];%tau
nVarSag=numel(DistName_dexp);
nVarNoSag=numel(DistName_mexp);
%% Sag Probability
Psag=[0.3226;
0.7586;
0.6897;
0.9362];
%% Randomly Assign Cells with E sag or no sag
CellSag_class=cell(nClass,1);
NSag=zeros(nClass,1);
NNoSag=zeros(nClass,1);
for k=1:nClass
temp=rand(N(k),1);
CellSag_class{k}=(temp0
%Generate a random sample from the Gaussian copula
Data_copula_gen_sag{k}=copularnd('Gaussian',Rho_sag{k},NSag(k));
%Transform the random sample back to the original scale of the data
Data_gen_class_sag{k}=zeros(size(Data_copula_gen_sag{k}));
for j=1:nVarSag
Data_gen_class_sag{k}(:,j)=icdf(DistName_dexp{j},...
Data_copula_gen_sag{k}(:,j),mu_dexp(j,k),sig_dexp(j,k));
end
end
end
%Cells with no sag
disp('Generate Random Sample: Eref Parameters - Cells with No Sag')
Data_copula_gen_nosag=cell(nClass,1);
Data_gen_class_nosag=cell(nClass,1);
for k=1:nClass
if NNoSag(k)>0
%Generate a random sample from the t copula
Data_copula_gen_nosag{k}=copularnd('Gaussian',Rho_nosag{k},...
NNoSag(k));
%Transform the random sample back to the original scale of the data
Data_gen_class_nosag{k}=zeros(size(Data_copula_gen_nosag{k}));
for j=1:nVarNoSag
Data_gen_class_nosag{k}(:,j)=icdf(DistName_mexp{j},...
Data_copula_gen_nosag{k}(:,j),mu_mexp(j),sig_mexp(j));
end
end
end
%% Fit Double Exponential Parameters Cells' Sag Response
disp('Fit Double Exponential to Cells'' Sag Response')
betaE=cell(nClass,1);
Ejump=cell(nClass,1);
Esag=cell(nClass,1);
tsag=cell(nClass,1);
t0=cell(nClass,1);
for k=1:nClass
betaE{k}(~CellSag_class{k},:)=[repmat([0 10],NNoSag(k),1),...
Data_gen_class_nosag{k}];
Ejump{k}=Data_gen_class_sag{k}(:,1);
Esag{k}=Data_gen_class_sag{k}(:,2);
tsag{k}=Data_gen_class_sag{k}(:,3);
t0{k}=Data_gen_class_sag{k}(:,4);
end
ind_total=1;
Tpoints=cell(nClass,1);
Epoints=cell(nClass,1);
opts=optimset('Display', 'off');
gs=GlobalSearch('NumStageOnePoints',200,'NumTrialPoints',1000,...
'StartPointsToRun','bounds-ineqs','Display', 'off');
warning off
dt=.05;t=(0:dt:300)';
func_dexp=@(x,t) -x(1)*exp(-t/x(2))+x(3)*exp(-t/x(4));
gs2=GlobalSearch('NumStageOnePoints',500,'NumTrialPoints',2000,...
'StartPointsToRun','bounds-ineqs','Display', 'off');
for ClassInd=1:nClass
ind=1;
Tpoints{ClassInd}=zeros(N(ClassInd),3);
Epoints{ClassInd}=zeros(N(ClassInd),3);
for k=1:N(ClassInd)
if CellSag_class{ClassInd}(k)
disp([' ',num2str(100*ind_total/sum(NSag)),'% Complete'])
Tpoints{ClassInd}(k,:)=[0 t0{ClassInd}(ind) tsag{ClassInd}(ind)];
Epoints{ClassInd}(k,:)=[Ejump{ClassInd}(ind) 0 -Esag{ClassInd}(ind)];
func=@(x) sum((-x(1)*exp(-Tpoints{ClassInd}(k,:)/x(2)) +...
x(3)*exp(-Tpoints{ClassInd}(k,:)/x(4)) -...
Epoints{ClassInd}(k,:)).^2);
c=@(x) (x(1)/x(2)^2)*((x(1)*x(4))/(x(3)*x(2)))^(-x(4)/(x(4)-x(2)))-...
(x(3)/x(4)^2)*((x(1)*x(4))/(x(3)*x(2)))^(-x(2)/(x(4)-x(2)));
ceq=@(x) [x(2)*x(4)*log((x(1)*x(4))/(x(3)*x(2)))/(x(4)-x(2))-...
tsag{ClassInd}(ind);
x(1)*exp(-tsag{ClassInd}(ind)/x(2))-...
x(3)*exp(-tsag{ClassInd}(ind)/x(4))-Esag{ClassInd}(ind)];
confun=@(x) deal(c(x),ceq(x));
problem=createOptimProblem('fmincon',...
'objective',func,...
'x0',[.5*Ejump{ClassInd}(ind) .5*tsag{ClassInd}(ind) ...
1.5*Ejump{ClassInd}(ind) .55*tsag{ClassInd}(ind)],...
'lb',[0 0 0 0],...
'ub',[Inf Inf Inf Inf],...
'Aineq',[1 0 -1 0;0 -1 0 1],...
'bineq',[0;0],...
'Aeq',[-1 0 1 0],...
'beq',Ejump{ClassInd}(ind),...
'nonlcon',confun,...
'options',opts);
% betaE{ClassInd}(k,:)=fmincon(problem);
betaE{ClassInd}(k,:)=run(gs,problem);
Espiketemp=func_dexp(betaE{ClassInd}(k,:),t);
Esagtemp=-min(Espiketemp);
if abs(Esag{ClassInd}(ind)-Esagtemp)>.2*Esag{ClassInd}(ind)
problem=createOptimProblem('fmincon',...
'objective',func,...
'x0',[.5*Ejump{ClassInd}(ind)*(.9+.2*rand(1)) ...
.5*tsag{ClassInd}(ind)*(.9+.2*rand(1)) ...
1.5*Ejump{ClassInd}(ind)*(.9+.2*rand(1)) ...
.55*tsag{ClassInd}(ind)*(.9+.2*rand(1))],...
'lb',[0 0 0 0],...
'ub',[Inf Inf Inf Inf],...
'Aineq',[1 0 -1 0;0 -1 0 1],...
'bineq',[0;0],...
'Aeq',[-1 0 1 0],...
'beq',Ejump{ClassInd}(ind),...
'nonlcon',confun,...
'options',opts);
% betaE{ClassInd}(k,:)=fmincon(problem);
betaE{ClassInd}(k,:)=run(gs2,problem);
end
figure,plot(t,DoubleExp([0,-betaE{ClassInd}(k,1),betaE{ClassInd}(k,2:end)],t),Tpoints{ClassInd}(k,:),Epoints{ClassInd}(k,:),'.')
ind=ind+1;ind_total=ind_total+1;
end
end
end
%% Store Data
for k=1:nClass
Data_gen_class{k}=[Data_gen_class{k},betaE{k}];
end
Variables=[Variables_rEIF;'A1';'tau1';'A2';'tau2'];
end