def a_run(self):
     v, spikes, weights = do_run(plot=False)
     # any checks go here
     v_test = neo_convertor.convert_data(v, name='v')
     spikes_test = neo_convertor.convert_data(spikes, name='spikes')
     self.assertEqual(25000, len(v_test))
     # Not sure checking spike len is telling us much
     self.assertLess(7750, len(spikes_test))
     self.assertGreater(8250, len(spikes_test))
     self.check_weights(weights)
示例#2
0
 def check_run(self):
     all1, all2 = do_run()
     spikes1 = neo_convertor.convert_spiketrains(
         all1.segments[0].spiketrains)
     spikes2 = neo_convertor.convert_spiketrains(
         all2.segments[1].spiketrains)
     self.assertEqual(spikes1.all(), spikes2.all())
     v1 = neo_convertor.convert_data(all1, name="v", run=0)
     v2 = neo_convertor.convert_data(all2, name="v", run=1)
     self.assertEqual(v1.all(), v2.all())
def do_run(nNeurons):
    p.setup(timestep=1.0, min_delay=1.0)
    p.set_number_of_neurons_per_core(p.Izhikevich, 100)

    cell_params_izk = {
        'a': 0.02,
        'b': 0.2,
        'c': -65,
        'd': 8,
        'v': -75,
        'u': 0,
        'tau_syn_E': 2,
        'tau_syn_I': 2,
        'i_offset': 0
        }

    populations = list()
    projections = list()

    weight_to_spike = 40
    delay = 1

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

    injectionConnection = [(0, 0, weight_to_spike, delay)]
    spikeArray = {'spike_times': [[50]]}
    populations.append(p.Population(nNeurons, p.Izhikevich, cell_params_izk,
                                    label='pop_1'))
    populations.append(p.Population(1, p.SpikeSourceArray, spikeArray,
                                    label='inputSpikes_1'))

    projections.append(p.Projection(populations[0], populations[0],
                                    p.FromListConnector(connections)))
    projections.append(p.Projection(populations[1], populations[0],
                                    p.FromListConnector(injectionConnection)))

    populations[0].record("v")
    populations[0].record("gsyn_exc")
    populations[0].record("spikes")

    p.run(500)

    neo = populations[0].get_data(["v", "spikes", "gsyn_exc"])

    v = neo_convertor.convert_data(neo, name="v")
    gsyn = neo_convertor.convert_data(neo, name="gsyn_exc")
    spikes = neo_convertor.convert_spikes(neo)

    p.end()

    return (v, gsyn, spikes)
示例#4
0
    def do_run(self):
        p.setup(timestep=1.0, min_delay=1.0)

        cell_params = {
            'i_offset': .1,
            'tau_refrac': 3.0,
            'v_rest': -65.0,
            'v_thresh': -51.0,
            'tau_syn_E': 2.0,
            'tau_syn_I': 5.0,
            'v_reset': -70.0,
            'e_rev_E': 0.,
            'e_rev_I': -80.
        }

        # setup test population
        if_pop = p.Population(1, p.IF_cond_exp, cell_params)
        # setup spike sources
        spike_times = [20., 40., 60.]
        exc_pop = p.Population(1, p.SpikeSourceArray,
                               {'spike_times': spike_times})
        inh_pop = p.Population(1, p.SpikeSourceArray,
                               {'spike_times': [120, 140, 160]})
        # setup excitatory and inhibitory connections
        listcon = p.FromListConnector([(0, 0, 0.05, 1.0)])
        p.Projection(exc_pop, if_pop, listcon, receptor_type='excitatory')
        p.Projection(inh_pop, if_pop, listcon, receptor_type='inhibitory')
        # setup recorder
        if_pop.record(["v"])
        p.run(100)
        p.reset()
        if_pop.initialize(v=-65)
        exc_pop.set(spike_times=[])
        inh_pop.set(spike_times=spike_times)
        p.run(100)
        # read out voltage and plot
        neo = if_pop.get_data("all")
        p.end()
        v = neo_convertor.convert_data(neo, "v", run=0)
        v2 = neo_convertor.convert_data(neo, "v", run=1)

        self.assertGreater(v[22][2], v[21][2])
        self.assertGreater(v[42][2], v[41][2])
        self.assertGreater(v[62][2], v[61][2])
        self.assertLess(v2[22][2], v2[21][2])
        self.assertLess(v2[42][2], v2[41][2])
        self.assertLess(v2[62][2], v2[61][2])
