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_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_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)
示例#4
0
    def test_build_ensemble_lif(self, n_neurons, size_in):
        """Test building LIF ensembles."""
        # Create a Nengo ensemble to build
        ens = nengo.Ensemble(n_neurons, size_in, add_to_container=False)

        # Create a model
        model = builder.Model()
        model.seeds[ens] = 1

        # Build the ensemble
        ensemble.build_ensemble(model, ens)

        # Check that the built ensemble was inserted into the params and that
        # the parameters are (loosely) as expected.
        assert model.params[ens].eval_points is not None
        assert (model.params[ens].encoders.shape ==
                model.params[ens].scaled_encoders.shape ==
                (n_neurons, size_in))
        assert (model.params[ens].intercepts.shape ==
                model.params[ens].max_rates.shape ==
                model.params[ens].gain.shape ==
                model.params[ens].bias.shape == (n_neurons, ))

        # Check that a new object was inserted into the objects dictionary
        assert isinstance(model.object_operators[ens],
                          operators.EnsembleLIF)
    def test_build_ensemble_lif(self, n_neurons, size_in):
        """Test building LIF ensembles."""
        # Create a Nengo ensemble to build
        ens = nengo.Ensemble(n_neurons, size_in, add_to_container=False)

        # Create a model
        model = builder.Model()
        model.seeds[ens] = 1

        # Build the ensemble
        ensemble.build_ensemble(model, ens)

        # Check that the built ensemble was inserted into the params and that
        # the parameters are (loosely) as expected.
        assert model.params[ens].eval_points is not None
        assert (model.params[ens].encoders.shape ==
                model.params[ens].scaled_encoders.shape ==
                (n_neurons, size_in))
        assert (model.params[ens].intercepts.shape ==
                model.params[ens].max_rates.shape ==
                model.params[ens].gain.shape == model.params[ens].bias.shape ==
                (n_neurons, ))

        # Check that a new object was inserted into the objects dictionary
        assert isinstance(model.object_operators[ens], operators.EnsembleLIF)
    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_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)
    def test_only_bias(self):
        """Build an ensemble with only bias specified."""
        # Create a Nengo ensemble to build
        ens = nengo.Ensemble(1, 1, add_to_container=False)
        ens.bias = np.array([-0.5])

        # Create a model
        model = builder.Model()
        model.seeds[ens] = 1

        # Build the ensemble
        ensemble.build_ensemble(model, ens)

        # Check that parameters are (loosely) as expected.
        assert model.params[ens].bias == ens.bias  # pragma : no cover
示例#10
0
    def test_only_bias(self):
        """Build an ensemble with only bias specified."""
        # Create a Nengo ensemble to build
        ens = nengo.Ensemble(1, 1, add_to_container=False)
        ens.bias = np.array([-0.5])

        # Create a model
        model = builder.Model()
        model.seeds[ens] = 1

        # Build the ensemble
        ensemble.build_ensemble(model, ens)

        # Check that parameters are (loosely) as expected.
        assert model.params[ens].bias == ens.bias  # pragma : no cover
    def test_with_encoders_and_gain_bias(self):
        """Test that the encoders we provide are used (albeit scaled)"""
        # Create a Nengo ensemble to build
        ens = nengo.Ensemble(1, 1, add_to_container=False)
        ens.radius = 10.0
        ens.encoders = np.array([[1.0]])
        ens.gain = np.array([0.5])
        ens.bias = np.array([0.0])

        # Create a model
        model = builder.Model()
        model.seeds[ens] = 1

        # Build the ensemble
        ensemble.build_ensemble(model, ens)

        # Check that parameters are (loosely) as expected.
        assert model.params[ens].encoders == ens.encoders
        assert model.params[ens].gain == ens.gain
        assert model.params[ens].bias == ens.bias
        assert model.params[ens].scaled_encoders == ens.encoders * (0.5 / 10)
示例#12
0
    def test_with_encoders_and_gain_bias(self):
        """Test that the encoders we provide are used (albeit scaled)"""
        # Create a Nengo ensemble to build
        ens = nengo.Ensemble(1, 1, add_to_container=False)
        ens.radius = 10.0
        ens.encoders = np.array([[1.0]])
        ens.gain = np.array([0.5])
        ens.bias = np.array([0.0])

        # Create a model
        model = builder.Model()
        model.seeds[ens] = 1

        # Build the ensemble
        ensemble.build_ensemble(model, ens)

        # Check that parameters are (loosely) as expected.
        assert model.params[ens].encoders == ens.encoders
        assert model.params[ens].gain == ens.gain
        assert model.params[ens].bias == ens.bias
        assert model.params[ens].scaled_encoders == ens.encoders * (0.5 / 10)