-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_ignition_decay.m
287 lines (225 loc) · 7.39 KB
/
run_ignition_decay.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
% This code runs the ignition and the decay variables
function run_ignition_decay(slurm_id,model_variant,range_perturb,jbal_flag)
% Default is to run the code to find the optimal Jbalanced terms
if(nargin<4)
jbal_flag=0;
end
STEPS_P=4; % this is how many steps you skip
% Default is to have a full range of the perturbation, otherwise break it up!
if(nargin<3 || isempty(range_perturb))
PERTURB=0.:0.001:0.2;
else
PERTURB=0.:0.001:0.2;
% Steps of 4
range_perturb=str2num(range_perturb);
PERTURB=PERTURB(range_perturb:STEPS_P:end);
% And a little extra for the first one to include 0.2 stimulation
if(range_perturb==1)
PERTURB=[PERTURB,0.2];
end
end
run_for_fig=1;
if(run_for_fig)
PERTURB=0.2;
end
% Now set up the Random number generator so we can reproduce the noisy terms:
% Also convert from a str to a num
slurm_id=str2num(slurm_id);
rng(slurm_id);
% Defining the SEED
SEED=10;
% First load in all the variables again
switch model_variant
case 'EI'
% Load in the genes
load DKcortex_selectedGenes.mat;
coefe=sum(expMeasures(:,18:25),2);
ratioE=coefe/(max(coefe));
ratioE(35:68)=ratioE(1:34);
coefi=sum(expMeasures(:,[2:9 12:14]),2); %% 18:21 ampa+ 22:25 nmda/gaba
ratioI=coefi/(max(coefi));
ratioI(35:68)=ratioI(1:34);
ratio=ratioE./ratioI;
ratio=ratio/(max(ratio)-min(ratio));
ratio=ratio-max(ratio)+1;
% Grand model simulation parameters
alpha=-0.3; %% -0.3
beta=1.8; %%1.8
we=2.1;
case 'T1T2'
load myelin_HCP_dk68.mat;
ratio=t1t2Cortex';
ratio=ratio/(max(ratio)-min(ratio));
ratio=ratio-max(ratio)+1;
ratio(find(ratio<0))=0;
alpha=-0.7; %% -0.3
beta=1.4; %%1.8
we=2.1;
case 'PCA'
% Here is the PCA model
load APARC_genedata.mat
coefei=data;
ratio=coefei/(max(coefei)-min(coefei));
ratio=ratio-max(ratio)+1;
ratio(35:68)=ratio(1:34);
alpha=-0.75; %% -0.3
beta=1.6; %%1.8
we=2.1;
case 'Null'
% Loads in the null spatial model for the genes
% indrnd=randi(10000);
% Loading in the pseudo random vector, to have more control over this and to be able to pre-calculate the values
load null_pseudoRandom.mat;
indrnd=randVector(slurm_id);
load DKcortex_selectedGenes_Permuted.mat;
% Load one of the permuted genes from a spin test:
coefe=sum(expMeasuresPerm(:,18:25,indrnd),2);
ratioE=coefe/(max(coefe));
% Reflect the left to the right hemisphere
ratioE(35:68)=ratioE(1:34);
% Here perform normalization
coefi=sum(expMeasuresPerm(:,[2:9 12:14],indrnd),2); %% 18:21 ampa+ 22:25 nmda/gaba
ratioI=coefi/(max(coefi));
% Also refelect this measure
ratioI(35:68)=ratioI(1:34);
% Now calcualte the ratio between excitatory genes / inhibitory genes
ratio=ratioE./ratioI;
% Perform some ratio normalization:
ratio=ratio/(max(ratio)-min(ratio));
ratio=ratio-max(ratio)+1;
% Last of all the parameters for the simulation - derived from a different simulation that performs and exhaustive search over these params
we=2.1;
alpha=-0.35;
beta=1.85;
case 'BEI'
ratio=ones(68,1);
alpha=0;
beta=0;
we=2.1;
end
% Define now the gain for the models:
gain=1+alpha+beta*ratio;
% Define the SC matrix
%%%%%%%%%%
load('SC_GenCog_PROB_30.mat');
C=GrCV([1:34 42:75],[1:34 42:75]);
C=C/max(max(C))*0.2;
% Balancing the model - re-calculating or re-loading, i have a parameter that you can switch it to run it
% or preload it - for the moment, if you want to calculate it, it saves jbal then exists
if(jbal_flag==1)
% Run the Jbalance optimization
Jbal=Balance_J_gain(we,C,gain);
system(['mkdir -p ',model_variant])
switch model_variant
case 'Null',
save([model_variant,'/JBAL_',model_variant,'_',num2str(slurm_id),'.mat'],'Jbal');
otherwise
save([model_variant,'/JBAL_',model_variant,'.mat'],'Jbal');
end
return
else
switch model_variant
case 'Null',
load([model_variant,'/JBAL_',model_variant,'_',num2str(slurm_id),'.mat']);
otherwise
load([model_variant,'/JBAL_',model_variant,'.mat']);
end
end
% The filename to save the simulation
if(strcmp(computer,'MACI64'))
cluster_folder='./';
else
% Please put in the path you need
disp('Enter your cluster folder on this line... exiting..')
return
% cluster_folder='/myClusterFolder/';
end
filename=[cluster_folder,model_variant,'/',model_variant,'_',num2str(slurm_id),'_Peturb_range_',num2str(range_perturb)];
% Here a little flag - if it was already run, do not run it again (can change later)
if(exist([filename,'.mat']))
disp('!!!!!!!!Found simulation - NOT overriding -- exiting now!')
return
end
%%%%%%%%%%%%%%%%%%
% Parameters for the mean field model:
dtt = 1e-3; % Sampling rate of simulated neuronal activity (seconds)
dt=0.1;
taon=100;
taog=10;
gamma=0.641;
sigma=0.01;
JN=0.15;
I0=0.382;
Jexte=1.;
Jexti=0.7;
w=1.4;
N=68;
Tmax=616;
% Settings for the ignition code:
sigfunc = @(A, x)(A(1) ./ (1 + exp(-A(2)*(x-A(3)))) + A(4));
options=optimset('MaxFunEvals',10000,'MaxIter',1000);
nseed=1;
Tmax=7000;
SUBTR=500;
nump=length(PERTURB);
neuro_act2=zeros(SUBTR,Tmax+1,N);
for seed=SEED %% Only 1 seed is being stimulated but here for convenience.
tseed=1:N;
tseed(find(seed==tseed))=[];
tseed(find(N/2+seed==tseed))=[];
kk=1;
for perturb=PERTURB %% for each stimulation..different strengths (Istim)
Istim=zeros(N,1);
% Here peforming the simulation over SUBTR times to form an average - this forms all the information for the next sections
for sub=1:SUBTR
disp(['Running ... ',num2str(sub)]);
% Initalize the code and perform the stimulation:
nn=1;
sn=0.001*ones(N,1);
sg=0.001*ones(N,1);
for t=0:dt:Tmax
if t==3000
Istim(seed)=perturb;
Istim(N/2+seed)=perturb;
elseif t==4000
Istim(seed)=0;
Istim(N/2+seed)=0;
end
xn=Istim+I0*Jexte+JN*w*sn+we*JN*C*sn-Jbal.*sg;
xg=I0*Jexti+JN*sn-sg;
rn=phie_gain(xn,gain);
rg=phii_gain(xg,gain);
sn=sn+dt*(-sn/taon+(1-sn)*gamma.*rn./1000.)+sqrt(dt)*sigma*randn(N,1);
sn(sn>1) = 1;
sn(sn<0) = 0;
sg=sg+dt*(-sg/taog+rg./1000.)+sqrt(dt)*sigma*randn(N,1);
sg(sg>1) = 1;
sg(sg<0) = 0;
if abs(mod(t,1))<0.01
neuro_act2(sub,nn,:)=rn';
nn=nn+1;
end
end
end
% From all the sub THR, we now look at averaging the activity so that it is all saved!
neuro_act1=squeeze(mean(neuro_act2(1:SUBTR,:,:),1));
ntwi=1;
for twi=1:20:nn-1-19
neuro_actf(ntwi,:)=mean(neuro_act1(twi:twi+19,:));
ntwi=ntwi+1;
end
ssnum=1;
for ss=tseed
peakrate3(ssnum)=mean(neuro_actf(160:200,ss),1);
basal(ssnum)=mean(neuro_actf(100:140,ss));
decayneuro=squeeze(neuro_actf(200:end,ss));
end
peakrate2(kk,:)=peakrate3./basal;
neuro_act_all(:,:,kk) = neuro_actf;
kk=kk+1;
end
% Now save the results, but make a folder (doesnt overwrite it)
system(['mkdir -p ',cluster_folder,model_variant])
save(filename,'neuro_act_all','PERTURB','model_variant','slurm_id');
end
end