Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # based on https://www.nengo.ai/nengo/examples/basic/2d-representation.html
- import matplotlib.pyplot as plt
- import numpy as np
- import nengo
- from nengo.dists import Uniform
- from nengo.utils.matplotlib import rasterplot
- model = nengo.Network(label="2D representation")
- with model:
- neurons = nengo.Ensemble(
- 100, #number of neurons
- dimensions=2, # Represent a 2-dimensional signal (input or output?)
- # Set intercept to 0.5
- #intercepts=Uniform(-0.5, -0.5),
- # Set the maximum firing rate of the neuron to 100hz
- #max_rates=Uniform(100, 100),
- # Set the neuron's firing rate to increase for positive input
- #encoders=[[1], [-1]], # One 'on' and one 'off' neuron
- )
- #****************
- # PROVIDE INPUT
- #****************
- #input_signal = nengo.Node(lambda t: np.cos(8 * t))
- sin = nengo.Node(output=np.sin)
- cos = nengo.Node(output=np.cos)
- #****************
- # CONNECT ELEMENTS
- #****************
- #Connect the input signal to the neuron
- # The indices in neurons define which dimension the input will project to
- #nengo.Connection(input_signal, A, synapse=0.01)
- nengo.Connection(sin, neurons[0])
- nengo.Connection(cos, neurons[1])
- #****************
- # PROBES
- #****************
- # The original input
- #input_signal_probe = nengo.Probe(input_signal)
- sin_probe = nengo.Probe(sin, "output")
- cos_probe = nengo.Probe(cos, "output")
- # The raw spikes from the neuron
- neurons_rawspikes_probe = nengo.Probe(neurons.neurons)
- # Subthreshold soma voltage of the neuron
- #voltage = nengo.Probe(A.neurons, "voltage")
- # Spikes filtered by a 10ms post-synaptic filter
- #filtered = nengo.Probe(A.neurons, synapse=0.01)
- #filtered = nengo.Probe(A, synapse=0.01)
- neurons_probe = nengo.Probe(neurons, "decoded_output", synapse=0.01)
- with nengo.Simulator(model) as sim: # Create the simulator
- #****************
- # Run
- #****************
- sim.run(5) # Run it for 1 second
- #****************
- # plot the results
- #****************
- t = sim.trange()
- # Plot the decoded output of the ensemble
- plt.figure()
- plt.plot(sim.trange(), sim.data[neurons_probe], label="A_output")
- #plt.plot(sim.trange(), sim.data[input_signal_probe])
- plt.plot(sim.trange(), sim.data[sin_probe])
- plt.plot(sim.trange(), sim.data[cos_probe])
- #plt.xlim(0, 1)
- #plt.plot(sim.trange(), sim.data[neurons_rawspikes_probe])
- # Plot the spiking output of the ensemble
- #plt.figure()
- #rasterplot(sim.trange(), sim.data[neurons_rawspikes_probe])
- #plt.xlim(0, 1)
- # Plot the spiking output of the ensemble
- # plt.figure(figsize=(10, 8))
- # plt.subplot(221)
- # rasterplot(sim.trange(), sim.data[spikes])
- # plt.yticks((1,2),("On neuron", "Off neuron"))
- # plt.ylabel("Neuron")
- # plt.xlim(0, 1)
- # plt.ylim(2.5, 0.5)
- # # Plot the soma voltages of the neurons
- # plt.subplot(222)
- # #plt.plot(sim.trange(), sim.data[voltage][:, 0], "r")
- # plt.plot(t, sim.data[voltage][:, 0] + 1, "r")
- # plt.plot(t, sim.data[voltage][:, 1], "k")
- # plt.xlim(0, 1)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement