Advertisement
toweber

nengo_fifth_test

Sep 19th, 2022
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. # based on https://www.nengo.ai/nengo/examples/basic/combining.html
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. import nengo
  5. from nengo.dists import Uniform
  6. from nengo.utils.matplotlib import rasterplot
  7.  
  8.  
  9. model = nengo.Network(label="2D representation")
  10.  
  11. with model:
  12.     A = nengo.Ensemble(100, dimensions=1) #neurons, dimensions
  13.     B = nengo.Ensemble(100, dimensions=1) #neurons, dimensions
  14.  
  15.     output = nengo.Ensemble(100, dimensions=2, label="2D Population") #neurons, dimensions
  16.  
  17.     #****************        
  18.     # PROVIDE INPUT
  19.     #****************
  20.     #input_signal = nengo.Node(lambda t: np.cos(8 * t))
  21.     sin = nengo.Node(output=np.sin)
  22.     cos = nengo.Node(output=np.cos)
  23.  
  24.     #****************
  25.     # CONNECT ELEMENTS
  26.     #****************
  27.     #Connect the input signal to the neuron
  28.     # The indices in neurons define which dimension the input will project to
  29.  
  30.     #nengo.Connection(input_signal, A, synapse=0.01)
  31.     #nengo.Connection(sin, neurons[0])
  32.     #nengo.Connection(cos, neurons[1])
  33.     nengo.Connection(sin, A)
  34.     nengo.Connection(cos, B)
  35.  
  36.     nengo.Connection(A, output[0])
  37.     nengo.Connection(B, output[1])
  38.  
  39.     #****************
  40.     # PROBES
  41.     #****************
  42.     # The original input
  43.     #input_signal_probe = nengo.Probe(input_signal)
  44.     sin_probe = nengo.Probe(sin, "output")
  45.     cos_probe = nengo.Probe(cos, "output")
  46.  
  47.     A_probe = nengo.Probe(A, synapse=0.01)  # 10ms filter
  48.     B_probe = nengo.Probe(B, synapse=0.01)  # 10ms filter
  49.     out_probe = nengo.Probe(output, synapse=0.01)  # 10ms filter
  50.  
  51. with nengo.Simulator(model) as sim:  # Create the simulator
  52.     #****************
  53.     # Run
  54.     #****************
  55.     sim.run(5)  # Run it for 1 second
  56.  
  57. #****************
  58. # plot the results
  59. #****************
  60. t =  sim.trange()
  61. # Plot the decoded output of the ensemble
  62.  
  63.  
  64. plt.figure()
  65.  
  66. plt.plot(sim.trange(), sim.data[out_probe][:, 0], "b", label="2D output[0]")
  67. plt.plot(sim.trange(), sim.data[out_probe][:, 1], "g", label="2D output[1]")
  68. plt.plot(sim.trange(), sim.data[A_probe], "r", label="A output")
  69. plt.plot(sim.trange(), sim.data[sin_probe], "k", label="Sine")
  70.  
  71. plt.legend()
  72. plt.show()
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement