Implementing Regression Model

I am no Sir (not yet knighted! :joy:). With respect to plotting the spikes, I would suggest you to go step by step, and try to understand how spikes are calculated/represented.

As I mentioned in my previous reply,

scaled_data = data[conv0_probe][ii] * scale_firing_rates * dt # where dt = 0.001

gives you the spikes where data is the output of sim.predict(). In your above plotting code, scaled_data = data[probe_l1][ii] * scale_firing_rates doesn’t give you spikes yet, you still need to multiply by the dt (which is 0.001 in your case, unless you changed it during simulation). This is done in scaled_data *= 0.001 line. This line rates = np.sum(scaled_data, axis=0) / (n_steps * nengo_sim.dt) calculates the firing rate from the spikes scaled_data. Once you would simply print scaled_data, it should like [0, 0, 10.0, 0, 0, 10.0, 0, 0, 10.0 ...], i.e. a bunch of zeros and non-zero values. The non-zero values are the spikes (more accurately → spike amplitudes).

Now, it should be very easy to plot it, a simple plt.plot(scaled_data) should show you where (and how) the spikes occur - the plotting curve will be continuous though. Therefore, for aesthetic reasons, we plot it via a rasterplot(), to get discrete lines in place of spikes.

For using rasterplot(), as I mentioned in my previous reply, reshape scaled_data (if not already in) your neuron spikes matrix as (timesteps, num_neurons). That is, if you are simulating your network for 40ms, and trying to plot spikes for 3 randomly selected neurons, your scaled_data (before feeding to rasterplot()) should look like: (40, 3) matrix, i.e. each column corresponds to a neuron, and it has the temporal spikes along the row axis. Another argument to your rasterplot() should be timesteps themselves, i.e. timesteps = np.arange(sim_tsteps) * dt. Therefore the function call should be rasterplot(timestep, scaled_data). If you don’t want to use rasterplot(), you can refer the def plot_spikes() function in this tutorial as well.

Overall, you may be required to first understand the linked tutorials line by line, see the outputs of the spike matrices, etc. before learning how to plot them.