lava.lib.dnf.utils

lava.lib.dnf.utils.convenience

lava.lib.dnf.utils.convenience.num_dims(shape)

Computes the dimensionality of a shape, assuming that (1,) represents a zero-dimensional shape.

Parameters:

shape (tuple(int)) – shape of a population of neurons

Returns:

number of dimensions

Return type:

int

lava.lib.dnf.utils.convenience.num_neurons(shape)

Computes the number of neurons from a shape.

Return type:

int

Parameters:

shapetuple(int)

shape of a neural population (or input)

Returns:

: num_neurons : int

number of neurons

lava.lib.dnf.utils.convenience.to_ndarray(x)

Converts float, tuple, or list variables to numpy.ndarray.

Parameters:

x (float, tuple, list, numpy.ndarray) – variable to convert

Returns:

return – input converted to numpy.ndarray

Return type:

numpy.ndarray

lava.lib.dnf.utils.math

lava.lib.dnf.utils.math.gauss(shape, domain=None, amplitude=1.0, mean=None, stddev=None)

Evaluates the Gaussian function over a specified domain in multiple dimensions.

If a domain is specified, the function will evaluate the Gaussian at linearly interpolated values between the lower and upper bounds of the domain. The number of samples is determined by the shape parameter. For example, for given parameters shape=(5,) and domain=[[-5, -1]], it will evaluate the function at positions -5,-4,-3,-2,-1.

If no domain is specified, the function will evaluate the Gaussian at the indices of the sampling points. For instance, for a given shape of shape=(5,), it will evaluate the function at positions 0,1,2,3,4.

Parameters:
  • shape (tuple(int)) – number of sampling points along each dimension

  • domain (numpy.ndarray, optional) – lower and upper bound of input values for each dimension at which the Gaussian function is evaluated

  • amplitude (float, optional) – amplitude of the Gaussian, defaults to 1

  • mean (numpy.ndarray, optional) – mean of the Gaussian, defaults to 0

  • stddev (numpy.ndarray, optional) – standard deviation of the Gaussian, defaults to 1

Returns:

gaussian – multi-dimensional array with samples of the Gaussian

Return type:

numpy.ndarray

lava.lib.dnf.utils.math.is_odd(n)

Checks whether n is an odd number.

Parameters:

n (int) – number to check

Returns bool:

True if <n> is an odd number

Return type:

bool

lava.lib.dnf.utils.plotting

lava.lib.dnf.utils.plotting.compute_spike_rates(spike_data, window_size=11)

Computes instantaneous spike rates for all neurons over time

This method uses the window_size parameter to derive a kernel with which it convolves the spike_data. Yields an array of the same shape, with each value representing the spike rate of a neuron over the specified time window.

Parameters:
  • spike_data (numpy.ndarray) – spike data of dtype=bool (spike: 1, no-spike: 0) and shape (num_time_steps, num_neurons)

  • window_size (int, optional) – size of the time window in number of time steps

Returns:

spike_rates – array of same shape as spike_data which represents the instantaneous spike rate of every neuron at every time step

Return type:

numpy.ndarray

lava.lib.dnf.utils.plotting.raster_plot(spike_data, window_size=11)

Creates a raster plot, showing the spikes of all neurons over time.

The plot will use color to express the spike rate within a time window determined by rate_window (specified in number of time steps).

Parameters:
  • spike_data (numpy.ndarray) – spike data of dtype=bool (spike: 1, no-spike: 0) and shape (num_time_steps, num_neurons)

  • window_size (int, optional) – size of the time window in number of time steps

Return type:

None

lava.lib.dnf.utils.validation

lava.lib.dnf.utils.validation.validate_shape(shape)

Validate and potentially convert shape parameter.

The shape of different elements of the DNF library can be passed in as type tuple(int) or list(int) for multiple dimensions, or type int for a single dimension. In all cases, it is converted to tuple(int).

Return type:

Tuple[int, ...]

Parameters:

shapetuple(int) or list(int)

shape parameter to be validated

Returns:

: shape : tuple(int)

validated and converted shape parameter