Exemple #1
0
 def test_connect_with_no_self_connections(self):
     connector = AllToAllConnector(allow_self_connections=False,
                                   weights=0.1)
     prj = MockProjection(self.p1, self.p1, self.rng, "excitatory")
     connector.connect(prj)
     self.assertEqual(prj.n, self.p1.size * (self.p1.size - 1))
     self.assertEqual(prj.connection_manager.weights, [[0.1]] * prj.n)
Exemple #2
0
 def test_connect_with_weight_array(self):
     w_in = numpy.arange(self.p1.size*self.p2.size, 0.0, -1.0).reshape(self.p1.size, self.p2.size)
     connector = AllToAllConnector(weights=w_in)
     prj = MockProjection(self.p1, self.p2, self.rng, "excitatory")
     connector.connect(prj)
     self.assertEqual(prj.n, self.p1.size*self.p2.size)
     assert_arrays_almost_equal(numpy.array(prj.connection_manager.weights), w_in.flatten(), 1e-6)
Exemple #3
0
 def test_connect_with_no_self_connections(self):
     connector = AllToAllConnector(allow_self_connections=False,
                                   weights=0.1)
     prj = MockProjection(self.p1, self.p1, self.rng, "excitatory")
     connector.connect(prj)
     self.assertEqual(prj.n, self.p1.size*(self.p1.size-1))
     self.assertEqual(prj.connection_manager.weights, [[0.1]]*prj.n)
Exemple #4
0
 def test_connect_with_single_weight(self):
     connector = AllToAllConnector(allow_self_connections=True,
                                   weights=0.1)
     prj = MockProjection(self.p1, self.p2, self.rng, "excitatory")
     connector.connect(prj)
     self.assertEqual(prj.n, self.p1.size*self.p2.size)
     self.assertEqual(prj.connection_manager.weights, [[0.1]]*prj.n)
Exemple #5
0
 def __init__(self,
              allow_self_connections=True,
              safe=True,
              verbose=None,
              callbacks=None):
     """
     :param allow_self_connections: \
         if the connector is used to connect a Population to itself, this\
         flag determines whether a neuron is allowed to connect to itself,\
         or only to other neurons in the Population.
     :type allow_self_connections: bool
     :param safe: if True, check that weights and delays have valid\
         values. If False, this check is skipped.
     :param verbose:
     :param callbacks:
     """
     CommonAllToAllConnector.__init__(
         self,
         allow_self_connections=allow_self_connections,
         safe=safe,
         verbose=verbose)
     PyNNAllToAllConnector.__init__(
         self,
         allow_self_connections=allow_self_connections,
         safe=safe,
         callback=callbacks)
Exemple #6
0
 def test_connect_with_random_weights(self):
     connector = AllToAllConnector(
         weights=RandomDistribution("uniform", [0.3, 0.4], rng=self.rng))
     prj = MockProjection(self.p1, self.p2, self.rng, "excitatory")
     connector.connect(prj)
     self.assertEqual(prj.n, self.p1.size * self.p2.size)
     assert_arrays_almost_equal(numpy.array(prj.connection_manager.weights),
                                numpy.arange(0, prj.n), 1e-6)
Exemple #7
0
 def test_connect_with_weight_array(self):
     w_in = numpy.arange(self.p1.size * self.p2.size, 0.0,
                         -1.0).reshape(self.p1.size, self.p2.size)
     connector = AllToAllConnector(weights=w_in)
     prj = MockProjection(self.p1, self.p2, self.rng, "excitatory")
     connector.connect(prj)
     self.assertEqual(prj.n, self.p1.size * self.p2.size)
     assert_arrays_almost_equal(numpy.array(prj.connection_manager.weights),
                                w_in.flatten(), 1e-6)
Exemple #8
0
 def test_connect_with_distance_dependent_weights_simple(self):
     self.p1.positions = numpy.zeros((3,self.p1.size))
     connector = AllToAllConnector(weights="d*d")
     prj = MockProjection(self.p1, self.p2, self.rng, "excitatory")
     connector.connect(prj)
     self.assertEqual(prj.n, self.p1.size*self.p2.size)
     w_expected = numpy.array([w*w for w in range(self.p2.size)]*self.p1.size, float).flatten()
     assert_arrays_almost_equal(numpy.array(prj.connection_manager.weights),
                                w_expected, 1e-6)
Exemple #9
0
 def test_connect_with_distance_dependent_weights_simple(self):
     self.p1.positions = numpy.zeros((3, self.p1.size))
     connector = AllToAllConnector(weights="d*d")
     prj = MockProjection(self.p1, self.p2, self.rng, "excitatory")
     connector.connect(prj)
     self.assertEqual(prj.n, self.p1.size * self.p2.size)
     w_expected = numpy.array([w * w
                               for w in range(self.p2.size)] * self.p1.size,
                              float).flatten()
     assert_arrays_almost_equal(numpy.array(prj.connection_manager.weights),
                                w_expected, 1e-6)
Exemple #10
0
 def __init__(
     self,
     allow_self_connections=True,
     safe=True,
     callback=None,
 ):
     GeNNConnectorMixin.__init__(self, use_sparse=False)
     AllToAllPyNN.__init__(self,
                           allow_self_connections=allow_self_connections,
                           safe=safe,
                           callback=callback)
Exemple #11
0
 def test_connect_with_single_weight(self):
     connector = AllToAllConnector(allow_self_connections=True, weights=0.1)
     prj = MockProjection(self.p1, self.p2, self.rng, "excitatory")
     connector.connect(prj)
     self.assertEqual(prj.n, self.p1.size * self.p2.size)
     self.assertEqual(prj.connection_manager.weights, [[0.1]] * prj.n)
Exemple #12
0
 def test_create_with_delays_None(self):
     connector = AllToAllConnector(weights=0.1, delays=None)
     self.assertEqual(connector.weights, 0.1)
     self.assertEqual(connector.delays, common.get_min_delay())
     self.assert_(connector.safe)
     self.assert_(connector.allow_self_connections)
Exemple #13
0
 def test_connect_with_random_weights(self):
     connector = AllToAllConnector(weights=RandomDistribution("uniform", [0.3, 0.4], rng=self.rng))
     prj = MockProjection(self.p1, self.p2, self.rng, "excitatory")
     connector.connect(prj)
     self.assertEqual(prj.n, self.p1.size*self.p2.size)
     assert_arrays_almost_equal(numpy.array(prj.connection_manager.weights), numpy.arange(0, prj.n), 1e-6)