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
Пример #2
0
    def test_normal_source(self):
        # Create a network and standard model
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(200, 4)

            a_b = nengo.Connection(a, b[1:3])

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

        source = ensemble.get_ensemble_source(model, a_b)
        assert source.target.obj is a_ens
        assert source.target.port is OutputPort.standard
def test_neurons_source():
    """Test that neurons sources are sane."""
    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 a in it
    model = builder.Model()
    a_ens = operators.EnsembleLIF(a)
    model.object_operators[a] = a_ens

    # Get the source, check that an appropriate target is return
    source = ensemble.get_neurons_source(model, a_b)
    assert source.target.obj is a_ens
    assert source.target.port is ensemble.EnsembleOutputPort.neurons
Пример #4
0
    def test_encoder_learnt_sink(self):
        # Create a network and standard model
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(100, 2)

            a_b = nengo.Connection(a, b)
            a_b.learning_rule_type = nengo.Voja()

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

        sink = ensemble.get_ensemble_sink(model, a_b)
        assert sink.target.obj is b_ens
        assert sink.target.port is ensemble.EnsembleInputPort.learnt
    def test_constant_node_sink_with_slice(self):
        """Test that connections from constant valued Nodes to Ensembles are
        optimised out correctly.
        """
        # Create a network and standard model
        with nengo.Network():
            a = nengo.Node([0.5, 1.0])
            b = nengo.Ensemble(200, 2)

            a_b = nengo.Connection(a[0], b[1])

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

        # Check that no sink is created but that the direct input is modified
        assert np.all(b_ens.direct_input == np.zeros(2))
        assert ensemble.get_ensemble_sink(model, a_b) is None
        assert np.all(b_ens.direct_input == [0.0, 0.5])
    def test_normal_sink_for_process_node(self):
        """Test that sinks for most connections into Ensembles do nothing
        special.
        """
        # Create a network and standard model
        with nengo.Network():
            a = nengo.Node(nengo.processes.WhiteNoise(), size_out=4)
            b = nengo.Ensemble(200, 4)

            a_b = nengo.Connection(a, b)

        # 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_ensemble_sink(model, a_b)
        assert sink.target.obj is b_ens
        assert sink.target.port is InputPort.standard
Пример #7
0
    def test_decoder_learnt_source(self):
        # Create a network and standard model
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(100, 2)
            e = nengo.Ensemble(100, 2)

            a_b = nengo.Connection(a, b)
            a_b.learning_rule_type = nengo.PES()

            e_l = nengo.Connection(e, a_b.learning_rule)

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

        source = ensemble.get_ensemble_source(model, a_b)
        assert source.target.obj is a_ens
        assert source.target.port is ensemble.EnsembleOutputPort.learnt
    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
Пример #9
0
    def test_encoder_learning_rule_sink(self):
        """Test that sinks for most connections into Ensembles do nothing
        special.
        """
        # Create a network and standard model
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(100, 2)
            e = nengo.Ensemble(100, 1)

            a_b = nengo.Connection(a, b)
            a_b.learning_rule_type = nengo.Voja()

            e_l = nengo.Connection(e, a_b.learning_rule)

        # 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_learning_rule_sink(model, e_l)
        assert sink.target.obj is b_ens
        assert sink.target.port is a_b.learning_rule