Handing over the simulation time to the learning function

Hello everybody,

I just tried to let my ensemble learn a simple division equation.
Therefore, I took two varying input-functions of p1 = (0.85 * np.sin(float(10)*float(i)/float(1000))+1.15) and
p2 =(1.15 * np.sin(float(10)*float(i)/float(1000))+1.85) This works pretty well.

FineResult

But now I would like to replace the learning equation with a more variable one.
I would like to change the function, so that an additional parameter is added that changes in time.
So every time when the function is called by the connection, it has to know the actual time value.

I thought it could be an easy solution to calculate the results depending on the time in advance and save them to an array. Then I could simply implement a counter and every time the function is called it takes the next value out of the calculated array.

In a first approach I just calculated the division-equation in advance, without any changing values in the learning function. Instead it just should return the value of the calculated array at the appropriate time value.
But this seems to be no good idea, or at least I don’t understand the behavior of my model.
When I do it like this, then the results get really worse. But actually nothing should have changed.

worseResult

Obviously something is wrong with my idea of implementing a simple counter. Maybe the learning function is not called every time step ?

Could anybody tell me how i can find out at which timesteps of the simulation the learning function is called?
Is it possible to use a learning-function with a time-variable?
Why does this counter-solution behave so wrong?

I put my code example to this post in hope that it makes clear what i want to do.

exp.py (5.4 KB)

Thanks in advance for every kind of help :slightly_smiling_face:

1 Like

Hello,

When you specify nengo.Connection(..., function=my_func), function is defining how the weights should be initialized. It isn’t defining a dynamic output that is called each timestep, it is just called once in order to solve for the initial connection weights. It maps evaluation points to target values (e.g., given an input of 0.5, I want my output to be my_func(0.5)).

So your function is only being called once, with an array of evaluation points, and it is mapping all those points to the same value (where counter=0). After that the function doesn’t change, which is why you aren’t getting the results you expect.

If you’d like to make an object that outputs values that change over time, I’d recommend using a Node instead. Node functions are called each timestep, and they get the simulation time as one of the inputs to the function. So, for example, you could make a Node that would output your p1 equation like

def p1(t):
    return 0.85 * np.sin(10 * t) + 1.15
p1_node = nengo.Node(p1)
2 Likes