def generate_synapse_list( self, presynaptic_population, postsynaptic_population, delay_scale, weight_scale, synapse_type): prevertex = presynaptic_population._get_vertex postvertex = postsynaptic_population._get_vertex id_lists = list() weight_lists = list() delay_lists = list() type_lists = list() for _ in range(0, prevertex.n_atoms): id_lists.append(list()) weight_lists.append(list()) delay_lists.append(list()) type_lists.append(list()) num_incoming_axons = prevertex.n_atoms num_target_neurons = postvertex.n_atoms for _ in range(0, self._num_synapses): source = int(random.random() * num_incoming_axons) target = int(random.random() * num_target_neurons) weight = generate_parameter(self._weights, target) * weight_scale delay = generate_parameter(self._delays, target) * delay_scale id_lists[source].append(target) weight_lists[source].append(weight) delay_lists[source].append(delay) type_lists[source].append(synapse_type) connection_list = [SynapseRowInfo(id_lists[i], weight_lists[i], delay_lists[i], type_lists[i]) for i in range(0, prevertex.n_atoms)] return SynapticList(connection_list)
def generate_synapse_list(self, presynaptic_population, postsynaptic_population, delay_scale, weight_scale, synapse_type): prevertex = presynaptic_population._get_vertex postvertex = postsynaptic_population._get_vertex if prevertex.n_atoms != postvertex.n_atoms: raise exceptions.ConfigurationException( "The two populations to be connected with a One to One " "connector have to have the same size") connection_list = list() for pre_atom in range(0, prevertex.n_atoms): delay = generate_parameter(self._delays, pre_atom) * delay_scale weight = generate_parameter(self._weights, pre_atom) * weight_scale connection_list.append( SynapseRowInfo([pre_atom], [weight], [delay], [synapse_type])) return SynapticList(connection_list)
def generate_synapse_list( self, presynaptic_population, postsynaptic_population, delay_scale, weight_scale, synapse_type): prevertex = presynaptic_population._get_vertex postvertex = postsynaptic_population._get_vertex if prevertex.n_atoms != postvertex.n_atoms: raise exceptions.ConfigurationException( "The two populations to be connected with a One to One " "connector have to have the same size") connection_list = list() for pre_atom in range(0, prevertex.n_atoms): delay = generate_parameter(self._delays, pre_atom) * delay_scale weight = generate_parameter(self._weights, pre_atom) * weight_scale connection_list.append(SynapseRowInfo([pre_atom], [weight], [delay], [synapse_type])) return SynapticList(connection_list)
def _write_poisson_parameters(self, spec, key, num_neurons): """ Generate Neuron Parameter data for Poisson spike sources :param spec: :param key: :param num_neurons: :return: """ spec.comment("\nWriting Neuron Parameters for {} poisson sources:\n" .format(num_neurons)) # Set the focus to the memory region 2 (neuron parameters): spec.switch_write_focus( region=self._POISSON_SPIKE_SOURCE_REGIONS .POISSON_PARAMS_REGION.value) # Write header info to the memory region: # Write Key info for this core: if key is None: # if there's no key, then two false will cover it. spec.write_value(data=0) spec.write_value(data=0) else: # has a key, thus set has key to 1 and then add key spec.write_value(data=1) spec.write_value(data=key) # Write the random seed (4 words), generated randomly! spec.write_value(data=self._rng.randint(0x7FFFFFFF)) spec.write_value(data=self._rng.randint(0x7FFFFFFF)) spec.write_value(data=self._rng.randint(0x7FFFFFFF)) spec.write_value(data=self._rng.randint(0x7FFFFFFF)) # For each neuron, get the rate to work out if it is a slow # or fast source slow_sources = list() fast_sources = list() for i in range(0, num_neurons): # Get the parameter values for source i: rate_val = generate_parameter(self._rate, i) start_val = generate_parameter(self._start, i) end_val = None if self._duration is not None: end_val = generate_parameter(self._duration, i) + start_val # Decide if it is a fast or slow source and spikes_per_tick = \ (float(rate_val) * (self._machine_time_step / 1000000.0)) if spikes_per_tick <= SLOW_RATE_PER_TICK_CUTOFF: slow_sources.append([i, rate_val, start_val, end_val]) else: fast_sources.append([i, spikes_per_tick, start_val, end_val]) # Write the numbers of each type of source spec.write_value(data=len(slow_sources)) spec.write_value(data=len(fast_sources)) # Now write one struct for each slow source as follows # # typedef struct slow_spike_source_t # { # uint32_t neuron_id; # uint32_t start_ticks; # uint32_t end_ticks; # # accum mean_isi_ticks; # accum time_to_spike_ticks; # } slow_spike_source_t; for (neuron_id, rate_val, start_val, end_val) in slow_sources: if rate_val == 0: isi_val = 0 else: isi_val = float(1000000.0 / (rate_val * self._machine_time_step)) start_scaled = int(start_val * 1000.0 / self._machine_time_step) end_scaled = 0xFFFFFFFF if end_val is not None: end_scaled = int(end_val * 1000.0 / self._machine_time_step) spec.write_value(data=neuron_id, data_type=DataType.UINT32) spec.write_value(data=start_scaled, data_type=DataType.UINT32) spec.write_value(data=end_scaled, data_type=DataType.UINT32) spec.write_value(data=isi_val, data_type=DataType.S1615) spec.write_value(data=0x0, data_type=DataType.UINT32) # Now write # typedef struct fast_spike_source_t # { # uint32_t neuron_id; # uint32_t start_ticks; # uint32_t end_ticks; # # unsigned long fract exp_minus_lambda; # } fast_spike_source_t; for (neuron_id, spikes_per_tick, start_val, end_val) in fast_sources: if spikes_per_tick == 0: exp_minus_lamda = 0 else: exp_minus_lamda = math.exp(-1.0 * spikes_per_tick) start_scaled = int(start_val * 1000.0 / self._machine_time_step) end_scaled = 0xFFFFFFFF if end_val is not None: end_scaled = int(end_val * 1000.0 / self._machine_time_step) spec.write_value(data=neuron_id, data_type=DataType.UINT32) spec.write_value(data=start_scaled, data_type=DataType.UINT32) spec.write_value(data=end_scaled, data_type=DataType.UINT32) spec.write_value(data=exp_minus_lamda, data_type=DataType.U032)
def write_poisson_parameters(self, spec, key, num_neurons): """ Generate Neuron Parameter data for Poisson spike sources (region 2): :param spec: :param key: :param num_neurons: :return: """ spec.comment( "\nWriting Neuron Parameters for {} poisson sources:\n".format( num_neurons)) # Set the focus to the memory region 2 (neuron parameters): spec.switch_write_focus(region=self._POISSON_SPIKE_SOURCE_REGIONS. POISSON_PARAMS_REGION.value) # Write header info to the memory region: # Write Key info for this core: if key is None: # if theres no key, then two falses will cover it. spec.write_value(data=0) spec.write_value(data=0) else: # has a key, thus set has key to 1 and then add key spec.write_value(data=1) spec.write_value(data=key) # Write the random seed (4 words), generated randomly! if self._seed is None: spec.write_value(data=numpy.random.randint(0x7FFFFFFF)) spec.write_value(data=numpy.random.randint(0x7FFFFFFF)) spec.write_value(data=numpy.random.randint(0x7FFFFFFF)) spec.write_value(data=numpy.random.randint(0x7FFFFFFF)) else: spec.write_value(data=self._seed[0]) spec.write_value(data=self._seed[1]) spec.write_value(data=self._seed[2]) spec.write_value(data=self._seed[3]) # For each neuron, get the rate to work out if it is a slow # or fast source slow_sources = list() fast_sources = list() for i in range(0, num_neurons): # Get the parameter values for source i: rate_val = generate_parameter(self._rate, i) start_val = generate_parameter(self._start, i) end_val = None if self._duration is not None: end_val = generate_parameter(self._duration, i) + start_val # Decide if it is a fast or slow source and spikes_per_tick = \ (float(rate_val) * (self._machine_time_step / 1000000.0)) if spikes_per_tick <= SLOW_RATE_PER_TICK_CUTOFF: slow_sources.append([i, rate_val, start_val, end_val]) else: fast_sources.append([i, spikes_per_tick, start_val, end_val]) # Write the numbers of each type of source spec.write_value(data=len(slow_sources)) spec.write_value(data=len(fast_sources)) # Now write one struct for each slow source as follows # # typedef struct slow_spike_source_t # { # uint32_t neuron_id; # uint32_t start_ticks; # uint32_t end_ticks; # # accum mean_isi_ticks; # accum time_to_spike_ticks; # } slow_spike_source_t; for (neuron_id, rate_val, start_val, end_val) in slow_sources: isi_val = float(1000000.0 / (rate_val * self._machine_time_step)) start_scaled = int(start_val * 1000.0 / self._machine_time_step) end_scaled = 0xFFFFFFFF if end_val is not None: end_scaled = int(end_val * 1000.0 / self._machine_time_step) spec.write_value(data=neuron_id, data_type=DataType.UINT32) spec.write_value(data=start_scaled, data_type=DataType.UINT32) spec.write_value(data=end_scaled, data_type=DataType.UINT32) spec.write_value(data=isi_val, data_type=DataType.S1615) spec.write_value(data=0x0, data_type=DataType.UINT32) # Now write # typedef struct fast_spike_source_t # { # uint32_t neuron_id; # uint32_t start_ticks; # uint32_t end_ticks; # # unsigned long fract exp_minus_lambda; # } fast_spike_source_t; for (neuron_id, spikes_per_tick, start_val, end_val) in fast_sources: exp_minus_lamda = math.exp(-1.0 * spikes_per_tick) start_scaled = int(start_val * 1000.0 / self._machine_time_step) end_scaled = 0xFFFFFFFF if end_val is not None: end_scaled = int(end_val * 1000.0 / self._machine_time_step) spec.write_value(data=neuron_id, data_type=DataType.UINT32) spec.write_value(data=start_scaled, data_type=DataType.UINT32) spec.write_value(data=end_scaled, data_type=DataType.UINT32) spec.write_value(data=exp_minus_lamda, data_type=DataType.U032) return
def generate_synapse_list( self, presynaptic_population, postsynaptic_population, delay_scale, weight_scale, synapse_type): prevertex = presynaptic_population._get_vertex postvertex = postsynaptic_population._get_vertex if (presynaptic_population.structure is None or postsynaptic_population.structure is None): raise ValueError("Attempted to create a" "DistanceDependentProbabilityConnector" "with un-structured populations") return None id_lists = list() weight_lists = list() delay_lists = list() type_lists = list() # distances are set by comparing positions. An attempt to access # positions that have not been set yet will trigger generation of # the positions, so this computation will create positions if # necessary. distances = self.space.distances(presynaptic_population.positions, postsynaptic_population.positions) connections = self._dd_is_there_a_connection( d_expression=self.d_expression, distances=distances) if (not self.allow_self_connections and presynaptic_population == postsynaptic_population): numpy.fill_diagonal(connections, False) weights = numpy.fromfunction(function=self._distance_dependence, shape=distances.shape, dtype=int, d_expression=self.weights, distances=distances) delays = numpy.fromfunction(function=self._distance_dependence, shape=distances.shape, dtype=int, d_expression=self.delays, distances=distances) for i in range(0, prevertex.n_atoms): self._conn_list.extend([(i, j, weights[i, j], delays[i, j]) for j in range(postvertex.n_atoms) if connections[i, j]]) id_lists.append(list()) weight_lists.append(list()) delay_lists.append(list()) type_lists.append(list()) for i in range(0, len(self._conn_list)): conn = self._conn_list[i] pre_atom = generate_parameter(conn[0], i) post_atom = generate_parameter(conn[1], i) if not 0 <= pre_atom < prevertex.n_atoms: raise ConfigurationException( "Invalid neuron id in presynaptic population {}".format( pre_atom)) if not 0 <= post_atom < postvertex.n_atoms: raise ConfigurationException( "Invalid neuron id in postsynaptic population {}".format( post_atom)) weight = generate_parameter(conn[2], i) * weight_scale delay = generate_parameter(conn[3], i) * delay_scale id_lists[pre_atom].append(post_atom) weight_lists[pre_atom].append(weight) delay_lists[pre_atom].append(delay) type_lists[pre_atom].append(synapse_type) connection_list = [SynapseRowInfo(id_lists[i], weight_lists[i], delay_lists[i], type_lists[i]) for i in range(0, prevertex.n_atoms)] return SynapticList(connection_list)
def generate_synapse_list( self, presynaptic_population, postsynaptic_population, delay_scale, weight_scale, synapse_type): prevertex = presynaptic_population._get_vertex postvertex = postsynaptic_population._get_vertex id_lists = list() weight_lists = list() delay_lists = list() type_lists = list() for _ in range(0, prevertex.n_atoms): id_lists.append(list()) weight_lists.append(list()) delay_lists.append(list()) type_lists.append(list()) for i in range(0, len(self._conn_list)): conn = self._conn_list[i] len_list = [] if isinstance(conn[0], list): len_list.append(len(conn[0])) else: len_list.append(1) if isinstance(conn[1], list): len_list.append(len(conn[1])) else: len_list.append(1) if isinstance(conn[2], list) and (isinstance(conn[0], list) or isinstance(conn[1], list)): len_list.append(len(conn[2])) else: len_list.append(1) if isinstance(conn[3], list) and (isinstance(conn[0], list) or isinstance(conn[1], list)): len_list.append(len(conn[3])) else: len_list.append(1) valid_len = reduce(lambda x, y: x if (y == 1 or y == x) else (y if x == 1 else 0), len_list, 1) if (valid_len): for j in range(valid_len): pre_atom = generate_parameter(conn[0], j) post_atom = generate_parameter(conn[1], j) if not 0 <= pre_atom < prevertex.n_atoms: raise exceptions.ConfigurationException( "Invalid neuron id in presynaptic population {}" .format(pre_atom)) if not 0 <= post_atom < postvertex.n_atoms: raise exceptions.ConfigurationException( "Invalid neuron id in postsynaptic population {}" .format(post_atom)) weight = generate_parameter(conn[2], j) * weight_scale delay = generate_parameter(conn[3], j) * delay_scale id_lists[pre_atom].append(post_atom) weight_lists[pre_atom].append(weight) delay_lists[pre_atom].append(delay) type_lists[pre_atom].append(synapse_type) connection_list = [SynapseRowInfo(id_lists[i], weight_lists[i], delay_lists[i], type_lists[i]) for i in range(0, prevertex.n_atoms)] return SynapticList(connection_list)