This demo implements a simple harmonic oscillator in a 2D neural population. The oscillator is more visually interesting on its own than the integrator, but the principle at work is the same. Here, instead of having the recurrent input just integrate (i.e. feeding the full input value back to the population), we have two dimensions which interact. In Nengo there is a ‘Linear System’ template which can also be used to quickly construct a harmonic oscillator (or any other linear system).
In [ ]:
# Create the model object
import nengo
model = nengo.Network(label='Oscillator')
with model:
# Create the ensemble for the oscillator
neurons = nengo.Ensemble(nengo.LIF(200), dimensions=2)
In [ ]:
from nengo.utils.functions import piecewise
with model:
# Create an input signal
input = nengo.Node(output=piecewise({0: [1, 0], 0.1: [0, 0]}))
# Connect the input signal to the neural ensemble
nengo.Connection(input, neurons)
# Create the feedback connection
nengo.Connection(neurons, neurons, transform=[[1, 1], [-1, 1]], synapse=0.1)
In [ ]:
with model:
input_probe = nengo.Probe(input, 'output')
neuron_probe = nengo.Probe(neurons, 'decoded_output', synapse=0.1)
In [ ]:
# Create the simulator
sim = nengo.Simulator(model)
# Run it for 5 seconds
sim.run(5)
In [ ]:
import matplotlib.pyplot as plt
plt.plot(sim.trange(), sim.data[neuron_probe])
plt.xlabel('Time (s)', fontsize='large')
plt.legend(['$x_0$', '$x_1$'])
In [ ]:
data = sim.data[neuron_probe]
plt.plot(data[:,0], data[:,1], label='Decoded Output')
plt.xlabel('$x_0$', fontsize=20)
plt.ylabel('$x_1$', fontsize=20)
plt.legend()