Exemple #1
0
 def test_population_size(self):
     populations = list()
     populations.append(pyNN.Population(1, pyNN.IF_curr_exp, cell_params_lif,
                                        label="One population"))
     populations.append(
         pyNN.Population(10, pyNN.IF_curr_exp, cell_params_lif,
                         label="Two population"))
     self.assertEqual(populations[0]._size, 1)
     self.assertEqual(populations[1]._size, 10)
Exemple #2
0
    def test_recording_numerious_element(self):
        p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
        n_neurons = 20  # number of neurons in each population
        p.set_number_of_neurons_per_core("IF_curr_exp", n_neurons / 2)

        cell_params_lif = {
            'cm': 0.25,
            'i_offset': 0.0,
            'tau_m': 20.0,
            'tau_refrac': 2.0,
            'tau_syn_E': 5.0,
            'tau_syn_I': 5.0,
            'v_reset': -70.0,
            'v_rest': -65.0,
            'v_thresh': -50.0
        }

        populations = list()
        projections = list()

        boxed_array = numpy.zeros(shape=(0, 2))
        spike_array = list()
        for neuron_id in range(0, n_neurons):
            spike_array.append(list())
            for random_time in range(0, 20):
                random_time2 = random.randint(0, 5000)
                boxed_array = numpy.append(boxed_array,
                                           [[neuron_id, random_time2]],
                                           axis=0)
                spike_array[neuron_id].append(random_time)
        spike_array_params = {'spike_times': spike_array}
        populations.append(
            p.Population(n_neurons,
                         p.IF_curr_exp,
                         cell_params_lif,
                         label='pop_1'))
        populations.append(
            p.Population(n_neurons,
                         p.SpikeSourceArray,
                         spike_array_params,
                         label='inputSpikes_1'))

        projections.append(
            p.Projection(populations[1], populations[0],
                         p.OneToOneConnector()))

        populations[1].record()

        p.run(5000)

        spike_array_spikes = populations[1].getSpikes()
        boxed_array = boxed_array[numpy.lexsort(
            (boxed_array[:, 1], boxed_array[:, 0]))]
        numpy.testing.assert_array_equal(spike_array_spikes, boxed_array)
        p.end()
    def _create_network(self,
                        record_spikes=False,
                        record_v=False,
                        verbose=False):

        print(
            "INFO: Creating Cooperative Network of size {0} (in microensembles)."
            .format(self.size))

        #        if record_spikes:
        #            from pyNN.spiNNaker import record

        network = []
        neural_params = self.cell_params['neural']
        for x in range(0, self.size):
            blocker_columns = ps.Population(
                self.dim_y * 2,
                ps.IF_curr_exp, {
                    'tau_syn_E': neural_params['tau_E'],
                    'tau_syn_I': neural_params['tau_I'],
                    'tau_m': neural_params['tau_mem'],
                    'v_reset': neural_params['v_reset_blocker']
                },
                label="Blocker {0}".format(x))

            collector_column = ps.Population(
                self.dim_y,
                ps.IF_curr_exp, {
                    'tau_syn_E': neural_params['tau_E'],
                    'tau_syn_I': neural_params['tau_I'],
                    'tau_m': neural_params['tau_mem'],
                    'v_reset': neural_params['v_reset_collector']
                },
                label="Collector {0}".format(x))

            if record_spikes:
                collector_column.record()  # records only the spikes
            if record_v:
                collector_column.record_v(
                )  # records the membrane potential -- very resource demanding!
                blocker_columns.record_v()

            network.append((blocker_columns, collector_column))

        self._interconnect_neurons(network, verbose=verbose)
        if self.dim_x > 1:
            self._interconnect_neurons_inhexc(network, verbose)
        else:
            global _retina_proj_l, _retina_proj_r, same_disparity_indices
            _retina_proj_l = [[0]]
            _retina_proj_r = [[0]]
            same_disparity_indices = [[0]]

        return network
 def test_connector_populations_of_different_sizes(self):
     weight = 2
     delay = 5
     p1 = pyNN.Population(10,
                          pyNN.IF_curr_exp,
                          cell_params_lif,
                          label="pop 1")
     p2 = pyNN.Population(5,
                          pyNN.IF_curr_exp,
                          cell_params_lif,
                          label="pop 2")
     with self.assertRaises(ConfigurationException):
         pyNN.Projection(p1, p2, pyNN.OneToOneConnector(weight, delay))
 def test_synapse_list_generation_for_different_sized_populations(self):
     number_of_neurons = 10
     first_population = pyNN.Population(number_of_neurons, pyNN.IF_curr_exp,
                                        cell_params_lif, label="One pop")
     second_population = pyNN.Population(number_of_neurons + 5,
                                         pyNN.IF_curr_exp, cell_params_lif,
                                         label="Second pop")
     weight = 2
     delay = 1
     connection = pyNN.FixedProbabilityConnector(0.1, weight, delay)
     synaptic_list = connection.generate_synapse_list(
         first_population, second_population, 1, 1.0, 0)
     pp(synaptic_list.get_rows())
    def test_projection_params(self):
        populations = list()
        projection_details = list()
        populations = list()
        weight_to_spike = 2
        delay = 5
        populations.append(
            pyNN.Population(no_neurons,
                            pyNN.IF_curr_exp,
                            cell_params_lif,
                            label="LIF Pop"))
        populations.append(
            pyNN.Population(no_neurons,
                            pyNN.IF_curr_dual_exp,
                            cell_params_lif2exp,
                            label="IF_curr_dual_exp Pop"))
        populations.append(
            pyNN.Population(no_neurons,
                            pyNN.IF_cond_exp,
                            cell_params_lifexp,
                            label="IF_cond_exp Pop"))
        populations.append(
            pyNN.Population(no_neurons,
                            pyNN.IZK_curr_exp,
                            cell_params_izk,
                            label="IZK_curr_exp Pop"))

        for i in range(4):
            for j in range(4):
                projection_details.append({
                    'presyn':
                    populations[i],
                    'postsyn':
                    populations[j],
                    'connector':
                    pyNN.OneToOneConnector(weight_to_spike, delay)
                })
                projections.append(
                    pyNN.Projection(
                        populations[i], populations[j],
                        pyNN.OneToOneConnector(weight_to_spike, delay)))

        for i in range(4):
            for j in range(4):
                self.assertEqual(
                    projections[i + j]._projection_edge._pre_vertex,
                    projection_details[i + j]['presyn']._vertex)
                self.assertEqual(
                    projections[i + j]._projection_edge._post_vertex,
                    projection_details[i + j]['postsyn']._vertex)
 def test_one_to_one_connector_from_high_to_low(self):
     weight_to_spike, delay = 2, 5
     second_population = pyNN.Population(no_neurons,
                                         pyNN.IF_curr_exp,
                                         cell_params_lif,
                                         label="LIF Pop")
     different_population = pyNN.Population(
         20,
         pyNN.IF_curr_exp,
         cell_params_lif,
         label="A random sized population")
     with self.assertRaises(exc.ConfigurationException):
         pyNN.Projection(different_population, second_population,
                         pyNN.OneToOneConnector(weight_to_spike, delay))
 def test_multiple_connections_between_same_populations(self):
     p1 = pyNN.Population(no_neurons,
                          pyNN.IF_curr_exp,
                          cell_params_lif,
                          label="LIF Pop")
     p2 = pyNN.Population(no_neurons,
                          pyNN.IF_curr_exp,
                          cell_params_lif,
                          label="LIF Pop")
     pyNN.Projection(p1, p2, pyNN.OneToOneConnector(1, 1))
     self.assertIsInstance(
         pyNN.Projection(p1, p2, pyNN.OneToOneConnector(1, 1)), Projection,
         "Failed to create multiple connections between"
         " the same pair of populations")
 def test_synapse_list_generation_for_different_sized_populations(self):
     number_of_neurons = 10
     first_population = pyNN.Population(number_of_neurons,
                                        pyNN.IF_curr_exp,
                                        cell_params_lif,
                                        label="One pop")
     second_population = pyNN.Population(number_of_neurons + 5,
                                         pyNN.IF_curr_exp,
                                         cell_params_lif,
                                         label="Second pop")
     weight = 2
     delay = 1
     connection = pyNN.OneToOneConnector(weight, delay)
     with self.assertRaises(ConfigurationException):
         connection.generate_synapse_list(first_population,
                                          second_population, 1, 1.0, 0)
