def test_weights_built(self):
        """Test a build using a weights-based solver."""
        # Create the network
        with nengo.Network():
            a = nengo.Ensemble(200, 2)
            b = nengo.Ensemble(400, 2)
            a_b = nengo.Connection(a,
                                   b,
                                   solver=nengo.solvers.Lstsq(weights=True))

        # Create the model and built the pre-synaptic Ensemble
        model = builder.Model()
        model.rng = np.random
        model.seeds[a] = 1
        model.seeds[b] = 2
        model.seeds[a_b] = 3
        ensemble.build_ensemble(model, a)
        ensemble.build_ensemble(model, b)

        # Now build the connection and check that the params seem sensible
        ensemble.build_from_ensemble_connection(model, a_b)

        # Check that the params stored in the model are correct
        params = model.params[a_b]
        assert params.decoders.shape == (200, 400)
    def test_weights_built(self):
        """Test a build using a weights-based solver."""
        # Create the network
        with nengo.Network():
            a = nengo.Ensemble(200, 2)
            b = nengo.Ensemble(400, 2)
            a_b = nengo.Connection(
                a, b, solver=nengo.solvers.Lstsq(weights=True)
            )

        # Create the model and built the pre-synaptic Ensemble
        model = builder.Model()
        model.rng = np.random
        model.seeds[a] = 1
        model.seeds[b] = 2
        model.seeds[a_b] = 3
        ensemble.build_ensemble(model, a)
        ensemble.build_ensemble(model, b)

        # Now build the connection and check that the params seem sensible
        ensemble.build_from_ensemble_connection(model, a_b)

        # Check that the params stored in the model are correct
        params = model.params[a_b]
        assert params.decoders.shape == (200, 400)
    def test_to_global_inhibition(self):
        """Test that the transmission parameters are modified for a global
        inhibition connection.
        """
        # Create the network
        with nengo.Network():
            a = nengo.Ensemble(200, 3)
            b = nengo.Ensemble(300, 1)
            a_b = nengo.Connection(a,
                                   b.neurons,
                                   transform=[[1.0, 0.5, 0.2]] * b.n_neurons)

        # Create the model and built the pre-synaptic Ensemble
        model = builder.Model()
        model.rng = np.random
        model.seeds[a] = 1
        model.seeds[a_b] = 2
        ensemble.build_ensemble(model, a)

        # Now build the connection and check that the params seem sensible
        tparams = ensemble.build_from_ensemble_connection(model, a_b)
        assert tparams.decoders.shape == (1, 200)

        # Check that the params stored in the model are correct
        params = model.params[a_b]
        assert np.all(params.transform == a_b.transform)
    def test_standard_build(self):
        """Test relatively standard build."""
        # Create the network
        with nengo.Network():
            a = nengo.Ensemble(200, 3)
            b = nengo.Node(lambda t, x: None, size_in=2)
            a_b = nengo.Connection(a[:2],
                                   b,
                                   transform=np.array([[0.5, 0], [0.0, 0.0]]))

        # Create the model and built the pre-synaptic Ensemble
        model = builder.Model()
        model.rng = np.random
        model.seeds[a] = 1
        model.seeds[a_b] = 2
        ensemble.build_ensemble(model, a)

        # Now build the connection and check that the params seem sensible
        tparams = ensemble.build_from_ensemble_connection(model, a_b)
        assert tparams.decoders.shape == (2, 200)
        assert np.all(tparams.decoders[1, :] == 0.0)

        # Check that the params stored in the model are correct
        params = model.params[a_b]
        assert params.decoders.shape == (200, 2)
        assert np.all(params.transform == a_b.transform)
        assert np.all(params.eval_points == model.params[a].eval_points)
        assert params.solver_info is not None
    def test_standard_build(self):
        """Test relatively standard build."""
        # Create the network
        with nengo.Network():
            a = nengo.Ensemble(200, 3)
            b = nengo.Node(lambda t, x: None, size_in=2)
            a_b = nengo.Connection(a[:2], b, transform=np.array([[0.5, 0],
                                                                 [0.0, 0.0]]))

        # Create the model and built the pre-synaptic Ensemble
        model = builder.Model()
        model.rng = np.random
        model.seeds[a] = 1
        model.seeds[a_b] = 2
        ensemble.build_ensemble(model, a)

        # Now build the connection and check that the params seem sensible
        tparams = ensemble.build_from_ensemble_connection(model, a_b)
        assert tparams.full_decoders.shape == (2, 200)
        assert np.all(tparams.full_decoders[1, :] == 0.0)

        # Check that the params stored in the model are correct
        params = model.params[a_b]
        assert params.decoders.shape == (200, 2)
        assert np.all(params.transform == a_b.transform)
        assert np.all(params.eval_points == model.params[a].eval_points)
        assert params.solver_info is not None
    def test_to_global_inhibition(self):
        """Test that the transmission parameters are modified for a global
        inhibition connection.
        """
        # Create the network
        with nengo.Network():
            a = nengo.Ensemble(200, 3)
            b = nengo.Ensemble(300, 1)
            a_b = nengo.Connection(a, b.neurons,
                                   transform=[[1.0, 0.5, 0.2]]*b.n_neurons)

        # Create the model and built the pre-synaptic Ensemble
        model = builder.Model()
        model.rng = np.random
        model.seeds[a] = 1
        model.seeds[a_b] = 2
        ensemble.build_ensemble(model, a)

        # Now build the connection and check that the params seem sensible
        tparams = ensemble.build_from_ensemble_connection(model, a_b)
        assert tparams.decoders.shape == (1, 200)

        # Check that the params stored in the model are correct
        params = model.params[a_b]
        assert np.all(params.transform == a_b.transform)