def do_run(nNeurons):

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

    cell_params_lif_in = {
        'tau_m': 333.33,
        'cm': 208.33,
        'v':
        [0.0, 0.0146789550781, 0.029296875, 0.0438842773438, 0.0584106445312],
        'v_rest': 0.1,
        'v_reset': 0.0,
        'v_thresh': 1.0,
        'tau_syn_E': 1,
        'tau_syn_I': 2,
        'tau_refrac': 2.5,
        'i_offset': 3.0
    }

    pop1 = p.Population(nNeurons,
                        p.IF_curr_exp,
                        cell_params_lif_in,
                        label='pop_0')

    pop1.record("v")
    pop1.record("gsyn_exc")
    pop1.record("spikes")

    p.run(100)

    neo = pop1.get_data(["v", "spikes", "gsyn_exc"])

    v = neo_convertor.convert_data(neo, name="v")
    gsyn = neo_convertor.convert_data(neo, name="gsyn_exc")
    spikes = neo_convertor.convert_spikes(neo)

    p.end()

    return (v, gsyn, spikes)
        self.assertEqual(self.S_COUNTS, s_counts)
        single_connected = self.directly_connected(weights)
        two_step_connected = self.next_connected(single_connected,
                                                 single_connected)
        three_step_connected = self.next_connected(two_step_connected,
                                                   single_connected)

        for i in range(25):
            self.assertEqual(25, len(three_step_connected[i]))

    def a_run(self):
        v, spikes, weights = do_run(plot=False)
        # any checks go here
        v_test = neo_convertor.convert_data(v, name='v')
        spikes_test = neo_convertor.convert_data(spikes, name='spikes')
        self.assertEqual(25000, len(v_test))
        # Not sure checking spike len is telling us much
        self.assertLess(7750, len(spikes_test))
        self.assertGreater(8250, len(spikes_test))
        self.check_weights(weights)

    def test_a_run(self):
        self.runsafe(self.a_run)


if __name__ == '__main__':
    _v, _spikes, _weights = do_run(plot=True)
    print(len(neo_convertor.convert_data(_v, name='v')))
    print(len(neo_convertor.convert_data(_spikes, name='spikes')))
    print(len(_weights))
示例#7
0
    def test_one_core(self):
        self.runsafe(self.one_core)

    def three_cores(self):
        n_neurons = 6
        n_cores = 3
        neo = do_run(n_neurons, n_cores, 1, 2)
        spiketrains = neo.segments[0].spiketrains
        for spiketrain in spiketrains:
            assert numpy.array_equal(spiketrain.magnitude, self.expected)

    def test_three_cores(self):
        self.runsafe(self.three_cores)


if __name__ == '__main__':
    n_neurons = 40
    n_cores = 3
    neo = do_run(n_neurons, n_cores, 1, 2)
    spikes = neo_convertor.convert_spikes(neo)
    v = neo_convertor.convert_data(neo, "v")
    gsyn = neo_convertor.convert_data(neo, "gsyn_exc")

    print(spikes)
    plot_utils.plot_spikes(spikes)
    plot_utils.heat_plot(v)
    plot_utils.heat_plot(gsyn)

    times = set(spikes[:, 1])
    print(n_neurons * len(times), len(spikes))
示例#8
0
 def get_output_pop_voltage_numpy(self):
     v_neo = self._recorded_v_list[0]
     return neo_convertor.convert_data(v_neo, "v")
示例#9
0
 def get_output_pop_gsyn_inh_numpy(self):
     gsyn_inh_neo = self._recorded_gsyn_inh_list[0]
     return neo_convertor.convert_data(gsyn_inh_neo, "gsyn_exc")
示例#10
0

class TinyTest(BaseTestCase):
    def check_run(self):
        # pylint: disable=no-member
        all1, all2 = do_run()
        spikes1 = neo_convertor.convert_spiketrains(
            all1.segments[0].spiketrains)
        spikes2 = neo_convertor.convert_spiketrains(
            all2.segments[1].spiketrains)
        self.assertEqual(spikes1.all(), spikes2.all())
        v1 = neo_convertor.convert_data(all1, name="v", run=0)
        v2 = neo_convertor.convert_data(all2, name="v", run=1)
        self.assertEqual(v1.all(), v2.all())

    def test_run(self):
        self.runsafe(self.check_run)


if __name__ == '__main__':
    # pylint: disable=no-member
    _all1, _all2 = do_run()
    _spikes1 = neo_convertor.convert_spiketrains(_all1.segments[0].spiketrains)
    print(_spikes1)
    _spikes2 = neo_convertor.convert_spiketrains(_all2.segments[1].spiketrains)
    print(_spikes2)
    _v1 = neo_convertor.convert_data(_all1, name="v", run=0)
    print(_v1)
    _v2 = neo_convertor.convert_data(_all2, name="v", run=1)
    print(_v2)