def test_script(self):
        """
        test that tests the printing of v from a pre determined recording
        :return:
        """
        p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
        n_neurons = 128 * 128  # number of neurons in each population
        p.set_number_of_neurons_per_core("IF_cond_exp", 256)

        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,
                           'e_rev_E': 0.,
                           'e_rev_I': -80.
                           }

        populations = list()
        projections = list()

        weight_to_spike = 0.035
        delay = 17

        spikes = read_spikefile('test.spikes', n_neurons)
        print spikes
        spike_array = {'spike_times': spikes}

        populations.append(p.Population(
            n_neurons, p.SpikeSourceArray, spike_array, label='inputSpikes_1'))
        populations.append(p.Population(
            n_neurons, p.IF_cond_exp, cell_params_lif, label='pop_1'))
        projections.append(p.Projection(
            populations[0], populations[1], p.OneToOneConnector(
                weights=weight_to_spike, delays=delay)))
        populations[1].record()

        p.run(1000)

        spikes = populations[1].getSpikes(compatible_output=True)

        if spikes is not None:
            print spikes
            pylab.figure()
            pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".")
            pylab.xlabel('Time/ms')
            pylab.ylabel('spikes')
            pylab.title('spikes')
            pylab.show()
        else:
            print "No spikes received"

        p.end()
Пример #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 test_recording_numerious_element_over_limit(self):
        p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
        n_neurons = 2000  # 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, 200000):
                random_time2 = random.randint(0, 50000)
                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(50000)

        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()
Пример #4
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()
Пример #5
0
    def test_get_weights(self):
        # Population parameters
        cell_params = {
            'cm': 0.2,  # nF
            'i_offset': 0.2,
            'tau_m': 20.0,
            'tau_refrac': 5.0,
            'tau_syn_E': 5.0,
            'tau_syn_I': 10.0,
            'v_reset': -60.0,
            'v_rest': -60.0,
            'v_thresh': -50.0
        }

        # Reduce number of neurons to simulate on each core
        sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 10)

        # Build inhibitory plasticity  model
        stdp_model = sim.STDPMechanism(
            timing_dependence=sim.SpikePairRule(tau_plus=20.0,
                                                tau_minus=12.7,
                                                nearest=True),
            weight_dependence=sim.AdditiveWeightDependence(w_min=0.0,
                                                           w_max=1.0,
                                                           A_plus=0.05),
            mad=True)

        # Build plastic network
        plastic_ex_pop, plastic_ie_projection =\
            self.build_network(sim.SynapseDynamics(slow=stdp_model),
                               cell_params)

        # Run simulation
        sim.run(1000)

        # Get plastic spikes and save to disk
        plastic_spikes = plastic_ex_pop.getSpikes(compatible_output=True)
        #numpy.save("plastic_spikes.npy", plastic_spikes)

        plastic_weights = plastic_ie_projection.getWeights(format="array")
        #  mean_weight = numpy.average(plastic_weights)

        # End simulation on SpiNNaker
        sim.end()
    def test_get_weights(self):
        # Population parameters
        cell_params = {
            'cm': 0.2,  # nF
            'i_offset': 0.2,
            'tau_m': 20.0,
            'tau_refrac': 5.0,
            'tau_syn_E': 5.0,
            'tau_syn_I': 10.0,
            'v_reset': -60.0,
            'v_rest': -60.0,
            'v_thresh': -50.0
        }

        # Reduce number of neurons to simulate on each core
        sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100)

        # Build inhibitory plasticity  model
        stdp_model = sim.STDPMechanism(
            timing_dependence=sim.SpikePairRule(
                tau_plus=20.0, tau_minus=12.7, nearest=True),
            weight_dependence=sim.AdditiveWeightDependence(
                w_min=0.0, w_max=1.0, A_plus=0.05),
            mad=True
        )

        # Build plastic network
        plastic_ex_pop, plastic_ie_projection =\
            self.build_network(sim.SynapseDynamics(slow=stdp_model), 
                               cell_params)

        # Run simulation
        sim.run(10000)

        # Get plastic spikes and save to disk
        plastic_spikes = plastic_ex_pop.getSpikes(compatible_output=True)
        #numpy.save("plastic_spikes.npy", plastic_spikes)

        plastic_weights = plastic_ie_projection.getWeights(format="array")
        #  mean_weight = numpy.average(plastic_weights)

        # End simulation on SpiNNaker
        sim.end()
