bindsnet package

Subpackages

Submodules

bindsnet.utils module

bindsnet.utils.col2im_indices(cols: torch.Tensor, x_shape: Tuple[int, int, int, int], kernel_height: int, kernel_width: int, padding: Tuple[int, int] = (0, 0), stride: Tuple[int, int] = (1, 1)) → torch.Tensor[source]

col2im is a special case of fold which is implemented inside of Pytorch.

Parameters:
  • cols – Image tensor in column-wise format.
  • x_shape – Shape of original image tensor.
  • kernel_height – Height of the convolutional kernel in pixels.
  • kernel_width – Width of the convolutional kernel in pixels.
  • padding – Amount of zero padding on the input image.
  • stride – Amount to stride over image by per convolution.
Returns:

Image tensor in original image shape.

bindsnet.utils.get_square_assignments(assignments: torch.Tensor, n_sqrt: int) → torch.Tensor[source]

Return a grid of assignments.

Parameters:
  • assignments – Vector of integers corresponding to class labels.
  • n_sqrt – Square root of no. of assignments.
Returns:

Reshaped square matrix of assignments.

bindsnet.utils.get_square_weights(weights: torch.Tensor, n_sqrt: int, side: Union[int, Tuple[int, int]]) → torch.Tensor[source]

Return a grid of a number of filters sqrt ** 2 with side lengths side.

Parameters:
  • weights – Two-dimensional tensor of weights for two-dimensional data.
  • n_sqrt – Square root of no. of filters.
  • side – Side length(s) of filter.
Returns:

Reshaped weights to square matrix of filters.

bindsnet.utils.im2col_indices(x: torch.Tensor, kernel_height: int, kernel_width: int, padding: Tuple[int, int] = (0, 0), stride: Tuple[int, int] = (1, 1)) → torch.Tensor[source]

im2col is a special case of unfold which is implemented inside of Pytorch.

Parameters:
  • x – Input image tensor to be reshaped to column-wise format.
  • kernel_height – Height of the convolutional kernel in pixels.
  • kernel_width – Width of the convolutional kernel in pixels.
  • padding – Amount of zero padding on the input image.
  • stride – Amount to stride over image by per convolution.
Returns:

Input tensor reshaped to column-wise format.

bindsnet.utils.reshape_conv2d_weights(weights: torch.Tensor) → torch.Tensor[source]

Flattens a connection weight matrix of a Conv2dConnection

Parameters:
  • weights – Weight matrix of Conv2dConnection object.
  • wmin – Minimum allowed weight value.
  • wmax – Maximum allowed weight value.
bindsnet.utils.reshape_local_connection_2d_weights(w: torch.Tensor, n_filters: int, kernel_size: Union[int, Tuple[int, int]], conv_size: Union[int, Tuple[int, int]], input_sqrt: Union[int, Tuple[int, int]]) → torch.Tensor[source]

Reshape a slice of weights of a LocalConnection2D slice for plotting. :param w: Slice of weights from a LocalConnection2D object. :param n_filters: Number of filters (output channels). :param kernel_size: Side length(s) of convolutional kernel. :param conv_size: Side length(s) of convolution population. :param input_sqrt: Sides length(s) of input neurons. :return: A slice of LocalConnection2D weights reshaped as a collection of spatially ordered square grids.

bindsnet.utils.reshape_locally_connected_weights(w: 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]]) → torch.Tensor[source]

Get the weights from a locally connected layer and reshape them to be two-dimensional and square.

Parameters:
  • w – Weights from a locally connected layer.
  • n_filters – No. of neuron filters.
  • kernel_size – Side length(s) of convolutional kernel.
  • conv_size – Side length(s) of convolution population.
  • locations – Binary mask indicating receptive fields of convolution population neurons.
  • input_sqrt – Sides length(s) of input neurons.
Returns:

Locally connected weights reshaped as a collection of spatially ordered square grids.

Module contents