bindsnet.analysis package

Submodules

bindsnet.analysis.pipeline_analysis module

class bindsnet.analysis.pipeline_analysis.MatplotlibAnalyzer(**kwargs)[source]

Bases: bindsnet.analysis.pipeline_analysis.PipelineAnalyzer

Renders output using Matplotlib.

Matplotlib requires objects to be kept around over the full lifetime of the plots; this is done through self.plots. An interactive session is needed so that we can continue processing and just update the plots.

Initializes the analyzer.

Keyword arguments:

Parameters:volts_type (str) – Type of plotting for voltages ("color" or "line").
finalize_step() → None[source]

Flush the output from the current step

plot_conv2d_weights(weights: torch.Tensor, tag: str = 'conv2d', step: int = None) → None[source]

Plot a connection weight matrix of a Conv2dConnection.

Parameters:
  • weights – Weight matrix of Conv2dConnection object.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_obs(obs: torch.Tensor, tag: str = 'obs', step: int = None) → None[source]

Pulls the observation off of torch and sets up for Matplotlib plotting.

Parameters:
  • obs – A 2D array of floats depicting an input image.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_reward(reward_list: list, reward_window: int = None, tag: str = 'reward', step: int = None) → None[source]

Plot the accumulated reward for each episode.

Parameters:
  • reward_list – The list of recent rewards to be plotted.
  • reward_window – The length of the window to compute a moving average over.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_spikes(spike_record: Dict[str, torch.Tensor], tag: str = 'spike', step: int = None) → None[source]

Plots all spike records inside of spike_record. Keeps unique plots for all unique tags that are given.

Parameters:
  • spike_record – Dictionary of spikes to be rasterized.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_voltages(voltage_record: Dict[str, torch.Tensor], thresholds: Optional[Dict[str, torch.Tensor]] = None, tag: str = 'voltage', step: int = None) → None[source]

Plots all voltage records and given thresholds. Keeps unique plots for all unique tags that are given.

Parameters:
  • voltage_record – Dictionary of voltages for neurons inside of networks organized by the layer they correspond to.
  • thresholds – Optional dictionary of threshold values for neurons.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
class bindsnet.analysis.pipeline_analysis.PipelineAnalyzer[source]

Bases: abc.ABC

Responsible for pipeline analysis. Subclasses maintain state information related to plotting or logging.

finalize_step() → None[source]

Flush the output from the current step.

plot_conv2d_weights(weights: torch.Tensor, tag: str = 'conv2d', step: int = None) → None[source]

Plot a connection weight matrix of a Conv2dConnection.

Parameters:
  • weights – Weight matrix of Conv2dConnection object.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_obs(obs: torch.Tensor, tag: str = 'obs', step: int = None) → None[source]

Pulls the observation from PyTorch and sets up for Matplotlib plotting.

Parameters:
  • obs – A 2D array of floats depicting an input image.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_reward(reward_list: list, reward_window: int = None, tag: str = 'reward', step: int = None) → None[source]

Plot the accumulated reward for each episode.

Parameters:
  • reward_list – The list of recent rewards to be plotted.
  • reward_window – The length of the window to compute a moving average over.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_spikes(spike_record: Dict[str, torch.Tensor], tag: str = 'spike', step: int = None) → None[source]

Plots all spike records inside of spike_record. Keeps unique plots for all unique tags that are given.

Parameters:
  • spike_record – Dictionary of spikes to be rasterized.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_voltages(voltage_record: Dict[str, torch.Tensor], thresholds: Optional[Dict[str, torch.Tensor]] = None, tag: str = 'voltage', step: int = None) → None[source]

Plots all voltage records and given thresholds. Keeps unique plots for all unique tags that are given.

Parameters:
  • voltage_record – Dictionary of voltages for neurons inside of networks organized by the layer they correspond to.
  • thresholds – Optional dictionary of threshold values for neurons.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
class bindsnet.analysis.pipeline_analysis.TensorboardAnalyzer(summary_directory: str = './logs')[source]

