Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # based on https://www.nengo.ai/nengo/examples/basic/combining.html
- import matplotlib.pyplot as plt
- import numpy as np
- import nengo
- from nengo.dists import Uniform
- from nengo.utils.matplotlib import rasterplot
- model = nengo.Network(label="2D representation")
- with model:
- A = nengo.Ensemble(100, dimensions=1) #neurons, dimensions
- B = nengo.Ensemble(100, dimensions=1) #neurons, dimensions
- output = nengo.Ensemble(100, dimensions=2, label="2D Population") #neurons, dimensions
- #****************
- # PROVIDE INPUT
- #****************
- #input_signal = nengo.Node(lambda t: np.cos(8 * t))
- sin = nengo.Node(output=np.sin)
- cos = nengo.Node(output=np.cos)
- #****************
- # CONNECT ELEMENTS
- #****************
- #Connect the input signal to the neuron
- # The indices in neurons define which dimension the input will project to
- #nengo.Connection(input_signal, A, synapse=0.01)
- #nengo.Connection(sin, neurons[0])
- #nengo.Connection(cos, neurons[1])
- nengo.Connection(sin, A)
- nengo.Connection(cos, B)
- nengo.Connection(A, output[0])
- nengo.Connection(B, output[1])
- #****************
- # PROBES
- #****************
- # The original input
- #input_signal_probe = nengo.Probe(input_signal)
- sin_probe = nengo.Probe(sin, "output")
- cos_probe = nengo.Probe(cos, "output")
- A_probe = nengo.Probe(A, synapse=0.01) # 10ms filter
- B_probe = nengo.Probe(B, synapse=0.01) # 10ms filter
- out_probe = nengo.Probe(output, synapse=0.01) # 10ms filter
- with nengo.Simulator(model) as sim: # Create the simulator
- #****************
- # Run
- #****************
- sim.run(5) # Run it for 1 second
- #****************
- # plot the results
- #****************
- t = sim.trange()
- # Plot the decoded output of the ensemble
- plt.figure()
- plt.plot(sim.trange(), sim.data[out_probe][:, 0], "b", label="2D output[0]")
- plt.plot(sim.trange(), sim.data[out_probe][:, 1], "g", label="2D output[1]")
- plt.plot(sim.trange(), sim.data[A_probe], "r", label="A output")
- plt.plot(sim.trange(), sim.data[sin_probe], "k", label="Sine")
- plt.legend()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement