def test_connect_with_default_args_again(self, sim=sim):
        C = connectors.FixedProbabilityConnector(p_connect=0.5,
                                                 rng=MockRNG2(1 - np.array([1, 0, 0, 1,
                                                                               0, 0, 0, 1,
                                                                               1, 1, 0, 0,
                                                                               1, 0, 1, 0,
                                                                               1, 1, 0, 1]),
                                                              parallel_safe=True))
        syn = sim.StaticSynapse()
        prj = sim.Projection(self.p1, self.p2, C, syn)

        # 20 possible connections. Due to the mock RNG, only the following
        # are created (0,0), (3,0), (3,1), (0,2), (1,2), (0,3), (2,3), (0,4), (1,4), (3,4)
        # (note that the outer loop is over post-synaptic cells (columns), the inner loop over pre-synaptic (rows))
        assert_array_almost_equal(prj.get('delay', format='array'),
                                  np.array([[0.123,   nan, 0.123, 0.123, 0.123],
                                               [nan,   nan, 0.123,   nan, 0.123],
                                               [nan,   nan,   nan, 0.123,   nan],
                                               [0.123, 0.123,   nan,   nan, 0.123]]),
                                  9)
        self.assertEqual(prj.get(["weight", "delay"], format='list'),
                         [(0, 0, 0.0, 0.123),
                          (3, 0, 0.0, 0.123),
                          (3, 1, 0.0, 0.123),
                          (0, 2, 0.0, 0.123),
                          (1, 2, 0.0, 0.123),
                          (0, 3, 0.0, 0.123),
                          (2, 3, 0.0, 0.123),
                          (0, 4, 0.0, 0.123),
                          (1, 4, 0.0, 0.123),
                          (3, 4, 0.0, 0.123)
                          ])
 def test_connect_with_probability_one(self, sim=sim):
     C = connectors.FixedProbabilityConnector(p_connect=1.)
     syn = sim.StaticSynapse()
     prj = sim.Projection(self.p1, self.p2, C, syn)
     self.assertEqual(prj.get(["weight", "delay"], format='list'),
                      [(0, 0, 0.0, 0.123),
                       (1, 0, 0.0, 0.123),
                       (2, 0, 0.0, 0.123),
                       (3, 0, 0.0, 0.123),
                       (0, 1, 0.0, 0.123),
                       (1, 1, 0.0, 0.123),
                       (2, 1, 0.0, 0.123),
                       (3, 1, 0.0, 0.123),
                       (0, 2, 0.0, 0.123),
                       (1, 2, 0.0, 0.123),
                       (2, 2, 0.0, 0.123),
                       (3, 2, 0.0, 0.123),
                       (0, 3, 0.0, 0.123),
                       (1, 3, 0.0, 0.123),
                       (2, 3, 0.0, 0.123),
                       (3, 3, 0.0, 0.123),
                       (0, 4, 0.0, 0.123),
                       (1, 4, 0.0, 0.123),
                       (2, 4, 0.0, 0.123),
                       (3, 4, 0.0, 0.123),
                       ])
Exemple #3
0
    def test_connect_with_default_args_again(self):
        C = connectors.FixedProbabilityConnector(p_connect=0.5,
                                                 rng=MockRNG2(1 - numpy.array([1, 0, 0, 1,
                                                                               0, 0, 0, 1,
                                                                               1, 1, 0, 0,
                                                                               1, 0, 1, 0,
                                                                               1, 1, 0, 1]),
                                                              parallel_safe=True))
        syn = sim.StaticSynapse()
        prj = sim.Projection(self.p1, self.p2, C, syn)

        # 20 possible connections. Due to the mock RNG, only the following
        # are created (0,0), (3,0), (3,1), (0,2), (1,2), (0,3), (2,3), (0,4), (1,4), (3,4)
        # of these, (3,1), (0,3), (2,3) are created on this node
        # (note that the outer loop is over post-synaptic cells (columns), the inner loop over pre-synaptic (rows))
        nan = numpy.nan
        assert_array_almost_equal(prj.get('delay', format='array', gather=False),
                                  numpy.array([[nan, nan,   nan, 0.123, nan],
                                               [nan, nan,   nan, nan,   nan],
                                               [nan, nan,   nan, 0.123, nan],
                                               [nan, 0.123, nan, nan,   nan]]),
                                  9)
        self.assertEqual(prj.get(["weight", "delay"], format='list', gather=False),  # use gather False because we are faking the MPI
                         [(3, 1, 0.0, 0.123),
                          (0, 3, 0.0, 0.123),
                          (2, 3, 0.0, 0.123)])
Exemple #4
0
 def test_connect_with_random_delays_parallel_safe(self):
     rd = random.RandomDistribution('uniform', [0.1, 1.1], rng=MockRNG(start=1.0, delta=0.2, parallel_safe=True))
     syn = sim.StaticSynapse(delay=rd)
     C = connectors.FixedProbabilityConnector(p_connect=0.75, rng=MockRNG(delta=0.1))
     prj = sim.Projection(self.p1, self.p2, C, syn)
     self.assertEqual(prj.get(["weight", "delay"], format='list', gather=False),  # use gather False because we are faking the MPI
                      [(0, 1, 0.0, 1.0+0.2*4),
                       (1, 1, 0.0, 1.0+0.2*5),
                       (2, 1, 0.0, 1.0+0.2*6),
                       (3, 1, 0.0, 1.0+0.2*7)])
Exemple #5
0
 def test_connect_with_weight_function(self):
     C = connectors.FixedProbabilityConnector(p_connect=0.75,
                                              rng=MockRNG(delta=0.1))
     syn = sim.StaticSynapse(weight=lambda d: 0.1*d)
     prj = sim.Projection(self.p1, self.p2, C, syn)
     self.assertEqual(prj.get(["weight", "delay"], format='list', gather=False),  # use gather False because we are faking the MPI
                      [(0, 1, 0.1, 0.123),
                       (1, 1, 0.0, 0.123),
                       (2, 1, 0.1, 0.123),
                       (3, 1, 0.2, 0.123)])
Exemple #6
0
 def test_connect_with_default_args(self):
     C = connectors.FixedProbabilityConnector(p_connect=0.75)
     C.progressbar = Mock()
     C.progression = Mock()
     C.connect(self.prj)
     # 20 possible connections. Due to the mock RNG, only the
     # first 8 are created (17, 79), (17, 80), (17,81), (17,82), (17,83), (18,79), (18,80), (18,81)
     # of these, (17,80), (17,82), (18,80) are created on this node
     assert_equal(self.prj.connections, [(17, 80, 0.0, MIN_DELAY),
                                         (17, 82, 0.0, MIN_DELAY),
                                         (18, 80, 0.0, MIN_DELAY)])
Exemple #7
0
    def test_connect_with_default_args(self):
        C = connectors.FixedProbabilityConnector(p_connect=0.75,
                                                 rng=MockRNG(delta=0.1, parallel_safe=True))
        syn = sim.StaticSynapse()
        prj = sim.Projection(self.p1, self.p2, C, syn)

        # 20 possible connections. Due to the mock RNG, only the
        # first 8 are created (0,0), (1,0), (2,0), (3,0), (0,1), (1,1), (2,1), (3,1)
        # of these, (0,1), (1,1), (2,1), (3,1) are created on this node
        self.assertEqual(prj.get(["weight", "delay"], format='list', gather=False),  # use gather False because we are faking the MPI
                         [(0, 1, 0.0, 0.123),
                          (1, 1, 0.0, 0.123),
                          (2, 1, 0.0, 0.123),
                          (3, 1, 0.0, 0.123)])
    def test_connect_with_probability_1(self, sim=sim):
        # see https://github.com/NeuralEnsemble/PyNN/issues/309
        C = connectors.FixedProbabilityConnector(p_connect=1,
                                                 rng=MockRNG(
                                                     delta=0.01,
                                                     parallel_safe=True))
        syn = sim.StaticSynapse()
        prj = sim.Projection(self.p1, self.p2, C, syn)

        # 20 connections, only some of which are created on this node
        self.assertEqual(
            prj.get(["weight", "delay"], format='list', gather=False
                    ),  # use gather False because we are faking the MPI
            [(0, 1, 0.0, 0.123), (1, 1, 0.0, 0.123), (2, 1, 0.0, 0.123),
             (3, 1, 0.0, 0.123), (0, 3, 0.0, 0.123), (1, 3, 0.0, 0.123),
             (2, 3, 0.0, 0.123), (3, 3, 0.0, 0.123)])
 def test_connect_weight_function_and_one_post_synaptic_neuron_not_connected(self, sim=sim):
     C = connectors.FixedProbabilityConnector(p_connect=0.8,
                                              rng=MockRNG(delta=0.05))
     syn = sim.StaticSynapse(weight=lambda d: 0.1 * d)
     prj = sim.Projection(self.p1, self.p2, C, syn)
     assert_array_almost_equal(prj.get(["weight", "delay"], format='array'),
                               np.array([
                                   [[0., 0.1, 0.2, 0.3, nan],
                                    [0.1,  0., 0.1, 0.2, nan],
                                       [0.2, 0.1, 0.0, 0.1, nan],
                                       [0.3, 0.2, 0.1, 0.0, nan]],
                                   [[0.123, 0.123, 0.123, 0.123, nan],
                                    [0.123, 0.123,   0.123, 0.123, nan],
                                    [0.123, 0.123,   0.123, 0.123, nan],
                                    [0.123, 0.123,   0.123, 0.123, nan]]
                               ]),
                               9)