Пример #7
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()
    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[0], populations[0],
                           p.OneToOneConnector()))

        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_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()
Пример #10
0
    def test_something(self):
        #!/usr/bin/python
        import pylab

        import spynnaker.pyNN as p

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

        cell_params_lif = {
            'cm': 0.25,  # nF
            '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()

        weight_to_spike = 2.0
        delay = 17

        loop_connections = list()
        for i in range(0, nNeurons):
            single_connection = (i, ((i + 1) % nNeurons), weight_to_spike,
                                 delay)
            loop_connections.append(single_connection)

        injection_connection = [(0, 0, weight_to_spike, 1)]
        spike_array = {'spike_times': [[0]]}
        populations.append(
            p.Population(nNeurons,
                         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[0], populations[0],
                         p.FromListConnector(loop_connections)))
        projections.append(
            p.Projection(populations[1], populations[0],
                         p.FromListConnector(injection_connection)))

        populations[0].record_v()
        #populations[0].record_gsyn()
        #populations[0].record(visualiser_mode=p.VISUALISER_MODES.RASTER)

        p.run(5000)

        v = None
        gsyn = None
        spikes = None

        v = populations[0].get_v(compatible_output=True)

        #assert(v == )

        #gsyn = populations[0].get_gsyn(compatible_output=True)
        #spikes = populations[0].getSpikes(compatible_output=True)

        if spikes is not None:
            print spikes
            pylab.figure()
            pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".")
            pylab.xlabel('Time/ms')
            pylab.ylabel('spikes')
            pylab.title('spikes')
            pylab.show()
        else:
            print "No spikes received"

        # Make some graphs

        if v is not None:
            ticks = len(v) / nNeurons
            pylab.figure()
            pylab.xlabel('Time/ms')
            pylab.ylabel('v')
            pylab.title('v')
            for pos in range(0, nNeurons, 20):
                v_for_neuron = v[pos * ticks:(pos + 1) * ticks]
                pylab.plot([i[1] for i in v_for_neuron],
                           [i[2] for i in v_for_neuron])
            pylab.show()

        if gsyn is not None:
            ticks = len(gsyn) / nNeurons
            pylab.figure()
            pylab.xlabel('Time/ms')
            pylab.ylabel('gsyn')
            pylab.title('gsyn')
            for pos in range(0, nNeurons, 20):
                gsyn_for_neuron = gsyn[pos * ticks:(pos + 1) * ticks]
                pylab.plot([i[1] for i in gsyn_for_neuron],
                           [i[2] for i in gsyn_for_neuron])
            pylab.show()

        p.end(stop_on_board=True)
    def test_print_spikes(self):
        machine_time_step = 0.1

        p.setup(timestep=machine_time_step, min_delay=1.0, max_delay=14.40)
        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()

        weight_to_spike = 2.0
        delay = 1.7

        loop_connections = list()
        for i in range(0, n_neurons):
            single_connection = (i, ((i + 1) % n_neurons), weight_to_spike,
                                 delay)
            loop_connections.append(single_connection)

        injection_connection = [(0, 0, weight_to_spike, 1)]
        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[0], populations[0],
                         p.FromListConnector(loop_connections)))
        projections.append(
            p.Projection(populations[1], populations[0],
                         p.FromListConnector(injection_connection)))

        populations[0].record_v()
        populations[0].record_gsyn()
        populations[0].record()

        p.run(500)

        spikes = populations[0].getSpikes(compatible_output=True)

        current_file_path = os.path.dirname(os.path.abspath(__file__))
        current_file_path = os.path.join(current_file_path, "spikes.data")
        spike_file = populations[0].printSpikes(current_file_path)

        spike_reader = p.utility_calls.read_spikes_from_file(
            current_file_path,
            min_atom=0,
            max_atom=n_neurons,
            min_time=0,
            max_time=500)
        read_in_spikes = spike_reader.spike_times
        p.end()
        os.remove(current_file_path)

        for spike_element, read_element in zip(spikes, read_in_spikes):
            self.assertEqual(round(spike_element[0], 1),
                             round(read_element[0], 1))
            self.assertEqual(round(spike_element[1], 1),
                             round(read_element[1], 1))
