The code is modified based on the code for the article: Predicting non-linear dynamics by stable local learning in a recurrent spiking neural network Aditya Gilra, Wulfram Gerstner, eLife, 6: e28295, 2017. https://elifesciences.org/articles/28295.

The figures shown in https://elifesciences.org/articles/28295/figures

Introduction:

In the original article, the neural network is used to simulate the signal defined by differential equations (corresponding to non-linear dynamic system) under 3 dimensions. The author adopted Van Der Pol Oscillator to generate 2-dim output, Lorenz system to generate 3-dim output and two-link arm dynamics to generate 4-dim output (two group of angle and angular velocity). The modified code can follow high dimension (>3) signal provided by data file.

Environment Configuration:

nengo and nengo_ocl should be installed.

Using

pip install nengo

pip install nengo_ocl

Don't follow the instruction according to the author of the article, no need to change the version of nengo_ocl. Working in virtual environment is highly recommended. Don't forget set OCL flag = True in the script file otherwise it will be running on CPU instead of GPU.

Running Demos:

There are three demos:

  1. Learning a model for Van der Pol Oscillator (2-dim):

    vdp_test.py

  2. Learning a model for two-link (4-dim) arm dynamics

  3. Learning a model for three-link (7-dim) arm dynamics

    rb1_test.py

The first demo can be tested by running vdp_test.py. The second and third demo can be tested by running rb1_test.py. Using "nohup" command to run these scripts is highly recommended.

E.g. "nohup python vdp_test.py &> nohup0.out &"

The real-time output of the script will be saved into file "nohup0.out". You can use command "cat nohup0.out" to check the result.

As for the structure of the code, it starts with lots of flag configuration.

In general, it should remain default.

Then the dynamic equation is defined by the "funcType". There are two important parameters, "Nexc" , "Tperiod" and "Tmax". "Nexc" is the number of neurons in the command representation layer (feedforward layer) and recurrent network. "Tperiod" defines part of each input pattern (see details on page 21). In the default configuration, in the first "Tperiod " and last 4 * Tperiod, the error feedback is off while the neural network is not learning. "Tmax" is the total simulation time.

After that, the input mode can be selected in the original code. In "vdp_test.py", the code is highly simplified by only remaining the Van Der Pol Oscillator function and "amplVaryHeightScaled" as the only input mode. (For different types of function tests, running input_ff_rec_transform_nengo_ocl.py )

The last section of the code is the neural network architecture creation and running.

Architecture of the NN:

The architecture is shown as below:

img

$u_β(t)$ is input, $x_α(t)$ is the reference signal generated by the input while the output of the neural network is the predicted signal $\hat x_α(t)$ , the error is the difference between reference signal and predicted signal. The When the error feedback loop is on, the synaptic weights($w^{ff}{il}$, $w{ij}$ )

See the 5$^{th}$ page of the paper for details.

Characteristics of the Data:

In the folder “dataset”, there are three .csv files. Each file includes the information of angle changing over time. In this experiment, only the right arm is controlled to collect the data. Therefore, we only focus the time and the angle information of the right arm. It consists of 2-dim information from shoulder (right_s0, right_s1), 2-dim information from elbow (right_e0, right_e1) and 3-dim information from wrist (right_w0, right_w1, right_w2). The right_gripper is not applicable here.

The content of the data:

baxter_traj: Grasping an object

baxter_traj_2: Oscillating like wave

baxter_traj_3: Scratching the back

FAQ

Q1: Learning rate selection:

Under the old version of nengo and nengo_ocl, the default value of learning rate is 2e-3. Under the new version of the modules, the learning rate should be modified to 1e-4, which is 20 times smaller than before.

Q2: Input mode selection:

Normally, the output under specific input mode had better have similar characteristics with the reference output. For example, the 7-dim robotic signal is changing slowly. So the zero input mode is more appropriate than "amplVaryHeights" since the output of the latter one oscillates violently.

Q3: environment variable:

If nengo_ocl cannot be found, add the directory to .bashrc (e.g. export PATH=/data1/wanghuaijin/nengo_ocl:$PATH) and execute "source ~/.bashrc in the terminal"