Plot spikes for any group(s) of neurons. :param spikes: Mapping from layer names to spiking data. Spike data has shape ``[time, n_1, ..., n_k]``, where ``[n_1, ..., n_k]`` is the shape of the recorded layer. :param time: Plot spiking activity of neurons in the given tim
(
spikes: Dict[str, torch.Tensor],
time: Optional[Tuple[int, int]] = None,
n_neurons: Optional[Dict[str, Tuple[int, int]]] = None,
ims: Optional[List[PathCollection]] = None,
axes: Optional[Union[Axes, List[Axes]]] = None,
figsize: Tuple[float, float] = (8.0, 4.5),
)
| 71 | |
| 72 | |
| 73 | def plot_spikes( |
| 74 | spikes: Dict[str, torch.Tensor], |
| 75 | time: Optional[Tuple[int, int]] = None, |
| 76 | n_neurons: Optional[Dict[str, Tuple[int, int]]] = None, |
| 77 | ims: Optional[List[PathCollection]] = None, |
| 78 | axes: Optional[Union[Axes, List[Axes]]] = None, |
| 79 | figsize: Tuple[float, float] = (8.0, 4.5), |
| 80 | ) -> Tuple[List[AxesImage], List[Axes]]: |
| 81 | # language=rst |
| 82 | """ |
| 83 | Plot spikes for any group(s) of neurons. |
| 84 | |
| 85 | :param spikes: Mapping from layer names to spiking data. Spike data has shape |
| 86 | ``[time, n_1, ..., n_k]``, where ``[n_1, ..., n_k]`` is the shape of the |
| 87 | recorded layer. |
| 88 | :param time: Plot spiking activity of neurons in the given time range. Default is |
| 89 | entire simulation time. |
| 90 | :param n_neurons: Plot spiking activity of neurons in the given range of neurons. |
| 91 | Default is all neurons. |
| 92 | :param ims: Used for re-drawing the plots. |
| 93 | :param axes: Used for re-drawing the plots. |
| 94 | :param figsize: Horizontal, vertical figure size in inches. |
| 95 | :return: ``ims, axes``: Used for re-drawing the plots. |
| 96 | """ |
| 97 | n_subplots = len(spikes.keys()) |
| 98 | if n_neurons is None: |
| 99 | n_neurons = {} |
| 100 | |
| 101 | spikes = {k: v.view(v.size(0), -1) for (k, v) in spikes.items()} |
| 102 | if time is None: |
| 103 | # Set it for entire duration |
| 104 | for key in spikes.keys(): |
| 105 | time = (0, spikes[key].shape[0]) |
| 106 | break |
| 107 | |
| 108 | # Use all neurons if no argument provided. |
| 109 | for key, val in spikes.items(): |
| 110 | if key not in n_neurons.keys(): |
| 111 | n_neurons[key] = (0, val.shape[1]) |
| 112 | |
| 113 | if ims is None: |
| 114 | fig, axes = plt.subplots(n_subplots, 1, figsize=figsize) |
| 115 | if n_subplots == 1: |
| 116 | axes = [axes] |
| 117 | |
| 118 | ims = [] |
| 119 | for i, datum in enumerate(spikes.items()): |
| 120 | spikes = ( |
| 121 | datum[1][ |
| 122 | time[0] : time[1], n_neurons[datum[0]][0] : n_neurons[datum[0]][1] |
| 123 | ] |
| 124 | .detach() |
| 125 | .clone() |
| 126 | .cpu() |
| 127 | .numpy() |
| 128 | ) |
| 129 | ims.append( |
| 130 | axes[i].scatter( |
no test coverage detected