Advertisement
toweber

nengo-first_test.py

Sep 19th, 2022
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.02 KB | None | 0 0
  1. # https://www.nengo.ai/nengo/examples/basic/single-neuron.html
  2.  
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. import nengo
  6. from nengo.dists import Uniform
  7. from nengo.utils.matplotlib import rasterplot
  8.  
  9.  
  10. model = nengo.Network("My model")
  11.  
  12. model = nengo.Network(label="A Single Neuron")
  13.  
  14. with model:
  15.     neuron = nengo.Ensemble(
  16.         1,
  17.         dimensions=1,  # Represent a scalar
  18.         # Set intercept to 0.5
  19.         intercepts=Uniform(-0.5, -0.5),
  20.         # Set the maximum firing rate of the neuron to 100hz
  21.         max_rates=Uniform(100, 100),
  22.         # Set the neuron's firing rate to increase for positive input
  23.         encoders=[[1]],
  24.     )
  25.  
  26.     #****************        
  27.     # PROVIDE INPUT
  28.     #****************
  29.     cos = nengo.Node(lambda t: np.cos(8 * t))
  30.  
  31.     #****************
  32.     # CONNECT ELEMENTS
  33.     #****************
  34.     #Connect the input signal to the neuron
  35.     nengo.Connection(cos, neuron)
  36.  
  37.     #****************
  38.     # PROBES
  39.     #****************
  40.     # The original input
  41.     cos_probe = nengo.Probe(cos)
  42.     # The raw spikes from the neuron
  43.     spikes = nengo.Probe(neuron.neurons)
  44.     # Subthreshold soma voltage of the neuron
  45.     voltage = nengo.Probe(neuron.neurons, "voltage")
  46.     # Spikes filtered by a 10ms post-synaptic filter
  47.     filtered = nengo.Probe(neuron, 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.  
  60. # Plot the decoded output of the ensemble
  61. plt.figure()
  62. plt.plot(sim.trange(), sim.data[filtered])
  63. plt.plot(sim.trange(), sim.data[cos_probe])
  64. plt.xlim(0, 1)
  65.  
  66. # Plot the spiking output of the ensemble
  67. plt.figure(figsize=(10, 8))
  68. plt.subplot(221)
  69. rasterplot(sim.trange(), sim.data[spikes])
  70. plt.ylabel("Neuron")
  71. plt.xlim(0, 1)
  72.  
  73. # Plot the soma voltages of the neurons
  74. plt.subplot(222)
  75. plt.plot(sim.trange(), sim.data[voltage][:, 0], "r")
  76. plt.xlim(0, 1)
  77. plt.show()
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement