Variable synapse time constant

I am trying to implement a synapse whose time-constant is computed by a function based on some input A. How can I do this?

import nengo
model = nengo.Network()
with model:
    A = nengo.Ensemble(n_neurons=50, dimensions=1)
    B = nengo.Ensemble(n_neurons=50, dimensions=1)
    C = nengo.Ensemble(n_neurons=50, dimensions=1)
    tau = nengo.Ensemble(n_neurons=50, dimensions=1)
    def compute_tau(A):
        tau = 35/(1+(0.04*A)**2)
        return tau
    nengo.Connection(A, tau, function=compute_tau)

But now I want to use this computed tau as the time constant in another synapse :
nengo.Connection(B, C, synapse=tau)
I noticed that synapse can’t take either a function or an ensemble as an argument. So how can I feed a changing time constant?

You’ll need to write your own synapse model for this, since you’re defining a new type of synapse. However, Nengo is set up to make that relatively easy to do. You can take a look at some of the existing implementations to see how this works, e.g. the Triangle synapse implementation here.

Basically you create a subclass of nengo.synapses.Synapse, and implement the make_step function. This is a function that creates the synaptic step function. That step function takes two things as input, the current simulation time and the current input value of the synapse on one timestep, and outputs the computed output value of the synapse for that simulation step. So you can write whatever logic you want in the middle there (and it can be dependent on the input value of the synapse, which is what you need). Then you just pass that process you made as the synapse parameter, like nengo.Connection(B, C, synapse=MySynapse()).

If you want to use the output of multiple ensembles to compute the synaptic output, then I would concatenate them together using an intermediate node and then apply your synapse to that concatenated signal (so that inside the Synapse step function you have access to the output of both ensembles in the synapse input signal). E.g.,

node = nengo.Node(size_in=A.size_out + B.size_out)
nengo.Connection(A, node[:A.size_out])
nengo.Connection(B, node[A.size_out:])
nengo.Connection(node, C, synapse=MySynapse())
1 Like

Thank you very much Daniel!