Пример #12
0
                     'v_rest'    : -65.0,
                     'v_thresh'  : -55.4
                     }


# Other simulation parameters
e_rate = 200
in_rate = 350

n_stim_test = 5
n_stim_pairing = 10
dur_stim = 20

pop_size = 40

sim.set_number_of_neurons_per_core(model, 10)

ISI = 150.
start_test_pre_pairing = 200.
start_pairing = 1500.
start_test_post_pairing = 700.

simtime = start_pairing + start_test_post_pairing + ISI*(n_stim_pairing + n_stim_test ) + 550.  # let's make it 5000

# Initialisations of the different types of populations
IAddPre = []
IAddPost = []

# +-------------------------------------------------------------------+
# | Creation of neuron populations                                    |
# +-------------------------------------------------------------------+
Пример #13
0
"""
Synfirechain-like example
"""
import spynnaker.pyNN as p
import pylab

p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
nNeurons = 200  # number of neurons in each population
p.set_number_of_neurons_per_core("IF_curr_exp", nNeurons / 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()

weight_to_spike = 2.0
delay = 17

loopConnections = list()
for i in range(0, nNeurons):
    singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay)
spike_list = {'spike_times': [float(x) for x in range(0, 599, 50)]}
#p.setup(timestep=1.0, min_delay = 1.0, max_delay = 32.0)
p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0)

#p.set_number_of_neurons_per_core("SpikeSourceArray", 256) #FAILS
#nNeurons = (256*3)-2 # number of neurons in each population #FAIL
#p.set_number_of_neurons_per_core("SpikeSourceArray", 6) # works
#nNeurons = 18 # number of neurons in each population # works
#p.set_number_of_neurons_per_core("SpikeSourceArray", 200) #FAILS
#nNeurons = (600) # number of neurons in each population #FAIL
#p.set_number_of_neurons_per_core("SpikeSourceArray", 150) #FAILS
#nNeurons = (600) # number of neurons in each population #FAIL
#p.set_number_of_neurons_per_core("SpikeSourceArray", 100) #FAILS
#nNeurons = (600) # number of neurons in each population #FAIL

p.set_number_of_neurons_per_core("SpikeSourceArray", 100)  #FAILS
nNeurons = (600)  # number of neurons in each population #FAIL

populations = list()
projections = list()

populations.append(
    p.Population(nNeurons, p.SpikeSourceArray, spike_list, label='input'))
populations.append(
    p.Population(1, p.IF_curr_exp, cell_params_lif, label='pop_1'))
projections.append(
    p.Projection(populations[0], populations[1], p.AllToAllConnector()))

populations[0].record()

p.run(1000)
parallel_safe = True

ts = 0.1  # simulation timestep in ms
simulation_time = 2000  # ms

n_input_neurons = 4
n_readout_neurons = 2  #
n_reservoir_neurons = 59
exc_rate = 0.8  # 80% of reservoir neurons are excitatory

n_reservoir_exc = int(np.ceil(n_reservoir_neurons * exc_rate))
n_reservoir_inh = n_reservoir_neurons - n_reservoir_exc

pynn.setup(timestep=ts, min_delay=ts, max_delay=2.0 * ts)

pynn.set_number_of_neurons_per_core('IF_curr_exp',
                                    100)  # this will set 100 neurons per core

#======================================================
#===
#===        Define Neural Populations
#===
#======================================================

############# Reservoir #################

# set up the reservoir population
celltype = pynn.IZK_cond_exp()
cell_params = {}
exc_cells = Population(n_reservoir_exc,
                       pynn.IF_curr_exp,
                       cell_params,
    def test_get_spikes(self):
        """
        test for get spikes
        :return:
        """
        p.setup(timestep=1, min_delay=1.0, max_delay=14.40)
        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()

        weight_to_spike = 2.0
        delay = 1.7

        loop_connections = list()
        for i in range(0, n_neurons):
            single_connection = (i, ((i + 1) % n_neurons), weight_to_spike, delay)
            loop_connections.append(single_connection)

        injection_connection = [(0, 0, weight_to_spike, 1)]
        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[0], populations[0],
                           p.FromListConnector(loop_connections)))
        projections.append(p.Projection(populations[1], populations[0],
                           p.FromListConnector(injection_connection)))

        populations[0].record_v()
        populations[0].record_gsyn()
        populations[0].record()

        p.run(500)

        spikes = populations[0].getSpikes(compatible_output=True)
        pre_recorded_spikes = [
            [0, 3.5], [1, 6.7], [2, 9.9], [3, 13.1], [4, 16.3],
            [5, 19.5], [6, 22.7], [7, 25.9], [8, 29.1],
            [9, 32.3], [10, 35.5], [11, 38.7], [12, 41.9],
            [13, 45.1], [14, 48.3], [15, 51.5], [16, 54.7],
            [17, 57.9], [18, 61.1], [19, 64.3], [20, 67.5],
            [21, 70.7], [22, 73.9], [23, 77.1], [24, 80.3],
            [25, 83.5], [26, 86.7], [27, 89.9], [28, 93.1],
            [29, 96.3], [30, 99.5], [31, 102.7], [32, 105.9],
            [33, 109.1], [34, 112.3], [35, 115.5], [36, 118.7],
            [37, 121.9], [38, 125.1], [39, 128.3], [40, 131.5],
            [41, 134.7], [42, 137.9], [43, 141.1], [44, 144.3],
            [45, 147.5], [46, 150.7], [47, 153.9], [48, 157.1],
            [49, 160.3], [50, 163.5], [51, 166.7], [52, 169.9],
            [53, 173.1], [54, 176.3], [55, 179.5], [56, 182.7],
            [57, 185.9], [58, 189.1], [59, 192.3], [60, 195.5]]

        p.end()

        for spike_element, read_element in zip(spikes, pre_recorded_spikes):
            self.assertEqual(round(spike_element[0], 1),
                             round(read_element[0], 1))
            self.assertEqual(round(spike_element[1], 1),
                             round(read_element[1], 1))
Пример #17
0
    def test_script(self):
        """
        test that tests the printing of v from a pre determined recording
        :return:
        """
        p.setup(timestep=0.1, min_delay=1.0, max_delay=14.0)
        n_neurons = 128 * 128  # number of neurons in each population
        p.set_number_of_neurons_per_core("IF_cond_exp", 256)

        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,
            'e_rev_E': 0.,
            'e_rev_I': -80.
        }

        populations = list()
        projections = list()

        weight_to_spike = 0.035
        delay = 1.7

        spikes = read_spikefile('test.spikes', n_neurons)
        print spikes
        spike_array = {'spike_times': spikes}

        populations.append(
            p.Population(n_neurons,
                         p.SpikeSourceArray,
                         spike_array,
                         label='inputSpikes_1'))
        populations.append(
            p.Population(n_neurons,
                         p.IF_cond_exp,
                         cell_params_lif,
                         label='pop_1'))
        projections.append(
            p.Projection(
                populations[0], populations[1],
                p.OneToOneConnector(weights=weight_to_spike, delays=delay)))
        populations[1].record()

        p.run(100)

        spikes = populations[1].getSpikes(compatible_output=True)

        if spikes is not None:
            print spikes
            pylab.figure()
            pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".")
            pylab.xlabel('Time/ms')
            pylab.ylabel('spikes')
            pylab.title('spikes')
            pylab.show()
        else:
            print "No spikes received"

        p.end()
spike_list = {'spike_times': [float(x) for x in range(0, 599, 50)]}
#p.setup(timestep=1.0, min_delay = 1.0, max_delay = 32.0)
p.setup(timestep=1.0, min_delay = 1.0, max_delay = 32.0)

#p.set_number_of_neurons_per_core("SpikeSourceArray", 256) #FAILS
#nNeurons = (256*3)-2 # number of neurons in each population #FAIL
#p.set_number_of_neurons_per_core("SpikeSourceArray", 6) # works
#nNeurons = 18 # number of neurons in each population # works
#p.set_number_of_neurons_per_core("SpikeSourceArray", 200) #FAILS
#nNeurons = (600) # number of neurons in each population #FAIL
#p.set_number_of_neurons_per_core("SpikeSourceArray", 150) #FAILS
#nNeurons = (600) # number of neurons in each population #FAIL
#p.set_number_of_neurons_per_core("SpikeSourceArray", 100) #FAILS
#nNeurons = (600) # number of neurons in each population #FAIL

p.set_number_of_neurons_per_core("SpikeSourceArray", 100) #FAILS
nNeurons = (600) # number of neurons in each population #FAIL


