def _retrieve_synaptic_data_from_machine(self):
        synapse_list = None
        delay_synapse_list = None
        if self._projection_edge is not None:
            synapse_list = \
                self._projection_edge.get_synaptic_list_from_machine(
                    graph_mapper=self._spinnaker.graph_mapper,
                    partitioned_graph=self._spinnaker.partitioned_graph,
                    placements=self._spinnaker.placements,
                    transceiver=self._spinnaker.transceiver,
                    routing_infos=self._spinnaker.routing_infos)
        if self._delay_edge is not None:
            delay_synapse_list = \
                self._delay_edge.get_synaptic_list_from_machine(
                    graph_mapper=self._spinnaker.graph_mapper,
                    placements=self._spinnaker.placements,
                    transceiver=self._spinnaker.transceiver,
                    partitioned_graph=self._spinnaker.partitioned_graph,
                    routing_infos=self._spinnaker.routing_infos)

        # If there is both a delay and a non-delay list, merge them
        if synapse_list is not None and delay_synapse_list is not None:
            rows = synapse_list.get_rows()
            delay_rows = delay_synapse_list.get_rows()
            combined_rows = list()
            for i in range(len(rows)):
                combined_row = rows[i][self._projection_list_ranges[i]]
                combined_row.append(delay_rows[i][self._delay_list_ranges[i]])
                combined_rows.append(combined_row)
            self._host_based_synapse_list = SynapticList(combined_rows)

        # If there is only a synapse list, return that
        elif synapse_list is not None:
            rows = synapse_list.get_rows()
            new_rows = list()
            for i in range(len(rows)):
                new_rows.append(rows[i][self._projection_list_ranges[i]])
            self._host_based_synapse_list = SynapticList(new_rows)

        # Otherwise return the delay list (there should be at least one!)
        else:
            rows = delay_synapse_list.get_rows()
            new_rows = list()
            for i in range(len(rows)):
                new_rows.append(rows[i][self._delay_list_ranges[i]])
            self._host_based_synapse_list = SynapticList(new_rows)

        self._has_retrieved_synaptic_list_from_machine = True
Exemple #2
0
    def _calculate_synapse_sublist(self, graph_mapper):
        pre_vertex_slice = graph_mapper.get_subvertex_slice(
            self._pre_subvertex)
        post_vertex_slice = graph_mapper.get_subvertex_slice(
            self._post_subvertex)

        delay_edge = graph_mapper.get_partitionable_edge_from_partitioned_edge(
            self)
        synapse_sublist = delay_edge.synapse_list.create_atom_sublist(
            pre_vertex_slice, post_vertex_slice)

        if synapse_sublist.get_n_rows() > 256:
            raise exceptions.SynapticMaxIncomingAtomsSupportException(
                "Delay sub-vertices can only support up to 256 incoming"
                " neurons!")

        full_delay_list = list()
        for stage in range(0, delay_edge.num_delay_stages):
            min_delay = ((stage + 1) * delay_edge.max_delay_per_neuron) + 1
            max_delay = ((stage + 2) * delay_edge.max_delay_per_neuron)
            delay_list = synapse_sublist.get_delay_sublist(
                min_delay, max_delay)
            for row in delay_list:
                row.delays -= (min_delay - 1)
            full_delay_list.extend(delay_list)

        self._synapse_sublist = SynapticList(full_delay_list)
        self._synapse_delay_rows = len(full_delay_list)
Exemple #3
0
    def _translate_synaptic_block_from_memory(self, synaptic_block, n_atoms,
                                              max_row_length, synapse_io,
                                              weight_scales):
        """
        translates a collection of memory into synaptic rows
        """
        synaptic_list = list()
        numpy_block = numpy.frombuffer(dtype='uint8',
                                       buffer=synaptic_block).view(dtype='<u4')
        position_in_block = 0
        for atom in range(n_atoms):

            # extract the 3 elements of a row (PP, FF, FP)
            p_p_entries, f_f_entries, f_p_entries = \
                self._extract_row_data_from_memory_block(numpy_block,
                                                         position_in_block)

            # new position in synpaptic block
            position_in_block = (
                (atom + 1) *
                (max_row_length + constants.SYNAPTIC_ROW_HEADER_WORDS))

            bits_reserved_for_type = self.get_n_synapse_type_bits()
            synaptic_row = synapse_io.create_row_info_from_elements(
                p_p_entries, f_f_entries, f_p_entries, bits_reserved_for_type,
                weight_scales)

            synaptic_list.append(synaptic_row)
        return SynapticList(synaptic_list)
