forked from hcc11/SpatialNeuronNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_weights.m
167 lines (142 loc) · 5.61 KB
/
gen_weights.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
function [Wrr,Wrf]=gen_weights(Ne,Ni,Nx,sigmaRX,sigmaRR,Prr,Prx,dimension)
% sigmaRR=[sigmaee, sigmaei; sigmaie, sigmaii]; 2x2
% sigmaRX=[sigmaeX; sigmaiX];
% dimension='1D' or '2D'
% sort post syn index
switch dimension
case '2D'
% x, y range: [1 Ne1], [1,Ni1], [1 Nx1]
% exc. ID [1, Ne], x=ceil(I/Ne1); y=(mod((I-1),Ne1)+1); I=(x-1)*Ne1+y
% inh. ID [Ne+1, Ne+Ni], x=ceil((I-Ne)/Ni1); y=(mod((I-Ne-1),Ni1)+1); I=(x-1)*Ni1+y+Ne;
% Connection widths
sigmaeX=sigmaRX(1);
sigmaiX=sigmaRX(2);
sigmaee=sigmaRR(1,1);
sigmaei=sigmaRR(1,2);
sigmaie=sigmaRR(2,1);
sigmaii=sigmaRR(2,2);
pee0=Prr(1,1);
pei0=Prr(1,2);
pie0=Prr(2,1);
pii0=Prr(2,2);
pex0=Prx(1);
pix0=Prx(2);
Ne1=sqrt(Ne);
Ni1=sqrt(Ni);
Nx1=sqrt(Nx);
betaee=sigmaee*(Ne1);
betaei=sigmaei*(Ne1);
betaie=sigmaie*(Ni1);
betaii=sigmaii*(Ni1);
betaex=sigmaeX*(Ne1);
betaix=sigmaiX*(Ni1);
% Kab is the total number of projections a neuron from
% pop b makes to ALL neurons in pop a
Kee=ceil(pee0*Ne);
Kei=ceil(pei0*Ne);
Kie=ceil(pie0*Ni);
Kii=ceil(pii0*Ni);
Kex=ceil(pex0*Ne);
Kix=ceil(pix0*Ni);
CircRandN=@(mu,sigma,min,max,n)(mod(round(sigma*randn(n,1)+mu)-min,max-min+1)+min);
Ke=Kee+Kie; % Number of excitatory and inhibitory connections per cell
Ki=Kei+Kii;
Kx=Kex+Kix;
Wrr=zeros(Ke*Ne+Ki*Ni,1,'int32'); % recurrent connections
Wrf=zeros(Kx*Nx,1,'int32'); % feedforward connections
for j=1:Ne
% E pre, E post
x_pre=ceil(j/Ne1);
y_pre=mod(j-1,Ne1)+1;
x_post=CircRandN(x_pre,betaee,1,Ne1,Kee);
y_post=CircRandN(y_pre,betaee,1,Ne1,Kee);
Wrr((1+(j-1)*Ke):(Kee+(j-1)*Ke))=sort((x_post-1)*Ne1+y_post);
% E pre, I post
x_pre=ceil(j/Ne1)*Ni1/Ne1;
y_pre=(mod(j-1,Ne1)+1)*Ni1/Ne1;
x_post=CircRandN(x_pre,betaie,1,Ni1,Kie);
y_post=CircRandN(y_pre,betaie,1,Ni1,Kie);
Wrr((Kee+1+(j-1)*Ke):(Kee+Kie+(j-1)*Ke))=sort((x_post-1)*Ni1+y_post+Ne);
end
for j=1:Ni
% I pre, E post
x_pre=ceil(j/Ni1)*Ne1/Ni1;
y_pre=(mod(j-1,Ni1)+1)*Ne1/Ni1;
x_post=CircRandN(x_pre,betaei,1,Ne1,Kei);
y_post=CircRandN(y_pre,betaei,1,Ne1,Kei);
Wrr((Ne*Ke+1+(j-1)*Ki):(Ne*Ke+Kei+(j-1)*Ki))=sort((x_post-1)*Ne1+y_post);
% I pre, I post
x_pre=ceil(j/Ni1);
y_pre=(mod(j-1,Ni1)+1);
x_post=CircRandN(x_pre,betaii,1,Ni1,Kii);
y_post=CircRandN(y_pre,betaii,1,Ni1,Kii);
Wrr((Ne*Ke+Kei+1+(j-1)*Ki):(Ne*Ke+Kei+Kii+(j-1)*Ki))=sort((x_post-1)*Ni1+y_post+Ne);
end
for j=1:Nx
% X pre, E post
x_pre=ceil(j/Nx1)*Ne1/Nx1;
y_pre=(mod(j-1,Nx1)+1)*Ne1/Nx1;
x_post=CircRandN(x_pre,betaex,1,Ne1,Kex);
y_post=CircRandN(y_pre,betaex,1,Ne1,Kex);
Wrf((Kx*(j-1)+1):(Kx*(j-1)+Kex))=sort((x_post-1)*Ne1+y_post);
% X pre, I post
x_pre=ceil(j/Nx1)*Ni1/Nx1;
y_pre=(mod(j-1,Nx1)+1)*Ni1/Nx1;
x_post=CircRandN(x_pre,betaix,1,Ni1,Kix);
y_post=CircRandN(y_pre,betaix,1,Ni1,Kix);
Wrf((Kex+1+(j-1)*Kx):(j*Kx))=sort((x_post-1)*Ni1+y_post+Ne);
end
case '1D'
% Connection widths
sigmaeX=sigmaRX(1);
sigmaiX=sigmaRX(2);
sigmaee=sigmaRR(1,1);
sigmaei=sigmaRR(1,2);
sigmaie=sigmaRR(2,1);
sigmaii=sigmaRR(2,2);
% Connection widths in units of neuron indices
pee0=Prr(1,1);
pei0=Prr(1,2);
pie0=Prr(2,1);
pii0=Prr(2,2);
pex0=Prx(1);
pix0=Prx(2);
betaee=sigmaee*(Ne);
betaei=sigmaei*(Ne);
betaie=sigmaie*(Ni);
betaii=sigmaii*(Ni);
betaex=sigmaeX*(Ne);
betaix=sigmaiX*(Ni);
% Kab is the total number of projections a neuron from
% pop b makes to ALL neurons in pop a
Kee=ceil(pee0*Ne);
Kei=ceil(pei0*Ne);
Kie=ceil(pie0*Ni);
Kii=ceil(pii0*Ni);
Kex=ceil(pex0*Ne);
Kix=ceil(pix0*Ni);
CircRandN=@(mu,sigma,min,max,n)(mod(round(sigma*randn(n,1)+mu)-min,max-min+1)+min);
Ke=Kee+Kie; % Number of excitatory and inhibitory connections per cell
Ki=Kei+Kii;
Kx=Kex+Kix;
Wrr=zeros(Ke*Ne+Ki*Ni,1,'int32'); % recurrent connections
Wrf=zeros(Kx*Nx,1,'int32'); % feedforward connections
for j=1:Ne
% E pre, E post
Wrr((1+(j-1)*Ke):(Kee+(j-1)*Ke))=(CircRandN(j,betaee,1,Ne,Kee));
% E pre, I post
Wrr((Kee+1+(j-1)*Ke):(Kee+Kie+(j-1)*Ke))=(CircRandN(j/Ne*Ni+Ne,betaie,Ne+1,Ni+Ne,Kie));
end
for j=1:Ni
% I pre, E post
Wrr((Ne*Ke+1+(j-1)*Ki):(Ne*Ke+Kei+(j-1)*Ki))=(CircRandN(j/Ni*Ne,betaei,1,Ne,Kei));
% I pre, I post
Wrr((Ne*Ke+Kei+1+(j-1)*Ki):(Ne*Ke+Kei+Kii+(j-1)*Ki))=(CircRandN(j+Ne,betaii,Ne+1,Ne+Ni,Kii));
end
for j=1:Nx
% X pre, E post
Wrf((Kx*(j-1)+1):(Kx*(j-1)+Kex))=(CircRandN(j/Nx*Ne,betaex,1,Ne,Kex));
% X pre, I post
Wrf((Kex+1+(j-1)*Kx):(j*Kx))=(CircRandN(j/Nx*Ni+Ne,betaix,Ne+1,Ne+Ni,Kix));
end
end