コード例 #1
0
ファイル: test_core.py プロジェクト: agravier/pynn
def test_apply_function_to_structured_array():
    f = lambda m: 2 * m + 3
    input = numpy.arange(12).reshape((4, 3))
    m0 = LazyArray(input, shape=(4, 3))
    m1 = f(m0)
    assert isinstance(m1, larray)
    assert_arrays_equal(m1.evaluate(simplify=True), input * 2 + 3)
コード例 #2
0
ファイル: test_space.py プロジェクト: p-muller/PyNN
 def test_infinite_space_with_3D_distances(self):
     s = space.Space()
     self.assertEqual(s.distances(self.A, self.B), sqrt(3))
     self.assertEqual(s.distances(self.C, self.B), sqrt(12))
     self.assertArraysEqual(s.distances(self.A, self.ABCD),
                            numpy.array([0.0,
                                         sqrt(3),
                                         sqrt(3),
                                         sqrt(29)]))
     self.assertArraysEqual(s.distances(self.A, self.ABCD),
                            s.distances(self.ABCD, self.A).T)
     assert_arrays_equal(
         s.distances(self.ABCD, self.ABCD),
         numpy.array([
             0.0,
             sqrt(3),
             sqrt(3),
             sqrt(29),
             sqrt(3), 0.0,
             sqrt(12),
             sqrt(14),
             sqrt(3),
             sqrt(12), 0.0,
             sqrt(50.0),
             sqrt(29),
             sqrt(14),
             sqrt(50.0), 0.0
         ]))
     self.assertArraysEqual(s.distances(self.ABCD, self.A),
                            numpy.array([0.0,
                                         sqrt(3),
                                         sqrt(3),
                                         sqrt(29)]))
コード例 #3
0
ファイル: test_nest.py プロジェクト: wau/PyNN
def test_tsodyks_markram_synapse():
    if not have_nest:
        raise SkipTest
    import nest
    sim = pyNN.nest
    sim.setup()
    spike_source = sim.Population(
        1, sim.SpikeSourceArray(spike_times=numpy.arange(10, 100, 10)))
    neurons = sim.Population(
        5, sim.IF_cond_exp(e_rev_I=-75, tau_syn_I=numpy.arange(0.2, 0.7, 0.1)))
    synapse_type = sim.TsodyksMarkramSynapse(U=0.04,
                                             tau_rec=100.0,
                                             tau_facil=1000.0,
                                             weight=0.01,
                                             delay=0.5)
    connector = sim.AllToAllConnector()
    prj = sim.Projection(spike_source,
                         neurons,
                         connector,
                         receptor_type='inhibitory',
                         synapse_type=synapse_type)
    neurons.record('gsyn_inh')
    sim.run(100.0)
    connections = nest.GetConnections(numpy.unique(prj._sources).tolist(),
                                      synapse_model=prj.nest_synapse_model)
    tau_psc = numpy.array(nest.GetStatus(connections, 'tau_psc'))
    assert_arrays_equal(tau_psc, numpy.arange(0.2, 0.7, 0.1))
コード例 #4
0
def test_tset_with_numeric_values():
    p = MockPopulation()
    p._set_array = Mock()
    tau_m = numpy.linspace(10.0, 20.0, num=p.size)
    p.tset("tau_m", tau_m)
    assert_arrays_equal(p._set_array.call_args[1]['tau_m'],
                        tau_m[p._mask_local])
コード例 #5
0
ファイル: test_connectors.py プロジェクト: agravier/pynn
 def test_really_simple1(self):
     A = numpy.ones((3, ))
     B = numpy.zeros((3, 5))
     D = connectors.DistanceMatrix(B, space.Space())
     D.set_source(A)
     assert_arrays_equal(D.as_array(),
                         numpy.sqrt(3 * numpy.ones((5, ), float)))
コード例 #6
0
ファイル: test_core.py プロジェクト: agravier/pynn
def test_setitem_nonexpanded_different_value():
    A = LazyArray(3, shape=(5, ))
    assert A.evaluate(simplify=True) == 3
    A[0] = 4
    A[4] = 5
    assert_arrays_equal(A.evaluate(simplify=True), numpy.array([4, 3, 3, 3,
                                                                5]))
コード例 #7
0
ファイル: test_recording.py プロジェクト: agravier/pynn
def test__make_compatible_v():
    r = recording.Recorder('v')
    input_data = numpy.array([[0, 0.0, -65.0], [3, 0.0, -65.0],
                              [0, 0.1, -64.3], [3, 0.1, -65.1],
                              [0, 0.2, -63.7], [3, 0.2, -65.5]])
    output_data = r._make_compatible(input_data) # voltage id
    assert_arrays_equal(input_data[:,(2,0)], output_data) 
コード例 #8
0
def test_reset_recording(sim):
    """
    Check that record(None) resets the list of things to record.

    This test injects different levels of current into two neurons. In the
    first run, we record one of the neurons, in the second we record the other.
    The main point is to check that the first neuron is not recorded in the
    second run.
    """
    sim.setup()
    p = sim.Population(7, sim.IF_cond_exp())
    p[3].i_offset = 0.1
    p[4].i_offset = 0.2
    p[3:4].record('v')
    sim.run(10.0)
    sim.reset()
    p.record(None)
    p[4:5].record('v')
    sim.run(10.0)
    data = p.get_data()
    ti = lambda i: data.segments[i].analogsignalarrays[0].times
    assert_arrays_equal(ti(0), ti(1))
    idx = lambda i: data.segments[i].analogsignalarrays[0].channel_index
    assert idx(0) == [3]
    assert idx(1) == [4]
    vi = lambda i: data.segments[i].analogsignalarrays[0]
    assert vi(0).shape == vi(1).shape == (101, 1)
    assert vi(0)[0, 0] == vi(1)[0, 0] == p.initial_values['v'].evaluate(simplify=True)*pq.mV # the first value should be the same
    assert not (vi(0)[1:, 0] == vi(1)[1:, 0]).any()            # none of the others should be, because of different i_offset
