# Where do attractors come in to play in Nengo?

Where are attractors used?

Hello!

Do you mean where are there examples of attractors in Nengo?
The following code you should be able to copy into a file and run with ‘python filename.py

``````""" Implementing ddy = alpha * (beta * (y* - y) - dy) """

import numpy as np
from scipy.linalg import expm

import nengo

def generate(net=None, n_neurons=200, alpha=1000.0, beta=1000.0/4.0, dt=0.001):
tau = 0.1  # synaptic time constant

# the A matrix for our point attractor
A = np.array([[0.0, 1.0],
[-alpha*beta, -alpha]])

# the B matrix for our point attractor
B = np.array([[0.0, 0.0], [alpha*beta, 1.0]])

# discretize
Bd = np.dot(np.linalg.inv(A), np.dot((Ad - np.eye(2)), B))
# account for discrete lowpass filter
a = np.exp(-dt/tau)
A = 1.0 / (1.0 - a) * (Ad - a * np.eye(2))
B = 1.0 / (1.0 - a) * Bd

if net is None:
net = nengo.Network(label='Point Attractor')
config = nengo.Config(nengo.Connection, nengo.Ensemble)
config[nengo.Connection].synapse = nengo.Lowpass(tau)
# config[nengo.Ensemble].neuron_type = nengo.Direct()

with config, net:
net.ydy = nengo.Ensemble(n_neurons=n_neurons, dimensions=2,
# set it up so neurons are tuned to one dimensions only
encoders=nengo.dists.Choice([[1, 0], [-1, 0], [0, 1], [0, -1]]))
# set up Ax part of point attractor
nengo.Connection(net.ydy, net.ydy, transform=A)

# hook up input
net.input = nengo.Node(size_in=2, size_out=2)
# set up Bu part of point attractor
nengo.Connection(net.input, net.ydy, transform=B)

# hook up output
net.output = nengo.Node(size_in=1, size_out=1)
nengo.Connection(net.ydy[0], net.output, synapse=None)

return net

if __name__ == '__main__':

time = 5  # number of seconds to run simulation
model = nengo.Network()
with model:
def goal_func(t):
return [float(int(t)) / time * 2 - 1, 0]
goal = nengo.Node(output=goal_func)
pa = generate(n_neurons=1000)
nengo.Connection(goal, pa.input, synapse=None)

probe_ans = nengo.Probe(goal)
probe = nengo.Probe(pa.output, synapse=.01)

sim = nengo.Simulator(model, dt=.001)
sim.run(time)

import matplotlib.pyplot as plt
plt.plot(sim.trange(), sim.data[probe])
plt.plot(sim.trange(), sim.data[probe_ans][:, 0], 'r--')
plt.legend(['continuous', 'discrete', 'desired'])
plt.show()
``````

Does that help?

Yes, it helps. Thanks. There is a theory of chaotic attractors in the nose by Walter Freeman Jr. that would be nice to try out.