def setup(self,setup_options=True): model = super(ExamplesGCAL, self).setup(setup_options) if setup_options is True or 'sheets' in setup_options: model.sheets.Retina.update(nominal_bounds=sheet.BoundingBox(radius=self.area/2.0+1.125)) model.sheets.LGNOn.update(nominal_bounds=sheet.BoundingBox(radius=self.area/2.0+0.75)) model.sheets.LGNOff.update(nominal_bounds=sheet.BoundingBox(radius=self.area/2.0+0.75)) model.sheets.V1.update(nominal_density=48) if setup_options is True or 'projections' in setup_options: order_projections(model, ['afferent', 'lateral_gain_control', ('V1_afferent', {'polarity':'On'}), ('V1_afferent', {'polarity':'Off'}), 'lateral_excitatory', 'lateral_inhibitory']) return model
def Retina(self, properties): input_generator=self['training_patterns'][properties['eye']+'Retina' if 'eye' in properties else 'Retina'] if 'cr' in self.dims and self.dataset!='Gaussian': for pattern_number, individual_generator in enumerate(input_generator.generators): brightness_difference=numbergen.UniformRandom(lbound=(-1.0+self.dim_fraction)/2.0, ubound=(1.0-self.dim_fraction)/2.0, seed=456+pattern_number, name="Dim"+str(pattern_number)) if 'eye' in properties and properties['eye']=='Left': hsv = colorsys.rgb_to_hsv(*self.cone_scale) hsv_dimmed=(hsv[0],hsv[1],hsv[2]+brightness_difference) channel_factors = list(colorsys.hsv_to_rgb(*hsv_dimmed)) elif 'eye' in properties and properties['eye']=='Right': hsv = colorsys.rgb_to_hsv(*self.cone_scale) hsv_dimmed=(hsv[0],hsv[1],hsv[2]-brightness_difference) channel_factors = list(colorsys.hsv_to_rgb(*hsv_dimmed)) else: channel_factors = self.cone_scale individual_generator.channel_transforms.append( ScaleChannels(channel_factors = channel_factors)) return Model.ChannelGeneratorSheet.params( period=self['period'], phase=0.05, nominal_density=self.retina_density, nominal_bounds=sheet.BoundingBox(radius=self.area/2.0 + self.v1aff_radius*self.sf_spacing**(max(self['SF'])-1) + self.lgnaff_radius*self.sf_spacing**(max(self['SF'])-1) + self.lgnlateral_radius), input_generator=input_generator)
def afferent(self, src_properties, dest_properties): channel = dest_properties['SF'] if 'SF' in dest_properties else 1 centerg = imagen.Gaussian( size=0.07385 * self.sf_spacing**(channel - 1), aspect_ratio=1.0, output_fns=[transferfn.DivisiveNormalizeL1()]) surroundg = imagen.Gaussian( size=(4 * 0.07385) * self.sf_spacing**(channel - 1), aspect_ratio=1.0, output_fns=[transferfn.DivisiveNormalizeL1()]) on_weights = imagen.Composite(generators=[centerg, surroundg], operator=numpy.subtract) off_weights = imagen.Composite(generators=[surroundg, centerg], operator=numpy.subtract) #TODO: strength=+strength_scale/len(cone_types) for 'On' center #TODO: strength=-strength_scale/len(cone_types) for 'Off' center #TODO: strength=-strength_scale/len(cone_types) for 'On' surround #TODO: strength=+strength_scale/len(cone_types) for 'Off' surround return Model.SharedWeightCFProjection.params( delay=0.05, strength=2.33 * self.strength_factor, name='Afferent', nominal_bounds_template=sheet.BoundingBox( radius=self.lgnaff_radius * self.sf_spacing**(channel - 1)), weights_generator=on_weights if dest_properties['polarity'] == 'On' else off_weights)
def V1_afferent(self, src_properties, dest_properties): sf_channel = src_properties['SF'] if 'SF' in src_properties else 1 # Adjust delays so same measurement protocol can be used with and without gain control. LGN_V1_delay = 0.05 if self.gain_control else 0.10 name='' if 'eye' in src_properties: name+=src_properties['eye'] if 'opponent' in src_properties: name+=src_properties['opponent']+src_properties['surround'] name+=('LGN'+src_properties['polarity']+'Afferent') if sf_channel>1: name+=('SF'+str(src_properties['SF'])) gaussian_size = 2.0 * self.v1aff_radius *self.sf_spacing**(sf_channel-1) weights_generator = imagen.random.GaussianCloud(gaussian_size=gaussian_size) return [Model.CFProjection.params( delay=LGN_V1_delay+lag, dest_port=('Activity','JointNormalize','Afferent'), name= name if lag==0 else name+('Lag'+str(lag)), learning_rate=self.aff_lr, strength=self.aff_strength*(1.0 if not self.gain_control else 1.5), weights_generator=weights_generator, nominal_bounds_template=sheet.BoundingBox(radius= self.v1aff_radius*self.sf_spacing**(sf_channel-1))) for lag in self['lags']]
def lateral_excitatory(self, src_properties, dest_properties): return Model.CFProjection.params( delay=0.05, name='LateralExcitatory', weights_generator=imagen.Gaussian(aspect_ratio=1.0, size=0.05), strength=self.exc_strength, learning_rate=self.exc_lr, nominal_bounds_template=sheet.BoundingBox(radius=self.latexc_radius))
def lateral_inhibitory(self, src_properties, dest_properties): return Model.CFProjection.params( delay=0.05, name='LateralInhibitory', weights_generator=imagen.random.GaussianCloud(gaussian_size=0.15), strength=-1.0*self.inh_strength, learning_rate=self.inh_lr, nominal_bounds_template=sheet.BoundingBox(radius=self.latinh_radius))
def V1(self, properties): return Model.SettlingCFSheet.params( tsettle=16, plastic=True, joint_norm_fn=optimized.compute_joint_norm_totals_cython, output_fns=[transferfn.misc.HomeostaticResponse(t_init=self.t_init, learning_rate=0.01 if self.homeostasis else 0.0)], nominal_density=self.cortex_density, nominal_bounds=sheet.BoundingBox(radius=self.area/2.0))
def lr_lateral_excitatory(self, src_properties, dest_properties): return Model.CFProjection.params( delay=0.1, name='LRExcitatory', activity_group=(0.9, MultiplyWithConstant()), weights_generator=imagen.Gaussian(aspect_ratio=1.0, size=self.lateral_size), strength=self.latexc_strength, learning_rate=self.latexc_lr, nominal_bounds_template=sheet.BoundingBox(radius=self.lateral_radius))
def Retina(self, properties): return Model.GeneratorSheet.params( period=self['period'], phase=0.05, nominal_density=self.retina_density, nominal_bounds=sheet.BoundingBox(radius=self.area/2.0 + self.v1aff_radius*self.sf_spacing**(max(self['SF'])-1) + self.lgnaff_radius*self.sf_spacing**(max(self['SF'])-1) + self.lgnlateral_radius), input_generator=self['training_patterns'][properties['eye']+'Retina' if 'eye' in properties else 'Retina'])
def LGN(self, properties): channel = properties['SF'] if 'SF' in properties else 1 return Model.SettlingCFSheet.params( mask=topo.base.projection.SheetMask(), measure_maps=False, output_fns=[transferfn.misc.HalfRectify()], nominal_density=self.lgn_density, nominal_bounds=sheet.BoundingBox( radius=self.area / 2.0 + self.v1aff_radius * self.sf_spacing**(channel - 1) + self.lgnlateral_radius), tsettle=2 if self.gain_control else 0, strict_tsettle=1 if self.gain_control else 0)
def lateral_inhibitory(self, src_properties, dest_properties): """ Switch to divisive inhibition, otherwise parameters unchanged. """ return Model.CFProjection.params( delay=0.05, name='LateralInhibitory', weights_generator=ig.random.GaussianCloud( gaussian_size=self.latinh_size), strength=self.inh_strength, activity_group=(0.6, DivideWithConstant(c=self.division_constant)), learning_rate=self.inh_lr, nominal_bounds_template=sheet.BoundingBox( radius=self.latinh_radius))
def lateral_gain_control(self, src_properties, dest_properties): #TODO: Are those 0.25 the same as lgnlateral_radius/2.0? return Model.SharedWeightCFProjection.params( delay=0.05, dest_port=('Activity'), activity_group=(0.6, DivideWithConstant(c=0.11)), weights_generator=imagen.Gaussian( size=0.25, aspect_ratio=1.0, output_fns=[transferfn.DivisiveNormalizeL1()]), nominal_bounds_template=sheet.BoundingBox(radius=0.25), name=('LateralGC' + src_properties['eye'] if 'eye' in src_properties else 'LateralGC'), strength=0.6 / len(self.attrs.Eyes))
def afferent_surround(self, src_properties, dest_properties): surrounds=[] for color, color_code in self.ColorToChannel.items(): if color in dest_properties['surround']: surrounds.append(color_code) return [Model.SharedWeightCFProjection.params( delay=0.05, strength=(4.7/2.33)*self.lgnaff_strength/len(surrounds)*(-1 if dest_properties['polarity'] == 'On' else 1), src_port='Activity%d'%surround, dest_port='Activity', weights_generator=imagen.Gaussian(size=0.07385*(4 if dest_properties['opponent'] is not 'Blue' else 1), aspect_ratio=1.0, output_fns=[transferfn.DivisiveNormalizeL1()]), name='AfferentSurround'+str(surround), nominal_bounds_template=sheet.BoundingBox(radius=self.lgnaff_radius)) for surround in surrounds]
def afferent_surround(self, src_properties, dest_properties): #TODO: strength=-strength_scale for 'On', +strength_scale for 'Off' #TODO: strength=-strength_scale/2 for dest_properties['opponent']=='Blue' # dest_properties['surround']=='RedGreen' and dest_properties['polarity']=='On' #TODO: strength=+strength_scale/2 for above, but 'Off' #TODO: strength=-strength_scale/len(cone_types) for Luminosity 'On' #TODO: strength=+strength_scale/len(cone_types) for Luminosity 'Off' return Model.SharedWeightCFProjection.params( delay=0.05, strength=2.33 * self.strength_factor, weights_generator=imagen.Gaussian( size=4 * 0.07385, aspect_ratio=1.0, output_fns=[transferfn.DivisiveNormalizeL1()]), name='AfferentSurround' + src_properties['cone'], nominal_bounds_template=sheet.BoundingBox( radius=self.lgnaff_radius))
def lateral_gain_control(self, src_properties, dest_properties): #TODO: Are those 0.25 the same as lgnlateral_radius/2.0? name='LateralGC' if 'eye' in src_properties: name+=src_properties['eye'] if 'SF' in src_properties and self.gain_control_SF: name+=('SF'+str(src_properties['SF'])) return Model.SharedWeightCFProjection.params( delay=0.05, dest_port=('Activity'), activity_group=(0.6,DivideWithConstant(c=0.11)), weights_generator=imagen.Gaussian(size=self.gain_control_size, aspect_ratio=1.0, output_fns=[transferfn.DivisiveNormalizeL1()]), nominal_bounds_template=sheet.BoundingBox(radius=self.gain_control_size), name=name, strength=0.6/(2 if self['binocular'] else 1))
def afferent_center(self, src_properties, dest_properties): #TODO: It shouldn't be too hard to figure out how many retina sheets it connects to, # then all the below special cases can be generalized! #TODO: strength=+strength_scale for 'On', strength=-strength_scale for 'Off' #TODO: strength=+strength_scale for dest_properties['opponent']=='Blue' # dest_properties['surround']=='RedGreen' and dest_properties['polarity']=='On' #TODO: strength=-strength_scale for above, but 'Off' #TODO: strength=+strength_scale/len(cone_types) for Luminosity 'On' #TODO: strength=-strength_scale/len(cone_types) for Luminosity 'Off' return Model.SharedWeightCFProjection.params( delay=0.05, strength=2.33 * self.strength_factor, weights_generator=imagen.Gaussian( size=0.07385, aspect_ratio=1.0, output_fns=[transferfn.DivisiveNormalizeL1()]), name='AfferentCenter' + src_properties['cone'], nominal_bounds_template=sheet.BoundingBox( radius=self.lgnaff_radius))
def V1_afferent(self, src_properties, dest_properties): sf_channel = src_properties['SF'] if 'SF' in src_properties else 1 # Adjust delays so same measurement protocol can be used with and without gain control. LGN_V1_delay = 0.05 if self.gain_control else 0.10 name='' if 'eye' in src_properties: name+=src_properties['eye'] if 'opponent' in src_properties: name+=src_properties['opponent']+src_properties['surround'] name+=('LGN'+src_properties['polarity']+'Afferent') if sf_channel>1: name+=('SF'+str(src_properties['SF'])) gaussian_size = 2.0 * self.v1aff_radius *self.sf_spacing**(sf_channel-1) weights_generator = imagen.random.GaussianCloud(gaussian_size=gaussian_size) #TFALERT: Changes regarding color begin if 'opponent' in src_properties: # Determine strength per channel from how many luminosity and color channels there are num_tot=len(self['polarities'])*len(self['opponents']) num_lum=len(self['polarities']) num_col=num_tot-num_lum color_scale=((1.0*num_tot/num_lum*(1.0-self.color_strength)) if src_properties['opponent']=="RedGreenBlue" else (1.0*num_tot/num_col*self.color_strength)) else: color_scale=1.0 #TFALERT: Changes regarding color end #TFALERT: Mind the change in the strength compared to the non-color version return [Model.CFProjection.params( delay=LGN_V1_delay+lag, dest_port=('Activity','JointNormalize','Afferent'), name= name if lag==0 else name+('Lag'+str(lag)), learning_rate=self.aff_lr, strength=self.aff_strength*color_scale* (1.0 if (not self.gain_control or ('opponent' in src_properties and not self.gain_control_color)) else 1.5), weights_generator=weights_generator, nominal_bounds_template=sheet.BoundingBox(radius= self.v1aff_radius*self.sf_spacing**(sf_channel-1))) for lag in self['lags']]
def LGN(self, properties): channel=properties['SF'] if 'SF' in properties else 1 sf_aff_multiplier = self.sf_spacing**(max(self['SF'])-1) if self.gain_control_SF else \ self.sf_spacing**(channel-1) luminosity_channel='RedGreenBlue' if self.color_sim_type=='Trichromatic' else 'GreenBlue' gain_control = self.gain_control_SF if 'SF' in properties else \ self.gain_control_color if 'opponent' in properties and \ properties['opponent']!=luminosity_channel else \ self.gain_control return Model.SettlingCFSheet.params( mask = topo.base.projection.SheetMask(), measure_maps=False, output_fns=[transferfn.misc.HalfRectify()], nominal_density=self.lgn_density, nominal_bounds=sheet.BoundingBox(radius=self.area/2.0 + self.v1aff_radius * sf_aff_multiplier + self.lgnlateral_radius), tsettle=2 if gain_control else 0, strict_tsettle=1 if gain_control else 0)