def test_synaptic_propagation_2(): # This tests for the bug in github issue #461 source = NeuronGroup(100, '', threshold='True') sub_source = source[99:] target = NeuronGroup(1, 'v:1') syn = Synapses(sub_source, target, on_pre='v+=1') syn.connect() run(defaultclock.dt + schedule_propagation_offset()) assert target.v[0] == 1.0
def test_propagation(): # Using a PoissonGroup as a source for Synapses should work as expected P = PoissonGroup(2, np.array([0, 1. / defaultclock.dt]) * Hz) G = NeuronGroup(2, 'v:1') S = Synapses(P, G, on_pre='v+=1') S.connect(j='i') run(2 * defaultclock.dt + schedule_propagation_offset()) assert_equal(G.v[:], np.array([0., 2.]))
def test_no_reference_3(): ''' Using subgroups without keeping an explicit reference. Monitors ''' G = NeuronGroup(2, 'v:1', threshold='v>1', reset='v=0') G.v = [1.1, 0] S = Synapses(G[:1], G[1:], on_pre='v+=1') S.connect() run(defaultclock.dt + schedule_propagation_offset()) assert_equal(G.v[:], np.array([0, 1]))
def test_synaptic_propagation(): G1 = NeuronGroup(10, 'v:1', threshold='v>1', reset='v=0') G1.v['i%2==1'] = 1.1 # odd numbers should spike G2 = NeuronGroup(20, 'v:1') SG1 = G1[1:6] SG2 = G2[10:] S = Synapses(SG1, SG2, on_pre='v+=1') S.connect('i==j') run(defaultclock.dt + schedule_propagation_offset()) expected = np.zeros(len(G2)) # Neurons 1, 3, 5 spiked and are connected to 10, 12, 14 expected[[10, 12, 14]] = 1 assert_equal(np.asarray(G2.v).flatten(), expected)
def test_no_reference_4(): ''' Using subgroups without keeping an explicit reference. Synapses ''' G1 = NeuronGroup(10, 'v:1', threshold='v>1', reset='v=0') G1.v['i%2==1'] = 1.1 # odd numbers should spike G2 = NeuronGroup(20, 'v:1') S = Synapses(G1[1:6], G2[10:], on_pre='v+=1') S.connect('i==j') run(defaultclock.dt + schedule_propagation_offset()) expected = np.zeros(len(G2)) # Neurons 1, 3, 5 spiked and are connected to 10, 12, 14 expected[[10, 12, 14]] = 1 assert_equal(np.asarray(G2.v).flatten(), expected)
def test_poissongroup_subgroup(): # It should be possible to take a subgroup of a PoissonGroup P = PoissonGroup(4, [0, 0, 0, 0] * Hz) P1 = P[:2] P2 = P[2:] P2.rates = 1. / defaultclock.dt G = NeuronGroup(4, 'v:1') S1 = Synapses(P1, G[:2], on_pre='v+=1') S1.connect(j='i') S2 = Synapses(P2, G[2:], on_pre='v+=1') S2.connect(j='i') run(2 * defaultclock.dt + schedule_propagation_offset()) assert_equal(G.v[:], np.array([0., 0., 2., 2.]))
def test_poissoninput_refractory(): eqs = ''' dv/dt = 0/second : 1 (unless refractory) ''' G = NeuronGroup(10, eqs, reset='v=0', threshold='v>4.5', refractory=5 * defaultclock.dt) # Will increase the value by 1.0 at each time step P = PoissonInput(G, 'v', 1, 1 / defaultclock.dt, weight=1.0) mon = StateMonitor(G, 'v', record=5) run(10 * defaultclock.dt) expected = np.arange(10, dtype=np.float) expected[6 - int(schedule_propagation_offset() / defaultclock.dt):] = 0 assert_allclose(mon[5].v[:], expected)
def test_spikegenerator_connected(): ''' Test that `SpikeGeneratorGroup` connects properly. ''' G = NeuronGroup(10, 'v:1') mon = StateMonitor(G, 'v', record=True, when='end') indices = np.array([3, 2, 1, 1, 4, 5]) times = np.array([6, 5, 4, 3, 3, 1]) * ms SG = SpikeGeneratorGroup(10, indices, times) S = Synapses(SG, G, on_pre='v+=1') S.connect(j='i') run(7*ms) # The following neurons should not receive any spikes for idx in [0, 6, 7, 8, 9]: assert all(mon[idx].v == 0) offset = schedule_propagation_offset() # The following neurons should receive a single spike for idx, time in zip([2, 3, 4, 5], [5, 6, 3, 1]*ms): assert all(mon[idx].v[mon.t<time+offset] == 0) assert all(mon[idx].v[mon.t>=time+offset] == 1) # This neuron receives two spikes assert all(mon[1].v[mon.t<3*ms+offset] == 0) assert all(mon[1].v[(mon.t>=3*ms+offset) & (mon.t<4*ms+offset)] == 1) assert all(mon[1].v[(mon.t>=4*ms+offset)] == 2)