コード例 #9
0
ファイル: test_recording.py プロジェクト: costypetrisor/PyNN
def test_reset_recording(sim):
    """
    Check that record(None) resets the list of things to record.

    This test injects different levels of current into two neurons. In the
    first run, we record one of the neurons, in the second we record the other.
    The main point is to check that the first neuron is not recorded in the
    second run.
    """
    sim.setup()
    p = sim.Population(7, sim.IF_cond_exp())
    p[3].i_offset = 0.1
    p[4].i_offset = 0.2
    p[3:4].record('v')
    sim.run(10.0)
    sim.reset()
    p.record(None)
    p[4:5].record('v')
    sim.run(10.0)
    data = p.get_data()
    sim.end()
    ti = lambda i: data.segments[i].analogsignalarrays[0].times
    assert_arrays_equal(ti(0), ti(1))
    idx = lambda i: data.segments[i].analogsignalarrays[0].channel_index
    assert idx(0) == [3]
    assert idx(1) == [4]
    vi = lambda i: data.segments[i].analogsignalarrays[0]
    assert vi(0).shape == vi(1).shape == (101, 1)
    assert vi(0)[0, 0] == vi(1)[0, 0] == p.initial_values['v'].evaluate(simplify=True)*pq.mV # the first value should be the same
    assert not (vi(0)[1:, 0] == vi(1)[1:, 0]).any()            # none of the others should be, because of different i_offset
コード例 #10
0
ファイル: scenarios.py プロジェクト: nivedita/PyNN
def issue241(sim):
    spike_train1 = sim.Population(1, sim.SpikeSourcePoisson, {
        'rate': [5],
        'start': [1000],
        'duration': [1234]
    })
    spike_train2 = sim.Population(2, sim.SpikeSourcePoisson, {
        'rate': [5, 6],
        'start': [1000, 1001],
        'duration': [1234, 2345]
    })
    spike_train3 = sim.Population(1, sim.SpikeSourcePoisson, {
        'rate': [5],
        'start': [1000],
        'duration': 1234
    })
    spike_train4 = sim.Population(1, sim.SpikeSourcePoisson, {
        'rate': [5],
        'start': [1000]
    })
    spike_train5 = sim.Population(2, sim.SpikeSourcePoisson, {
        'rate': [5, 6],
        'start': [1000, 1001]
    })
    assert_arrays_equal(spike_train2.get('duration'), numpy.array([1234,
                                                                   2345]))
    assert_equal(spike_train3.get(['rate', 'start', 'duration']),
                 [5, 1000, 1234])
コード例 #11
0
def test_get_positions():
    p = MockPopulation(11, MockStandardCell)
    ppos = numpy.random.uniform(size=(3, 11))
    p._positions = ppos
    pv = common.PopulationView(parent=p, selector=slice(3, 9, 2))
    assert_arrays_equal(pv.positions,
                        numpy.array([ppos[:, 3], ppos[:, 5], ppos[:, 7]]).T)
コード例 #12
0
ファイル: test_core.py プロジェクト: agravier/pynn
def test_columnwise_iteration_with_structured_array_and_mask():
    input = numpy.arange(12).reshape((4, 3))
    m = LazyArray(input, shape=(4, 3))  # 4 rows, 3 columns
    mask = numpy.array([False, True, True])
    cols = [col for col in m.by_column(mask=mask)]
    assert_arrays_equal(cols[0], input[:, 1])
    assert_arrays_equal(cols[1], input[:, 2])
コード例 #13
0
ファイル: test_space.py プロジェクト: costypetrisor/PyNN
 def test_infinite_space_with_3D_distances(self):
     s = space.Space()
     self.assertEqual(s.distances(self.A, self.B), sqrt(3))
     self.assertEqual(s.distances(self.C, self.B), sqrt(12))
     self.assertArraysEqual(s.distances(self.A, self.ABCD), numpy.array([0.0, sqrt(3), sqrt(3), sqrt(29)]))
     self.assertArraysEqual(s.distances(self.A, self.ABCD), s.distances(self.ABCD, self.A).T)
     assert_arrays_equal(
         s.distances(self.ABCD, self.ABCD),
         numpy.array(
             [
                 0.0,
                 sqrt(3),
                 sqrt(3),
                 sqrt(29),
                 sqrt(3),
                 0.0,
                 sqrt(12),
                 sqrt(14),
                 sqrt(3),
                 sqrt(12),
                 0.0,
                 sqrt(50.0),
                 sqrt(29),
                 sqrt(14),
                 sqrt(50.0),
                 0.0,
             ]
         ),
     )
     self.assertArraysEqual(s.distances(self.ABCD, self.A), numpy.array([0.0, sqrt(3), sqrt(3), sqrt(29)]))
コード例 #14
0
ファイル: test_connectors.py プロジェクト: agravier/pynn
 def test_really_simple1(self):
     A = numpy.ones((3,))
     B = numpy.zeros((3,5))
     D = connectors.DistanceMatrix(B, space.Space())
     D.set_source(A)
     assert_arrays_equal(D.as_array(),
                         numpy.sqrt(3*numpy.ones((5,), float)))