populations = list()
projections = list()

populations.append(p.Population(nNeurons, p.SpikeSourceArray, spike_list, label='input'))
populations.append(p.Population(1, p.IF_curr_exp, cell_params_lif, label='pop_1'))
projections.append(p.Projection(populations[0], populations[1], p.AllToAllConnector()))

populations[0].record()


p.run(1000)
spikes = populations[0].getSpikes(compatible_output=True)
"""
Synfirechain-like example
"""
import spynnaker.pyNN as p
import pylab
from fake_if_curr import FakeIFCurrExp

p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
nNeurons = 200  # number of neurons in each population
p.set_number_of_neurons_per_core(FakeIFCurrExp, nNeurons / 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()

weight_to_spike = 2.0
delay = 17

loopConnections = list()
for i in range(0, nNeurons):
    'tau_m'     : 20.0,
    'tau_refrac': 5.0,
    'tau_syn_E' : 5.0,
    'tau_syn_I' : 10.0,
    'v_reset'   : -60.0,
    'v_rest'    : -60.0,
    'v_thresh'  : -50.0
    }


# How large should the population of excitatory neurons be?
# (Number of inhibitory neurons is proportional to this)
NUM_EXCITATORY = 2000

# Reduce number of neurons to simulate on each core
sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100)

# Function to build the basic network - dynamics should be a PyNN synapse dynamics object
def build_network(dynamics):
    # SpiNNaker setup
    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')
    def test_get_voltage(self):
        """
        test that tests the getting of v from a pre determined recording
        :return:
        """
        p.setup(timestep=1, min_delay=1.0, max_delay=14.40)
        n_neurons = 200  # number of neurons in each population
        runtime = 500
        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()

        weight_to_spike = 2.0
        delay = 1.7

        loop_connections = list()
        for i in range(0, n_neurons):
            single_connection = (i, ((i + 1) % n_neurons), weight_to_spike,
                                 delay)
            loop_connections.append(single_connection)

        injection_connection = [(0, 0, weight_to_spike, 1)]
        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[0], populations[0],
                         p.FromListConnector(loop_connections)))
        projections.append(
            p.Projection(populations[1], populations[0],
                         p.FromListConnector(injection_connection)))

        populations[0].record_v()
        populations[0].record_gsyn()
        populations[0].record()

        p.run(runtime)

        v = populations[0].get_v(compatible_output=True)

        current_file_path = os.path.dirname(os.path.abspath(__file__))
        current_file_path = os.path.join(current_file_path, "v.data")
        pre_recorded_data = p.utility_calls.read_in_data_from_file(
            current_file_path, 0, n_neurons, 0, runtime)

        p.end()

        for spike_element, read_element in zip(v, pre_recorded_data):
            self.assertEqual(round(spike_element[0], 1),
                             round(read_element[0], 1))
            self.assertEqual(round(spike_element[1], 1),
                             round(read_element[1], 1))
            self.assertEqual(round(spike_element[2], 1),
                             round(read_element[2], 1))
Пример #22
0
"""
Synfirechain-like example
"""
import spynnaker.pyNN as p
import pylab
from fake_if_curr import FakeIFCurrExp

