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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)