예제 #1
0
    def test_global_inhibition_sink(self):
        """Test that sinks are correctly determined for connections which are
        global inhibition connections.
        """
        # Create a model with a global inhibition connection
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(200, 4)

            a_b = nengo.Connection(a, b.neurons, transform=[[1.0, 0.5]]*200)

        # Create a model with the Ensemble for b in it
        model = builder.Model()
        b_ens = operators.EnsembleLIF(b)
        model.object_operators[b] = b_ens

        decs = mock.Mock()
        evals = mock.Mock()
        si = mock.Mock()
        model.params[a_b] = builder.BuiltConnection(decs, evals, a_b.transform,
                                                    si)

        # Get the sink, check that an appropriate target is return
        sink = ensemble.get_neurons_sink(model, a_b)
        assert sink.target.obj is b_ens
        assert sink.target.port is ensemble.EnsembleInputPort.global_inhibition

        assert model.params[a_b].decoders is decs
        assert model.params[a_b].eval_points is evals
        assert model.params[a_b].solver_info is si
        assert np.all(model.params[a_b].transform == np.array([[1.0, 0.5]]))
        assert model.params[a_b].transform.shape == (1, 2)
    def test_arbitrary_neuron_sink(self, source):
        """Test that standard connections to neurons return an appropriate
        sink.

        We have no plan to support arbitrary connections to neurons, but we
        allow them at this stage because they may later become global
        inhibition connections when we optimise out passthrough Nodes.
        """
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(100, 4)

            if source == "neurons":
                a_b = nengo.Connection(a.neurons,
                                       b.neurons,
                                       transform=np.eye(100))
            else:
                a_b = nengo.Connection(a,
                                       b.neurons,
                                       transform=[[1.0, 0.5]] * 99 +
                                       [[0.5, 1.0]])

        # Create a model with the Ensemble for b in it
        model = builder.Model()
        b_ens = operators.EnsembleLIF(b)
        model.object_operators[b] = b_ens

        # Get the sink, check that an appropriate target is return
        sink = ensemble.get_neurons_sink(model, a_b)
        assert sink.target.obj is b_ens
        assert sink.target.port is ensemble.EnsembleInputPort.neurons
예제 #3
0
    def test_arbitrary_neuron_sink(self, source):
        """Test that standard connections to neurons return an appropriate
        sink.

        We have no plan to support arbitrary connections to neurons, but we
        allow them at this stage because they may later become global
        inhibition connections when we optimise out passthrough Nodes.
        """
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(100, 4)

            if source == "neurons":
                a_b = nengo.Connection(a.neurons, b.neurons,
                                       transform=np.eye(100))
            else:
                a_b = nengo.Connection(a, b.neurons,
                                       transform=[[1.0, 0.5]]*99 +
                                                 [[0.5, 1.0]])

        # Create a model with the Ensemble for b in it
        model = builder.Model()
        b_ens = operators.EnsembleLIF(b)
        model.object_operators[b] = b_ens

        # Get the sink, check that an appropriate target is return
        sink = ensemble.get_neurons_sink(model, a_b)
        assert sink.target.obj is b_ens
        assert sink.target.port is ensemble.EnsembleInputPort.neurons
예제 #4
0
    def test_arbitrary_neuron_sink(self):
        """We have no plan to support arbitrary connections to neurons."""
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(200, 4)

            a_b = nengo.Connection(a, b.neurons,
                                   transform=[[1.0, 0.5]]*199 + [[0.5, 1.0]])

        # Create a model with the Ensemble for b in it
        model = builder.Model()
        b_ens = operators.EnsembleLIF(b)
        model.object_operators[b] = b_ens

        # This should fail
        with pytest.raises(NotImplementedError):
            ensemble.get_neurons_sink(model, a_b)
예제 #5
0
    def test_neuron_sink(self):
        """Test that standard connections to neurons return an appropriate
        sink.
        """
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(100, 4)

            a_b = nengo.Connection(a.neurons, b.neurons, transform=np.eye(100))

        # Create a model with the Ensemble for b in it
        model = builder.Model()
        b_ens = operators.EnsembleLIF(b)
        model.object_operators[b] = b_ens

        # Get the sink, check that an appropriate target is return
        sink = ensemble.get_neurons_sink(model, a_b)
        assert sink.target.obj is b_ens
        assert sink.target.port is ensemble.EnsembleInputPort.neurons
    def test_global_inhibition_sink(self):
        """Test that sinks are correctly determined for connections which are
        global inhibition connections.
        """
        # Create a model with a global inhibition connection
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(200, 4)

            a_b = nengo.Connection(a, b.neurons, transform=[[1.0, 0.5]] * 200)

        # Create a model with the Ensemble for b in it
        model = builder.Model()
        b_ens = operators.EnsembleLIF(b)
        model.object_operators[b] = b_ens

        decs = mock.Mock()
        evals = mock.Mock()
        si = mock.Mock()

        # Get the sink, check that an appropriate target is return
        sink = ensemble.get_neurons_sink(model, a_b)
        assert sink.target.obj is b_ens
        assert sink.target.port is ensemble.EnsembleInputPort.global_inhibition
    def test_global_inhibition_sink(self):
        """Test that sinks are correctly determined for connections which are
        global inhibition connections.
        """
        # Create a model with a global inhibition connection
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(200, 4)

            a_b = nengo.Connection(a, b.neurons, transform=[[1.0, 0.5]]*200)

        # Create a model with the Ensemble for b in it
        model = builder.Model()
        b_ens = operators.EnsembleLIF(b)
        model.object_operators[b] = b_ens

        decs = mock.Mock()
        evals = mock.Mock()
        si = mock.Mock()

        # Get the sink, check that an appropriate target is return
        sink = ensemble.get_neurons_sink(model, a_b)
        assert sink.target.obj is b_ens
        assert sink.target.port is ensemble.EnsembleInputPort.global_inhibition