def __init__(self, sheet, parameters): DirectStimulator.__init__(self, sheet,parameters) exc_syn = self.sheet.sim.StaticSynapse(weight=self.parameters.exc_weight) inh_syn = self.sheet.sim.StaticSynapse(weight=self.parameters.inh_weight) if not self.sheet.parameters.mpi_safe: from pyNN.nest import native_cell_type if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0): self.np_exc = self.sheet.sim.Population(1, native_cell_type("poisson_generator"),{'rate': 0}) self.sheet.sim.Projection(self.np_exc, self.sheet.pop,self.sheet.sim.AllToAllConnector(),synapse_type=exc_syn,receptor_type='excitatory') if (self.parameters.inh_firing_rate != 0 or self.parameters.inh_weight != 0): self.np_inh = self.sheet.sim.Population(1, native_cell_type("poisson_generator"),{'rate': 0}) self.sheet.sim.Projection(self.np_inh, self.sheet.pop,self.sheet.sim.AllToAllConnector(),synapse_type=inh_syn,receptor_type='inhibitory') else: if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0): self.ssae = self.sheet.sim.Population(self.sheet.pop.size,self.sheet.sim.SpikeSourceArray()) seeds=mozaik.get_seeds((self.sheet.pop.size,)) self.stgene = [stgen.StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in numpy.nonzero(self.sheet.pop._mask_local)[0]] self.sheet.sim.Projection(self.ssae, self.sheet.pop,self.sheet.sim.OneToOneConnector(),synapse_type=exc_syn,receptor_type='excitatory') if (self.parameters.inh_firing_rate != 0 or self.parameters.inh_weight != 0): self.ssai = self.sheet.sim.Population(self.sheet.pop.size,self.sheet.sim.SpikeSourceArray()) seeds=mozaik.get_seeds((self.sheet.pop.size,)) self.stgeni = [stgen.StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in numpy.nonzero(self.sheet.pop._mask_local)[0]] self.sheet.sim.Projection(self.ssai, self.sheet.pop,self.sheet.sim.OneToOneConnector(),synapse_type=inh_syn,receptor_type='inhibitory')
def __init__(self, sheet, parameters): DirectStimulator.__init__(self, sheet,parameters) exc_syn = self.sheet.sim.StaticSynapse(weight=self.parameters.exc_weight,delay=self.sheet.model.parameters.min_delay) inh_syn = self.sheet.sim.StaticSynapse(weight=self.parameters.inh_weight,delay=self.sheet.model.parameters.min_delay) if not self.sheet.parameters.mpi_safe: from pyNN.nest import native_cell_type if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0): self.np_exc = self.sheet.sim.Population(1, native_cell_type("poisson_generator"),{'rate': 0}) self.sheet.sim.Projection(self.np_exc, self.sheet.pop,self.sheet.sim.AllToAllConnector(),synapse_type=exc_syn,receptor_type='excitatory') if (self.parameters.inh_firing_rate != 0 or self.parameters.inh_weight != 0): self.np_inh = self.sheet.sim.Population(1, native_cell_type("poisson_generator"),{'rate': 0}) self.sheet.sim.Projection(self.np_inh, self.sheet.pop,self.sheet.sim.AllToAllConnector(),synapse_type=inh_syn,receptor_type='inhibitory') else: if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0): self.ssae = self.sheet.sim.Population(self.sheet.pop.size,self.sheet.sim.SpikeSourceArray()) seeds=mozaik.get_seeds((self.sheet.pop.size,)) self.stgene = [StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in numpy.nonzero(self.sheet.pop._mask_local)[0]] self.sheet.sim.Projection(self.ssae, self.sheet.pop,self.sheet.sim.OneToOneConnector(),synapse_type=exc_syn,receptor_type='excitatory') if (self.parameters.inh_firing_rate != 0 or self.parameters.inh_weight != 0): self.ssai = self.sheet.sim.Population(self.sheet.pop.size,self.sheet.sim.SpikeSourceArray()) seeds=mozaik.get_seeds((self.sheet.pop.size,)) self.stgeni = [StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in numpy.nonzero(self.sheet.pop._mask_local)[0]] self.sheet.sim.Projection(self.ssai, self.sheet.pop,self.sheet.sim.OneToOneConnector(),synapse_type=inh_syn,receptor_type='inhibitory')
def __init__(self, sheet, parameters): DirectStimulator.__init__(self, sheet, parameters) population_selector = load_component( self.parameters.population_selector.component) self.ids = population_selector( sheet, self.parameters.population_selector.params ).generate_idd_list_of_neurons() d = dict((j, i) for i, j in enumerate(self.sheet.pop.all_cells)) self.local_and_to_stimulate_indexes = [ d[i] for i in set(self.ids) & set(self.sheet.pop.local_cells) ] exc_syn = self.sheet.sim.StaticSynapse( weight=self.parameters.exc_weight) if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0): self.ssae = self.sheet.sim.Population( self.sheet.pop.size, self.sheet.sim.SpikeSourceArray()) seeds = mozaik.get_seeds((self.sheet.pop.size, )) self.stgene = [ stgen.StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in self.local_and_to_stimulate_indexes ] self.sheet.sim.Projection(self.ssae, self.sheet.pop, self.sheet.sim.OneToOneConnector(), synapse_type=exc_syn, receptor_type='excitatory')
def __init__(self, model, parameters): SensoryInputComponent.__init__(self, model, parameters) self.shape = (self.parameters.density,self.parameters.density) self.sheets = {} self._built = False self.rf_types = ('X_ON', 'X_OFF') sim = self.model.sim self.pops = {} self.scs = {} self.ncs = {} self.ncs_rng = {} for rf_type in self.rf_types: p = RetinalUniformSheet(model, ParameterSet({'sx': self.parameters.size[0], 'sy': self.parameters.size[1], 'density': self.parameters.density, 'cell': self.parameters.cell, 'name': rf_type, 'artificial_stimulators' : {}, 'recorders' : self.parameters.recorders, 'mpi_safe': False})) self.sheets[rf_type] = p for rf_type in self.rf_types: self.scs[rf_type] = [] self.ncs[rf_type] = [] self.ncs_rng[rf_type] = [] seeds=mozaik.get_seeds((self.sheets[rf_type].pop.size,)) for i, lgn_cell in enumerate(self.sheets[rf_type].pop.all_cells): scs = sim.StepCurrentSource(times=[0.0], amplitudes=[0.0]) if not self.parameters.mpi_reproducible_noise: ncs = sim.NoisyCurrentSource(**self.parameters.noise) else: ncs = sim.StepCurrentSource(times=[0.0], amplitudes=[0.0]) if self.sheets[rf_type].pop._mask_local[i]: self.ncs_rng[rf_type].append(numpy.random.RandomState(seed=seeds[i])) self.scs[rf_type].append(scs) self.ncs[rf_type].append(ncs) lgn_cell.inject(scs) lgn_cell.inject(ncs) P_rf = self.parameters.receptive_field rf_function = eval(P_rf.func) rf_ON = SpatioTemporalReceptiveField(rf_function, P_rf.func_params, P_rf.width, P_rf.height, P_rf.duration) rf_OFF = SpatioTemporalReceptiveField(lambda x, y, t, p: -1.0 * rf_function(x, y, t, p), P_rf.func_params, P_rf.width, P_rf.height, P_rf.duration) dx = dy = P_rf.spatial_resolution dt = P_rf.temporal_resolution for rf in rf_ON, rf_OFF: rf.quantize(dx, dy, dt) self.rf = {'X_ON': rf_ON, 'X_OFF': rf_OFF}
def _connect(self): # This is due to native synapses models (which we currently use as the short term synaptic plasticity model) # do not apply the 1000 factor scaler as the pyNN synaptic models wf = self.parameters.weight_factor * self.weight_scaler seeds = mozaik.get_seeds(self.target.pop.size) weights = self.connection_matrix delays = self.delay_matrix cl = [] for i in range(0, self.target.pop.size): co = Counter( sample_from_bin_distribution(weights[:, i].flatten(), int(self.parameters.num_samples), seeds[i])) cl.extend([(int(k), int(i), wf * co[k] / self.parameters.num_samples, delays[k][i]) for k in co.keys()]) method = self.sim.FromListConnector(cl) self.proj = self.sim.Projection( self.source.pop, self.target.pop, method, synapse_type=self.init_synaptic_mechanisms(), label=self.name, receptor_type=self.parameters.target_synapses)
def __init__(self, model, parameters): SensoryInputComponent.__init__(self, model, parameters) self.shape = (self.parameters.density,self.parameters.density) self.sheets = {} self._built = False self.rf_types = ('X_ON', 'X_OFF') sim = self.model.sim self.on_pop = None self.off_pop = None self.pops = {} self.scs = {} self.ncs = {} self.ncs_rng = {} self.init_sheets(model) for rf_type in self.rf_types: self.scs[rf_type] = [] self.ncs[rf_type] = [] self.ncs_rng[rf_type] = [] seeds=mozaik.get_seeds((self.pops[rf_type].size,)) for i, lgn_cell in enumerate(self.pops[rf_type].all_cells): scs = sim.StepCurrentSource(times=[0.0], amplitudes=[0.0]) if not self.parameters.mpi_reproducible_noise: ncs = sim.NoisyCurrentSource(**self.parameters.noise[rf_type]) else: ncs = sim.StepCurrentSource(times=[0.0], amplitudes=[0.0]) if self.pops[rf_type]._mask_local[i]: self.ncs_rng[rf_type].append(numpy.random.RandomState(seed=seeds[i])) self.scs[rf_type].append(scs) self.ncs[rf_type].append(ncs) lgn_cell.inject(scs) lgn_cell.inject(ncs) P_rf = self.parameters.receptive_field rf_function = eval(P_rf.func) rf_ON = SpatioTemporalReceptiveField(rf_function, P_rf.func_params, P_rf.width, P_rf.height, P_rf.duration) rf_OFF = SpatioTemporalReceptiveField(lambda x, y, t, p: -1.0 * rf_function(x, y, t, p), P_rf.func_params, P_rf.width, P_rf.height, P_rf.duration) dx = dy = P_rf.spatial_resolution dt = P_rf.temporal_resolution for rf in rf_ON, rf_OFF: rf.quantize(dx, dy, dt) self.rf = {'X_ON': rf_ON, 'X_OFF': rf_OFF}
def __init__(self, sheet, parameters): DirectStimulator.__init__(self, sheet,parameters) population_selector = load_component(self.parameters.population_selector.component) self.ids = population_selector(sheet,self.parameters.population_selector.params).generate_idd_list_of_neurons() d = dict((j,i) for i,j in enumerate(self.sheet.pop.all_cells)) self.local_and_to_stimulate_indexes = [d[i] for i in set(self.ids) & set(self.sheet.pop.local_cells)] exc_syn = self.sheet.sim.StaticSynapse(weight=self.parameters.exc_weight) if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0): self.ssae = self.sheet.sim.Population(self.sheet.pop.size,self.sheet.sim.SpikeSourceArray()) seeds=mozaik.get_seeds((self.sheet.pop.size,)) self.stgene = [stgen.StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in self.local_and_to_stimulate_indexes] self.sheet.sim.Projection(self.ssae, self.sheet.pop,self.sheet.sim.OneToOneConnector(),synapse_type=exc_syn,receptor_type='excitatory')
def __init__(self, sheet, parameters): DirectStimulator.__init__(self, sheet, parameters) population_selector = load_component( self.parameters.population_selector.component) self.ids = population_selector( sheet, self.parameters.population_selector.params ).generate_idd_list_of_neurons() # print(self.ids[0].id) # 1901 # d = dict((j, i) for i, j in enumerate(self.sheet.pop.all_cells)) # nest d = dict((str(j), i) for i, j in enumerate(self.sheet.pop.all_cells)) # spinnaker # d = dict((i, j) for i, j in enumerate(numpy.asarray(self.sheet.pop.all_cells))) # spinnaker abbott # d = dict((j, i) for i, j in enumerate(self.sheet.pop.all_cells)) # spinnaker abbott # print("self.ids ", self.ids) # print("d ", d) # self.to_stimulate_indexes = [d[i.id] for i in self.ids] self.to_stimulate_indexes = [d[str(i)] for i in self.ids ] # str because there is an object # workaround # self.to_stimulate_indexes = [k.item() for k in self.ids] # spinnaker abbott exc_syn = self.sheet.sim.StaticSynapse( weight=self.parameters.exc_weight, delay=self.sheet.model.parameters.min_delay) if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0): self.ssae = self.sheet.sim.Population( self.sheet.pop.size, self.sheet.sim.SpikeSourceArray()) seeds = mozaik.get_seeds((self.sheet.pop.size, )) self.stgene = [ StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in self.to_stimulate_indexes ] print("sheet Kick projection ", self.ssae) print("sheet Kick projection ", self.sheet.pop) self.p = self.sheet.sim.Projection( self.ssae, self.sheet.pop, self.sheet.sim.OneToOneConnector(), synapse_type=exc_syn, receptor_type='excitatory')
def __init__(self, model, parameters): SensoryInputComponent.__init__(self, model, parameters) self.shape = (self.parameters.density, self.parameters.density) self.sheets = OrderedDict() self._built = False self.rf_types = ('X_ON', 'X_OFF') sim = self.model.sim self.pops = OrderedDict() self.scs = OrderedDict() self.ncs = OrderedDict() self.ncs_rng = OrderedDict() self.internal_stimulus_cache = OrderedDict() for rf_type in self.rf_types: p = RetinalUniformSheet( model, ParameterSet({ 'sx': self.parameters.size[0], 'sy': self.parameters.size[1], 'density': self.parameters.density, 'cell': self.parameters.cell, 'name': rf_type, 'artificial_stimulators': OrderedDict(), 'recorders': self.parameters.recorders, 'recording_interval': self.parameters.recording_interval, 'mpi_safe': False })) self.sheets[rf_type] = p for rf_type in self.rf_types: self.scs[rf_type] = [] self.ncs[rf_type] = [] self.ncs_rng[rf_type] = [] seeds = mozaik.get_seeds((self.sheets[rf_type].pop.size, )) for i, lgn_cell in enumerate(self.sheets[rf_type].pop.all_cells): scs = sim.StepCurrentSource(times=[0.0], amplitudes=[0.0]) if not self.parameters.mpi_reproducible_noise: ncs = sim.NoisyCurrentSource(**self.parameters.noise) else: ncs = sim.StepCurrentSource(times=[0.0], amplitudes=[0.0]) if self.sheets[rf_type].pop._mask_local[i]: self.ncs_rng[rf_type].append( numpy.random.RandomState(seed=seeds[i])) self.scs[rf_type].append(scs) self.ncs[rf_type].append(ncs) lgn_cell.inject(scs) lgn_cell.inject(ncs) P_rf = self.parameters.receptive_field rf_function = eval(P_rf.func) rf_ON = SpatioTemporalReceptiveField(rf_function, P_rf.func_params, P_rf.width, P_rf.height, P_rf.duration) rf_OFF = SpatioTemporalReceptiveField( lambda x, y, t, p: -1.0 * rf_function(x, y, t, p), P_rf.func_params, P_rf.width, P_rf.height, P_rf.duration) dx = dy = P_rf.spatial_resolution dt = P_rf.temporal_resolution for rf in rf_ON, rf_OFF: rf.quantize(dx, dy, dt) self.rf = {'X_ON': rf_ON, 'X_OFF': rf_OFF}
def _connect(self): # Check if the delay function is incompatible with multiprocessing cl = [] v = 0 # Generates a splitted and of cells indices to be passed to each subprocesses seeds = mozaik.get_seeds( len(numpy.nonzero(self.target.pop._mask_local)[0])) splitted_seeds = numpy.array_split(seeds, int(self.model.num_threads)) splitted_cell_indices = numpy.array_split( numpy.nonzero(self.target.pop._mask_local)[0], int(self.model.num_threads)) import multiprocessing # This code will be ran by each subprocess def build_connector(indices, seeds, queue_cl, queue_v): cli = [] vi = 0 for i in range(len(indices)): samples = self.target.get_neuron_annotation( indices[i], self.parameters.annotation_reference_name) weights = self._obtain_weights(indices[i], seeds[i]) delays = self._obtain_delays(indices[i], seeds[i]) if self.parameters.num_samples == 0: co = Counter( sample_from_bin_distribution(weights, int(samples), seeds[i])) else: assert self.parameters.num_samples > 2 * int( samples), "%s: %d %d" % ( self.name, self.parameters.num_samples, 2 * int(samples), ) co = Counter( sample_from_bin_distribution( weights, int(self.parameters.num_samples - 2 * int(samples)), seeds[i], )) vi = vi + numpy.sum(list(co.values())) k = list(co.keys()) a = numpy.array([ k, numpy.zeros(len(k)) + indices[i], self.weight_scaler * numpy.multiply( self.parameters.base_weight.copy(seeds[i]).next( len(k)), list(co.values())), numpy.array(delays)[k], ]) cli.append(a) # Add the output to the two queues to communicate it with the main process queue_cl.put(cli) queue_v.put(vi) # Generate a list of subprocesses and of queues processes = [] list_queue_cl = [] list_queue_v = [] for i in range(len(splitted_cell_indices)): # Each queue will be used by the subprocesses to communicate with the main process list_queue_cl.append(multiprocessing.Queue()) list_queue_v.append(multiprocessing.Queue()) proc = multiprocessing.Process( target=build_connector, args=( splitted_cell_indices[i], splitted_seeds[i], list_queue_cl[i], list_queue_v[i], ), ) proc.start() processes.append(proc) # Gather the output of each subprocesses cl = [] v = 0 for i, p in enumerate(processes): cli = list_queue_cl[i].get() for clii in cli: cl.append(clii) v += list_queue_v[i].get() p.join() cl = numpy.hstack(cl).T method = self.sim.FromListConnector(cl) logger.warning( "%s(%s): %g connections were created, %g per target neuron [%g]" % (self.name, self.__class__.__name__, len(cl), len(cl) / len(numpy.nonzero(self.target.pop._mask_local)[0]), v / len(numpy.nonzero(self.target.pop._mask_local)[0]))) if len(cl) > 0: self.proj = self.sim.Projection( self.source.pop, self.target.pop, method, synapse_type=self.init_synaptic_mechanisms(), label=self.name, receptor_type=self.parameters.target_synapses) else: logger.warning( "%s(%s): empty projection - pyNN projection not created." % (self.name, self.__class__.__name__))