コード例 #15
0
def test_create_with_boolean_array_selector():
    p = MockPopulation(11, MockStandardCell)
    mask = numpy.array([0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0], dtype=bool)
    pv = common.PopulationView(parent=p, selector=mask)
    assert_arrays_equal(
        pv.all_cells,
        numpy.array([p.all_cells[3], p.all_cells[5], p.all_cells[7]]))
コード例 #16
0
ファイル: test_populationview.py プロジェクト: agravier/pynn
def test_get_positions():
    p = MockPopulation(11, MockStandardCell)
    ppos = numpy.random.uniform(size=(3,11))
    p._positions = ppos
    pv = common.PopulationView(parent=p,
                               selector=slice(3,9,2))
    assert_arrays_equal(pv.positions, numpy.array([ppos[:,3], ppos[:,5], ppos[:,7]]).T)
コード例 #17
0
def issue241(sim):
    # "Nest SpikeSourcePoisson populations require all parameters to be passed to constructor"
    sim.setup()
    spike_train1 = sim.Population(1, sim.SpikeSourcePoisson, {
        'rate': [5],
        'start': [1000],
        'duration': [1234]
    })
    spike_train2 = sim.Population(2, sim.SpikeSourcePoisson, {
        'rate': [5, 6],
        'start': [1000, 1001],
        'duration': [1234, 2345]
    })
    spike_train3 = sim.Population(1, sim.SpikeSourcePoisson, {
        'rate': [5],
        'start': [1000],
        'duration': 1234
    })
    spike_train4 = sim.Population(1, sim.SpikeSourcePoisson, {
        'rate': [5],
        'start': [1000]
    })
    spike_train5 = sim.Population(2, sim.SpikeSourcePoisson, {
        'rate': [5, 6],
        'start': [1000, 1001]
    })
    assert_arrays_equal(spike_train2.get('duration'), numpy.array([1234,
                                                                   2345]))
    assert_equal(spike_train3.get(['rate', 'start', 'duration']),
                 [5, 1000, 1234])
    sim.end()