Exemple #10
0
 def test_a(self):
     weight = 2
     delay = 1
     first_pop = pyNN.Population(5,
                                 pyNN.IF_curr_exp,
                                 cell_params_lif,
                                 label="First normal pop")
     second_pop = pyNN.Population(10,
                                  pyNN.IF_curr_exp,
                                  cell_params_lif,
                                  label="Second normal pop")
     pyNN.Projection(
         first_pop, second_pop,
         pyNN.MultapseConnector(num_synapses=5,
                                weights=weight,
                                delays=delay))
Exemple #11
0
 def test_spikes_per_second_not_set_in_a_pop(self):
     pop = pyNN.Population(10,
                           pyNN.IF_curr_exp,
                           cell_params_lif,
                           label="Constrained population")
     spikes_per_second = pop._get_vertex.spikes_per_second
     self.assertEqual(spikes_per_second, 30)
Exemple #12
0
 def test_set_constraint_to_population(self):
     pop = pyNN.Population(10, pyNN.IF_curr_exp, cell_params_lif,
                           label="Constrained population")
     placer_constraint = pyNN.PlacerChipAndCoreConstraint(x=1, y=0)
     pop.set_constraint(placer_constraint)
     constraints = pop._get_vertex.constraints
     self.assertIn(placer_constraint, constraints)
Exemple #13
0
 def test_ring_buffer_sigma_not_set_in_a_pop(self):
     pop = pyNN.Population(10,
                           pyNN.IF_curr_exp,
                           cell_params_lif,
                           label="Constrained population")
     ring_buffer_sigma = pop._get_vertex.ring_buffer_sigma
     self.assertEqual(ring_buffer_sigma, 5.0)
Exemple #14
0
    def test_not_safe_and_verbose(self):
        number_of_neurons = 5
        first_population = pyNN.Population(number_of_neurons,
                                           pyNN.IF_curr_exp,
                                           cell_params_lif,
                                           label="One pop")
        weight = 2
        delay = 1
        connection_list = list()
        for i in range(5):
            for j in range(5):
                connection_list.append((i, j, weight, delay))

        synapse_type = 0
        connection = pyNN.FromListConnector(connection_list,
                                            safe=False,
                                            verbose=True)
        synaptic_list = connection.generate_synapse_list(
            first_population, first_population, 1, 1.0, synapse_type)
        self.assertEqual(synaptic_list.get_max_weight(), weight)
        self.assertEqual(synaptic_list.get_min_weight(), weight)
        pp(synaptic_list.get_rows())
        self.assertEqual(synaptic_list.get_n_rows(), number_of_neurons)
        self.assertEqual(synaptic_list.get_max_delay(), delay)
        self.assertEqual(synaptic_list.get_min_delay(), delay)