Bases: bindsnet.analysis.pipeline_analysis.PipelineAnalyzer

Initializes the analyzer.

Parameters:summary_directory – Directory to save log files.
finalize_step() → None[source]

No-op for TensorboardAnalyzer.

plot_conv2d_weights(weights: torch.Tensor, tag: str = 'conv2d', step: int = None) → None[source]

Plot a connection weight matrix of a Conv2dConnection.

Parameters:
  • weights – Weight matrix of Conv2dConnection object.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_obs(obs: torch.Tensor, tag: str = 'obs', step: int = None) → None[source]

Pulls the observation off of torch and sets up for Matplotlib plotting.

Parameters:
  • obs – A 2D array of floats depicting an input image.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_reward(reward_list: list, reward_window: int = None, tag: str = 'reward', step: int = None) → None[source]

Plot the accumulated reward for each episode.

Parameters:
  • reward_list – The list of recent rewards to be plotted.
  • reward_window – The length of the window to compute a moving average over.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_spikes(spike_record: Dict[str, torch.Tensor], tag: str = 'spike', step: int = None) → None[source]

Plots all spike records inside of spike_record. Keeps unique plots for all unique tags that are given.

Parameters:
  • spike_record – Dictionary of spikes to be rasterized.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.
plot_voltages(voltage_record: Dict[str, torch.Tensor], thresholds: Optional[Dict[str, torch.Tensor]] = None, tag: str = 'voltage', step: int = None) → None[source]

Plots all voltage records and given thresholds. Keeps unique plots for all unique tags that are given.

Parameters:
  • voltage_record – Dictionary of voltages for neurons inside of networks organized by the layer they correspond to.
  • thresholds – Optional dictionary of threshold values for neurons.
  • tag – A unique tag to associate the data with.
  • step – The step of the pipeline.

bindsnet.analysis.plotting module

bindsnet.analysis.plotting.plot_assignments(assignments: torch.Tensor, im: Optional[matplotlib.image.AxesImage] = None, figsize: Tuple[int, int] = (5, 5), classes: Optional[Sized] = None, save: Optional[str] = None) → matplotlib.image.AxesImage[source]

Plot the two-dimensional neuron assignments.

Parameters:
  • assignments – Vector of neuron label assignments.
  • im – Used for re-drawing the assignments plot.
  • figsize – Horizontal, vertical figure size in inches.
  • classes – Iterable of labels for colorbar ticks corresponding to data labels.
  • save – file name to save fig, if None = not saving fig.
Returns:

Used for re-drawing the assigments plot.

bindsnet.analysis.plotting.plot_conv2d_weights(weights: torch.Tensor, wmin: float = 0.0, wmax: float = 1.0, im: Optional[matplotlib.image.AxesImage] = None, figsize: Tuple[int, int] = (5, 5), cmap: str = 'hot_r') → matplotlib.image.AxesImage[source]

Plot a connection weight matrix of a Conv2dConnection.

Parameters:
  • weights – Weight matrix of Conv2dConnection object.
  • wmin – Minimum allowed weight value.
  • wmax – Maximum allowed weight value.
  • im – Used for re-drawing the weights plot.
  • figsize – Horizontal, vertical figure size in inches.
  • cmap – Matplotlib colormap.
Returns:

Used for re-drawing the weights plot.

bindsnet.analysis.plotting.plot_input(image: torch.Tensor, inpt: torch.Tensor, label: Optional[int] = None, axes: List[matplotlib.axes._axes.Axes] = None, ims: List[matplotlib.image.AxesImage] = None, figsize: Tuple[int, int] = (8, 4)) → Tuple[List[matplotlib.axes._axes.Axes], List[matplotlib.image.AxesImage]][source]

Plots a two-dimensional image and its corresponding spike-train representation.

Parameters:
  • image – A 2D array of floats depicting an input image.
  • inpt – A 2D array of floats depicting an image’s spike-train encoding.
  • label – Class label of the input data.
  • axes – Used for re-drawing the input plots.
  • ims – Used for re-drawing the input plots.
  • figsize – Horizontal, vertical figure size in inches.
Returns:

Tuple of (axes, ims) used for re-drawing the input plots.

bindsnet.analysis.plotting.plot_local_connection_2d_weights(lc: object, input_channel: int = 0, output_channel: int = None, im: Optional[matplotlib.image.AxesImage] = None, lines: bool = True, figsize: Tuple[int, int] = (5, 5), cmap: str = 'hot_r', color: str = 'r') → matplotlib.image.AxesImage[source]

Plot a connection weight matrix of a Connection with locally connected structure <http://yann.lecun.com/exdb/publis/pdf/gregor-nips-11.pdf>_. :param lc: An object of the class LocalConnection2D :param input_channel: The input channel to plot its corresponding weights, default is the first channel :param output_channel: If not None, will only plot the weights corresponding to this output channel (filter) :param lines: Indicates whether or not draw horizontal and vertical lines separating input regions. :param figsize: Horizontal and vertical figure size in inches. :param cmap: Matplotlib colormap. :return: ``ims, axes`: Used for re-drawing the plots.

bindsnet.analysis.plotting.plot_locally_connected_weights(weights: torch.Tensor, n_filters: int, kernel_size: Union[int, Tuple[int, int]], conv_size: Union[int, Tuple[int, int]], locations: torch.Tensor, input_sqrt: Union[int, Tuple[int, int]], wmin: float = 0.0, wmax: float = 1.0, im: Optional[matplotlib.image.AxesImage] = None, lines: bool = True, figsize: Tuple[int, int] = (5, 5), cmap: str = 'hot_r') → matplotlib.image.AxesImage[source]

Plot a connection weight matrix of a Connection with `locally connected structure <http://yann.lecun.com/exdb/publis/pdf/gregor-nips-11.pdf>_.

Parameters:
  • weights – Weight matrix of Conv2dConnection object.
  • n_filters – No. of convolution kernels in use.
  • kernel_size – Side length(s) of 2D convolution kernels.
  • conv_size – Side length(s) of 2D convolution population.
  • locations – Indices of input receptive fields for convolution population neurons.
  • input_sqrt – Side length(s) of 2D input data.
  • wmin – Minimum allowed weight value.
  • wmax – Maximum allowed weight value.
  • im – Used for re-drawing the weights plot.
  • lines – Whether or not to draw horizontal and vertical lines separating input regions.
  • figsize – Horizontal, vertical figure size in inches.
  • cmap – Matplotlib colormap.
Returns:

Used for re-drawing the weights plot.

bindsnet.analysis.plotting.plot_performance(performances: Dict[str, List[float]], ax: Optional[matplotlib.axes._axes.Axes] = None, figsize: Tuple[int, int] = (7, 4), x_scale: int = 1, save: Optional[str] = None) → matplotlib.axes._axes.Axes[source]

Plot training accuracy curves.

Parameters:
  • performances – Lists of training accuracy estimates per voting scheme.
  • ax – Used for re-drawing the performance plot.
  • figsize – Horizontal, vertical figure size in inches.
  • x_scale – scaling factor for the x axis, equal to the number of examples per performance measure
  • save – file name to save fig, if None = not saving fig.
Returns:

Used for re-drawing the performance plot.

bindsnet.analysis.plotting.plot_spikes(spikes: Dict[str, torch.Tensor], time: Optional[Tuple[int, int]] = None, n_neurons: Optional[Dict[str, Tuple[int, int]]] = None, ims: Optional[List[matplotlib.collections.PathCollection]] = None, axes: Union[matplotlib.axes._axes.Axes, List[matplotlib.axes._axes.Axes], None] = None, figsize: Tuple[float, float] = (8.0, 4.5)) → Tuple[List[matplotlib.image.AxesImage], List[matplotlib.axes._axes.Axes]][source]

Plot spikes for any group(s) of neurons.

Parameters:
  • 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.
  • time – Plot spiking activity of neurons in the given time range. Default is entire simulation time.
  • n_neurons – Plot spiking activity of neurons in the given range of neurons. Default is all neurons.
  • ims – Used for re-drawing the plots.
  • axes – Used for re-drawing the plots.
  • figsize – Horizontal, vertical figure size in inches.
Returns:

ims, axes: Used for re-drawing the plots.

bindsnet.analysis.plotting.plot_voltages(voltages: Dict[str, torch.Tensor], ims: Optional[List[matplotlib.image.AxesImage]] = None, axes: Optional[List[matplotlib.axes._axes.Axes]] = None, time: Tuple[int, int] = None, n_neurons: Optional[Dict[str, Tuple[int, int]]] = None, cmap: Optional[str] = 'jet', plot_type: str = 'color', thresholds: Dict[str, torch.Tensor] = None, figsize: Tuple[float, float] = (8.0, 4.5)) → Tuple[List[matplotlib.image.AxesImage], List[matplotlib.axes._axes.Axes]][source]

Plot voltages for any group(s) of neurons.

Parameters:
  • voltages – Contains voltage data by neuron layers.
  • ims – Used for re-drawing the plots.
  • axes – Used for re-drawing the plots.
  • time – Plot voltages of neurons in given time range. Default is entire simulation time.
  • n_neurons – Plot voltages of neurons in given range of neurons. Default is all neurons.
  • cmap – Matplotlib colormap to use.
  • figsize – Horizontal, vertical figure size in inches.
  • plot_type – The way how to draw graph. ‘color’ for pcolormesh, ‘line’ for curved lines.
  • thresholds – Thresholds of the neurons in each layer.
Returns:

ims, axes: Used for re-drawing the plots.

bindsnet.analysis.plotting.plot_weights(weights: torch.Tensor, wmin: Optional[float] = 0, wmax: Optional[float] = 1, im: Optional[matplotlib.image.AxesImage] = None, figsize: Tuple[int, int] = (5, 5), cmap: str = 'hot_r', save: Optional[str] = None) → matplotlib.image.AxesImage[source]

Plot a connection weight matrix.

Parameters:
  • weights – Weight matrix of Connection object.
  • wmin – Minimum allowed weight value.
  • wmax – Maximum allowed weight value.
  • im – Used for re-drawing the weights plot.
  • figsize – Horizontal, vertical figure size in inches.
  • cmap – Matplotlib colormap.
  • save – file name to save fig, if None = not saving fig.
Returns:

AxesImage for re-drawing the weights plot.

bindsnet.analysis.visualization module

bindsnet.analysis.visualization.plot_spike_trains_for_example(spikes: torch.Tensor, n_ex: Optional[int] = None, top_k: Optional[int] = None, indices: Optional[List[int]] = None) → None[source]

Plot spike trains for top-k neurons or for specific indices.

Parameters:
  • spikes – Spikes for one simulation run of shape (n_examples, n_neurons, time).
  • n_ex – Allows user to pick which example to plot spikes for.
  • top_k – Plot k neurons that spiked the most for n_ex example.
  • indices – Plot specific neurons’ spiking activity instead of top_k.
bindsnet.analysis.visualization.plot_voltage(voltage: torch.Tensor, n_ex: int = 0, n_neuron: int = 0, time: Optional[Tuple[int, int]] = None, threshold: float = None) → None[source]

Plot voltage for a single neuron on a specific example.

Parameters:
  • voltage – Tensor or array of shape [n_examples, n_neurons, time].
  • n_ex – Allows user to pick which example to plot voltage for.
  • n_neuron – Neuron index for which to plot voltages for.
  • time – Plot spiking activity of neurons between the given range of time.
  • threshold – Neuron spiking threshold.
bindsnet.analysis.visualization.plot_weights_movie(ws: numpy.ndarray, sample_every: int = 1) → None[source]

Create and plot movie of weights.

Parameters:
  • ws – Array of shape [n_examples, source, target, time].
  • sample_every – Sub-sample using this parameter.
bindsnet.analysis.visualization.summary(net) → str[source]

Summarizes informations about a Network. Includes layers and connection informations.

Parameters:net – Network
Returns:string

Module contents