How to implement W*x(t) + f(y(t-1)) in using nengo.Dense?

Hi,
I want to implement the following functionality using nengo,

y(t) = W*X(t) + f(y(t-1))

where * is multiply operator. nengo.Dense can be used to compute ‘W*X(t)’. And f(y(t-1)) is not constant and changes with the input at the previous time step. So I was wondering how to implement this using nengo. Also, I am looking for a solution that will also be compatible with nengo_loihi simulations. Any sample codes or references will be greatly appreciated.

Thanks in advance.

Hi @joshivm22,

To start, if you are looking for a solution that is compatible with NengoLoihi, it’ll be better to implement this function using nengo.Ensemble rather than nengo.Dense.

Now, let us examine the function you want to implement:

$y(t) = W \times X(t) + f(y(t-1))$

Looking at this function, we first notice that it is similar to this simpler form:

$y(t) = X(t) + y(t-1)$

This is the formulation for a integrator, which is known to be implementable in Nengo (see this example for the basic code, and this example for the explanation on how the different weights are derived). An integrator is simply:

tau_fdbk = 0.1

with nengo.Network() as model:
    in_node = nengo.Node(input_func)
    ens = nengo.Ensemble(50, 1)
    nengo.Connection(ens, ens, synapse=tau_fdbk)
    nengo.Connection(in_node, ens, transform=tau_fdbk, synapse=tau_fdbk)

Now let’s start modifying the integrator to implement the function you want. First, we modify the input so that instead of just $X(t)$, it’s $W \times X(t)$. This can be done by simply changing the transform matrix of the input connection to the integrator:

    nengo.Connection(in_node, ens, transform=tau_fdbk * W, synapse=tau_fdbk)

As for the last part of the modification, we need to do $f(y(t-1))$ instead of just $y(t-1)$, but this is also a straightforward change to the integrator. To do this, we can simply define a function on the recurrent connection of the integrator:

    nengo.Connection(ens, ens, synapse=tau_fdbk, function=f)

With both of these changes, the new implementation looks like:

tau_fdbk = 0.1

with nengo.Network() as model:
    in_node = nengo.Node(input_func)
    ens = nengo.Ensemble(50, 1)
    nengo.Connection(ens, ens, synapse=tau_fdbk, function=f)
    nengo.Connection(in_node, ens, transform=tau_fdbk * W, synapse=tau_fdbk)

Note that you’ll need to define the function f and the weight W separately in your code.

1 Like

Thanks a lot. This looks promising. I will try this out.