jeshraghian / snntorch

Deep and online learning with spiking neural networks in Python
https://snntorch.readthedocs.io/en/latest/
MIT License
1.17k stars 202 forks source link

Tutorial 1 - 2.2.2 Index into Single Neuron Spike plot not displaying. #294

Closed Johnmakuta closed 4 months ago

Johnmakuta commented 4 months ago

Description

I'm trying to follow the instructions in Tutorial 1 Section 2.2.2 on the second plot. The first plot does display correctly (shown below).
image

When I try to follow the instructions for the second plot, I get this: image

What I Did

I have attempted modifying which index is used to specify a neuron. I have also attempted to using spike_data_sample2 instead of spike_data_sample. Both fail give the same result. I have also attempted to modify the s parameter passed. I still do not fully understand why the Time step is not 0 to 100 and is instead -0.04 to 0.04.

# 2.2.2 Raster Plots

# Reshape
spike_data_sample2 = spike_data_sample2.reshape((num_steps, -1))

# raster plot
fig = plt.figure(facecolor = "w", figsize = (10,5))
ax = fig.add_subplot(111)
splt.raster(spike_data_sample2, ax, s=1.5, c="black")

plt.title("Input Layer")
plt.xlabel("Time Step")
plt.ylabel("Neuron Number")
plt.show()

# Single Neuron Indexed

idx = 210  # index into 210th neuron

fig = plt.figure(facecolor="w", figsize=(8, 1))
ax = fig.add_subplot(111)

splt.raster(spike_data_sample.reshape(num_steps, -1)[:, idx].unsqueeze(1), ax, s=100, c="black", marker="|")

plt.title("Input Neuron")
plt.xlabel("Time step")
plt.yticks([])
plt.show()
Johnmakuta commented 4 months ago

Welp, not sure what happened but I cleared and reran my entire jupyter notebook and it worked this time. Not sure what I did, definitely my fault.