In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import nengo

In [2]:
model = nengo.Network()
with model:
   stim = nengo.Node(lambda t: (1,0.5,0.25,0) if 0.5<t<1.5 else (0,0,0,0))
   
   ens = nengo.Ensemble(n_neurons=4, dimensions=1,
                        neuron_type=nengo.RectifiedLinear(),
                        gain=nengo.dists.Choice([1]),
                        bias=nengo.dists.Choice([0]))
   nengo.Connection(stim, ens.neurons, synapse=None, transform=0.001)
   nengo.Connection(ens.neurons, ens.neurons, transform=0.99*np.eye(4), synapse=0)
   
   p_stim = nengo.Probe(stim)
   p = nengo.Probe(ens.neurons)
   
sim = nengo.Simulator(model)
sim.run(2.0)

plt.plot(sim.data[p])


0%
 
0%
 
Out[2]:
[<matplotlib.lines.Line2D at 0x1c71a9c92b0>,
 <matplotlib.lines.Line2D at 0x1c71a9c9400>,
 <matplotlib.lines.Line2D at 0x1c71a9c9550>,
 <matplotlib.lines.Line2D at 0x1c71a9c96a0>]

In [7]:
N = 10
J = 2000
span = np.linspace(0, 1, N)
image = (np.sin(2*np.pi*span)+1)/2

model = nengo.Network()
with model:
    stim = nengo.Node(image)
    
    residual = nengo.Node(None, size_in=N)
    
    v1 = nengo.Ensemble(n_neurons=J, dimensions=1,
                          neuron_type=nengo.RectifiedLinear(),
                          gain=nengo.dists.Choice([1]),
                          bias=nengo.dists.Choice([0]))
    
    nengo.Connection(v1.neurons, v1.neurons, synapse=0)
    
    w = np.random.uniform(-0.002, 0.002, (J, N))
    
    tau = 0.1
    nengo.Connection(residual, v1.neurons, transform=w, synapse=tau)
    
    nengo.Connection(stim, residual, synapse=0)
    nengo.Connection(v1.neurons, residual, transform=-w.T, synapse=tau)
    
    p_v1 = nengo.Probe(v1.neurons)
    p_res = nengo.Probe(residual)
    
    
sim = nengo.Simulator(model)
sim.run(3.0)


0%
 
0%
 

In [8]:
plt.plot(sim.trange(), sim.data[p_v1])
plt.show()



In [9]:
recon = np.dot(sim.data[p_v1], w)
plt.imshow(recon, aspect='auto')
plt.colorbar()
plt.figure()
plt.plot(image)
plt.plot(recon[-1])


Out[9]:
[<matplotlib.lines.Line2D at 0x1c720b6d668>]

In [10]:
plt.imshow(sim.data[p_res][:,:], aspect='auto')


Out[10]:
<matplotlib.image.AxesImage at 0x1c720a83710>

In [ ]: