def test_neurons_to_node(Simulator, nl_nodirect): name = 'neurons_to_node' N = 30 m = nengo.Model(name, seed=123) a = nengo.Ensemble(nl_nodirect(N), dimensions=1) out = nengo.Node(lambda t, x: x, size_in=N) nengo.Connection(a.neurons, out, filter=None) a_spikes = nengo.Probe(a, 'spikes') out_p = nengo.Probe(out, 'output') sim = Simulator(m) sim.run(0.6) t = sim.trange() with Plotter(Simulator, nl_nodirect) as plt: ax = plt.subplot(111) try: from nengo.matplotlib import rasterplot rasterplot(t, sim.data(a_spikes), ax=ax) rasterplot(t, sim.data(out_p), ax=ax) except ImportError: pass plt.savefig('test_connection.test_' + name + '.pdf') plt.close() assert np.allclose(sim.data(a_spikes)[:-1], sim.data(out_p)[1:])
def test_neurons_to_node(Simulator, nl_nodirect): name = 'neurons_to_node' N = 30 m = nengo.Network(label=name, seed=123) with m: m.config[nengo.Ensemble].neuron_type = nl_nodirect() a = nengo.Ensemble(N, dimensions=1) out = nengo.Node(lambda t, x: x, size_in=N) nengo.Connection(a.neurons, out, synapse=None) a_spikes = nengo.Probe(a.neurons) out_p = nengo.Probe(out) sim = Simulator(m) sim.run(0.6) t = sim.trange() with Plotter(Simulator, nl_nodirect) as plt: ax = plt.subplot(111) try: from nengo.matplotlib import rasterplot rasterplot(t, sim.data[a_spikes], ax=ax) rasterplot(t, sim.data[out_p], ax=ax) except ImportError: pass plt.savefig('test_connection.test_' + name + '.pdf') plt.close() assert np.allclose(sim.data[a_spikes], sim.data[out_p])
def test_neurons_to_node(Simulator, nl_nodirect): name = 'neurons_to_node' N = 30 m = nengo.Network(label=name, seed=123) with m: m.config[nengo.Ensemble].neuron_type = nl_nodirect() a = nengo.Ensemble(N, dimensions=1) out = nengo.Node(lambda t, x: x, size_in=N) nengo.Connection(a.neurons, out, synapse=None) a_spikes = nengo.Probe(a, 'spikes') out_p = nengo.Probe(out, 'output') sim = Simulator(m) sim.run(0.6) t = sim.trange() with Plotter(Simulator, nl_nodirect) as plt: ax = plt.subplot(111) try: from nengo.matplotlib import rasterplot rasterplot(t, sim.data[a_spikes], ax=ax) rasterplot(t, sim.data[out_p], ax=ax) except ImportError: pass plt.savefig('test_connection.test_' + name + '.pdf') plt.close() assert np.allclose(sim.data[a_spikes][:-1], sim.data[out_p][1:])
def _plot(data_fname, plot_fname, params, sims, sims_time, before_spikes, before_time, after_spikes, after_time, show=False): print "Plotting..." fig = plt.figure() plt.subplots_adjust(right=0.93, top=0.98, bottom=0.11, left=0.07, hspace=0.05) #plt.rc('text', usetex=True) mpl.rcParams['lines.linewidth'] = 1.5 mpl.rc('font', size=14) xticks = [2 * i * params.testing_time for i in range(4)] time = before_time spacing = 4 title_fontsize = 20 ax = plt.subplot(211) ax_spike = ax.twinx() ax.plot(sims_time, sims, color="Gray") spikes = np.concatenate((np.zeros((time.size, spacing)), before_spikes), axis=1) rasterplot(time, spikes, ax=ax_spike, color="Black") ax.set_ylim((0.0, 1.05)) ax.set_ylabel(r'$Similarity$', fontsize=title_fontsize) ax.set_yticks([0,1]) ax.set_xticks(xticks) ax.xaxis.set_ticklabels([]) ax_spike.set_yticks([]) ax = plt.subplot(212) ax_spike = ax.twinx() ax.plot(sims_time, sims, color="Gray") spikes = np.concatenate((np.zeros((time.size, spacing)), after_spikes), axis=1) rasterplot(time, spikes, ax=ax_spike, color="Black") ax.xaxis.set_tick_params(pad=8) ax.set_xlabel(r'$Time\ (s)$', fontsize=title_fontsize) ax.set_xticks(xticks) ax.set_ylabel(r'$Similarity$', fontsize=title_fontsize) ax.set_ylim((0.0, 1.05)) ax.set_yticks([0,1]) ax_spike.set_yticks([]) plt.savefig(plot_fname) if show: plt.show()
offset += 1 plt.subplot(offset) plt.plot(t, sim.data(error_p)[-trunc:, :], label='Error') plt.ylabel('Error: Decoded') remove_xlabels() offset += 1 plt.subplot(offset) plt.plot(t, sim.data(cleanup_p)[-trunc:, :], label='Cleanup') plt.ylabel('Cleanup: (Orig. Decoders)') remove_xlabels() offset += 1 plt.subplot(offset) rasterplot(spike_time, sim.data(cleanup_s)[-trunc:, :]) plt.ylabel('Cleanup: Spikes') offset += 1 plt.subplot(offset) connection_weights = np.squeeze(sim.data(weights_p)[-trunc:, :, :]) maxes = np.amax(connection_weights, 1) mins = np.amin(connection_weights, 1) plt.plot(t, maxes, label='weights') plt.plot(t, mins, label='weights') plt.ylabel('Oja Weights') offset += 1 if plot_connection_weights: extremes_only = True for i in range(min(1, cleanup_n)):
offset += 1 plt.subplot(offset) plt.plot(t, sim.data(error_p)[-trunc:,:], label='Error') plt.ylabel('Error: Decoded') remove_xlabels() offset += 1 plt.subplot(offset) plt.plot(t, sim.data(cleanup_p)[-trunc:,:], label='Cleanup') plt.ylabel('Cleanup: (Orig. Decoders)') remove_xlabels() offset += 1 plt.subplot(offset) rasterplot(spike_time, sim.data(cleanup_s)[-trunc:,:]) plt.ylabel('Cleanup: Spikes') offset += 1 plt.subplot(offset) connection_weights = np.squeeze(sim.data(weights_p)[-trunc:,:,:]) maxes = np.amax(connection_weights, 1) mins = np.amin(connection_weights, 1) plt.plot(t, maxes, label='weights') plt.plot(t, mins, label='weights') plt.ylabel('Oja Weights') offset += 1 if plot_connection_weights: extremes_only = True for i in range(min(1, cleanup_n)):
num_plots = 7 offset = num_plots * 100 + 10 + 1 # ----- Plot! ----- print "Plotting..." #Testing Phase 1 plt.subplot(offset) plt.plot(t1, inn1) plt.ylabel('Input') offset += 1 plt.title('Clean then noisy') plt.subplot(offset) rasterplot(t1, spikes1) plt.ylabel('Cleanup: Spikes') offset += 1 #Testing Phase 2 plt.subplot(offset) plt.plot(t1, inn2[-len(t1):]) plt.ylabel('Input') offset += 1 plt.subplot(offset) plt.plot(t1, [np.dot(i, training_vector) for i in inn2[-len(t1):]]) plt.ylabel('Similarity to training_vector') offset += 1 plt.subplot(offset)
n_output = nengo.Probe(n, 'decoded_output', filter = 0.01) # Spikes filtered by a 10ms post-synaptic filter sim = nengo.Simulator(model) #Create a simulator sim.run(1) # Run it for 5 seconds import matplotlib.pyplot as plt # Plot the decoded output of the ensemble t = sim.data(model.t_probe) #Get the time steps plt.plot(t, sim.data(n_output)) plt.plot(t, sim.data(sin_p)) plt.xlim(0,1) # Plot the spiking output of the ensemble from nengo.matplotlib import rasterplot plt.figure(figsize=(10,8)) plt.subplot(221) rasterplot(t, sim.data(n_spikes), colors=[(1,0,0), (0,0,0)]) plt.xlim(0,1) plt.yticks((1, 2), ("On neuron", "Off neuron")) # Plot the soma voltages of the neurons #plt.subplot(222) #data = sim.data('Neurons.voltages') #plt.plot(t, data[:,0]+1, 'r') #plt.plot(t, data[:,1], 'k') #plt.yticks(()) #plt.axis([0,1,0,2]) #plt.subplots_adjust(wspace=0.05) plt.show()