def _update_synapses_per_post_vertex(self, pre_slices, post_slices): """ :param list(~pacman.model.graphs.common.Slice) pre_slices: :param list(~pacman.model.graphs.common.Slice) post_slices: """ if (self.__synapses_per_edge is None or len(self.__pre_slices) != len(pre_slices) or len(self.__post_slices) != len(post_slices)): n_pre_atoms = sum(pre.n_atoms for pre in pre_slices if pre) n_post_atoms = sum(post.n_atoms for post in post_slices if post) n_connections = n_pre_atoms * n_post_atoms if (not self.__with_replacement and n_connections < self.__num_synapses): raise SpynnakerException( "FixedNumberTotalConnector will not work correctly when " "with_replacement=False & num_synapses > n_pre * n_post") prob_connect = [ pre.n_atoms * post.n_atoms / float(n_connections) if pre and post else 0 for pre in pre_slices for post in post_slices ] # Use the multinomial directly if possible if (hasattr(self._rng, "rng") and hasattr(self._rng.rng, "multinomial")): self.__synapses_per_edge = self._rng.rng.multinomial( self.__num_synapses, prob_connect) else: self.__synapses_per_edge = self.get_rng_next( self.__num_synapses, prob_connect) if sum(self.__synapses_per_edge) != self.__num_synapses: raise SpynnakerException("{} of {} synapses generated".format( sum(self.__synapses_per_edge), self.__num_synapses)) self.__pre_slices = pre_slices self.__post_slices = post_slices
def _generate_values(self, values, sources, targets, n_connections, connection_slices, pre_slice, post_slice, synapse_info): """ :param values: :type values: ~pyNN.random.NumpyRNG or int or float or list(int) or list(float) or ~numpy.ndarray or str or callable :param int n_connections: :param list(slice) connection_slices: :param ~pacman.model.graphs.common.Slice pre_slice: :param ~pacman.model.graphs.common.Slice post_slice: :param SynapseInformation synapse_info: :rtype: ~numpy.ndarray """ if isinstance(values, RandomDistribution): return self._generate_random_values(values, n_connections, pre_slice, post_slice) elif isinstance(values, str) or callable(values): if self.__space is None: raise SpynnakerException( "No space object specified in projection {}-{}".format( synapse_info.pre_population, synapse_info.post_population)) expand_distances = True if isinstance(values, str): expand_distances = self._expand_distances(values) # At this point we need to now get the values corresponding to # the distances between connections in "sources" and "targets" eval_values = numpy.zeros(n_connections, dtype="float64") for i in range(n_connections): # get the distance for this source and target pair dist = self.__space.distances( synapse_info.pre_population.positions[sources[i]], synapse_info.post_population.positions[targets[i]], expand_distances) # evaluate expression at this distance eval_values[i] = _expr_context.eval(values, d=dist) return eval_values d = self.__space.distances( synapse_info.pre_population.positions[sources[i]], synapse_info.post_population.positions[targets[i]], expand_distances) return values(d) elif numpy.isscalar(values): return numpy.repeat([values], n_connections).astype("float64") elif hasattr(values, "__getitem__"): return numpy.concatenate([ values[connection_slice] for connection_slice in connection_slices ]).astype("float64") raise SpynnakerException("Unrecognised values format {} - what on " "earth are you giving me?".format(values))
def set_projection_information(self, synapse_info): super().set_projection_information(synapse_info) if (not self.__with_replacement and self.__n_post > synapse_info.n_post_neurons): raise SpynnakerException( "FixedNumberPostConnector will not work when " "with_replacement=False and n > n_post_neurons") if (not self.__with_replacement and not self.__allow_self_connections and self.__n_post == synapse_info.n_post_neurons): raise SpynnakerException( "FixedNumberPostConnector will not work when " "with_replacement=False, allow_self_connections=False " "and n = n_post_neurons")
def set_projection_information( self, pre_population, post_population, rng, machine_time_step): AbstractConnector.set_projection_information( self, pre_population, post_population, rng, machine_time_step) if (not self._with_replacement and self._n_pre > self._n_pre_neurons): raise SpynnakerException( "FixedNumberPreConnector will not work when " "with_replacement=False and n > n_pre_neurons") if (not self._with_replacement and not self._allow_self_connections and self._n_pre == self._n_pre_neurons): raise SpynnakerException( "FixedNumberPreConnector will not work when " "with_replacement=False, allow_self_connections=False " "and n = n_pre_neurons")
def _generate_weights(self, sources, targets, n_connections, connection_slices, pre_slice, post_slice, synapse_info): """ Generate weight values. :param int n_connections: :param list(slice) connection_slices: :param ~pacman.model.graphs.common.Slice pre_slice: :param ~pacman.model.graphs.common.Slice post_slice: :param SynapseInformation synapse_info: :rtype: ~numpy.ndarray """ weights = self._generate_values(synapse_info.weights, sources, targets, n_connections, connection_slices, pre_slice, post_slice, synapse_info) if self.__safe: if not weights.size: warn_once(logger, "No connection in " + str(self)) elif numpy.amin(weights) < 0 < numpy.amax(weights): raise SpynnakerException( "Weights must be either all positive or all negative" " in projection {}->{}".format( synapse_info.pre_population.label, synapse_info.post_population.label)) return numpy.abs(weights)
def generate_data_specification(self, spec, placement, routing_info): # pylint: disable=too-many-arguments, arguments-differ # reserve regions self.reserve_memory_regions(spec) # Write the setup region spec.comment("\n*** Spec for robot motor control ***\n\n") # handle simulation data spec.switch_write_focus(self._SYSTEM_REGION) spec.write_array( simulation_utilities.get_simulation_header_array( placement.vertex.get_binary_file_name())) # Get the key edge_key = routing_info.get_first_key_from_pre_vertex( placement.vertex, self.MOTOR_PARTITION_ID) if edge_key is None: raise SpynnakerException( "This motor should have one outgoing edge to the robot") # write params to memory spec.switch_write_focus(region=self._PARAMS_REGION) spec.write_value(data=edge_key) spec.write_value(data=self.__speed) spec.write_value(data=self.__sample_time) spec.write_value(data=self.__update_time) spec.write_value(data=self.__delay_time) spec.write_value(data=self.__delta_threshold) spec.write_value(data=int(self.__continue_if_not_different)) # End-of-Spec: spec.end_specification()
def _get_n_connections_from_pre_vertex_with_delay_maximum( self, delays, n_total_connections, n_connections, min_delay, max_delay, synapse_info): """ Get the expected number of delays that will fall within min_delay and max_delay given given a float, RandomDistribution or list of delays. :param delays: :type delays: ~numpy.ndarray or pyNN.random.NumpyRNG or int or float or list(int) or list(float) :param int n_total_connections: :param int n_connections: :param float min_delay: :param float max_delay: :rtype: float """ if isinstance(delays, RandomDistribution): prob_in_range = utility_calls.get_probability_within_range( delays, min_delay, max_delay) return int( math.ceil( utility_calls.get_probable_maximum_selected( n_total_connections, n_connections, prob_in_range))) elif isinstance(delays, str): d = self._get_distances(delays, synapse_info) delays = _expr_context.eval(delays, d=d) n_delayed = sum([ len([ delay for delay in delays if min_delay <= delay <= max_delay ]) ]) if n_delayed == 0: return 0 n_total = len(delays) prob_delayed = float(n_delayed) / float(n_total) return int( math.ceil( utility_calls.get_probable_maximum_selected( n_total_connections, n_connections, prob_delayed))) elif numpy.isscalar(delays): if min_delay <= delays <= max_delay: return int(math.ceil(n_connections)) return 0 elif hasattr(delays, "__getitem__"): n_delayed = sum([ len([ delay for delay in delays if min_delay <= delay <= max_delay ]) ]) if n_delayed == 0: return 0 n_total = len(delays) prob_delayed = float(n_delayed) / float(n_total) return int( math.ceil( utility_calls.get_probable_maximum_selected( n_total_connections, n_connections, prob_delayed))) raise SpynnakerException("Unrecognised delay format")
def _update_synapses_per_post_vertex(self, pre_slices, post_slices): if (self.__synapses_per_edge is None or len(self.__pre_slices) != len(pre_slices) or len(self.__post_slices) != len(post_slices)): n_pre_atoms = sum([pre.n_atoms for pre in pre_slices if pre != []]) n_post_atoms = sum( [post.n_atoms for post in post_slices if post != []]) n_connections = n_pre_atoms * n_post_atoms if (not self.__with_replacement and n_connections < self.__num_synapses): raise SpynnakerException( "FixedNumberTotalConnector will not work correctly when " "with_replacement=False & num_synapses > n_pre * n_post") prob_connect = [ float(pre.n_atoms * post.n_atoms) / float(n_connections) if (pre != []) and (post != []) else 0 for pre in pre_slices for post in post_slices ] self.__synapses_per_edge = self.get_rng_next( self.__num_synapses, prob_connect) if sum(self.__synapses_per_edge) != self.__num_synapses: raise Exception("{} of {} synapses generated".format( sum(self.__synapses_per_edge), self.__num_synapses)) self.__pre_slices = pre_slices self.__post_slices = post_slices
def __get_kernel_vals(self, vals): """ Convert kernel values given into the correct format. :param vals: :type vals: int or float or ~pyNN.random.NumpyRNG or ~numpy.ndarray\ or ConvolutionKernel :rtype: ~numpy.ndarray """ if vals is None: return None krn_size = self._kernel_h * self._kernel_w krn_shape = (self._kernel_h, self._kernel_w) if isinstance(vals, RandomDistribution): return numpy.array(vals.next(krn_size)).reshape(krn_shape) elif numpy.isscalar(vals): return vals * numpy.ones(krn_shape) elif ((isinstance(vals, numpy.ndarray) or isinstance(vals, ConvolutionKernel)) and vals.shape[HEIGHT] == self._kernel_h and vals.shape[WIDTH] == self._kernel_w): return vals.view(ConvolutionKernel) # TODO: make this error more descriptive? raise SpynnakerException( "Error generating KernelConnector values; if you have supplied " "weight and/or delay kernel then ensure they are the same size " "as specified by the shape kernel values.")
def _get_weight_maximum(self, weights, n_connections, synapse_info): """ Get the maximum of the weights. :param weights: :type weights: ~numpy.ndarray or ~pyNN.random.NumpyRNG or int or float or list(int) or list(float) :param int n_connections: :rtype: float """ if isinstance(weights, RandomDistribution): mean_weight = utility_calls.get_mean(weights) if mean_weight < 0: min_weight = utility_calls.get_minimum_probable_value( weights, n_connections) low = utility_calls.low(weights) if low is None: return abs(min_weight) return abs(max(min_weight, low)) else: max_weight = utility_calls.get_maximum_probable_value( weights, n_connections) high = utility_calls.high(weights) if high is None: return abs(max_weight) return abs(min(max_weight, high)) elif isinstance(weights, str): d = self._get_distances(weights, synapse_info) return numpy.max(_expr_context.eval(weights, d=d)) elif numpy.isscalar(weights): return abs(weights) elif hasattr(weights, "__getitem__"): return numpy.amax(numpy.abs(weights)) raise SpynnakerException("Unrecognised weight format")
def __init__( self, tau_m=20, cm=1.0, e_rev_E=0.0, e_rev_I=-70.0, v_rest=-65.0, v_reset=-65.0, v_thresh=-50.0, tau_syn_E=0.3, tau_syn_I=0.5, tau_refrac=0.1, i_offset=0, v=-65.0, gsyn_exc=0.0, gsyn_inh=0.0): # pylint: disable=too-many-arguments, too-many-locals, unused-argument raise SpynnakerException( "This neuron model is currently not supported by the tool chain")
def _get_delay_maximum(self, delays, n_connections, synapse_info): """ Get the maximum delay given a float, RandomDistribution or list of\ delays. :param delays: :type delays: ~numpy.ndarray or ~pyNN.random.NumpyRNG or int or float or list(int) or list(float) :param int n_connections: """ if isinstance(delays, RandomDistribution): max_estimated_delay = utility_calls.get_maximum_probable_value( delays, n_connections) high = utility_calls.high(delays) if high is None: return max_estimated_delay # The maximum is the minimum of the possible maximums return min(max_estimated_delay, high) elif isinstance(delays, str): d = self._get_distances(delays, synapse_info) return numpy.max(_expr_context.eval(delays, d=d)) elif numpy.isscalar(delays): return delays elif hasattr(delays, "__getitem__"): return numpy.max(delays) raise SpynnakerException("Unrecognised delay format: {:s}".format( type(delays)))
def __init__(self, time, key, mask=0xFFFFFFFF, payload=None, repeat=0, delay_between_repeats=0): """ :param time: The time within the simulation at which to send the\ commmand. 0 or a positive value indicates the number of\ timesteps after the start of the simulation at which\ the command is to be sent. A negative value indicates the\ (number of timesteps - 1) before the end of simulation at\ which the command is to be sent (thus -1 means the last\ timestep of the simulation). :type time: int :param key: The key of the command :type key: int :param mask: A mask to indicate the important bits of the command key.\ By default, all bits are assumed to be important, but this\ can be used to optimize the sending of a group of commands :type mask: int :param payload: The payload of the command :type payload: int :param repeat: The number of times that the command should be\ repeated after sending it once. This could be used to\ ensure that the command is sent despite lost packets.\ Must be between 0 and 65535 :type repeat: int :param delay_between_repeats: The amount of time in micro seconds to\ wait between sending repeats of the same command.\ Must be between 0 and 65535, and must be 0 if repeat is 0 :type delay_between_repeats: int :raise SpynnakerException: If the repeat or delay are out of range """ if repeat < 0 or repeat > 0xFFFF: raise SpynnakerException("repeat must be between 0 and 65535") if delay_between_repeats < 0 or delay_between_repeats > 0xFFFF: raise SpynnakerException( "delay_between_repeats must be between 0 and 65535") if delay_between_repeats > 0 and repeat == 0: raise SpynnakerException( "If repeat is 0, delay_betweeen_repeats must be 0") self._time = time self._key = key self._mask = mask self._payload = payload self._repeat = repeat self._delay_between_repeats = delay_between_repeats
def __init__( self, gbar_K=6.0, cm=0.2, e_rev_Na=50.0, tau_syn_E=0.2, tau_syn_I=2.0, i_offset=0.0, g_leak=0.01, e_rev_E=0.0, gbar_Na=20.0, e_rev_leak=-65.0, e_rev_I=-80, e_rev_K=-90.0, v_offset=-63, v=-65.0, gsyn_exc=0.0, gsyn_inh=0.0): # pylint: disable=too-many-arguments, too-many-locals, unused-argument raise SpynnakerException( "This neuron model is currently not supported by the tool chain")
def synapse_expander( app_graph, graph_mapper, placements, transceiver, provenance_file_path, executable_finder): """ Run the synapse expander - needs to be done after data has been loaded """ synapse_expander = executable_finder.get_executable_path(SYNAPSE_EXPANDER) delay_expander = executable_finder.get_executable_path(DELAY_EXPANDER) progress = ProgressBar(len(app_graph.vertices) + 2, "Expanding Synapses") # Find the places where the synapse expander and delay receivers should run expander_cores = ExecutableTargets() for vertex in progress.over(app_graph.vertices, finish_at_end=False): # Find population vertices if isinstance( vertex, (AbstractPopulationVertex, DelayExtensionVertex)): # Add all machine vertices of the population vertex to ones # that need synapse expansion for m_vertex in graph_mapper.get_machine_vertices(vertex): vertex_slice = graph_mapper.get_slice(m_vertex) if vertex.gen_on_machine(vertex_slice): placement = placements.get_placement_of_vertex(m_vertex) if isinstance(vertex, AbstractPopulationVertex): binary = synapse_expander else: binary = delay_expander expander_cores.add_processor( binary, placement.x, placement.y, placement.p) # Launch the delay receivers expander_app_id = transceiver.app_id_tracker.get_new_id() transceiver.execute_application(expander_cores, expander_app_id) progress.update() # Wait for everything to finish finished = False try: transceiver.wait_for_cores_to_be_in_state( expander_cores.all_core_subsets, expander_app_id, [CPUState.FINISHED]) progress.update() finished = True _extract_iobuf(expander_cores, transceiver, provenance_file_path) progress.end() except Exception: logger.exception("Synapse expander has failed") _handle_failure( expander_cores, transceiver, provenance_file_path) finally: transceiver.stop_application(expander_app_id) transceiver.app_id_tracker.free_id(expander_app_id) if not finished: raise SpynnakerException( "The synapse expander failed to complete")
def __call__(self, report_folder, application_graph): """ :param report_folder: the report folder to put figure into :param application_graph: the app graph :rtype: None """ try: import graphviz except: raise SpynnakerException( "graphviz is required to use this report. Please install" " graphviz if you want to use this report.") # create holders for data vertex_holders = dict() dot_diagram = graphviz.Digraph( comment="The graph of the network in graphical form") # build progress bar for the vertices, edges, and rendering progress_bar = ProgressBar( application_graph.n_vertices + application_graph.n_outgoing_edge_partitions + 1, "generating the graphical representation of the neural network") # write vertices into dot diagram vertex_counter = 0 for vertex in application_graph.vertices: dot_diagram.node( "{}".format(vertex_counter), "{} ({} neurons)".format(vertex.label, vertex.n_atoms)) vertex_holders[vertex] = vertex_counter vertex_counter += 1 progress_bar.update() # write edges into dot diagram for partition in application_graph.outgoing_edge_partitions: for edge in partition.edges: source_vertex_id = vertex_holders[edge.pre_vertex] dest_vertex_id = vertex_holders[edge.post_vertex] if isinstance(edge, ProjectionApplicationEdge): for synapse_info in edge.synapse_information: dot_diagram.edge( "{}".format(source_vertex_id), "{}".format(dest_vertex_id), "{}".format(synapse_info.connector)) else: dot_diagram.edge( "{}".format(source_vertex_id), "{}".format(dest_vertex_id)) progress_bar.update() # write dot file and generate pdf file_to_output = os.path.join(report_folder, "network_graph.gv") dot_diagram.render(file_to_output, view=False) progress_bar.update() progress_bar.end()
def _get_diagram(label): # pylint: disable=import-error try: import graphviz except ImportError: raise SpynnakerException( "graphviz is required to use this report. " "Please install graphviz if you want to use this report.") return graphviz.Digraph(comment=label)
def connect(self, projection): """ Apply this connector to a projection. .. warning:: Do *not* call this! SpyNNaker does not work that way. :param ~spynnaker.pyNN.models.projection.Projection projection: :raises SpynnakerException: Always. Method not supported; profiled out. """ raise SpynnakerException("Standard pyNN connect method not supported")
def to_2d_shape(shape): if numpy.isscalar(shape): return numpy.asarray([shape, shape], dtype='int') elif len(shape) == 1: return numpy.asarray([shape[0], 1], dtype='int') elif len(shape) == 2: return numpy.asarray(shape, dtype='int') raise SpynnakerException('The current implementation does not support' 'more dimensions than 2')
def create_synaptic_block(self, pre_slices, post_slices, pre_vertex_slice, post_vertex_slice, synapse_type, synapse_info): # pylint: disable=too-many-arguments # update the synapses as required, and get the number of connections pre_slice_index = pre_slices.index(pre_vertex_slice) post_slice_index = post_slices.index(post_vertex_slice) self._update_synapses_per_post_vertex(pre_slices, post_slices) n_connections = self._get_n_connections(pre_slice_index, post_slice_index) if n_connections == 0: return numpy.zeros(0, dtype=self.NUMPY_SYNAPSES_DTYPE) # get connection slice connection_slice = self._get_connection_slice(pre_slice_index, post_slice_index) # set up array for synaptic block block = numpy.zeros(n_connections, dtype=AbstractConnector.NUMPY_SYNAPSES_DTYPE) # Create pairs between the pre- and post-vertex slices pairs = numpy.mgrid[pre_vertex_slice.as_slice, post_vertex_slice.as_slice].T.reshape((-1, 2)) # Deal with case where self-connections aren't allowed if (not self.__allow_self_connections and synapse_info.pre_population is synapse_info.post_population): pairs = pairs[pairs[:, 0] != pairs[:, 1]] # Now do the actual random choice from the available connections try: chosen = numpy.random.choice(pairs.shape[0], size=n_connections, replace=self.__with_replacement) except Exception as e: raise SpynnakerException( "MultapseConnector: The number of connections is too large " "for sampling without replacement; " "reduce the value specified in the connector") from e # Set up synaptic block block["source"] = pairs[chosen, 0] block["target"] = pairs[chosen, 1] block["weight"] = self._generate_weights( block["source"], block["target"], n_connections, [connection_slice], pre_vertex_slice, post_vertex_slice, synapse_info) block["delay"] = self._generate_delays(block["source"], block["target"], n_connections, [connection_slice], pre_vertex_slice, post_vertex_slice, synapse_info) block["synapse_type"] = synapse_type return block
def __init__(self, n_neurons, spikes_per_second=None, ring_buffer_sigma=None, incoming_spike_buffer_size=None, constraints=None, label=None, tau_m=9.3667, cm=0.281, v_rest=-70.6, v_reset=-70.6, v_thresh=-50.4, tau_syn_E=5.0, tau_syn_I=0.5, tau_refrac=0.1, i_offset=0.0, a=4.0, b=0.0805, v_spike=-40.0, tau_w=144.0, e_rev_E=0.0, e_rev_I=-80.0, delta_T=2.0, v_init=None): raise SpynnakerException( "This neuron model is currently not supported by the tool chain")
def _get_mask(self, mode): if mode == ExternalFPGARetinaDevice.MODE_128: return 0xFFFFC000 elif mode == ExternalFPGARetinaDevice.MODE_64: return 0xFFFFF000 elif mode == ExternalFPGARetinaDevice.MODE_32: return 0xFFFFFC00 elif mode == ExternalFPGARetinaDevice.MODE_16: return 0xFFFFFF00 raise SpynnakerException( "the FPGA retina does not recognise this mode")
def __init__(self, g_leak=40.0, tau_syn_E=30.0, tau_syn_I=30.0, v_thresh=-55.0, v_rest=-65.0, e_rev_I=-80, v_reset=-80.0, v=-65.0): # pylint: disable=too-many-arguments, unused-argument raise SpynnakerException( "This neuron model is currently not supported by the tool chain")
def _get_mask(self, cochlea_n_channels): if cochlea_n_channels == ExternalCochleaDevice.CHANNELS_128: return 0xFFFFC000 elif cochlea_n_channels == ExternalCochleaDevice.CHANNELS_64: return 0xFFFFF000 elif cochlea_n_channels == ExternalCochleaDevice.CHANNELS_32: return 0xFFFFFC00 elif cochlea_n_channels == ExternalCochleaDevice.CHANNELS_16: return 0xFFFFFF00 #elif cochlea_n_channels == ExternalCochleaDevice.CHANNELS_16: #return 0xFFFFFFC0 else: raise SpynnakerException( "the FPGA cochlea does not recognise this number of channels")
def _get_diagram(label): """ :param str label: :rtype: tuple(~graphviz.Digraph, type) """ # pylint: disable=import-error try: import graphviz except ImportError as e: raise SpynnakerException( "graphviz is required to use this report. " "Please install graphviz if you want to use this report.") from e return (graphviz.Digraph(comment=label), graphviz.backend.ExecutableNotFound)
def get_n_neurons(cochlea_n_channels, cochlea_type, cochlea_polarity): device_n_neurons, device_n_channels, device_n_src, device_n_spikes = 1, 1, 1, 1 if cochlea_type == ExternalCochleaDevice.TYPE_MONO: device_n_src = 1 elif cochlea_type == ExternalCochleaDevice.TYPE_STEREO: device_n_src = 2 else: raise SpynnakerException( "the FPGA cochlea does not recognise this type of cochlea") if cochlea_n_channels == ExternalCochleaDevice.CHANNELS_256: device_n_channels = 256 elif cochlea_n_channels == ExternalCochleaDevice.CHANNELS_128: device_n_channels = 128 elif cochlea_n_channels == ExternalCochleaDevice.CHANNELS_64: device_n_channels = 64 elif cochlea_n_channels == ExternalCochleaDevice.CHANNELS_32: device_n_channels = 32 elif cochlea_n_channels == ExternalCochleaDevice.CHANNELS_16: device_n_channels = 16 else: raise SpynnakerException( "the FPGA cochlea does not recognise this number of channels") if cochlea_polarity == ExternalCochleaDevice.POLARITY_UP or cochlea_polarity == ExternalCochleaDevice.POLARITY_DOWN: device_n_spikes = 1 elif cochlea_polarity == ExternalCochleaDevice.POLARITY_MERGED: device_n_spikes = 2 else: raise SpynnakerException( "the FPGA cochlea does not reognise this type of polarity") device_n_neurons = (device_n_channels * device_n_src * device_n_spikes) return device_n_neurons
def __init__(self, retina_key, spinnaker_link_id, position, label=None, polarity=default_parameters['polarity'], board_address=default_parameters['board_address']): """ :param int retina_key: :param int spinnaker_link_id: The SpiNNaker link to which the retina is connected :param str position: ``LEFT`` or ``RIGHT`` :param str label: :param str polarity: ``UP``, ``DOWN`` or ``MERGED`` :param str board_address: """ # pylint: disable=too-many-arguments if polarity is None: polarity = MunichRetinaDevice.MERGED_POLARITY self.__fixed_key = (retina_key & 0xFFFF) << 16 self.__fixed_mask = 0xFFFF8000 if polarity == MunichRetinaDevice.UP_POLARITY: self.__fixed_key |= 0x4000 if polarity == MunichRetinaDevice.MERGED_POLARITY: # There are 128 x 128 retina "pixels" x 2 polarities fixed_n_neurons = 128 * 128 * 2 else: # There are 128 x 128 retina "pixels" fixed_n_neurons = 128 * 128 self.__fixed_mask = 0xFFFFC000 self.__polarity = polarity self.__position = position super(MunichRetinaDevice, self).__init__(n_atoms=fixed_n_neurons, spinnaker_link_id=spinnaker_link_id, max_atoms_per_core=fixed_n_neurons, label=label, board_address=board_address) if self.__position not in self._RETINAS: raise SpynnakerException( "The external Retina does not recognise this _position")
def __init__(self, n_neurons, spikes_per_second=None, ring_buffer_sigma=None, incoming_spike_buffer_size=None, constraints=None, label=None, g_leak=40.0, tau_syn_E=30.0, tau_syn_I=30.0, v_thresh=-55.0, v_rest=-65.0, e_rev_I=-80, v_reset=-80.0, v_init=None): raise SpynnakerException( "This neuron model is currently not supported by the tool chain")
def get_weight_variance(self, weights, synapse_info): """ Get the variance of the weights. :param weights: :type weights: ~numpy.ndarray or ~pyNN.random.NumpyRNG or int or float or list(int) or list(float) :rtype: float """ if isinstance(weights, RandomDistribution): return utility_calls.get_variance(weights) elif isinstance(weights, str): d = self._get_distances(weights, synapse_info) return numpy.var(_expr_context.eval(weights, d=d)) elif numpy.isscalar(weights): return 0.0 elif hasattr(weights, "__getitem__"): return numpy.var(weights) raise SpynnakerException("Unrecognised weight format")
def _check_parameter(self, values, name, allow_lists): """ Check that the types of the values is supported. :param values: :type values: ~numpy.ndarray or ~pyNN.random.NumpyRNG or int or float or list(int) or list(float) :param str name: :param bool allow_lists: """ if (not numpy.isscalar(values) and not (isinstance(values, RandomDistribution)) and not hasattr(values, "__getitem__")): raise SpynnakerException( "Parameter {} format unsupported".format(name)) if not allow_lists and hasattr(values, "__getitem__"): raise NotImplementedError( "Lists of {} are not supported by the implementation of {} on " "this platform".format(name, self.__class__))