Nengo summer school lecture 5: Building a Critter with Nengo

When I tried the example of @tcstewar in Nengo Summer School Lecture 5, I encountered several problems that I couldn’t understand:

My code:

import nengo

model = nengo.Network()
with model:
    stim_food = nengo.Node([0, 0])
    stim_fear = nengo.Node(-1)
    
    food = nengo.Ensemble(n_neurons=100, dimensions=2)
    do_food = nengo.Ensemble(n_neurons=300, dimensions=3)
    motor = nengo.Ensemble(n_neurons=100, dimensions=2)
    
    fear = nengo.Ensemble(n_neurons=100, dimensions=1)
    
    do_home = nengo.Ensemble(n_neurons=300, dimensions=3)
    
    nengo.Connection(stim_food, food)
    nengo.Connection(stim_fear, fear)
    nengo.Connection(fear, do_food[0])
    nengo.Connection(food, do_food[1:])
    
    def fear_func(x):
        fear, food_x, food_y = x
        if fear > 0:
            return 0, 0
        else:
            return food_x, food_y
    
    nengo.Connection(do_food, motor, function=fear_func)
    
    pos = nengo.Ensemble(n_neurons=500, dimensions=2, radius=1)
    
    nengo.Connection(pos, pos, synapse=0.1)
    nengo.Connection(motor, pos, synapse=0.1, transform=0.1)
    
    def home_func(x):
        fear, pos_x, pos_y = x
        if fear > 0:
            return -pos_x, -pos_y
        else:
            return 0, 0
    
    nengo.Connection(fear, do_home[0])
    nengo.Connection(pos, do_home[1:])
    nengo.Connection(do_home, motor, function=home_func)
  1. After I complete the code for this task, I start by placing the fear slider at -1.Adjust the x and y sliders in stim_food while running the model simulation, and then place the fear slider to 1.However, at the moment thefear slider is placed to 1, a strange phenomenon appears in the xy-value of the motor module: as shown in the figure, the xy coordinates of the motor module will change to -x and -y instantly and then slowly return to the origin.

  2. When I tried to adjust the fear slider, I found that the maximum radius of the XY-value blue dot moving in the motor module seemed to change.

  3. Despite listening to @tcstewar and @chris , I’m still not familiar with the synapse parameter in the nengo.Connection () function.

Is there anyone who understands my above three questions and can explain them to me?Thank you very much!

I believe this is intended behaviour. From the description of the critter, when fear is 1, the critter should “go in the opposite direction of where it is and return home (to the origin)”. In your example, the critter is located at about -1, 1, so when fear is set to 1, the motor system (which indicates where the critter is moving towards) will flip to 1, -1 (or -x, -y), indicating that the critter is headed away from its current position and towards the origin. The reason why the motor output slowly returns to the origin is because as the critter approaches the origin, so does the function (-x, -y), meaning the critter slows down as it approaches the origin.

This is expected behaviour. Keep note that the neural populations aren’t “computing” a function. Rather, they are approximating the function you defined when the connection is made. One type of function that is really hard to approximate are discontinuous functions (functions that have a sharp change in output). In the critter example, both the fear_func and home_func are such discontinuous functions. At the discontinuous points of the function, the neurons will try to approximate as best it can, but usually, what you will observe is a smooth change at the discontinuity.

As an example, the following code defines a 1-dimensional (scalar) discontinuity similar to the fear_func function if the food was at y=1:

def step_func(x):
    if x < 0:
        return 0
    else:
        return 1

ensA = nengo.Ensemble(n_neurons=50, dimensions=1)
ensB = nengo.Ensemble(n_neurons=50, dimensions=1)
nengo.Connection(ensA, ensB, function=step_func)

If we were to provide ensA with a steady ramp from -1 to 1, what we should see is something like this:

But, if we look at the output of ensB, we see something different. The red dashed line is the “ideal”, while the blue line is the output of the neural population:

And as we can see, changing the value of x (especially near the discontinuity – i.e., x=0) changes the output of the neural population by quite a bit. Going back to the critter example, this is why at the limits (when fear=-1 or fear=1), the output of the motor population is expected; but near the discontinuity (when fear~=0) you see the output of the motor population change.

The synapse parameter on a Nengo connection is described in our Nengo documentation. It is used to apply some form of synaptic filter to the signals being transmitted over that specific nengo.Connection object. It can be used to turn a spike train into post-synaptic current:

Or, turn a filter a continuous valued signal:

Ok, perfect! Thiks, you’re the best teacher.