-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun1sim1.m
201 lines (117 loc) · 3.08 KB
/
run1sim1.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
function [ f, p, F, P, B ] = run1sim1( Smell, MC_ordA, MC_ordB, Ng, Np, Nt, dt, tau, thU, thL, ANoise, t_chr2, chr2, t_sm, WPP, WePB, cMult, cAdd, display )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
% [ f, p, F, P, B ] = run1sim1( 'B', [1:Ng]', [8, 6, 1, 5, 3, 7, 4, 2, 9:Ng]', Ng, Np, Nt, dt, .05, thU, thL, 0, 2, chr2, t_sm, PBExFwd, WPP*0.6, WePB*0.025, cMult, 1000, 1 );
if display
figure
end
if 0
if Smell == 'A'
MC_ord = MC_ordA;
else
MC_ord = MC_ordB;
end
else
MC_ord = [MC_ordA; MC_ordB];
ttt = [1:(length(MC_ordA))]';
if Smell == 'A'
TTT = [ttt; ttt*cMult+cAdd];
else
TTT = [ttt*cMult+cAdd; ttt];
end
[sTTT, ind] = sort(TTT, 'ascend');
MC_ord = MC_ord(ind);
% Remove duplicates
mmm = zeros(size(MC_ordA));
n_inc = 1;
if display
MC_ord(1:20)'
end
for i=1:length(MC_ord)
if MC_ord(i) == 0
continue
end
ind = find(MC_ord == MC_ord(i));
mmm(n_inc) = MC_ord(i);
n_inc = n_inc + 1;
MC_ord(ind)=0;
end
MC_ord = mmm;
end
B = zeros(Ng,Nt);
%dn_bulb = Nt/Ng*1.2;
%dn_bulb = Nt/Ng*2.1; % this was used in simulation on the night of
%5/22-23/2016
dn_bulb = round(0.2/10/dt); % 10 primary glomeruli in 0.2 sec
%dn_pulse = round(0.16/dt);
dn_pulse = round(0.5/dt);
n0_pulse = round(t_sm/dt);
if display
Mitral_cell_order = MC_ord(1:20)'
end
for i=1:Ng
n_glom = MC_ord(i);
dd=round(randn*0/dt); % jitter
t1 = round(dn_bulb*i+n0_pulse+dd);
t2 = round(dn_bulb*i+n0_pulse+dn_pulse+dd);
t2 = min(t2,Nt);
if t1<Nt
B(n_glom,t1:t2)=1;
end
end
NN = ANoise*randn(size(B));
B = B+NN;
I0 = 0*ones(Np,1);
% begin sim...............................................................
act = 0;
p = zeros(Np,1);
f = p;
f_prev = 0;
b = zeros(Ng,1);
p_prev = p;
P = zeros(Np,Nt);
F = P;
step=1;
t=0;
% add chr stim
%for i=round(t_chr2/dt):size(B,2)
for i=round(t_chr2/dt):min(round((t_chr2+0.1)/dt),size(B,2))
B(:,i) = B(:,i)+chr2;
end
B = sparse(B);
f = sparse(f);
b0 = sparse(B(:,1)*0);
dN = round(0.2/dt);
for i=(-dN):Nt
if i>0
b = B(:,i);
else
b = ANoise*randn(size(B(:,1)));
end
p_prev = p;
f_prev = f;
t=t+dt;
step = step+1;
I = I0 + WPP*f + WePB*b;
p = p_prev + dt/tau * (-p_prev + I);
ind = find(p>=thU);
f(ind)=1;
ind = find(p<=thL);
f(ind)=0;
ind = find((thL < p).*(p < thU));
f(ind) = f_prev(ind);
if display
subplot(1,2,1)
image(64*reshape(b,15,20)), axis equal, axis off, colormap winter
subplot(1,2,2)
image(64*reshape(f,25,40)), axis equal, axis off, colormap winter
title(sprintf('t=%g',i/Nt))
drawnow
pause(0.02)
end
if i>0
P(:,i)=p;
F(:,i)=f;
end
end
end