This is the model used to create the graph shown above
import numpy as np
import matplotlib.pyplot as plt
import nengo
import math
from stp_ocl_implementation import *
import pyopencl as cl
#input to the network, varying values of theta
theta=np.arange(-45,45,5)/180*math.pi
sin=np.sin(theta)
cos=np.cos(theta)
def input_func(t):
i=math.floor(t/0.25)
return np.sin(theta[i]),np.cos(theta[i])
#calculate difference between theta of A and B via their sine and cosine
def arctan_func(v):
x1,y1,x2,y2=v
return np.arctan2(x1,y1)-np.arctan2(x2,y2)
with nengo.Network() as model:
#ensemble A and B both represent the sine and cosine of theta
input_Node=nengo.Node(input_func)
ensemble_A = nengo.Ensemble(1000, dimensions=2)
ensemble_B = nengo.Ensemble(1000, dimensions=2)
nengo.Connection(input_Node, ensemble_A)
nengo.Connection(ensemble_A, ensemble_B,transform=.1)
#arctan calculates the difference between the theta represented by ensemble A and B
arctan = nengo.Ensemble(1000, dimensions=4, radius=1)
out = nengo.Ensemble(500, dimensions=1, radius=math.pi)
nengo.Connection(ensemble_A, arctan[:2])
nengo.Connection(ensemble_B, arctan[2:])
nengo.Connection(arctan, out, function=arctan_func)
#a nengo.Direct() implementation for comparison
arctan_direct = nengo.Ensemble(1000, dimensions=4, neuron_type=nengo.Direct())
out_direct = nengo.Ensemble(500, dimensions=1, radius=math.pi)
nengo.Connection(ensemble_A, arctan_direct[:2])
nengo.Connection(ensemble_B, arctan_direct[2:])
nengo.Connection(arctan_direct, out_direct, function=arctan_func)
#probes
p_out=nengo.Probe(out, synapse=0.01)
p_out_direct=nengo.Probe(out_direct, synapse=0.01)