-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc_lesi_oo_or.ty
354 lines (266 loc) · 17.1 KB
/
cc_lesi_oo_or.ty
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
"""
LESI-based orientation map with complex cell layer.
$Id: cc_lissom_oo_or.ty 8265 2008-03-26 17:09:15Z antolikjan $
"""
__version__='$Revision: 8265 $'
import numpy
from math import pi, sqrt
import param
import topo.pattern
import topo.pattern.random
import __main__
from topo.sheet.lissom import LISSOM, JointNormalizingCFSheet_Continuous
from topo.sheet.optimized import NeighborhoodMask_Opt, LISSOM_Opt
from topo.sheet import GeneratorSheet
from topo.projection import CFProjection, SharedWeightCFProjection,OneToOneProjection
from topo.responsefn.optimized import CFPRF_DotProduct_opt
from topo.base.cf import CFSheet
from topo.base.boundingregion import BoundingBox
from topo.learningfn.optimized import CFPLF_Hebbian_opt, CFPLF_Trace_opt
from topo.transferfn.optimized import CFPOF_DivisiveNormalizeL1_opt
from topo.transferfn.misc import HalfRectify
from topo.transferfn.misc import AttributeTrackingTF
from topo.transferfn import PiecewiseLinear,DivisiveNormalizeL1, HomeostaticMaxEnt,Sigmoid
from topo import numbergen
from topo.pattern import Gaussian
from topo.learningfn.projfn import CFPLF_Trace
from topo.base.functionfamily import CoordinateMapperFn
from contrib.jacommands import randomize_V1Simple_relative_LGN_strength,ActivityHysteresis, Translator,SimpleHomeoSigmoid, Jitterer, AddGC, SimpleHomeoLinear
topo.sim.name = "CCSimple"
shared_params = {"a_init":14.5, "b_init":-4, "mu":0.01, "smoothing":0.0003}
shared_debug_params = {"debug_params":["a", "b"] , "avg_params":["x"], "units":[(0,0),(11,11),(23,23)]}
core_size=locals().get('CS',0.5)
num_inputs=1
dataset=locals().get('dataset',"Natural") #set the input type by choosing the dataset parameter
if dataset=="Natural":
import topo.pattern.image
input_type=topo.pattern.image.Image
image_filenames=["images/shouval/combined%02d.png"%(i+1) for i in xrange(25)]
inputs=[input_type(filename=f,
size=10.0, #size_normalization='original',(size=10.0)
x=0,
y=0,
orientation=0)
for f in image_filenames]
input =Jitterer(generator=topo.pattern.Selector(generators=inputs),orientation=numbergen.UniformRandom(lbound=-pi,ubound=pi,seed=56),reset_period=locals().get('Period',10),jitter_magnitude=locals().get('JM',0.02))
disk_scale=locals().get('diskscale',0.35)
ring = topo.pattern.Composite(operator=numpy.add,x=numbergen.UniformRandom(lbound=-1.1,ubound=1.1,seed=12),
y=numbergen.UniformRandom(lbound=-1.1,ubound=1.1,seed=36),
generators=[topo.pattern.Ring(size=2, aspect_ratio=1.0, scale=0.25,thickness=locals().get('Thickness',0.01),
offset=0.0,
bounds=BoundingBox(radius=1.125), smoothing=0.03),
topo.pattern.random.UniformRandom(offset=locals().get('rand_offset',0), scale=locals().get('rand_scale',0.05))])
retinal_waves=Translator(generator=ring,orientation=numbergen.UniformRandom(lbound=-pi,ubound=pi,seed=56),reset_period=locals().get('Period',10),speed=locals().get('Speed',0.02))
zeroInput = topo.pattern.Null();
jitter = locals().get('Jitter',0.4)
class Jitter(CoordinateMapperFn):
"""Return the jittered x,y coordinate of the given coordinate."""
scale = jitter
rand = param.Parameter(default=None)
def __call__(self,x,y):
return x+(self.rand()-0.5)*self.scale,y+(self.rand()-0.5)*self.scale
jitterOn = Jitter(rand =numbergen.UniformRandom(seed=1023))
jitterOff = Jitter(rand =numbergen.UniformRandom(seed=1023))
# Specify weight initialization, response function, and learning function
CFProjection.weights_generator=topo.pattern.random.UniformRandom()
CFProjection.cf_shape=topo.pattern.Disk(smoothing=0.0)
CFProjection.response_fn=CFPRF_DotProduct_opt()
CFProjection.learning_fn=CFPLF_Hebbian_opt()
CFProjection.weights_output_fns=[CFPOF_DivisiveNormalizeL1_opt()]
## Homeostatic stuff
#Simple
units=[(0.25,0.25),(-0.25,0.25),
(0.25,-0.25),(-0.25,-0.25)]
if locals().get('SOF',"Sigmoid") == "HR":
V1Simple_OF=HalfRectify(t=locals().get('S_treshold',0.4))
elif locals().get('SOF',"Sigmoid") == "Homeo":
V1Simple_OF = SimpleHomeoSigmoid(a_init=locals().get('a_init',22),b_init=-12,mu=locals().get('SMU',0.01),eta=locals().get('SETA',0.02))
elif locals().get('SOF',"Homeo") == "SimpleHomeo":
V1Simple_OF = SimpleHomeoLinear(t_init=locals().get('STresh',7),alpha=locals().get('SAlpha',1),mu=locals().get('SMU',0.01),eta=locals().get('SETA',0.02))
else:
V1Simple_OF=Sigmoid(r=22,k=-12)
if locals().get('COF',"Sigmoid") == "HR":
V1Complex_OF=HalfRectify()
elif locals().get('COF',"Sigmoid") == "SimpleHomeo":
V1Complex_OF = SimpleHomeoLinear(t_init=0,mu=locals().get('CMU',0.02),eta=locals().get('CETA',0.02))
else:
V1Complex_OF=Sigmoid(r=locals().get('r_init',14.5),k=locals().get('k_init',-3))
###########################################
# build simulation
topo.sim['Retina']=GeneratorSheet(nominal_density=24.0,
input_generator=input,
period=1.0, phase=0.05,
nominal_bounds=BoundingBox(radius=core_size+0.25+0.375+0.5))
topo.sim['FakeRetina1']=GeneratorSheet(nominal_density=24.0,
input_generator=retinal_waves,
period=1.0, phase=0.05,
nominal_bounds=BoundingBox(radius=core_size+0.25+0.5))
topo.sim['FakeRetina2']=GeneratorSheet(nominal_density=24.0,
input_generator=retinal_waves,
period=1.0, phase=0.05,
nominal_bounds=BoundingBox(radius=core_size+0.25+0.5))
topo.sim['LGNOn']=LISSOM(nominal_density=24.0,
nominal_bounds=BoundingBox(radius=core_size+0.25+0.5),
output_fns=[HalfRectify()],tsettle=0,
measure_maps=False)
topo.sim['LGNOff']=LISSOM(nominal_density=24.0,
nominal_bounds=BoundingBox(radius=core_size+0.25+0.5),
output_fns=[HalfRectify()],tsettle=0,
measure_maps=False)
topo.sim['V1Simple'] = JointNormalizingCFSheet_Continuous(nominal_density=locals().get('default_density',96.0),
nominal_bounds=BoundingBox(radius=core_size),
output_fns=[ActivityHysteresis(time_constant=0.35),V1Simple_OF])
topo.sim['V1Complex'] = JointNormalizingCFSheet_Continuous(nominal_density=locals().get('default_density',96.0),
nominal_bounds=BoundingBox(radius=core_size),
output_fns=[ActivityHysteresis(time_constant=0.35),V1Complex_OF])
topo.sim['V1ComplexInh'] = JointNormalizingCFSheet_Continuous(nominal_density=locals().get('default_density',96.0),
nominal_bounds=BoundingBox(radius=core_size),
output_fns=[ActivityHysteresis(time_constant=0.35),V1Complex_OF])
# DoG weights for the LGN
#centerg = Gaussian(size=0.07385,aspect_ratio=1.0,output_fns=[DivisiveNormalizeL1()])
centerg = Gaussian(size=0.15,aspect_ratio=1.0,output_fns=[DivisiveNormalizeL1()])
surroundg = Gaussian(size=0.29540,aspect_ratio=1.0,output_fns=[DivisiveNormalizeL1()])
on_weights = topo.pattern.Composite(
generators=[centerg,surroundg],operator=numpy.subtract)
off_weights = topo.pattern.Composite(
generators=[surroundg,centerg],operator=numpy.subtract)
topo.sim.connect('FakeRetina1','LGNOn',delay=0.05,
connection_type=OneToOneProjection,strength=0.5,
nominal_bounds=BoundingBox(radius=0.375),name='Afferent')
topo.sim.connect('FakeRetina2','LGNOff',delay = 0.05,
connection_type=OneToOneProjection,strength=0.5,
nominal_bounds=BoundingBox(radius=0.375),name='Afferent')
g1 = Gaussian(aspect_ratio=1.0,scale=1.0,size=numbergen.UniformRandom(lbound=0.4,ubound=0.4,seed=56))
g1._Dynamic_time_fn = None
g2 = Gaussian(aspect_ratio=1.0,scale=1.0,size=numbergen.UniformRandom(lbound=0.4,ubound=0.4,seed=56))
g2._Dynamic_time_fn = None
#V1 Simple
topo.sim.connect('LGNOn','V1Simple',delay=0.05,dest_port=('Activity','JointNormalize', 'Afferent'),
connection_type=CFProjection,strength=locals().get('LGNStr',70),name='LGNOnAfferent',
weights_generator=topo.pattern.Composite(operator=numpy.multiply,
generators=[g1
,topo.pattern.random.UniformRandom()]),
nominal_bounds_template=BoundingBox(radius=0.27083),
coord_mapper=jitterOn,apply_output_fns_init=False,
learning_rate=(BoundedNumber(bounds=(0.137,None),generator=
ExponentialDecay(starting_value = locals().get('S_lr',5),
time_constant=locals().get('S_tc',16000)))))
topo.sim.connect('LGNOff','V1Simple',delay=0.05,dest_port=('Activity','JointNormalize', 'Afferent'),
connection_type=CFProjection,strength=locals().get('LGNStr',70),name='LGNOffAfferent',
weights_generator=topo.pattern.Composite(operator=numpy.multiply,
generators=[g2
,topo.pattern.random.UniformRandom()]),
nominal_bounds_template=BoundingBox(radius=0.27083),
coord_mapper=jitterOff,apply_output_fns_init=False,
learning_rate=(BoundedNumber(bounds=(0.137,None),generator=
ExponentialDecay(starting_value = locals().get('S_lr',5),
time_constant=locals().get('S_tc',16000)))))
simpleLateral = locals().get('SL',False)
if simpleLateral:
topo.sim.connect('V1Simple','V1Simple',delay=0.05,name='LateralExcitatoryL4',
connection_type=CFProjection,strength=locals().get('SxLatExcStr',0.1),
weights_generator=topo.pattern.Gaussian(aspect_ratio=1.0, size=locals().get('SxLatExcSize',0.04)),
nominal_bounds_template=BoundingBox(radius=locals().get('CxLatExcBB',0.04)),
learning_rate=0.0)
topo.sim.connect('V1Simple','V1Simple',delay=0.05,name='LateralInhibitoryL4',
connection_type=CFProjection,strength=-locals().get('SxLatInhStr',0.1),
weights_generator=topo.pattern.Composite(operator=numpy.multiply,
generators=[Gaussian(aspect_ratio=1.0, size=locals().get('SxLatInhSize',0.22917)),
topo.pattern.random.UniformRandom()]),
nominal_bounds_template=BoundingBox(radius=0.22917),
learning_rate=(BoundedNumber(bounds=(0.137,None),generator=
ExponentialDecay(starting_value = locals().get('LatInh_lr',0.3),
time_constant=locals().get('LatInh_tc',16000)))))
#V1 Complex
topo.sim.connect('V1Simple','V1Complex',delay=0.05,
connection_type=CFProjection,strength=locals().get('StoCStr',0.4),name='V1SimpleAfferent',
weights_generator=Gaussian(aspect_ratio=1.0, size=locals().get('StoCSize',0.05)),
nominal_bounds_template=BoundingBox(radius=locals().get('StoCBB',0.15)/2),learning_rate=locals().get('FF_lr',0.0))
topo.sim.connect('V1Complex','V1Simple',delay=0.05,
connection_type=CFProjection,strength=locals().get('FStrExc',0.2),name='V1SimpleFeedbackExc1',
weights_generator=Gaussian(aspect_ratio=1.0, size=18),
nominal_bounds_template=BoundingBox(radius=locals().get('FExcSize',0.005)/2),
learning_rate=0)
topo.sim.connect('V1Complex','V1Simple',delay=0.05,
connection_type=CFProjection,strength=locals().get('FStrInh',-3.5),name='V1SimpleFeedbackInh',
weights_generator=Gaussian(aspect_ratio=1.0, size=2.5),
nominal_bounds_template=BoundingBox(radius=locals().get('FInhSize',0.3)/2),learning_rate=0)
topo.sim.connect('V1Complex','V1Complex',delay=0.05,name='LateralExcitatoryToExcitatory',
connection_type=CFProjection,strength=locals().get('CxLatExcExcStr',2.0),
weights_generator=topo.pattern.Gaussian(aspect_ratio=1.0, size=locals().get('CxLatExcSize',0.06)),
nominal_bounds_template=BoundingBox(radius=locals().get('CxLatExcBB',0.25)),
learning_rate=locals().get('lat_exc_lr',0.0))
topo.sim.connect('V1Complex','V1ComplexInh',delay=0.05,name='LateralExcitatoryToInhibitory',
connection_type=CFProjection,strength=locals().get('CxLatExcInhStr',1.5),
weights_generator=topo.pattern.Gaussian(aspect_ratio=1.0, size=locals().get('CxLatExcSize',0.06)),
nominal_bounds_template=BoundingBox(radius=locals().get('CxLatExcBB',0.25)),
learning_rate=locals().get('lat_exc_lr',0.0))
topo.sim.connect('V1ComplexInh','V1Complex',delay=0.05,name='LateralInhibitoryToExcitatory',
connection_type=CFProjection,strength=-locals().get('CxLatInhExcStr',2.0),
weights_generator=topo.pattern.Gaussian(aspect_ratio=1.0, size=locals().get('CxLatInhSize',0.12)),
nominal_bounds_template=BoundingBox(radius=locals().get('CxLatInhBB',0.12)),
learning_rate=locals().get('lat_inh_lr',0.0))
topo.sim.connect('V1ComplexInh','V1ComplexInh',delay=0.05,name='LateralInhibitoryToInhibitory',
connection_type=CFProjection,strength=-locals().get('CxLatInhInhStr',1.3),
weights_generator=topo.pattern.Gaussian(aspect_ratio=1.0, size=locals().get('CxLatInhSize',0.12)),
nominal_bounds_template=BoundingBox(radius=locals().get('CxLatInhBB',0.12)),
learning_rate=locals().get('lat_inh_lr',0.0))
topo.sim.schedule_command(__main__.__dict__.get('SST',10000),"secondStage()")
AddGC()
def secondStage():
topo.sim.connect('Retina','LGNOn',delay=0.05,
connection_type=SharedWeightCFProjection,strength=2.33,
nominal_bounds_template=BoundingBox(radius=0.375),name='LGNOnAfferent1',
weights_generator=on_weights)
topo.sim.connect('Retina','LGNOff',delay = 0.05,
connection_type=SharedWeightCFProjection,strength=2.33,
nominal_bounds_template=BoundingBox(radius=0.375),name='LGNOffAfferent1',
weights_generator=off_weights)
topo.sim['FakeRetina1'].set_input_generator(zeroInput)
topo.sim['FakeRetina2'].set_input_generator(zeroInput)
topo.sim['LGNOn'].in_connections[0].strength=0
topo.sim['LGNOff'].in_connections[0].strength=0
randomize_V1Simple_relative_LGN_strength(prob=__main__.__dict__.get('CRS',0.5))
from topo.analysis.featureresponses import MeasureResponseCommand
MeasureResponseCommand.scale=3
def check_activity(a,b,c,d,e,f,g,h):
print a,b,c,d,e,f,g
import pylab
prefix="/disk/scratch/ActivityExploration1/"
pylab.figure(1)
V1Splastic = topo.sim["V1Simple"].plastic
V1Cplastic = topo.sim["V1Complex"].plastic
topo.sim["V1Simple"].plastic = False
topo.sim["V1Complex"].plastic = False
topo.sim.state_push()
topo.sim["V1Simple"].in_connections[0].strength=a
topo.sim["V1Simple"].in_connections[0].strength=a
topo.sim["V1Simple"].projections()["V1SimpleFeedbackExc1"].strength=b
topo.sim["V1Simple"].projections()["V1SimpleFeedbackInh"].strength=c
topo.sim["V1Complex"].projections()["LateralExcitatoryToExcitatory"].strength=d
topo.sim["V1ComplexInh"].projections()["LateralExcitatoryToInhibitory"].strength=e
topo.sim["V1Complex"].projections()["LateralInhibitoryToExcitatory"].strength=f
topo.sim["V1ComplexInh"].projections()["LateralInhibitoryToInhibitory"].strength=g
topo.sim["V1Complex"].projections()["V1SimpleAfferent"].strength=h
try:
topo.sim.run(0.8)
activity = topo.sim["V1Complex"].activity
topo.sim.run(0.05)
activity += topo.sim["V1Complex"].activity
topo.sim.run(0.05)
activity += topo.sim["V1Complex"].activity
topo.sim.run(0.05)
activity += topo.sim["V1Complex"].activity
topo.sim.run(0.05)
activity += topo.sim["V1Complex"].activity
pylab.clf()
pylab.imshow(activity)
pylab.colorbar()
pylab.savefig(prefix+ "Activity:" + "_" + str(a)+ "_" + str(b) + "_" + str(c) + "_" + str(d)+ "_" + str(e) + "_" + str(f) + "_" + str(g) +".png");
except FloatingPointError:
print "Error"
pass
topo.sim.state_pop()
topo.sim["V1Simple"].plastic = V1Splastic
topo.sim["V1Complex"].plastic = V1Cplastic
#contrib.jacommands.run_combinations(check_activity,[[70,60,80],[0.2,0.15,0.25],[-3.5,-3.0,-4.0],[2.0,1.5,2.5],[1.5,1.0,2.0],[-2.0,-1.5,-2.5],[-1.0,-0.8,-1.2],[0.4,0.3,0.5]])