Advertisement
toweber

nengo-third_test

Sep 19th, 2022
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 KB | None | 0 0
  1. # based on https://www.nengo.ai/nengo/examples/basic/many-neurons.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="Many Neurons")
  10.  
  11. with model:
  12.     A = nengo.Ensemble(
  13.         100, #number of neurons
  14.         dimensions=1,  # Represent a scalar
  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.  
  28.     #****************
  29.     # CONNECT ELEMENTS
  30.     #****************
  31.     #Connect the input signal to the neuron
  32.     nengo.Connection(input_signal, A, synapse=0.01)
  33.  
  34.     #****************
  35.     # PROBES
  36.     #****************
  37.     # The original input
  38.     input_signal_probe = nengo.Probe(input_signal)
  39.  
  40.  
  41.     # The raw spikes from the neuron
  42.     spikes = nengo.Probe(A.neurons)
  43.     # Subthreshold soma voltage of the neuron
  44.     #voltage = nengo.Probe(A.neurons, "voltage")
  45.     # Spikes filtered by a 10ms post-synaptic filter
  46.     #filtered = nengo.Probe(A.neurons, synapse=0.01)
  47.     filtered = nengo.Probe(A, synapse=0.01)
  48.  
  49.  
  50. with nengo.Simulator(model) as sim:  # Create the simulator
  51.     #****************
  52.     # Run
  53.     #****************
  54.     sim.run(1)  # Run it for 1 second
  55.  
  56. #****************
  57. # plot the results
  58. #****************
  59. t =  sim.trange()
  60. # Plot the decoded output of the ensemble
  61. plt.figure()
  62. plt.plot(sim.trange(), sim.data[filtered], label="A_output")
  63. plt.plot(sim.trange(), sim.data[input_signal_probe])
  64. plt.xlim(0, 1)
  65.  
  66.  
  67. # Plot the spiking output of the ensemble
  68. plt.figure()
  69. rasterplot(sim.trange(), sim.data[spikes])
  70. plt.xlim(0, 1)
  71.  
  72.  
  73. # Plot the spiking output of the ensemble
  74. # plt.figure(figsize=(10, 8))
  75. # plt.subplot(221)
  76. # rasterplot(sim.trange(), sim.data[spikes])
  77. # plt.yticks((1,2),("On neuron", "Off neuron"))
  78. # plt.ylabel("Neuron")
  79. # plt.xlim(0, 1)
  80. # plt.ylim(2.5, 0.5)
  81.  
  82. # # Plot the soma voltages of the neurons
  83. # plt.subplot(222)
  84. # #plt.plot(sim.trange(), sim.data[voltage][:, 0], "r")
  85. # plt.plot(t, sim.data[voltage][:, 0] + 1, "r")
  86. # plt.plot(t, sim.data[voltage][:, 1], "k")
  87.  
  88. # plt.xlim(0, 1)
  89. plt.show()
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement