Advertisement
toweber

nengo-sixth_test

Sep 19th, 2022
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import nengo
  4. from nengo.dists import Uniform
  5. from nengo.utils.matplotlib import rasterplot
  6.  
  7.  
  8. model = nengo.Network(label="overlay_test")
  9.  
  10. with model:
  11.     A = nengo.Ensemble(100, dimensions=1) #neurons, dimensions
  12.     B = nengo.Ensemble(100, dimensions=1) #neurons, dimensions
  13.     C = 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.     input_a = nengo.Node(output=0.5)
  22.     input_b = nengo.Node(output=0.3)
  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(input_a, A)
  34.     nengo.Connection(input_b, B)
  35.  
  36.  
  37.     nengo.Connection(A, C)
  38.     nengo.Connection(B, C)
  39.  
  40.     #****************
  41.     # PROBES
  42.     #****************
  43.     # The original input
  44.     #input_signal_probe = nengo.Probe(input_signal)
  45.     input_a_probe = nengo.Probe(input_a)
  46.     input_b_probe = nengo.Probe(input_b)
  47.  
  48.     A_probe = nengo.Probe(A, synapse=0.01)  # 10ms filter
  49.     B_probe = nengo.Probe(B, synapse=0.01)  # 10ms filter
  50.     C_probe = nengo.Probe(C, synapse=0.01)  # 10ms filter
  51.  
  52.  
  53. with nengo.Simulator(model) as sim:  # Create the simulator
  54.     #****************
  55.     # Run
  56.     #****************
  57.     sim.run(5)  # Run it for 1 second
  58.  
  59. #****************
  60. # plot the results
  61. #****************
  62. t =  sim.trange()
  63. # Plot the decoded output of the ensemble
  64.  
  65.  
  66. plt.figure()
  67.  
  68. plt.plot(sim.trange(), sim.data[input_a_probe], label="input a")
  69. plt.plot(sim.trange(), sim.data[input_b_probe], label="input b")
  70.  
  71. plt.plot(sim.trange(), sim.data[A_probe], label="A output")
  72. plt.plot(sim.trange(), sim.data[B_probe], label="B output")
  73. plt.plot(sim.trange(), sim.data[C_probe], label="C output")
  74.  
  75.  
  76. plt.legend()
  77. plt.show()
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement