Temporal Encoding with Event Data in Nengo

Hi Guys,

I currently trying to utilise event data with Nengo to decode a binary sequence of events. I have started playing around with an LMU implementation based on the Nengo-DL example (Legendre Memory Units in NengoDL — NengoDL 3.4.1.dev0 docs), but I was wanting to try and utilise Temporal encoding as i think it better suits the specific task I have in mind. I was hoping someone could steer me in the right direction with how to get started. I saw from similar topics (On the application of supervised learning in Nengo for data stream mining. Q1: encoding methods) that it should be possible to do this by creating a custom node, though I am unsure on the specifics as the Node object’s comments in the class, as I see it, says it simply passes/receives data to/from an ensemble. Though I imagine its because I am misunderstanding something. Any insight would be greatly appreciated.

Many Thanks,
Jack

That’s correct! The nengo.Node simply serves as a way for Nengo to connect arbitrary Python code to the rest of the Nengo network.

As an example, suppose you had some data:

data = [1, 2, 3, 4, 5]

And you wanted to present this data to a Nengo network every second (i.e., first second would present first item, then at 2s, present the second item, etc.). The Nengo node function that would do that would look something like this:

def present_func(t):
    ind = int(t)  # Note: more complexity needed here to handle list index overrun
    return data[ind]

And the nengo.Node itself would look like this:

with nengo.Network() as model:
    data_node = nengo.Node(present_func)

And that’s it! You can then connect the node to other Nengo objects using the nengo.Connections.

1 Like

Hi xchoo,

So how would i go about modifying it to encode the data with temporal rather than rate based encoding? or is it more that i modify my data to already be encoded before I use the node to feed it into the network?

Many Thanks,
Jack

I’m not quite sure what you are asking, as the data in my example is already “temporal” (i.e., changing with time). If you are asking how to present the data as spikes, then that’s relatively simple too. In Nengo, spikes are represented as a pulse of value $1/dt$ (where dt = 0.001 by default, but you can change it in the nengo.Simulator parameters):

dt = 0.001

def present_spike_func(t):
    # Output a spike every 10 timesteps
    if int(t / dt) % 10 == 0:
        return 1 / dt
    else:
        return 0

This depends on how your data is formatted. If you data is event-based, then you can just present the individual events. Otherwise, using the “rate” based encoding would be more straightforward.