Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# account for continuous lowpass filter
A = tau * A + np.eye(2)
B = tau * B
else:
# discretize state matrices
Ad = expm(A*dt)
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)
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=1, size_out=1)
# 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)
# add in forcing function
def generate(net=None, n_neurons=200, alpha=1000.0, beta=1000.0/4.0,
dt=0.001, analog=False):
tau = 0.1 # synaptic time constant
synapse = nengo.Lowpass(tau)
# 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], [alpha*beta]])
# if you have the nengolib library you can do it this way
# from nengolib.synapses import ss2sim
# C = np.eye(2)
# D = np.zeros((2, 2))
# linsys = ss2sim((A, B, C, D), synapse=synapse, dt=None if analog else dt)
# A = linsys.A
# B = linsys.B