Exemple #15
0
    def test_recording_1_element(self):
        p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
        n_neurons = 200  # number of neurons in each population
        p.set_number_of_neurons_per_core("IF_curr_exp", n_neurons / 2)

        cell_params_lif = {
            'cm': 0.25,
            'i_offset': 0.0,
            'tau_m': 20.0,
            'tau_refrac': 2.0,
            'tau_syn_E': 5.0,
            'tau_syn_I': 5.0,
            'v_reset': -70.0,
            'v_rest': -65.0,
            'v_thresh': -50.0
        }

        populations = list()
        projections = list()

        spike_array = {'spike_times': [[0]]}
        populations.append(
            p.Population(n_neurons,
                         p.IF_curr_exp,
                         cell_params_lif,
                         label='pop_1'))
        populations.append(
            p.Population(1,
                         p.SpikeSourceArray,
                         spike_array,
                         label='inputSpikes_1'))

        projections.append(
            p.Projection(populations[1], populations[0],
                         p.AllToAllConnector()))

        populations[1].record()

        p.run(5000)

        spike_array_spikes = populations[1].getSpikes()
        boxed_array = numpy.zeros(shape=(0, 2))
        boxed_array = numpy.append(boxed_array, [[0, 0]], axis=0)
        numpy.testing.assert_array_equal(spike_array_spikes, boxed_array)

        p.end()
 def test_synapse_list_generation_for_different_sized_populations(self):
     number_of_neurons = 10
     first_population = pyNN.Population(number_of_neurons, pyNN.IF_curr_exp,
                                        cell_params_lif, label="One pop")
     second_population = pyNN.Population(number_of_neurons + 5,
                                         pyNN.IF_curr_exp, cell_params_lif,
                                         label="Second pop")
     weight = 2
     delay = 1
     connection = pyNN.AllToAllConnector(weight, delay)
     synaptic_list = connection.generate_synapse_list(
         first_population, second_population, 1, 1.0, 0)
     self.assertEqual(synaptic_list.get_max_weight(), weight)
     self.assertEqual(synaptic_list.get_min_weight(), weight)
     self.assertEqual(synaptic_list.get_n_rows(), number_of_neurons)
     self.assertEqual(synaptic_list.get_max_delay(), delay)
     self.assertEqual(synaptic_list.get_min_delay(), delay)
Exemple #17
0
 def test_t_set_invalid(self):
     pop = pyNN.Population(10,
                           pyNN.IF_curr_exp,
                           cell_params_lif,
                           label="Constrained population")
     data = [0, 1, 2, 3, 4, 5, 6, 7]
     with self.assertRaises(ConfigurationException):
         pop.tset("cm", data)
Exemple #18
0
 def test_synapse_list_generation_for_simulated_one_to_one_smaller_to_larger(
         self):
     number_of_neurons = 10
     first_population = pyNN.Population(number_of_neurons,
                                        pyNN.IF_curr_exp,
                                        cell_params_lif, label="One pop")
     second_population = pyNN.Population(number_of_neurons + 5,
                                         pyNN.IF_curr_exp,
                                         cell_params_lif,
                                         label="Second pop")
     weight = 2
     delay = 1
     connection_list = list()
     for i in range(number_of_neurons + 5):
         connection_list.append((i, i, weight, delay))
     connection = pyNN.FromListConnector(connection_list)
     with self.assertRaises(ConfigurationException):
         connection.generate_synapse_list(
             second_population, first_population, 1, 1.0, 0)
Exemple #19
0
    def test_recording_poisson_spikes_rate_0(self):

        p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
        n_neurons = 256  # number of neurons in each population
        p.set_number_of_neurons_per_core("IF_curr_exp", n_neurons / 2)

        cell_params_lif = {
            'cm': 0.25,
            'i_offset': 0.0,
            'tau_m': 20.0,
            'tau_refrac': 2.0,
            'tau_syn_E': 5.0,
            'tau_syn_I': 5.0,
            'v_reset': -70.0,
            'v_rest': -65.0,
            'v_thresh': -50.0
        }

        populations = list()
        projections = list()

        populations.append(
            p.Population(n_neurons,
                         p.IF_curr_exp,
                         cell_params_lif,
                         label='pop_1'))
        populations.append(
            p.Population(n_neurons,
                         p.SpikeSourcePoisson, {'rate': 0},
                         label='inputSpikes_1'))

        projections.append(
            p.Projection(populations[1], populations[0],
                         p.OneToOneConnector()))

        populations[1].record()

        p.run(5000)

        spikes = populations[1].getSpikes()
        print spikes

        p.end()
Exemple #20
0
 def test_t_set(self):
     pop = pyNN.Population(10,
                           pyNN.IF_curr_exp,
                           cell_params_lif,
                           label="Constrained population")
     data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     pop.tset("cm", data)
     cm = pop.get("cm")
     for index in range(0, len(data)):
         self.assertEqual(cm[index], data[index])