コード例 #18
0
def test_set_synaptic_parameters(sim):
    sim.setup()
    mpi_rank = sim.rank()
    p1 = sim.Population(4, sim.IF_cond_exp())
    p2 = sim.Population(2, sim.IF_cond_exp())
    syn = sim.TsodyksMarkramSynapse(U=0.5, weight=0.123, delay=0.1)
    prj = sim.Projection(p1, p2, sim.AllToAllConnector(), syn)

    expected = numpy.array([
        (0.0, 0.0, 0.123, 0.1, 0.5),
        (0.0, 1.0, 0.123, 0.1, 0.5),
        (1.0, 0.0, 0.123, 0.1, 0.5),
        (1.0, 1.0, 0.123, 0.1, 0.5),
        (2.0, 0.0, 0.123, 0.1, 0.5),
        (2.0, 1.0, 0.123, 0.1, 0.5),
        (3.0, 0.0, 0.123, 0.1, 0.5),
        (3.0, 1.0, 0.123, 0.1, 0.5),
    ])
    actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_arrays_equal(actual[ind], expected)

    positional_weights = numpy.array([[0, 1], [2, 3], [4, 5], [6, 7]],
                                     dtype=float)
    prj.set(weight=positional_weights)
    expected = positional_weights
    actual = prj.get('weight', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    u_list = [0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]
    prj.set(U=u_list)
    expected = numpy.array([[0.9, 0.8], [0.7, 0.6], [0.5, 0.4], [0.3, 0.2]])
    actual = prj.get('U', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    f_delay = lambda d: 0.5 + d
    prj.set(delay=f_delay)
    expected = numpy.array([[0.5, 1.5], [1.5, 0.5], [2.5, 1.5], [3.5, 2.5]])
    actual = prj.get('delay', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    # final sanity check
    expected = numpy.array([
        (0.0, 0.0, 0.0, 0.5, 0.9),
        (0.0, 1.0, 1.0, 1.5, 0.8),
        (1.0, 0.0, 2.0, 1.5, 0.7),
        (1.0, 1.0, 3.0, 0.5, 0.6),
        (2.0, 0.0, 4.0, 2.5, 0.5),
        (2.0, 1.0, 5.0, 1.5, 0.4),
        (3.0, 0.0, 6.0, 3.5, 0.3),
        (3.0, 1.0, 7.0, 2.5, 0.2),
    ])
    actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_arrays_equal(actual[ind], expected)
コード例 #19
0
ファイル: test_core.py プロジェクト: agravier/pynn
def test_columnwise_iteration_with_structured_array_and_mask():
    input = numpy.arange(12).reshape((4,3))
    m = LazyArray(input, shape=(4,3)) # 4 rows, 3 columns
    mask = numpy.array([False, True, True])
    cols = [col for col in m.by_column(mask=mask)]    
    assert_arrays_equal(cols[0], input[:,1])
    assert_arrays_equal(cols[1], input[:,2])
コード例 #20
0
ファイル: test_core.py プロジェクト: agravier/pynn
def test_apply_function_to_structured_array():
    f = lambda m: 2*m + 3
    input = numpy.arange(12).reshape((4,3))
    m0 = LazyArray(input, shape=(4,3))
    m1 = f(m0)
    assert isinstance(m1, larray)
    assert_arrays_equal(m1.evaluate(simplify=True), input*2 + 3)
コード例 #21
0
ファイル: test_parameter_handling.py プロジェクト: jougs/PyNN
def test_set_synaptic_parameters(sim):
    sim.setup()
    mpi_rank = sim.rank()
    p1 = sim.Population(4, sim.IF_cond_exp())
    p2 = sim.Population(2, sim.IF_cond_exp())
    syn = sim.TsodyksMarkramSynapse(U=0.5, weight=0.123, delay=0.1)
    prj = sim.Projection(p1, p2, sim.AllToAllConnector(), syn)

    expected = numpy.array([
        (0.0, 0.0, 0.123, 0.1, 0.5),
        (0.0, 1.0, 0.123, 0.1, 0.5),
        (1.0, 0.0, 0.123, 0.1, 0.5),
        (1.0, 1.0, 0.123, 0.1, 0.5),
        (2.0, 0.0, 0.123, 0.1, 0.5),
        (2.0, 1.0, 0.123, 0.1, 0.5),
        (3.0, 0.0, 0.123, 0.1, 0.5),
        (3.0, 1.0, 0.123, 0.1, 0.5),
    ])
    actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_arrays_equal(actual[ind], expected)

    positional_weights = numpy.array([[0, 1], [2, 3], [4, 5], [6, 7]], dtype=float)
    prj.set(weight=positional_weights)
    expected = positional_weights
    actual = prj.get('weight', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    u_list = [0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]
    prj.set(U=u_list)
    expected = numpy.array([[0.9, 0.8], [0.7, 0.6], [0.5, 0.4], [0.3, 0.2]])
    actual = prj.get('U', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    f_delay = lambda d: 0.5+d
    prj.set(delay=f_delay)
    expected = numpy.array([[0.5, 1.5], [1.5, 0.5], [2.5, 1.5], [3.5, 2.5]])
    actual = prj.get('delay', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    # final sanity check
    expected = numpy.array([
        (0.0, 0.0, 0.0, 0.5, 0.9),
        (0.0, 1.0, 1.0, 1.5, 0.8),
        (1.0, 0.0, 2.0, 1.5, 0.7),
        (1.0, 1.0, 3.0, 0.5, 0.6),
        (2.0, 0.0, 4.0, 2.5, 0.5),
        (2.0, 1.0, 5.0, 1.5, 0.4),
        (3.0, 0.0, 6.0, 3.5, 0.3),
        (3.0, 1.0, 7.0, 2.5, 0.2),
    ])
    actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_arrays_equal(actual[ind], expected)
コード例 #22
0
ファイル: test_basepopulation.py プロジェクト: agravier/pynn
def test__record():
    p = MockPopulation()
    p.recorders = {'v': Mock()}
    p._record('v')
    meth, args, kwargs = p.recorders['v'].method_calls[0]
    id_arr, = args
    assert_equal(meth, 'record')
    assert_arrays_equal(id_arr, p.all_cells)
コード例 #23
0
def issue241(sim):
    spike_train1 = sim.Population(1, sim.SpikeSourcePoisson, {'rate' : [5], 'start' : [1000], 'duration': [1234]})
    spike_train2 = sim.Population(2, sim.SpikeSourcePoisson, {'rate' : [5, 6], 'start' : [1000, 1001], 'duration': [1234, 2345]})
    spike_train3 = sim.Population(1, sim.SpikeSourcePoisson, {'rate' : [5], 'start' : [1000], 'duration': 1234})
    spike_train4 = sim.Population(1, sim.SpikeSourcePoisson, {'rate' : [5], 'start' : [1000]})
    spike_train5 = sim.Population(2, sim.SpikeSourcePoisson, {'rate' : [5, 6], 'start' : [1000, 1001]})
    assert_arrays_equal(spike_train2.get('duration'), numpy.array([1234, 2345]))
    assert_equal(spike_train3.get(['rate', 'start', 'duration']), [5, 1000, 1234])
コード例 #24
0
def test_create_with_index_array_selector():
    p = MockPopulation(11, MockStandardCell)
    mask = numpy.array([3, 5, 7])
    pv = common.PopulationView(parent=p, selector=mask)
    assert_arrays_equal(
        pv.all_cells,
        numpy.array([p.all_cells[3], p.all_cells[5], p.all_cells[7]]))
    assert_arrays_equal(pv.mask, mask)
コード例 #25
0
ファイル: test_core.py プロジェクト: agravier/pynn
def test_apply_function_to_functional_array():
    input = lambda i, j: 2 * i + j
    m0 = LazyArray(input, shape=(4, 3))
    f = lambda m: 2 * m + 3
    m1 = f(m0)
    assert_arrays_equal(
        m1.evaluate(),
        numpy.array([[3, 5, 7], [7, 9, 11], [11, 13, 15], [15, 17, 19]]))
コード例 #26
0
def test__record():
    p = MockPopulation()
    p.recorders = {'v': Mock()}
    p._record('v')
    meth, args, kwargs = p.recorders['v'].method_calls[0]
    id_arr, = args
    assert_equal(meth, 'record')
    assert_arrays_equal(id_arr, p.all_cells)
コード例 #27
0
ファイル: test_core.py プロジェクト: agravier/pynn
def test_evaluate_with_functional_array():
    input = lambda i,j: 2*i + j
    m = LazyArray(input, shape=(4,3))
    assert_arrays_equal(m.evaluate(),
                        numpy.array([[0, 1, 2],
                                     [2, 3, 4],
                                     [4, 5, 6],
                                     [6, 7, 8]]))
コード例 #28
0
def test__make_compatible_v():
    r = recording.Recorder('v')
    input_data = numpy.array([[0, 0.0, -65.0], [3, 0.0,
                                                -65.0], [0, 0.1, -64.3],
                              [3, 0.1, -65.1], [0, 0.2, -63.7],
                              [3, 0.2, -65.5]])
    output_data = r._make_compatible(input_data)  # voltage id
    assert_arrays_equal(input_data[:, (2, 0)], output_data)
コード例 #29
0
def test_check_weight_with_NaN():
    w = numpy.arange(10.0)
    w[0] = numpy.nan
    assert_arrays_equal(
        w[1:],
        common.check_weight(
            w, 'excitatory',
            is_conductance=True)[1:])  # NaN != NaN by definition
コード例 #30
0
ファイル: test_population.py プロジェクト: agravier/pynn
def test_set_positions():
    p = MockPopulation(11, MockStandardCell)
    assert p._structure != None
    new_positions = numpy.random.uniform(size=(3,11))
    p.positions = new_positions
    assert_equal(p.structure, None)
    assert_arrays_equal(p.positions, new_positions)
    new_positions[0,0] = 99.9
    assert p.positions[0,0] != 99.9
コード例 #31
0
ファイル: test_basepopulation.py プロジェクト: agravier/pynn
def test_sample():
    orig_pv = populations.PopulationView
    populations.PopulationView = Mock()
    p = MockPopulation()
    rng = Mock()
    rng.permutation = Mock(return_value=numpy.array([7,4,8,12,0,3,9,1,2,11,5,10,6]))
    pv = p.sample(5, rng=rng)
    assert_arrays_equal(populations.PopulationView.call_args[0][1], numpy.array([7,4,8,12,0]))
    populations.PopulationView = orig_pv
コード例 #32
0
ファイル: test_basepopulation.py プロジェクト: agravier/pynn
def test_initialize_random_distribution():
    p = MockPopulation()
    p.initial_values = {}
    p._set_initial_value_array = Mock()
    class MockRandomDistribution(random.RandomDistribution):
        def next(self, n, mask_local):
            return 42*numpy.ones(n)[mask_local]
    p.initialize('v', MockRandomDistribution())
    assert_arrays_equal(p.initial_values['v'].evaluate(simplify=True), 42*numpy.ones(p.local_size))
コード例 #33
0
ファイル: test_recording.py プロジェクト: agravier/pynn
def test_get__zero_offset():
    r = recording.Recorder('spikes')
    fake_data = numpy.array([
                    (3, 12.3),
                    (4, 14.5),
                    (7, 19.8)
                ])
    r._get = Mock(return_value=fake_data)
    assert_arrays_equal(r.get(), fake_data)
コード例 #34
0
ファイル: test_population.py プロジェクト: agravier/pynn
def test_set_positions():
    p = MockPopulation(11, MockStandardCell)
    assert p._structure != None
    new_positions = numpy.random.uniform(size=(3, 11))
    p.positions = new_positions
    assert_equal(p.structure, None)
    assert_arrays_equal(p.positions, new_positions)
    new_positions[0, 0] = 99.9
    assert p.positions[0, 0] != 99.9
コード例 #35
0
ファイル: test_basepopulation.py プロジェクト: agravier/pynn
def test_tset_with_array_values():
    p = MockPopulation()
    p._set_array = Mock()
    spike_times = numpy.linspace(0.0, 1000.0, num=10*p.size).reshape((p.size,10))
    p.tset("spike_times", spike_times)
    call_args = p._set_array.call_args[1]['spike_times']
    assert_equal(call_args.shape, spike_times[p._mask_local].shape)
    assert_arrays_equal(call_args.flatten(),
                        spike_times[p._mask_local].flatten())
コード例 #36
0
ファイル: test_assembly.py プロジェクト: agravier/pynn
def test_local_cells():
    p1 = MockPopulation()
    p2 = MockPopulation()
    p3 = MockPopulation()
    a = Assembly(p1, p2, p3)
    assert_equal(a.local_cells.size,
                 p1.local_cells.size + p2.local_cells.size + p3.local_cells.size)
    assert_equal(a.local_cells[0], p1.local_cells[0])
    assert_equal(a.local_cells[-1], p3.local_cells[-1])
    assert_arrays_equal(a.local_cells, numpy.append(p1.local_cells, (p2.local_cells, p3.local_cells)))
コード例 #37
0
def test_tset_with_array_values():
    p = MockPopulation()
    p._set_array = Mock()
    spike_times = numpy.linspace(0.0, 1000.0, num=10 * p.size).reshape(
        (p.size, 10))
    p.tset("spike_times", spike_times)
    call_args = p._set_array.call_args[1]['spike_times']
    assert_equal(call_args.shape, spike_times[p._mask_local].shape)
    assert_arrays_equal(call_args.flatten(),
                        spike_times[p._mask_local].flatten())
コード例 #38
0
ファイル: test_core.py プロジェクト: agravier/pynn
def test_apply_function_to_functional_array():
    input = lambda i,j: 2*i + j
    m0 = LazyArray(input, shape=(4,3))
    f = lambda m: 2*m + 3
    m1 = f(m0)
    assert_arrays_equal(m1.evaluate(),
                        numpy.array([[3, 5, 7],
                                     [7, 9, 11],
                                     [11, 13, 15],
                                     [15, 17, 19]]))
コード例 #39
0
ファイル: test_projection.py プロジェクト: agravier/pynn
def test_weight_histogram_no_args():
    p1 = MockPopulation()
    p2 = MockPopulation()
    prj = common.Projection(p1, p2, method=Mock())
    prj.getWeights = Mock(return_value=numpy.array(range(10)*42))
    n, bins = prj.weightHistogram(nbins=10)
    assert_equal(n.size, 10)
    assert_equal(bins.size, n.size+1)
    assert_arrays_equal(n, 42*numpy.ones(10))
    assert_equal(n.sum(), 420)
    assert_arrays_equal(bins, numpy.arange(0.0, 9.1, 0.9))
コード例 #40
0
ファイル: test_assembly.py プロジェクト: agravier/pynn
def test_all_cells():
    p1 = MockPopulation()
    p2 = MockPopulation()
    p3 = MockPopulation()
    a = Assembly(p1, p2, p3)
    assert_equal(a.all_cells.size,
                 p1.all_cells.size + p2.all_cells.size + p3.all_cells.size)
    assert_equal(a.all_cells[0], p1.all_cells[0])
    assert_equal(a.all_cells[-1], p3.all_cells[-1])
    assert_arrays_equal(
        a.all_cells, numpy.append(p1.all_cells, (p2.all_cells, p3.all_cells)))
コード例 #41
0
def test_weight_histogram_no_args():
    p1 = MockPopulation()
    p2 = MockPopulation()
    prj = common.Projection(p1, p2, method=Mock())
    prj.getWeights = Mock(return_value=numpy.array(range(10) * 42))
    n, bins = prj.weightHistogram(nbins=10)
    assert_equal(n.size, 10)
    assert_equal(bins.size, n.size + 1)
    assert_arrays_equal(n, 42 * numpy.ones(10))
    assert_equal(n.sum(), 420)
    assert_arrays_equal(bins, numpy.arange(0.0, 9.1, 0.9))
コード例 #42
0
ファイル: test_assembly.py プロジェクト: agravier/pynn
def test_mask_local():
    p1 = MockPopulation()
    p2 = MockPopulation()
    p3 = MockPopulation()
    a = Assembly(p1, p2, p3)
    assert_equal(a._mask_local.size,
                 p1._mask_local.size + p2._mask_local.size + p3._mask_local.size)
    assert_equal(a._mask_local[0], p1._mask_local[0])
    assert_equal(a._mask_local[-1], p3._mask_local[-1])
    assert_arrays_equal(a._mask_local, numpy.append(p1._mask_local, (p2._mask_local, p3._mask_local)))
    assert_arrays_equal(a.local_cells, a.all_cells[a._mask_local])
コード例 #43
0
ファイル: test_space.py プロジェクト: JoelChavas/PyNN
 def test_generator_for_infinite_space_with_3D_distances(self):
     s = space.Space()
     f = lambda i: self.ABCD[i]
     g = lambda j: self.ABCD[j]
     self.assertArraysEqual(s.distance_generator(f, g)(0, numpy.arange(4)),
                            numpy.array([0.0, sqrt(3), sqrt(3), sqrt(29)]))
     assert_arrays_equal(numpy.fromfunction(s.distance_generator(f, g), shape=(4, 4), dtype=int),
                         numpy.array([(0.0, sqrt(3), sqrt(3), sqrt(29)),
                                      (sqrt(3), 0.0, sqrt(12), sqrt(14)),
                                      (sqrt(3), sqrt(12), 0.0, sqrt(50.0)),
                                      (sqrt(29), sqrt(14), sqrt(50.0), 0.0)]))
コード例 #44
0
def issue241(sim):
    # "Nest SpikeSourcePoisson populations require all parameters to be passed to constructor"
    sim.setup()
    spike_train1 = sim.Population(1, sim.SpikeSourcePoisson, {'rate' : [5], 'start' : [1000], 'duration': [1234]})
    spike_train2 = sim.Population(2, sim.SpikeSourcePoisson, {'rate' : [5, 6], 'start' : [1000, 1001], 'duration': [1234, 2345]})
    spike_train3 = sim.Population(1, sim.SpikeSourcePoisson, {'rate' : [5], 'start' : [1000], 'duration': 1234})
    spike_train4 = sim.Population(1, sim.SpikeSourcePoisson, {'rate' : [5], 'start' : [1000]})
    spike_train5 = sim.Population(2, sim.SpikeSourcePoisson, {'rate' : [5, 6], 'start' : [1000, 1001]})
    assert_arrays_equal(spike_train2.get('duration'), numpy.array([1234, 2345]))
    assert_equal(spike_train3.get(['rate', 'start', 'duration']), [5, 1000, 1234])
    sim.end()
コード例 #45
0
 def test_generator_for_infinite_space_with_3D_distances(self):
     s = space.Space()
     def f(i): return self.ABCD[i]
     def g(j): return self.ABCD[j]
     self.assertArraysEqual(s.distance_generator(f, g)(0, np.arange(4)),
                            np.array([0.0, sqrt(3), sqrt(3), sqrt(29)]))
     assert_arrays_equal(np.fromfunction(s.distance_generator(f, g), shape=(4, 4), dtype=int),
                         np.array([(0.0, sqrt(3), sqrt(3), sqrt(29)),
                                      (sqrt(3), 0.0, sqrt(12), sqrt(14)),
                                      (sqrt(3), sqrt(12), 0.0, sqrt(50.0)),
                                      (sqrt(29), sqrt(14), sqrt(50.0), 0.0)]))
コード例 #46
0
def test_sample():
    orig_pv = populations.PopulationView
    populations.PopulationView = Mock()
    p = MockPopulation()
    rng = Mock()
    rng.permutation = Mock(
        return_value=numpy.array([7, 4, 8, 12, 0, 3, 9, 1, 2, 11, 5, 10, 6]))
    pv = p.sample(5, rng=rng)
    assert_arrays_equal(populations.PopulationView.call_args[0][1],
                        numpy.array([7, 4, 8, 12, 0]))
    populations.PopulationView = orig_pv
コード例 #47
0
ファイル: test_basepopulation.py プロジェクト: agravier/pynn
def test_rset():
    """Population.rset()"""
    p = MockPopulation()
    rd = Mock()
    rnums = numpy.arange(p.size)
    rd.next = Mock(return_value=rnums)
    p.tset = Mock()
    p.rset("cm", rd)
    rd.next.assert_called_with(**{'mask_local': False, 'n': p.size})
    call_args = p.tset.call_args
    assert_equal(call_args[0][0], 'cm')
    assert_arrays_equal(call_args[0][1], rnums)
コード例 #48
0
def test_initialize_random_distribution():
    p = MockPopulation()
    p.initial_values = {}
    p._set_initial_value_array = Mock()

    class MockRandomDistribution(random.RandomDistribution):
        def next(self, n, mask_local):
            return 42 * numpy.ones(n)[mask_local]

    p.initialize('v', MockRandomDistribution())
    assert_arrays_equal(p.initial_values['v'].evaluate(simplify=True),
                        42 * numpy.ones(p.local_size))
コード例 #49
0
def test_rset():
    """Population.rset()"""
    p = MockPopulation()
    rd = Mock()
    rnums = numpy.arange(p.size)
    rd.next = Mock(return_value=rnums)
    p.tset = Mock()
    p.rset("cm", rd)
    rd.next.assert_called_with(**{'mask_local': False, 'n': p.size})
    call_args = p.tset.call_args
    assert_equal(call_args[0][0], 'cm')
    assert_arrays_equal(call_args[0][1], rnums)
コード例 #50
0
ファイル: test_files.py プロジェクト: agravier/pynn
def test_NumpyBinaryFile():
    nbf = files.NumpyBinaryFile("tmp.npz", "w")
    data=[(0, 2.3),(1, 3.4),(2, 4.3)]
    metadata = {'a': 1, 'b': 9.99}
    nbf.write(data, metadata)
    nbf.close()
    
    nbf = files.NumpyBinaryFile("tmp.npz", "r")
    assert_equal(nbf.get_metadata(), metadata)
    assert_arrays_equal(nbf.read().flatten(), numpy.array(data).flatten())
    nbf.close()

    os.remove("tmp.npz")
コード例 #51
0
def test_NumpyBinaryFile():
    nbf = files.NumpyBinaryFile("tmp.npz", "w")
    data = [(0, 2.3), (1, 3.4), (2, 4.3)]
    metadata = {'a': 1, 'b': 9.99}
    nbf.write(data, metadata)
    nbf.close()

    nbf = files.NumpyBinaryFile("tmp.npz", "r")
    assert_equal(nbf.get_metadata(), metadata)
    assert_arrays_equal(nbf.read().flatten(), numpy.array(data).flatten())
    nbf.close()

    os.remove("tmp.npz")
コード例 #52
0
ファイル: test_basepopulation.py プロジェクト: agravier/pynn
def test_save_positions():
    import os
    orig_rank = MockPopulation._simulator.state.mpi_rank
    MockPopulation._simulator.state.mpi_rank = 0
    p = MockPopulation()
    p.all_cells = numpy.array([34, 45, 56, 67])
    p.positions = numpy.arange(12).reshape((4,3)).T
    output_file = Mock()
    p.save_positions(output_file)
    assert_arrays_equal(output_file.write.call_args[0][0],
                        numpy.array([[34, 0, 1, 2], [45, 3, 4, 5], [56, 6, 7, 8], [67, 9, 10, 11]]))
    assert_equal(output_file.write.call_args[0][1], {'population': p.label})
    # arguably, the first column should contain indices, not ids.
    MockPopulation._simulator.state.mpi_rank = orig_rank
コード例 #53
0
ファイル: test_space.py プロジェクト: sbillaudelle/PyNN
 def test_generator_for_infinite_space_with_3D_distances(self):
     s = space.Space()
     f = lambda i: self.ABCD[:, i]
     g = lambda j: self.ABCD[:, j]
     self.assertArraysEqual(
         s.distance_generator(f, g)(0, numpy.arange(4)),
         numpy.array([0.0, sqrt(3), sqrt(3),
                      sqrt(29)]))
     assert_arrays_equal(
         s.distance_generator(f, g)(numpy.arange(4), numpy.arange(4)),
         numpy.array([(0.0, sqrt(3), sqrt(3), sqrt(29)),
                      (sqrt(3), 0.0, sqrt(12), sqrt(14)),
                      (sqrt(3), sqrt(12), 0.0, sqrt(50.0)),
                      (sqrt(29), sqrt(14), sqrt(50.0), 0.0)]))
コード例 #54
0
ファイル: test_assembly.py プロジェクト: agravier/pynn
def test_mask_local():
    p1 = MockPopulation()
    p2 = MockPopulation()
    p3 = MockPopulation()
    a = Assembly(p1, p2, p3)
    assert_equal(
        a._mask_local.size,
        p1._mask_local.size + p2._mask_local.size + p3._mask_local.size)
    assert_equal(a._mask_local[0], p1._mask_local[0])
    assert_equal(a._mask_local[-1], p3._mask_local[-1])
    assert_arrays_equal(
        a._mask_local,
        numpy.append(p1._mask_local, (p2._mask_local, p3._mask_local)))
    assert_arrays_equal(a.local_cells, a.all_cells[a._mask_local])
コード例 #55
0
ファイル: test_population.py プロジェクト: agravier/pynn
def test_position_generator():
    p = MockPopulation(11, MockStandardCell)
    assert_arrays_equal(p.position_generator(0), p.positions[:, 0])
    assert_arrays_equal(p.position_generator(10), p.positions[:, 10])
    assert_arrays_equal(p.position_generator(-1), p.positions[:, 10])
    assert_arrays_equal(p.position_generator(-11), p.positions[:, 0])
    assert_raises(IndexError, p.position_generator, 11)
    assert_raises(IndexError, p.position_generator, -12)
コード例 #56
0
ファイル: test_population.py プロジェクト: agravier/pynn
def test_position_generator():
    p = MockPopulation(11, MockStandardCell)
    assert_arrays_equal(p.position_generator(0), p.positions[:,0])
    assert_arrays_equal(p.position_generator(10), p.positions[:,10])
    assert_arrays_equal(p.position_generator(-1), p.positions[:,10])
    assert_arrays_equal(p.position_generator(-11), p.positions[:,0])
    assert_raises(IndexError, p.position_generator, 11)
    assert_raises(IndexError, p.position_generator, -12)
コード例 #57
0
ファイル: test_files.py プロジェクト: HBPNeurorobotics/PyNN
def test_HDF5ArrayFile():
    if files.have_hdf5:
        h5f = files.HDF5ArrayFile("tmp.h5", "w")
        data = [(0, 2.3), (1, 3.4), (2, 4.3)]
        metadata = {'a': 1, 'b': 9.99}
        h5f.write(data, metadata)
        h5f.close()
        
        h5f = files.HDF5ArrayFile("tmp.h5", "r")
        assert_equal(h5f.get_metadata(), metadata)
        assert_arrays_equal(numpy.array(h5f.read()).flatten(),
                            numpy.array(data).flatten())
        h5f.close()
    
        os.remove("tmp.h5")
コード例 #58
0
ファイル: test_assembly.py プロジェクト: agravier/pynn
def test_save_positions():
    import os
    Assembly._simulator = MockSimulator
    Assembly._simulator.state.mpi_rank = 0
    p1 = MockPopulation()
    p2 = MockPopulation()
    p1.all_cells = numpy.array([34, 45])
    p2.all_cells = numpy.array([56, 67])
    p1.positions = numpy.arange(0,6).reshape((2,3)).T
    p2.positions = numpy.arange(6,12).reshape((2,3)).T
    a = Assembly(p1, p2, label="test")
    output_file = Mock()
    a.save_positions(output_file)
    assert_arrays_equal(output_file.write.call_args[0][0],
                        numpy.array([[34, 0, 1, 2], [45, 3, 4, 5], [56, 6, 7, 8], [67, 9, 10, 11]]))
    assert_equal(output_file.write.call_args[0][1], {'assembly': a.label})
    # arguably, the first column should contain indices, not ids.
    del Assembly._simulator
コード例 #59
0
ファイル: test_recording.py プロジェクト: costypetrisor/PyNN
def test_mix_procedural_and_oo(sim):
    # cf Issues #217, #234
    fn_proc = "test_write_procedural.pkl"
    fn_oo = "test_write_oo.pkl"
    sim.setup(timestep=0.1, min_delay=0.1)
    cells = sim.Population(5, sim.IF_cond_exp(i_offset=0.2))
    sim.record('v', cells, fn_proc)
    sim.run(10.0)
    cells.write_data(fn_oo)   # explicitly write data
    sim.end()                 # implicitly write data using filename provided previously

    data_proc = get_io(fn_proc).read()[0]
    data_oo = get_io(fn_oo).read()[0]
    assert_arrays_equal(data_proc.segments[0].analogsignalarrays[0],
                        data_oo.segments[0].analogsignalarrays[0])

    os.remove(fn_proc)
    os.remove(fn_oo)
コード例 #60
0
ファイル: test_nest.py プロジェクト: costypetrisor/PyNN
def test_tsodyks_markram_synapse():
    import nest
    sim = pyNN.nest
    sim.setup()
    spike_source = sim.Population(1, sim.SpikeSourceArray(spike_times=numpy.arange(10, 100, 10)))
    neurons = sim.Population(5, sim.IF_cond_exp(e_rev_I=-75, tau_syn_I=numpy.arange(0.2, 0.7, 0.1)))
    synapse_type = sim.TsodyksMarkramSynapse(U=0.04, tau_rec=100.0,
                                             tau_facil=1000.0, weight=0.01,
                                             delay=0.5)
    connector = sim.AllToAllConnector()
    prj = sim.Projection(spike_source, neurons, connector,
                         receptor_type='inhibitory',
                         synapse_type=synapse_type)
    neurons.record('gsyn_inh')
    sim.run(100.0)
    connections = nest.GetConnections(prj._sources.tolist(), synapse_model=prj.nest_synapse_model)
    tau_psc = numpy.array(nest.GetStatus(connections, 'tau_psc'))
    assert_arrays_equal(tau_psc, numpy.arange(0.2, 0.7, 0.1))