Exemple #10
0
 def test_connect_with_random_delays_parallel_safe(self):
     rd = random.RandomDistribution('uniform', low=0.1, high=1.1, rng=MockRNG(start=1.0, delta=0.2, parallel_safe=True))
     syn = sim.StaticSynapse(delay=rd)
     C = connectors.FixedProbabilityConnector(p_connect=0.5,
                                              rng=MockRNG2(1 - numpy.array([1, 0, 0, 1,
                                                                            0, 0, 0, 1,
                                                                            1, 1, 0, 0,
                                                                            1, 0, 1, 0,
                                                                            1, 1, 0, 1]),
                                                           parallel_safe=True))
     prj = sim.Projection(self.p1, self.p2, C, syn)
     nan = numpy.nan
     assert_array_almost_equal(prj.get('delay', format='array', gather=False),
                               numpy.array([[nan, nan, nan, 2.0, nan],
                                            [nan, nan, nan, nan, nan],
                                            [nan, nan, nan, 2.2, nan],
                                            [nan, 1.4, nan, nan, nan]]),
                               9)
    def test_connect_with_default_args(self, sim=sim):
        C = connectors.FixedProbabilityConnector(p_connect=0.85,
                                                 rng=MockRNG(delta=0.1, parallel_safe=True))
        syn = sim.StaticSynapse()
        prj = sim.Projection(self.p1, self.p2, C, syn)

        # 20 possible connections. Due to the mock RNG, only the
        # first 9 are created (0,0), (1,0), (2,0), (3,0), (0,1), (1,1), (2,1), (3,1), (0,2)
        self.assertEqual(prj.get(["weight", "delay"], format='list'),
                         [(0, 0, 0.0, 0.123),
                          (1, 0, 0.0, 0.123),
                          (2, 0, 0.0, 0.123),
                          (3, 0, 0.0, 0.123),
                          (0, 1, 0.0, 0.123),
                          (1, 1, 0.0, 0.123),
                          (2, 1, 0.0, 0.123),
                          (3, 1, 0.0, 0.123),
                          (0, 2, 0.0, 0.123)
                          ])
    def test_connect_with_weight_function(self, sim=sim):
        C = connectors.FixedProbabilityConnector(p_connect=0.85,
                                                 rng=MockRNG(delta=0.1))
        syn = sim.StaticSynapse(weight=lambda d: 0.1 * d)
        prj = sim.Projection(self.p1, self.p2, C, syn)

        # 20 possible connections. Due to the mock RNG, only the
        # first 9 are created (0,0), (1,0), (2,0), (3,0), (0,1), (1,1), (2,1), (3,1), (0,2)
        assert_array_almost_equal(prj.get(["weight", "delay"], format='array'),
                                  np.array([
                                      [[0., 0.1, 0.2, nan, nan],
                                       [0.1,  0., nan, nan, nan],
                                          [0.2, 0.1, nan, nan, nan],
                                          [0.3, 0.2, nan, nan, nan]],
                                      [[0.123, 0.123, 0.123, nan, nan],
                                       [0.123, 0.123,   nan, nan, nan],
                                       [0.123, 0.123,   nan, nan, nan],
                                       [0.123, 0.123,   nan, nan, nan]]
                                  ]),
                                  9)
 def test_connect_with_random_delays_parallel_safe(self, sim=sim):
     rd = random.RandomDistribution('uniform', low=0.1, high=1.1,
                                    rng=MockRNG(start=1.0, delta=0.2, parallel_safe=True))
     syn = sim.StaticSynapse(delay=rd)
     C = connectors.FixedProbabilityConnector(p_connect=0.5,
                                              rng=MockRNG2(1 - np.array([1, 0, 0, 1,
                                                                            0, 0, 0, 1,
                                                                            1, 1, 0, 0,
                                                                            1, 0, 1, 0,
                                                                            1, 1, 0, 1]),
                                                           parallel_safe=True))
     prj = sim.Projection(self.p1, self.p2, C, syn)
     # 20 possible connections. Due to the mock RNG, only the following
     # are created (0,0), (3,0), (3,1), (0,2), (1,2), (0,3), (2,3), (0,4), (1,4), (3,4)
     # (note that the outer loop is over post-synaptic cells (columns), the inner loop over pre-synaptic (rows))
     assert_array_almost_equal(prj.get('delay', format='array'),
                               np.array([[1.0,   nan,   1.6,   2.0,   2.4],
                                            [nan,   nan,   1.8,   nan,   2.6],
                                            [nan,   nan,   nan,   2.2,   nan],
                                            [1.2,   1.4,   nan,   nan,   2.8]]),
                               9)