Exemple #21
0
    def build_network(self, dynamics, cell_params):
        """
        Function to build the basic network - dynamics should be a PyNN
         synapse dynamics object
:param dynamics:
:return:
        """
        # SpiNNaker setup
        model = sim.IF_curr_exp
        sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0)

        # Create excitatory and inhibitory populations of neurons
        ex_pop = sim.Population(NUM_EXCITATORY, model, cell_params)
        in_pop = sim.Population(NUM_EXCITATORY / 4, model, cell_params)

        # Record excitatory spikes
        ex_pop.record()

        # Make excitatory->inhibitory projections
        sim.Projection(ex_pop,
                       in_pop,
                       sim.FixedProbabilityConnector(0.02, weights=0.03),
                       target='excitatory')
        sim.Projection(ex_pop,
                       ex_pop,
                       sim.FixedProbabilityConnector(0.02, weights=0.03),
                       target='excitatory')

        # Make inhibitory->inhibitory projections
        sim.Projection(in_pop,
                       in_pop,
                       sim.FixedProbabilityConnector(0.02, weights=-0.3),
                       target='inhibitory')

        # Make inhibitory->excitatory projections
        ie_projection = sim.Projection(in_pop,
                                       ex_pop,
                                       sim.FixedProbabilityConnector(
                                           0.02, weights=0),
                                       target='inhibitory',
                                       synapse_dynamics=dynamics)

        return ex_pop, ie_projection
 def test_generate_synapse_list_pre_1(self):
     number_of_neurons = 5
     first_population = pyNN.Population(number_of_neurons, pyNN.IF_curr_exp,
                                        cell_params_lif, label="One pop")
     weight = 2
     delay = 1
     synapse_type = first_population._vertex.get_synapse_id('excitatory')
     connection = pyNN.FixedNumberPreConnector(1, weight, delay)
     synaptic_list = connection.generate_synapse_list(
         first_population, first_population, 1, 1.0, synapse_type)
     pp(synaptic_list.get_rows())
 def test_generate_synapse_list_probability_zero_percent(self):
     number_of_neurons = 5
     first_population = pyNN.Population(number_of_neurons, pyNN.IF_curr_exp,
                                        cell_params_lif, label="One pop")
     weight = 2
     delay = 1
     synapse_type = 0
     connection = pyNN.FixedProbabilityConnector(0, weight, delay)
     synaptic_list = connection.generate_synapse_list(
         first_population, first_population, 1, 1.0, synapse_type)
     pp(synaptic_list.get_rows())
    def test_inhibitory_connector(self):
        weight_to_spike = 2
        delay = 5
        p1 = pyNN.Population(no_neurons,
                             pyNN.IF_curr_exp,
                             cell_params_lif,
                             label="LIF Pop")
        p2 = pyNN.Population(no_neurons,
                             pyNN.IF_curr_exp,
                             cell_params_lif,
                             label="LIF Pop")

        s12_2 = pyNN.Projection(p1,
                                p2,
                                pyNN.OneToOneConnector(weight_to_spike, delay),
                                target='inhibitory')
        s21 = pyNN.Projection(p2,
                              p1,
                              pyNN.OneToOneConnector(weight_to_spike, delay),
                              target='excitatory')
Exemple #25
0
    def simulate(self, spinnaker, input_spike_times):

        # Cell parameters
        cell_params = {
            'tau_m': 20.0,
            'v_rest': -60.0,
            'v_reset': -60.0,
            'v_thresh': -40.0,
            'tau_syn_E': 2.0,
            'tau_syn_I': 2.0,
            'tau_refrac': 2.0,
            'cm': 0.25,
            'i_offset': 0.0,
        }

        rng = p.NumpyRNG(seed=28375)
        v_init = p.RandomDistribution('uniform', [-60, -40], rng)

        p.setup(timestep=1.0, min_delay=1.0, max_delay=10.0)

        pop = p.Population(1, p.IF_curr_exp, cell_params, label='population')
        pop.randomInit(v_init)
        pop.record()
        pop.record_v()

        noise = p.Population(1, p.SpikeSourceArray,
                             {"spike_times": input_spike_times})

        p.Projection(noise,
                     pop,
                     p.OneToOneConnector(weights=0.4, delays=1),
                     target='excitatory')

        # Simulate
        p.run(self.simtime)

        pop_voltages = pop.get_v(compatible_output=True)
        pop_spikes = pop.getSpikes(compatible_output=True)

        p.end()
        return pop_voltages, pop_spikes
