Import/Export function?

Hello together, hope you’re having a nice summer

I am still working on some small functions using nengo and would like to add a few more features.

One problem i start running into is the simulation time needed to test out my codes.

Since i have one bigger program i wanted to ask if there is an easy way to export/import the results of a simulation inside nengo to maybe split it into 2 modules?

For example:

Module 1 runs 5 Seconds and calculates a function.

Module 2 needs this function as an input to carry on.

A second problem is a program using an array of many ensembles to calculate different sums. I would like now to identify the ensembles that have the highest (highest 3, or even those above a certain threshold) values for further usage (maybe by inhibiting the others?!).

Any help would be greatly appreciated!

Hey Phil,

For your first question, how are you running your Nengo code? Are you doing it via the Nengo GUI or from the command line?

For you second question, there’s a few options.

  • If you want to do thresholding, you can check out this documentation.

  • If you want something that iterates through the highest numbers, we’ve done something like that with an associative memory, but you’ll have to ask @tcstewar where that code is

I hope this helps a bit. Hopefully some of my more experienced lab mates can elaborate on the second question.

Hi Seanny,

Thanks for the documentation on thresholding, i will try if that works for my problem.

And for the first part, i am running the code from the command line. I already thought about just saving the data to a file and importing that into a node, but i thought to ask first since the issue seems pretty common.

That’s definitely a feature we have on the to-do list, making it easier to run subsections of a model. For now though the best way is as you said to use a probe to capture the relevant input signals and then replay them using a Node. Check out the PresentInput process if you want an easy way to get a node to output data from an array.

Another possibility, if you just want to test out different parts of your model, is to change the ensembles in e.g. Module 1 to Direct mode (nengo.Ensemble(..., neuron_type=nengo.Direct()). This will cause those ensembles to just run as direct mathematical functions, rather than simulating all the individual neurons. So that will allow your simulation to run faster, and then once you have verified that Module 2 works the way you want with those Direct mode inputs, you can change Module 1 back to a more realistic neural simulation.

Thanks for the mentioning of the Direct type, that can be very helpful in testing parts of a module.

@Seanny123 i have tried the thresholding mentioned in the doc, but i cannot seem to get it to work.
Do you maybe have a very simple example? My program basically has an ensemble ( 0,1) with a certain value, but only if it is above 0.9 i want the value to go through to the next ensemble for further computation.

Thanks in advance

Were you able to run the last code clip from the notebook? Was the code confusing because it used a vocabulary instead of a simpler 1D signal? Would you prefer an example with a 1D signal?

Even with just copying the provided code, i was getting several error messages which point to missing packets or maybe I am using a different version somewhere.
So i couldn’t even get to understanding what is done there.

‘module’ object has no attribute ‘presets’

But since i only need a very simple version of it, an example in 1D would probably already work for me.

Oh shoot! I’m sorry Phil. I forgot that I was running off the master branch of Nengo, while you’re probably using Nengo from PyPI. So either you can install Nengo from source or you can just run this example:

import nengo

import matplotlib.pyplot as plt
import numpy as np

threshold = 0.3
config = nengo.Config(nengo.Ensemble)
config[nengo.Ensemble].dimensions = 1
config[nengo.Ensemble].intercepts = nengo.dists.Exponential(0.15, threshold, 1.)
config[nengo.Ensemble].encoders = nengo.dists.Choice([[1]])
config[nengo.Ensemble].eval_points = nengo.dists.Uniform(threshold, 1.)

with nengo.Network() as cleanup:
    stim = nengo.Node(lambda t: t)
    with config:
        ens = nengo.Ensemble(n_neurons=50, dimensions=1)
    output = nengo.Node(size_in=1)
    nengo.Connection(stim, ens)
    nengo.Connection(ens, output)

    p_in = nengo.Probe(stim, synapse=None)
    p_out = nengo.Probe(output, synapse=0.005)

with nengo.Simulator(cleanup) as sim:

plt.legend(["input", "output"])
plt.ylim(-0.1, 1)

Thank you for your patience