p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
nNeurons = 200  # number of neurons in each population
p.set_number_of_neurons_per_core(FakeIFCurrExp, nNeurons / 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()

weight_to_spike = 2.0
delay = 17

loopConnections = list()
for i in range(0, nNeurons):
    def test_something(self):
        #!/usr/bin/python
        import pylab

        import spynnaker.pyNN as p


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


        cell_params_lif = {'cm'        : 0.25, # nF
                             '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()

        weight_to_spike = 2.0
        delay = 17

        loop_connections = list()
        for i in range(0, nNeurons):
            single_connection = (i, ((i + 1) % nNeurons),
                                 weight_to_spike, delay)
            loop_connections.append(single_connection)

        injection_connection = [(0, 0, weight_to_spike, 1)]
        spike_array = {'spike_times': [[0]]}
        populations.append(p.Population(nNeurons, 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[0], populations[0],
                         p.FromListConnector(loop_connections)))
        projections.append(
            p.Projection(populations[1], populations[0],
                         p.FromListConnector(injection_connection)))

        populations[0].record_v()
        #populations[0].record_gsyn()
        #populations[0].record(visualiser_mode=p.VISUALISER_MODES.RASTER)

        p.run(5000)

        v = None
        gsyn = None
        spikes = None

        v = populations[0].get_v(compatible_output=True)

        #assert(v == )


        #gsyn = populations[0].get_gsyn(compatible_output=True)
        #spikes = populations[0].getSpikes(compatible_output=True)

        if spikes is not None:
            print spikes
            pylab.figure()
            pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".")
            pylab.xlabel('Time/ms')
            pylab.ylabel('spikes')
            pylab.title('spikes')
            pylab.show()
        else:
            print "No spikes received"

        # Make some graphs

        if v is not None:
            ticks = len(v) / nNeurons
            pylab.figure()
            pylab.xlabel('Time/ms')
            pylab.ylabel('v')
            pylab.title('v')
            for pos in range(0, nNeurons, 20):
                v_for_neuron = v[pos * ticks : (pos + 1) * ticks]
                pylab.plot([i[1] for i in v_for_neuron],
                        [i[2] for i in v_for_neuron])
            pylab.show()

        if gsyn is not None:
            ticks = len(gsyn) / nNeurons
            pylab.figure()
            pylab.xlabel('Time/ms')
            pylab.ylabel('gsyn')
            pylab.title('gsyn')
            for pos in range(0, nNeurons, 20):
                gsyn_for_neuron = gsyn[pos * ticks : (pos + 1) * ticks]
                pylab.plot([i[1] for i in gsyn_for_neuron],
                        [i[2] for i in gsyn_for_neuron])
            pylab.show()

        p.end(stop_on_board=True)
    def test_get_voltage(self):
        """
        test that tests the getting of v from a pre determined recording
        :return:
        """
        p.setup(timestep=0.1, min_delay=1.0, max_delay=14.40)
        n_neurons = 200  # number of neurons in each population
        runtime = 500
        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()

        weight_to_spike = 2.0
        delay = 1.7

        loop_connections = list()
        for i in range(0, n_neurons):
            single_connection = (i, ((i + 1) % n_neurons), weight_to_spike,
                                 delay)
            loop_connections.append(single_connection)

        injection_connection = [(0, 0, weight_to_spike, 1)]
        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[0], populations[0],
                           p.FromListConnector(loop_connections)))
        projections.append(p.Projection(populations[1], populations[0],
                           p.FromListConnector(injection_connection)))

        populations[0].record_v()
        populations[0].record_gsyn()
        populations[0].record()

        p.run(runtime)

        v = populations[0].get_v(compatible_output=True)

        current_file_path = os.path.dirname(os.path.abspath(__file__))
        current_file_path = os.path.join(current_file_path, "v.data")
        pre_recorded_data = p.utility_calls.read_in_data_from_file(
            current_file_path, 0, n_neurons, 0, runtime)

        p.end()

        for spike_element, read_element in zip(v, pre_recorded_data):
            self.assertEqual(round(spike_element[0], 1),
                             round(read_element[0], 1))
            self.assertEqual(round(spike_element[1], 1),
                             round(read_element[1], 1))
            self.assertEqual(round(spike_element[2], 1),
                             round(read_element[2], 1))
    def test_get_spikes(self):
        """
        test for get spikes
        :return:
        """
        p.setup(timestep=0.1, min_delay=1.0, max_delay=14.40)
        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()

        weight_to_spike = 2.0
        delay = 1.7

        loop_connections = list()
        for i in range(0, n_neurons):
            single_connection = (i, ((i + 1) % n_neurons), weight_to_spike,
                                 delay)
            loop_connections.append(single_connection)

        injection_connection = [(0, 0, weight_to_spike, 1)]
        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[0], populations[0],
                         p.FromListConnector(loop_connections)))
        projections.append(
            p.Projection(populations[1], populations[0],
                         p.FromListConnector(injection_connection)))

        populations[0].record_v()
        populations[0].record_gsyn()
        populations[0].record()

        p.run(500)

        spikes = populations[0].getSpikes(compatible_output=True)
        pre_recorded_spikes = [[0, 3.5], [1, 6.7], [2, 9.9], [3, 13.1],
                               [4, 16.3], [5, 19.5], [6, 22.7], [7, 25.9],
                               [8, 29.1], [9, 32.3], [10, 35.5], [11, 38.7],
                               [12, 41.9], [13, 45.1], [14, 48.3], [15, 51.5],
                               [16, 54.7], [17, 57.9], [18, 61.1], [19, 64.3],
                               [20, 67.5], [21, 70.7], [22, 73.9], [23, 77.1],
                               [24, 80.3], [25, 83.5], [26, 86.7], [27, 89.9],
                               [28, 93.1], [29, 96.3], [30, 99.5], [31, 102.7],
                               [32, 105.9], [33, 109.1], [34, 112.3],
                               [35, 115.5], [36, 118.7], [37, 121.9],
                               [38, 125.1], [39, 128.3], [40, 131.5],
                               [41, 134.7], [42, 137.9], [43, 141.1],
                               [44, 144.3], [45, 147.5], [46, 150.7],
                               [47, 153.9], [48, 157.1], [49, 160.3],
                               [50, 163.5], [51, 166.7], [52, 169.9],
                               [53, 173.1], [54, 176.3], [55, 179.5],
                               [56, 182.7], [57, 185.9], [58, 189.1],
                               [59, 192.3], [60, 195.5]]

        p.end()

        for spike_element, read_element in zip(spikes, pre_recorded_spikes):
            self.assertEqual(round(spike_element[0], 1),
                             round(read_element[0], 1))
            self.assertEqual(round(spike_element[1], 1),
                             round(read_element[1], 1))
