-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurrounnd_model_design.py
315 lines (251 loc) · 15.4 KB
/
surrounnd_model_design.py
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import param
import topo.pattern
import topo.pattern.random
import __main__
import os
import contrib
import topo
from topo.transferfn.misc import PatternCombine
from topo.transferfn.misc import HalfRectify
from topo import numbergen
from topo.pattern import Gaussian
from topo.numbergen import UniformRandom, BoundedNumber, ExponentialDecay
from topo.command import pattern_present
from param import normalize_path
import numpy
from topo.analysis.featureresponses import MeasureResponseCommand, FeatureMaps, SinusoidalMeasureResponseCommand, FeatureCurveCommand
FeatureMaps.num_orientation=16
MeasureResponseCommand.scale=1.0
MeasureResponseCommand.duration=4.0
SinusoidalMeasureResponseCommand.frequencies=[2.4]
FeatureCurveCommand.num_orientation=16
FeatureCurveCommand.curve_parameters=[{"contrast":15},{"contrast":50},{"contrast":90}]
from topo.command import load_snapshot
load_snapshot('CCSimple_010005_new_or_map.00.typ')
from topo.command import wipe_out_activity, clear_event_queue
wipe_out_activity()
clear_event_queue()
from topo.pattern import SineGrating, Disk
class SineGratingDiskTemp(SineGrating):
mask_shape = param.Parameter(default=Disk(smoothing=0,size=1.0))
def set_parameters(a,b,c,d,e,f,g,h,i,j,k,l):
print a,b,c,d,e,f,g,h,i,j,k,l
topo.sim["V1Simple"].projections()["V1SimpleFeedbackExc1"].strength=b
topo.sim["V1Simple"].projections()["V1SimpleFeedbackInh"].strength=c
topo.sim["V1Complex"].projections()["LongEE"].strength=d
topo.sim["V1ComplexInh"].projections()["LongEI"].strength=e
topo.sim["V1Complex"].projections()["LocalIE"].strength=f
topo.sim["V1ComplexInh"].projections()["LocalII"].strength=g
topo.sim["V1Complex"].projections()["V1SimpleAfferent"].strength=h
topo.sim["V1Complex"].projections()["LocalEE"].strength=i
topo.sim["V1ComplexInh"].projections()["LocalEI"].strength=j
topo.sim["V1Complex"].output_fns[1].t*=0
topo.sim["V1Complex"].output_fns[1].t+=k
topo.sim["V1ComplexInh"].output_fns[1].t*=0
topo.sim["V1ComplexInh"].output_fns[1].t+=l
def check_activity(a,b,c,d,e,f,g,h,i,j,k,l):
print a,b,c,d,e,f,g,h,i,j,k,l
topo.sim["V1Simple"].projections()["V1SimpleFeedbackExc1"].strength=b
topo.sim["V1Simple"].projections()["V1SimpleFeedbackInh"].strength=c
topo.sim["V1Complex"].projections()["LongEE"].strength=d
topo.sim["V1ComplexInh"].projections()["LongEI"].strength=e
topo.sim["V1Complex"].projections()["LocalIE"].strength=f
topo.sim["V1ComplexInh"].projections()["LocalII"].strength=g
topo.sim["V1Complex"].projections()["V1SimpleAfferent"].strength=h
topo.sim["V1Complex"].projections()["LocalEE"].strength=i
topo.sim["V1ComplexInh"].projections()["LocalEI"].strength=j
topo.sim["V1Complex"].output_fns[1].t*=0
topo.sim["V1Complex"].output_fns[1].t+=k
topo.sim["V1ComplexInh"].output_fns[1].t*=0
topo.sim["V1ComplexInh"].output_fns[1].t+=l
par = "_" + str(a)+ "_" + str(b) + "_" + str(c) + "_" + str(d)+ "_" + str(e) + "_" + str(f) + "_" + str(g) + "_" + str(h) + "_" + str(i) + "_" + str(j) + "_" + str(k) + "_" + str(l) +".png"
plot_neural_dynamics(par)
def make_full_analysis(a,b,c,d,e,f,g,h,i,j,k,l):
import topo
print a,b,c,d,e,f,g,h,i,j,k,l
topo.sim["V1Simple"].projections()["V1SimpleFeedbackExc1"].strength=b
topo.sim["V1Simple"].projections()["V1SimpleFeedbackInh"].strength=c
topo.sim["V1Complex"].projections()["LongEE"].strength=d
topo.sim["V1ComplexInh"].projections()["LongEI"].strength=e
topo.sim["V1Complex"].projections()["LocalIE"].strength=f
topo.sim["V1ComplexInh"].projections()["LocalII"].strength=g
topo.sim["V1Complex"].projections()["V1SimpleAfferent"].strength=h
topo.sim["V1Complex"].projections()["LocalEE"].strength=i
topo.sim["V1ComplexInh"].projections()["LocalEI"].strength=j
topo.sim["V1Complex"].output_fns[1].t*=0
topo.sim["V1Complex"].output_fns[1].t+=k
topo.sim["V1ComplexInh"].output_fns[1].t*=0
topo.sim["V1ComplexInh"].output_fns[1].t+=l
topo.sim['V1Simple'].output_fns[0].old_a*=0
topo.sim['V1Complex'].output_fns[0].old_a*=0
topo.sim['V1ComplexInh'].output_fns[0].old_a*=0
from topo.analysis.featureresponses import MeasureResponseCommand, FeatureMaps, SinusoidalMeasureResponseCommand,FeatureCurveCommand
FeatureMaps.num_orientation=16
MeasureResponseCommand.scale=1.0
SinusoidalMeasureResponseCommand.frequencies=[2.4]
FeatureCurveCommand.num_orientation=16
MeasureResponseCommand.duration=4.0
V1Splastic = topo.sim["V1Simple"].plastic
V1Cplastic = topo.sim["V1Complex"].plastic
V1CInhplastic = topo.sim["V1ComplexInh"].plastic
topo.sim["V1Simple"].plastic = False
topo.sim["V1Complex"].plastic = False
topo.sim["V1ComplexInh"].plastic = False
wipe_out_activity()
clear_event_queue()
par = 'Analysis:' + str(a)+ "_" + str(b) + "_" + str(c) + "_" + str(d)+ "_" + str(e) + "_" + str(f) + "_" + str(g) + "_" + str(h) + "_" + str(i) + "_" + str(j) + "_" + str(k) + "_" + str(l)
#d = os.path.dirname(par)
if not os.path.exists(par):
os.makedirs(par)
normalize_path.prefix = par
plot_neural_dynamics('neural_dynamics.png')
import contrib.surround_analysis
from topo.analysis.featureresponses import SinusoidalMeasureResponseCommand,FeatureCurveCommand
from topo.base.projection import ProjectionSheet
from topo.sheet import GeneratorSheet
import contrib.jacommands
import contrib.surround_analysis
exec "from topo.analysis.vision import analyze_complexity" in __main__.__dict__
from topo.analysis.featureresponses import PatternPresenter
PatternPresenter.duration=4.0
import topo.command.pylabplot
reload(topo.command.pylabplot)
contrib.surround_analysis.run_dynamics_analysis(0.0,0.0,0.7,__main__.__dict__.get("analysis_scale",0.3))
contrib.surround_analysis.size_tuning_analysis(0.0,0.0,1.0)
PatternPresenter.duration=4.0
a = topo.command.pylabplot.measure_or_tuning_fullfield.instance(sheet=topo.sim["V1Complex"])
a.duration=4.0
a()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,0]",sheet=topo.sim["V1Complex"],coords=[(0,0)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.1,0.1]",sheet=topo.sim["V1Complex"],coords=[(0.1,0.1)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.1,-0.1]",sheet=topo.sim["V1Complex"],coords=[(0.1,-0.1)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.1,0.1]",sheet=topo.sim["V1Complex"],coords=[(-0.1,0.1)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.1,-0.1]",sheet=topo.sim["V1Complex"],coords=[(-0.1,-0.1)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.2,0.2]",sheet=topo.sim["V1Complex"],coords=[(0.2,0.2)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.2,-0.2]",sheet=topo.sim["V1Complex"],coords=[(0.2,-0.2)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.2,0.2]",sheet=topo.sim["V1Complex"],coords=[(-0.2,0.2)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.2,-0.2]",sheet=topo.sim["V1Complex"],coords=[(-0.2,-0.2)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,0.1]",sheet=topo.sim["V1Complex"],coords=[(0.0,0.1)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,-0.1]",sheet=topo.sim["V1Complex"],coords=[(0.0,-0.1)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.1,0]",sheet=topo.sim["V1Complex"],coords=[(-0.1,0.0)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.1,0]",sheet=topo.sim["V1Complex"],coords=[(0.1,-0.0)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.3,0.3]",sheet=topo.sim["V1Complex"],coords=[(0.3,0.3)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.3,-0.3]",sheet=topo.sim["V1Complex"],coords=[(0.3,-0.3)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.3,0.3]",sheet=topo.sim["V1Complex"],coords=[(-0.3,0.3)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.3,-0.3]",sheet=topo.sim["V1Complex"],coords=[(-0.3,-0.3)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.24,0.24]",sheet=topo.sim["V1Complex"],coords=[(0.25,0.25)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.24,-0.24]",sheet=topo.sim["V1Complex"],coords=[(0.25,-0.25)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.24,0.24]",sheet=topo.sim["V1Complex"],coords=[(-0.25,0.25)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.24,-0.24]",sheet=topo.sim["V1Complex"],coords=[(-0.25,-0.25)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,0.24]",sheet=topo.sim["V1Complex"],coords=[(0.0,0.25)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,-0.24]",sheet=topo.sim["V1Complex"],coords=[(0.0,-0.25)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.24,0]",sheet=topo.sim["V1Complex"],coords=[(-0.25,0.0)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.24,0]",sheet=topo.sim["V1Complex"],coords=[(0.25,-0.0)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,0.3]",sheet=topo.sim["V1Complex"],coords=[(0.0,0.3)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,-0.3]",sheet=topo.sim["V1Complex"],coords=[(0.0,-0.3)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.3,0]",sheet=topo.sim["V1Complex"],coords=[(-0.3,0.0)])()
topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.3,0]",sheet=topo.sim["V1Complex"],coords=[(0.3,-0.0)])()
contrib.surround_analysis.surround_analysis().analyse([(0,0),(1.0,0.0),(0.0,1.0),(-1.0,0.0),(0.0,-1.0),(1.0,1.0),(-1.0,1.0),(1.0,-1.0),(-1.0,-1.0)])
def plot_neural_dynamics(params):
sheet_names=["V1Complex"]
ip = topo.sim['Retina'].input_generator
topo.sim['Retina'].set_input_generator(SineGratingDiskTemp(orientation=0.0,phase=0.0,size=10,scale=1.0,x=0.0,y=0.0,frequency=2.4))
from topo.pattern import OrientationContrast
from topo.command import pattern_present
from topo.base.functionfamily import PatternDrivenAnalysis
from topo.pattern import OrientationContrast
from topo.analysis.featureresponses import PatternPresenter
from topo.base.sheet import Sheet
import pylab
topo.sim['V1Simple'].output_fns[0].old_a*=0
topo.sim['V1Complex'].output_fns[0].old_a*=0
topo.sim['V1ComplexInh'].output_fns[0].old_a*=0
V1Splastic = topo.sim["V1Simple"].plastic
V1Cplastic = topo.sim["V1Complex"].plastic
V1CInhplastic = topo.sim["V1ComplexInh"].plastic
topo.sim["V1Simple"].plastic = False
topo.sim["V1Complex"].plastic = False
topo.sim["V1ComplexInh"].plastic = False
prefix="/home/antolikjan/topographica/ActivityExploration/"
topo.sim.state_push()
from topo.command import pattern_present
from topo.base.functionfamily import PatternDrivenAnalysis
from topo.pattern import OrientationContrast
from topo.analysis.featureresponses import PatternPresenter
from topo.base.sheet import Sheet
data={}
for key in sheet_names:
data[key] = {}
for i in topo.sim[key].projections().keys():
data[key][i]=[]
data[key]["act"]=[]
for i in xrange(0,100):
topo.sim.run(0.05)
for key in sheet_names:
for i in topo.sim[key].projections().keys():
data[key][i].append(topo.sim[key].projections()[i].activity.copy())
data[key]["act"].append(topo.sim[key].activity.copy())
acts = topo.sim["V1Simple"].activity.copy()
actc = topo.sim["V1Complex"].activity.copy()
topo.sim.state_pop()
m = numpy.argmax(data["V1Complex"]["act"][-1])
(X,Y) = numpy.unravel_index(m, data["V1Complex"]["act"][-1].shape)
print X,Y
pylab.figure(figsize=(20,5))
pylab.subplot(2,3,1)
pylab.title(prefix+sheet_names[0]+" [" + str(X) + "," +str(Y) + "]")
for projname in data[sheet_names[0]].keys():
a = []
for act in data[sheet_names[0]][projname]:
a.append(act[X,Y])
pylab.plot(a,label=projname)
#pylab.legend(loc='upper left')
pylab.subplot(2,3,2)
pylab.imshow(acts)
pylab.colorbar()
pylab.subplot(2,3,3)
pylab.imshow(actc)
pylab.colorbar()
(xx,yy) = topo.sim["V1Complex"].matrixidx2sheet(X,Y)
# now lets collect the size tuning
step_size=0.2
stc_lc = []
for i in xrange(0,20):
topo.sim['V1Simple'].output_fns[0].old_a*=0
topo.sim['V1Complex'].output_fns[0].old_a*=0
topo.sim['V1ComplexInh'].output_fns[0].old_a*=0
wipe_out_activity()
clear_event_queue()
topo.sim['Retina'].set_input_generator(SineGratingDiskTemp(orientation=0.0,phase=0.0,size=i*step_size,scale=0.3,x=xx,y=yy,frequency=2.4))
topo.sim.state_push()
topo.sim.run(4.0)
stc_lc.append(topo.sim["V1Complex"].activity[X,Y].copy())
topo.sim.state_pop()
stc_hc = []
for i in xrange(0,20):
topo.sim['V1Simple'].output_fns[0].old_a*=0
topo.sim['V1Complex'].output_fns[0].old_a*=0
topo.sim['V1ComplexInh'].output_fns[0].old_a*=0
wipe_out_activity()
clear_event_queue()
topo.sim['Retina'].set_input_generator(SineGratingDiskTemp(orientation=0.0,phase=0.0,size=i*step_size,scale=1.0,x=xx,y=yy,frequency=2.4))
topo.sim.state_push()
topo.sim.run(4.0)
stc_hc.append(topo.sim["V1Complex"].activity[X,Y].copy())
topo.sim.state_pop()
pylab.subplot(2,3,4)
pylab.plot(stc_lc,label='30%')
pylab.plot(stc_hc,label='100%')
pylab.legend()
topo.sim["V1Simple"].plastic = V1Splastic
topo.sim["V1Complex"].plastic = V1Cplastic
topo.sim["V1ComplexInh"].plastic = V1CInhplastic
wipe_out_activity()
clear_event_queue()
topo.sim['Retina'].set_input_generator(ip)
pylab.savefig(prefix+ sheet_names[0] + params);
#contrib.jacommands.run_combinations(check_activity,[[0],[0.1],[-2.5],[0.1],[4.0,5.0,6.0],[-1.0,-1.1],[-0.9,-0.8],[3.0],[1.7],[2.2],[0.1],[0.2,0.3]])
#make_full_analysis(0,0.1,-2.5,0.1,6.0,-1.1,-0.8,3.0,1.7,2.2,0.1,0.3)
#make_full_analysis(0,0.1,-2.5,0.4,0.1,-8.0,-1.2,1.5,0.7,0.15,0.1,0.3)
contrib.jacommands.run_combinations(check_activity,[[0],[0.1],[-2.5,-2.0,-3.0],[0.4,0.8],[0.1,0.2],[-8.0,-5.0,-6.0],[-1.2],[1.0],[0.6],[0.1],[0.05,0.1],[0.1,0.2]])
#contrib.jacommands.run_combinations(check_activity,[[0],[0.05,0.1,0.15],[-1.0,-2.0,-3.0],[0.4],[0.1],[-5.7],[-1.7],[0.5],[1.15,1.0,1.3],[0.2,0.15,0.25]])