Change node value programmatically

Hi,

I am using Nengo in the Neurorobotics Platform to couple some robots with a brain simulation. I ran accross the issue of not being able to change the value of an input Node which is corresponding to sensory feedback. My question is, is there a way to programmatically change the value of a Node? Thanks for the response.

Best regards,
Manos

Hi Manos,

Welcome to the Nengo forum!

Could you provide a few details about your problem? Are you working in the Nengo GUI? Is this code fully written in Nengo, or are you using the NengoDL Keras converter?

To programatically change the value of a Node, you can set or change the Node’s output parameter, which is the first argument to the constructor. For example,

constant1_node = nengo.Node([0.5])
constant3_node = nengo.Node([0.1, 0.3, 0.5])
function_node = nengo.Node(lambda t: np.sin(t))
process_node = nengo.Node(
    nengo.processes.WhiteSignal(period=10, high=5)
)

constant1_node will return a constant 1-dimensional (scalar) value of 0.5; constant3_node will return a constant 3-dimensional (vector) value.

Nodes can also use functions to determine their output, as demonstrated by function_node, which outputs a sine wave (the input for node functions is the simulation time t, unless you set the size_in of the node to allow you to connect other things into it).

Processes are a Nengo tool that allow you to implement arbitrary systems with state that are linear or non-linear, time-dependent or time-invariant; process_node demonstrates a WhiteSignal process, which generates a periodic (here with period 10 seconds) signal that is white (equal power at all frequencies) below the cutoff frequency given by high (here 5 Hz).

Hi Eric,

Thanks for the quick response. I am currently using Nengo through the Neurorobotics Platform, which has its’ own communication mechanism with nengo, but in short, it is equivalent to running Nengo in a stepped manner (i.e. after a physics evaluation step, the nengo simulation is explicitly stepped and so on in a loop). My question was whether you can change the Node value dynamically and not through the constructor or by providing a callback function. The logic behind this is that my Node is a non-spiking input node that represents sensory feedback, in this case a simple 2-D vector. The problem which I am facing is that this sensory feedback is available only through the physical simulation and thus not a priori known during the construction time, so none of the default construction methods would be suitable for this scenario. The processes functionality seems like a suitable approach, but I suppose that behind the scenes it is also providing a callback function that is known at construction time. I was hoping for something like:

my_node = nengo.Node([a,b])
if sensory_data_available:
     my_node.value = sensory_data

I suppose that the sliders in the GUI have some sort of on-demand adaptation of the value that the node is representing, but taking a look at the source code did not help me much.

Of course there is the workaround of using a neural population as the encoder of the sensor signal, but this does not seem like the natural way of providing feedback to my model.

Thanks again for the response!

Best,
Manos

Hi Manos,

Probably the easiest way to do this would just be to have a function that uses a global value, for example:


global_node_value = 0.5

def node_function(t):
    return global_node_value

with nengo.Network() as net:
    node = nengo.Node(node_function)

with nengo.Simulator(net) as sim:
    sim.run(0.5)
    global_node_value = 1.0
    sim.run(0.5)

The Simulator part is just there to show that you can change the global_node_value between steps; obviously in your code, you’d be doing this in Neurorobotics Platform somewhere (which I’m not at all familiar with).

In your code, if you have some sort of handle to the physics simulator when you’re creating the Node, you could even use that in node_function so that it just queries the physics simulator to see if the sensory data is available.

Dear Eric,

This is exactly what I was looking for, thanks!

Best,
Manos