Exemple #4
0
    def get_synaptic_list_from_machine(self, placements, transceiver,
                                       pre_subvertex, pre_n_atoms,
                                       post_subvertex, synapse_io, subgraph,
                                       routing_infos, weight_scales):
        """

        :param placements:
        :param transceiver:
        :param pre_subvertex:
        :param pre_n_atoms:
        :param post_subvertex:
        :param synapse_io:
        :param subgraph:
        :param routing_infos:
        :param weight_scales:
        :return:
        """

        synaptic_block, max_row_length = self._retrieve_synaptic_block(
            placements, transceiver, pre_subvertex, pre_n_atoms,
            post_subvertex, routing_infos, subgraph)

        # translate the synaptic block into a sublist of synapse_row_infos
        synapse_list = None
        if max_row_length > 0:
            synapse_list = \
                self._translate_synaptic_block_from_memory(
                    synaptic_block, pre_n_atoms, max_row_length, synapse_io,
                    weight_scales)
        else:
            synapse_list = SynapticList([])
        return synapse_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

        connection_list = list()
        for pre_atom in range(0, prevertex.n_atoms):
            present = numpy.ones(postvertex.n_atoms, dtype=numpy.uint32)
            if (not self._allow_self_connections
                    and presynaptic_population == postsynaptic_population):
                present[pre_atom] = 0
                n_present = postvertex.n_atoms - 1
            else:
                n_present = postvertex.n_atoms

            ids = numpy.where(present)[0]
            delays = (
                generate_parameter_array(self._delays, n_present, present) *
                delay_scale)
            weights = (
                generate_parameter_array(self._weights, n_present, present) *
                weight_scale)
            synapse_types = (numpy.ones(len(ids), dtype='uint32') *
                             synapse_type)

            connection_list.append(
                SynapseRowInfo(ids, weights, delays, synapse_types))

        return SynapticList(connection_list)
Exemple #6
0
    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())

        if not 0 <= self._n_pre <= prevertex.n_atoms:
            raise exceptions.ConfigurationException(
                "Sample size has to be a number less than the size of the "
                "population but greater than zero")
        pre_synaptic_neurons = random.sample(range(0, prevertex.n_atoms),
                                             self._n_pre)

        for pre_atom in pre_synaptic_neurons:

            present = numpy.ones(postvertex.n_atoms, dtype=numpy.uint32)
            if (not self._allow_self_connections
                    and presynaptic_population == postsynaptic_population):
                present[pre_atom] = 0
                n_present = postvertex.n_atoms - 1
            else:
                n_present = postvertex.n_atoms

            id_lists[pre_atom] = numpy.where(present)[0]
            weight_lists[pre_atom] = (
                generate_parameter_array(self._weights, n_present, present) *
                weight_scale)

            delay_lists[pre_atom] = (
                generate_parameter_array(self._delays, n_present, present) *
                delay_scale)

            type_lists[pre_atom] = generate_parameter_array(
                synapse_type, n_present, present)

        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)
Exemple #7
0
    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

        # Convert connection list into numpy record array
        conn_list_numpy = numpy.array(self._conn_list,
                                      dtype=[("source", "uint32"),
                                             ("target", "uint32"),
                                             ("weight", "float"),
                                             ("delay", "float")])
        if (conn_list_numpy["target"] >= postvertex.n_atoms).any():
            raise exceptions.ConfigurationException("Target atom out of range")

        # Sort by pre-synaptic neuron
        conn_list_numpy = numpy.sort(conn_list_numpy, order="source")

        # Apply weight and delay scaling
        conn_list_numpy["weight"] *= weight_scale
        conn_list_numpy["delay"] *= delay_scale

        # Count number of connections per pre-synaptic neuron
        pre_counts = numpy.histogram(conn_list_numpy["source"],
                                     numpy.arange(prevertex.n_atoms + 1))[0]

        # Take cumulative sum of these counts to get start and end indices of
        # the blocks of connections coming from each pre-synaptic neuron
        pre_end_idxs = numpy.cumsum(pre_counts)
        pre_start_idxs = numpy.append(0, pre_end_idxs[:-1])

        # Loop through slices of connections
        synaptic_rows = []
        for _, (start, end) in enumerate(zip(pre_start_idxs, pre_end_idxs)):

            # Get slice
            pre_conns = conn_list_numpy[start:end]

            # Repeat synapse type correct number of times
            synapse_type_row = numpy.empty(len(pre_conns), dtype="uint32")
            synapse_type_row.fill(synapse_type)

            # Combine post-synaptic neuron ids, weights, delays
            # and synapse types together into synaptic row
            synaptic_rows.append(
                SynapseRowInfo(pre_conns["target"], pre_conns["weight"],
                               pre_conns["delay"], synapse_type_row))

        # Return full synaptic list
        return SynapticList(synaptic_rows)
    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)