Пример #26
0
"""
Synfirechain-like example
"""
#!/usr/bin/python
import pylab

import spynnaker.pyNN as p


p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
nNeurons = 200 # number of neurons in each population
p.set_number_of_neurons_per_core("IF_curr_exp", 10)


cell_params_lif = {'cm'        : 0.25, # nF
                     '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()

weight_to_spike = 2.0
delay = 1
    def test_print_spikes(self):
        machine_time_step = 0.1

        p.setup(timestep=machine_time_step, min_delay=1.0, max_delay=14.40)
        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()

        weight_to_spike = 2.0
        delay = 1.7

        loop_connections = list()
        for i in range(0, n_neurons):
            single_connection = (i, ((i + 1) % n_neurons), weight_to_spike,
                                 delay)
            loop_connections.append(single_connection)

        injection_connection = [(0, 0, weight_to_spike, 1)]
        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[0], populations[0],
                           p.FromListConnector(loop_connections)))
        projections.append(p.Projection(populations[1], populations[0],
                           p.FromListConnector(injection_connection)))

        populations[0].record_v()
        populations[0].record_gsyn()
        populations[0].record()

        p.run(500)

        spikes = populations[0].getSpikes(compatible_output=True)

        current_file_path = os.path.dirname(os.path.abspath(__file__))
        current_file_path = os.path.join(current_file_path, "spikes.data")
        spike_file = populations[0].printSpikes(current_file_path)

        spike_reader = p.utility_calls.read_spikes_from_file(
            current_file_path, min_atom=0, max_atom=n_neurons,
            min_time=0, max_time=500)
        read_in_spikes = spike_reader.spike_times
        p.end()
        os.remove(current_file_path)

        for spike_element, read_element in zip(spikes, read_in_spikes):
            self.assertEqual(round(spike_element[0], 1),
                             round(read_element[0], 1))
            self.assertEqual(round(spike_element[1], 1),
                             round(read_element[1], 1))
"""
Synfirechain-like example
"""
import spynnaker.pyNN as p
import pylab

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

runtime = 1000
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()

weight_to_spike = 2.0
delay = 17

loopConnections = list()
for i in range(0, nNeurons):
Пример #29
0
    "v_rest": -65.0,
    "v_thresh": -55.4,
}


# Other simulation parameters
e_rate = 200
in_rate = 350

n_stim_test = 5
n_stim_pairing = 10
dur_stim = 20

pop_size = 40

sim.set_number_of_neurons_per_core(model, 10)

ISI = 150.0
start_test_pre_pairing = 200.0
start_pairing = 1500.0
start_test_post_pairing = 700.0

simtime = start_pairing + start_test_post_pairing + ISI * (n_stim_pairing + n_stim_test) + 550.0  # let's make it 5000

# Initialisations of the different types of populations
IAddPre = []
IAddPost = []

# +-------------------------------------------------------------------+
# | Creation of neuron populations                                    |
# +-------------------------------------------------------------------+