Intuitively understanding connections

Hello and happy new year,

I have created 2 ensembles of one neuron each and connected the neurons to each other. I inserted a probe in the connection using this code:

import matplotlib.pyplot as plt

import numpy as np

import nengo
from nengo.utils.matplotlib import rasterplot
import nengo_loihi
in_val = 2
with nengo.Network() as net:
    input = nengo.Node(lambda t: in_val, label='q')
    ens1 = nengo.Ensemble(1, dimensions=1)
    ens2 = nengo.Ensemble(2, dimensions=1)

    # Neuron to neuron
    #weights = np.random.uniform(size=(ens2.n_neurons, ens1.n_neurons))
    weights = [[1],[10]]
    conn1 = nengo.Connection(ens1.neurons, ens2.neurons, transform=weights)
    conn2 = nengo.Connection(input, ens1)
    output = nengo.Node(size_in=1, label='outp')
    conn3 = nengo.Connection(ens2,output)

with net:
    probe1 = nengo.Probe(conn1, "output", synapse=0.01)
    probe2 = nengo.Probe(output, synapse=0.01)

with nengo.Simulator(net) as sim:



Every time I run the code, I get a different plot even though the input and starting weights are the same. Can someone explain why the results are different each time?

1 Like

@arvoelke Is there any chance you could provide some insight or resources that would be helpful on understanding this?

1 Like

Happy New Year!

Ensembles in Nengo are generated with some random parameters, namely concerning the tuning/response curves. Set the seed on your network when you create it, e.g. nengo.Network(seed=0).


Hi Eric, thank you for the reply!
Another question that is somewhat related: I have an ensemble of 1000 neurons and only want to operate it as a 100-neuron ensemble. For this reason, I set the connection to the 900 neurons to zero and replaced the weights in the first 100 neurons with 100-neuron weight values. However, I still don’t get a correct result. I think this may be due to the fact that I am connecting an input Node to the input ensemble. Is there a way to connect a Node object to the first 100 neurons of an ensemble, instead of using an all-to-all connection?

Thank you in advance.

Yes, you can slice the ensemble.neurons attribute.

Hi Eric,

This works for ensemble-to-enseble connections, but when I use node-to-ensemble connections such as this one:
conn2 = nengo.Connection(input,ens1.neurons[:100])
I get the following error:

nengo.exceptions.ValidationError: Connection.transform: Transform output size (1) not equal to connection output size (100)

Should I create a custom weight matrix to use as a transform? If so, what should it be initialized to?
I have also tried making a node-to-small-ensemble connection, getting the weights and using it as a transform, but it doesn’t work.
At first I also tried modifying the ensemble-to-ensemble connection weights only, but in that case I get a wrong output.

Could you give me some example code of a linear transformation with 2 1000-neuron examples, that are used as 100-neuron ensembles after a few timesteps?

Hi @Eric,
I have been trying to figure this out for a few days now but have achieved no results. Is there any chance you could offer some insight?

So the first step is to have a decent understanding of the NEF algorithm. In brief, we use randomly generated encoders to connect into an ensemble (from e.g. a node), and then learned decoders out of that ensemble.

The easiest way to do what you want I think is to generate your own encoders. Then, you can do the connection into all 1000 neurons with the full 1000 encoders, and when you connect to the first 100 neurons, just use the first 100 encoders. This will keep each neuron having the same encoders.

Then you just need to figure out how you want to decode the activities from those 100 neurons.

Hi Eric,

Unfortunately, I still havent figured out how to write the encoders and decoders for this particular use case. Is there any chance you could provide an example or some additional resources to point me in the right direction?