Exemple #9
0
    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

        present = (numpy.random.rand(postvertex.n_atoms * prevertex.n_atoms) <=
                   self._p_connect)
        ids = numpy.where(present)[0]
        n_present = numpy.sum(present)

        source_ids = ids / postvertex.n_atoms
        source_ids.sort()
        target_ids = ids % postvertex.n_atoms
        delays = generate_parameter_array(self._delays, n_present,
                                          present) * delay_scale
        weights = generate_parameter_array(self._weights, n_present,
                                           present) * weight_scale

        pre_counts = numpy.histogram(source_ids,
                                     numpy.arange(prevertex.n_atoms + 1))[0]
        pre_end_idxs = numpy.cumsum(pre_counts)
        pre_start_idxs = numpy.append(0, pre_end_idxs[:-1])

        synaptic_rows = []
        n_synapses = 0
        for _, (start, end) in enumerate(zip(pre_start_idxs, pre_end_idxs)):

            this_target_ids = target_ids[start:end]
            this_weights = weights[start:end]
            this_delays = delays[start:end]
            this_synapes_types = numpy.ones(len(this_target_ids),
                                            dtype="uint32") * synapse_type
            n_synapses += len(this_target_ids)

            synaptic_rows.append(
                SynapseRowInfo(this_target_ids, this_weights, this_delays,
                               this_synapes_types))

        return SynapticList(synaptic_rows)
    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

        source_ids = numpy.random.choice(prevertex.n_atoms,
                                         size=self._num_synapses,
                                         replace=True)
        source_ids.sort()
        target_ids = numpy.random.choice(postvertex.n_atoms,
                                         size=self._num_synapses,
                                         replace=True)
        weights = generate_parameter_array(self._weights, self._num_synapses,
                                           target_ids) * weight_scale
        delays = generate_parameter_array(self._delays, self._num_synapses,
                                          target_ids) * delay_scale

        pre_counts = numpy.histogram(source_ids,
                                     numpy.arange(prevertex.n_atoms + 1))[0]
        pre_end_idxs = numpy.cumsum(pre_counts)
        pre_start_idxs = numpy.append(0, pre_end_idxs[:-1])

        synaptic_rows = []
        n_synapses = 0
        for _, (start, end) in enumerate(zip(pre_start_idxs, pre_end_idxs)):

            this_target_ids = target_ids[start:end]
            this_weights = weights[start:end]
            this_delays = delays[start:end]
            this_synapes_types = numpy.ones(len(this_target_ids),
                                            dtype="uint32") * synapse_type
            n_synapses += len(this_target_ids)

            synaptic_rows.append(
                SynapseRowInfo(this_target_ids, this_weights, this_delays,
                               this_synapes_types))

        return SynapticList(synaptic_rows)
Exemple #11
0
    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
        n_post_atoms = postvertex.n_atoms
        n_pre_atoms = prevertex.n_atoms
        if not 0 <= self._n_post <= n_post_atoms:
            raise exceptions.ConfigurationException(
                "Sample size has to be a number less than the size of the "
                "population but greater than zero")

        id_lists = list()
        weight_lists = list()
        delay_lists = list()
        type_lists = list()
        for _ in range(0, n_pre_atoms):
            id_lists.append(list())
            weight_lists.append(list())
            delay_lists.append(list())
            type_lists.append(list())

        for pre_atom in range(n_pre_atoms):
            post_synaptic_neurons = random.sample(range(0, n_post_atoms),
                                                  self._n_post)

            if (not self._allow_self_connections
                    and presynaptic_population == postsynaptic_population
                    and pre_atom in post_synaptic_neurons):
                post_synaptic_neurons.remove(pre_atom)

            n_present = len(post_synaptic_neurons)

            id_lists[pre_atom] = post_synaptic_neurons

            weight_lists[pre_atom] = (generate_parameter_array(
                self._weights, n_present, post_synaptic_neurons) *
                                      weight_scale)

            delay_lists[pre_atom] = (generate_parameter_array(
                self._delays, n_present, post_synaptic_neurons) * delay_scale)

            type_lists[pre_atom] = generate_parameter_array(
                synapse_type, n_present, post_synaptic_neurons)

            if self._debug:
                print("Connections going from PRE neuron %s (%s)" %
                      (pre_atom, n_present))
                print("Index, Weight, Delay, Type")
                print("[")
                for i in range(n_present):
                    print("[%s, %s, %s, %s]," %
                          (id_lists[pre_atom][i], weight_lists[pre_atom][i],
                           delay_lists[pre_atom][i], type_lists[pre_atom][i]))
                print("]")

                print("----------------------------------------------------")
                print("----------------------------------------------------")
                print("----------------------------------------------------")

        connection_list = [
            SynapseRowInfo(id_lists[i], weight_lists[i], delay_lists[i],
                           type_lists[i]) for i in range(0, n_pre_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 (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)