Exemple #26
0
 def test_synapse_list_generation_simulated_one_to_one_larger_to_smaller(
         self):
     number_of_neurons = 10
     first_population = pyNN.Population(number_of_neurons, pyNN.IF_curr_exp,
                                        cell_params_lif, label="One pop")
     second_population = pyNN.Population(number_of_neurons + 5,
                                         pyNN.IF_curr_exp, cell_params_lif,
                                         label="Second pop")
     weight = 2
     delay = 1
     connection_list = list()
     for i in range(number_of_neurons):
         connection_list.append((i, i, weight, delay))
     connection = pyNN.FromListConnector(connection_list)
     synaptic_list = connection.generate_synapse_list(
         first_population, second_population, 1, 1.0, 0)
     self.assertEqual(synaptic_list.get_max_weight(), weight)
     self.assertEqual(synaptic_list.get_min_weight(), weight)
     self.assertEqual(synaptic_list.get_n_rows(), number_of_neurons)
     self.assertEqual(synaptic_list.get_max_delay(), delay)
     self.assertEqual(synaptic_list.get_min_delay(), delay)
 def test_generate_synapse_list_pre_negative(self):
     number_of_neurons = 5
     first_population = pyNN.Population(number_of_neurons,
                                        pyNN.IF_curr_exp,
                                        cell_params_lif, label="One pop")
     weight = 2
     delay = 1
     synapse_type = first_population._vertex.get_synapse_id('excitatory')
     connection = pyNN.FixedNumberPreConnector(-1, weight, delay)
     with self.assertRaises(ConfigurationException):
         connection.generate_synapse_list(
             first_population, first_population, 1, 1.0, synapse_type)
 def test_allow_self_connections(self):
     number_of_neurons = 5
     first_population = pyNN.Population(number_of_neurons, pyNN.IF_curr_exp,
                                        cell_params_lif, label="One pop")
     weight = 2
     delay = 1
     synapse_type = 0
     connection = pyNN.FixedNumberPreConnector(5, weight, delay,
                                               allow_self_connections=False)
     synaptic_list = connection.generate_synapse_list(
         first_population, first_population, 1, 1.0, synapse_type)
     pp(synaptic_list.get_rows())
Exemple #29
0
 def test_get_default_parameters_of_if_curr_exp(self):
     pop = pyNN.Population(10,
                           pyNN.IF_curr_exp,
                           cell_params_lif,
                           label="Constrained population")
     default_params = pop.default_parameters
     boxed_defaults = \
         {'tau_m': 20.0, 'cm': 1.0, 'v_rest': -65.0, 'v_reset': -65.0,
          'v_thresh': -50.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0,
          'tau_refrac': 0.1, 'i_offset': 0, 'v_init': -65.0}
     for param in default_params.keys():
         self.assertEqual(default_params[param], boxed_defaults[param])
 def test_connect_two_different_populations(self):
     number_of_neurons = 10
     first_population = pyNN.Population(number_of_neurons,
                                        pyNN.IF_curr_exp,
                                        cell_params_lif,
                                        label="One pop")
     second_population = pyNN.Population(number_of_neurons,
                                         pyNN.IF_curr_exp,
                                         cell_params_lif,
                                         label="Second pop")
     weight = 2
     delay = 1
     synapse_type = 0
     connection = pyNN.OneToOneConnector(weight, delay)
     synaptic_list = connection.generate_synapse_list(
         first_population, second_population, 1, 1.0, synapse_type)
     self.assertEqual(synaptic_list.get_max_weight(), weight)
     self.assertEqual(synaptic_list.get_min_weight(), weight)
     pp(synaptic_list.get_rows())
     self.assertEqual(synaptic_list.get_n_rows(), number_of_neurons)
     self.assertEqual(synaptic_list.get_max_delay(), delay)
     self.assertEqual(synaptic_list.get_min_delay(), delay)