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
        
        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())

        if not 0 <= self._n_pre <= n_pre_atoms:
            raise exceptions.ConfigurationException(
                "Sample size has to be a number less than the size of the "
                "population but greater than zero")

        for post_atom in range(n_post_atoms):
            pre_synaptic_neurons = random.sample(range(0, n_pre_atoms),
                                                 self._n_pre)

            if (not self._allow_self_connections and
                presynaptic_population == postsynaptic_population and
                post_atom in pre_synaptic_neurons):
                pre_synaptic_neurons.remove(post_atom)

            #~ print("Connections going to POST neuron %s (%s)"%(post_atom, len(pre_synaptic_neurons)))
            #~ print(pre_synaptic_neurons)
            #~ print("----------------------------------------------------")
            
            for pre_atom in pre_synaptic_atoms:
                id_lists[pre_atom].append(post_atom)
                
                
                
        for pre_atom in range(n_pre_atoms):
            present = id_lists[pre_atom]
            n_present = len(id_lists[pre_atom])
            
            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, n_pre_atoms)]

        return SynapticList(connection_list)
Пример #2
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

        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)
Пример #3
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

        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)
Пример #4
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)
    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)
    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)
Пример #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

        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)
Пример #8
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

        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)
Пример #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

        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)
Пример #10
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)