Advertisement
toweber

nengo-forth_test

Sep 19th, 2022
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.11 KB | None | 0 0
  1. # based on https://www.nengo.ai/nengo/examples/basic/2d-representation.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.     neurons = nengo.Ensemble(
  13.         100, #number of neurons
  14.         dimensions=2,  # Represent a 2-dimensional signal (input or output?)
  15.         # Set intercept to 0.5
  16.         #intercepts=Uniform(-0.5, -0.5),
  17.         # Set the maximum firing rate of the neuron to 100hz
  18.         #max_rates=Uniform(100, 100),
  19.         # Set the neuron's firing rate to increase for positive input
  20.         #encoders=[[1], [-1]], # One 'on' and one 'off' neuron
  21.     )
  22.  
  23.     #****************        
  24.     # PROVIDE INPUT
  25.     #****************
  26.     #input_signal = nengo.Node(lambda t: np.cos(8 * t))
  27.     sin = nengo.Node(output=np.sin)
  28.     cos = nengo.Node(output=np.cos)
  29.  
  30.     #****************
  31.     # CONNECT ELEMENTS
  32.     #****************
  33.     #Connect the input signal to the neuron
  34.     # The indices in neurons define which dimension the input will project to
  35.  
  36.     #nengo.Connection(input_signal, A, synapse=0.01)
  37.     nengo.Connection(sin, neurons[0])
  38.     nengo.Connection(cos, neurons[1])
  39.  
  40.     #****************
  41.     # PROBES
  42.     #****************
  43.     # The original input
  44.     #input_signal_probe = nengo.Probe(input_signal)
  45.     sin_probe = nengo.Probe(sin, "output")
  46.     cos_probe = nengo.Probe(cos, "output")
  47.  
  48.     # The raw spikes from the neuron
  49.     neurons_rawspikes_probe = nengo.Probe(neurons.neurons)
  50.     # Subthreshold soma voltage of the neuron
  51.     #voltage = nengo.Probe(A.neurons, "voltage")
  52.     # Spikes filtered by a 10ms post-synaptic filter
  53.     #filtered = nengo.Probe(A.neurons, synapse=0.01)
  54.     #filtered = nengo.Probe(A, synapse=0.01)
  55.     neurons_probe = nengo.Probe(neurons, "decoded_output", synapse=0.01)
  56.  
  57.  
  58.  
  59. with nengo.Simulator(model) as sim:  # Create the simulator
  60.     #****************
  61.     # Run
  62.     #****************
  63.     sim.run(5)  # Run it for 1 second
  64.  
  65. #****************
  66. # plot the results
  67. #****************
  68. t =  sim.trange()
  69. # Plot the decoded output of the ensemble
  70. plt.figure()
  71. plt.plot(sim.trange(), sim.data[neurons_probe], label="A_output")
  72. #plt.plot(sim.trange(), sim.data[input_signal_probe])
  73. plt.plot(sim.trange(), sim.data[sin_probe])
  74. plt.plot(sim.trange(), sim.data[cos_probe])
  75. #plt.xlim(0, 1)
  76.  
  77. #plt.plot(sim.trange(), sim.data[neurons_rawspikes_probe])
  78.  
  79.  
  80. # Plot the spiking output of the ensemble
  81. #plt.figure()
  82. #rasterplot(sim.trange(), sim.data[neurons_rawspikes_probe])
  83. #plt.xlim(0, 1)
  84.  
  85.  
  86. # Plot the spiking output of the ensemble
  87. # plt.figure(figsize=(10, 8))
  88. # plt.subplot(221)
  89. # rasterplot(sim.trange(), sim.data[spikes])
  90. # plt.yticks((1,2),("On neuron", "Off neuron"))
  91. # plt.ylabel("Neuron")
  92. # plt.xlim(0, 1)
  93. # plt.ylim(2.5, 0.5)
  94.  
  95. # # Plot the soma voltages of the neurons
  96. # plt.subplot(222)
  97. # #plt.plot(sim.trange(), sim.data[voltage][:, 0], "r")
  98. # plt.plot(t, sim.data[voltage][:, 0] + 1, "r")
  99. # plt.plot(t, sim.data[voltage][:, 1], "k")
  100.  
  101. # plt.xlim(0, 1)
  102. plt.show()
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement