API Reference

receptual.encoder(stimulus, receptive_field)

Encodes a stimulus using a receptive field.

This function performs temporal convolution of the stimulus with the receptive field kernel along the first dimension (axis 0).

Args:
stimulus: numpy.ndarray

Input stimulus with shape:

  • axis 0: time/samples (T)

  • axis [1:]: spatial dimensions

receptive_field: numpy.ndarray

Receptive field kernel with shape:

  • axis 0: kernel timepoints (K) where K < T

  • axis 1: number of neurons (N)

  • axis [2:]: spatial dimensions (must match stimulus)

Returns:
numpy.ndarray:

The encoded stimulus with shape:

  • axis 0: time/samples (T) (same as input)

  • axis 1: number of neurons (N)

Notes:

We treat this as the application of a weight matrix found by linear regression to the stimulus:

Y = X*W

Where Y is an output matrix of shape (T, N), X is the design matrix of shape (T, K*spatial_dims), and W is the receptive field kernel of shape (K*spatial_dims,N).

Usage:

>> activity = encoder(stimulus, receptive_field)

receptual.receptive_field(stimulus, activity, kernel_size)

Computes the receptive field kernel that maps stimulus to activity.

This function inverts the encoder function by finding the optimal receptive field that transforms the stimulus into the given neural activity via a linear mapping.

Args:
stimulus: numpy.ndarray

Input stimulus with shape:

  • axis 0: time/samples (T)

  • axis [1:]: spatial dimensions

activity: numpy.ndarray

Neural activity with shape:

  • axis 0: time/samples (T) (must match stimulus)

  • axis 1: number of neurons (N)

kernel_size: int

Temporal size of the receptive field kernel (K)

Returns:
numpy.ndarray:

Estimated receptive field kernel with shape:

  • axis 0: kernel timepoints (K)

  • axis 1: number of neurons (N) from activity

  • axis [2:]: spatial dimensions from stimulus

Notes:

We treat this as the solution of a linear regression problem where the stimulus makes up the design matrix, activity is the target output, and the receptive field is the weight matrix:

W = (X^T * X)^-1 * (X^T * Y)

Where Y is an output matrix of shape (T, N), X is the design matrix of shape (T, K*spatial_dims), and W is the receptive field kernel of shape (K*spatial_dims,N).

Usage:

>> receptive_field = receptive_field(stimulus, activity, kernel_size)