lava.lib.dnf.operations
lava.lib.dnf.operations.enums

lava.lib.dnf.operations.exceptions

lava.lib.dnf.operations.operations

- class lava.lib.dnf.operations.operations.AbstractOperation(shape_handler)
Bases:
ABC
Abstract Operation, subclasses of which can be used to parameterize the connect() function.
- Parameters
shape_handler (AbstractShapeHandler) – handles, configures, and validates the input and output shape of the operation
- compute_weights()
Computes the connectivity weight matrix of the operation. This public method only validates the configuration of the operation. The actual weights are computed in the abstract method _compute_weights().
- Returns
connectivity weight matrix
- Return type
numpy.ndarray
- configure(input_shape)
Configures an operation by setting its input and output shape.
- Parameters
input_shape (tuple(int)) – input shape of the operation
- Return type
None
- property input_shape: Tuple[int, ...]
Return the output shape of the operation
- Return type
Tuple
[int
,...
]
- property output_shape: Tuple[int, ...]
Return the output shape of the operation
- Return type
Tuple
[int
,...
]
- class lava.lib.dnf.operations.operations.Convolution(kernel, border_types=BorderType.PADDED)
Bases:
AbstractOperation
Creates connectivity that resembles a convolution with a kernel. Perhaps contrary to other implementations of the convolution, this operation always leaves the shape of the input intact. That is, a Convolution operation applied, for instance, to the output of a population of neurons of shape (42, 42) will also yield an output of shape (42, 42).
- Parameters
kernel (Kernel) – kernel of weights that the input will be convolved with; must be of the same dimensionality as the input
border_types (BorderType or list(BorderType)) – determines how the Convolution operation treats borders; valid values are (1) PADDED, in which case the borders will be padded with a value that can be specified in the Kernel or (2) CIRCULAR, in which case the values from the other side of the input will be used as ‘padding’ (this is sometimes also called “wrapped”)
- property border_types: List[BorderType]
Returns the list of border types
- Return type
List
[BorderType
]
- class lava.lib.dnf.operations.operations.ExpandAlongDiagonal
Bases:
AbstractOperation
Creates connectivity that projects the output of a source population onto the diagonal of the target population, where the target population has twice the number of dimensions as the source population. The dimensions of the source population can only have odd sizes. For instance, if the source population is a grid of neurons of shape (99, 79), the operation will project the output of that two-dimensional population into a 4D target population of shape (50, 40, 50, 40) along its diagonal. Each entry in the output shape is computed by out_size = (in_size + 1) / 2.
- class lava.lib.dnf.operations.operations.ExpandDims(new_dims_shape)
Bases:
AbstractOperation
Operation that expands the dimensionality of the input by projecting the dimensions of the input to the newly added dimensions.
- class lava.lib.dnf.operations.operations.Flip(dims=None)
Bases:
AbstractOperation
Creates connectivity that flips all specified dimensions.
- Parameters
dims (tuple(int) or int) – indices of the dimensions that are to be flipped
- class lava.lib.dnf.operations.operations.ReduceAlongDiagonal
Bases:
AbstractOperation
Creates connectivity that projects the output of a source population along its diagonal. For instance, if the source population is a grid of neurons of shape (40, 40), the operation will project (sum) the output of that two-dimensional population along its diagonal, yielding a one-dimensional output of shape (79,). The output size is computed by 79 = 40 * 2 - 1.
- class lava.lib.dnf.operations.operations.ReduceDims(reduce_dims, reduce_method=ReduceMethod.SUM)
Bases:
AbstractOperation
Operation that reduces the dimensionality of the input by projecting a specified subset of dimensions onto the remaining dimensions.
- Parameters
reduce_dims (int or tuple(int)) – indices of dimension that will be reduced/removed
reduce_method (ReduceMethod) – method by which the dimensions will be reduced (SUM or MEAN)
- class lava.lib.dnf.operations.operations.ReorderDims(order)
Bases:
AbstractOperation
Operation that reorders the dimensions in the input to a specified new order.
- Parameters
order (tuple(int)) – new order of the dimensions (see ReorderDimsShapeHandler)
- class lava.lib.dnf.operations.operations.Weights(weight)
Bases:
AbstractOperation
Operation that generates one-to-one connectivity with given weights for every synapse.
- Parameters
weight (float) – weight used for every connection
lava.lib.dnf.operations.shape_handlers

- class lava.lib.dnf.operations.shape_handlers.AbstractShapeHandler
Bases:
ABC
Abstract class for handling input and output shape of the AbstractOperation class.
- assert_configured()
Assert that input and output shape is configured.
- Return type
None
- configure(input_shape)
Configures the input and output shape of an operation given an input shape.
- Parameters
input_shape (tuple(int)) – input shape of an operation
- Return type
None
- property input_shape: Tuple[int, ...]
Return the input shape of the handler
- Return type
Tuple
[int
,...
]
- property output_shape: Tuple[int, ...]
Return the output shape of the handler
- Return type
Tuple
[int
,...
]
- class lava.lib.dnf.operations.shape_handlers.ExpandAlongDiagonalShapeHandler
Bases:
AbstractShapeHandler
Shape handler for the ExpandAlongDiagonal operation, which projects diagonally onto a multi-dimensional population.
- class lava.lib.dnf.operations.shape_handlers.ExpandDimsShapeHandler(new_dims_shape)
Bases:
AbstractShapeHandler
Shape handler for operations that expand the dimensionality. New dimensions (axes) will be appended to the already existing ones of the input. Their sizes must be specified using the <new_dims_shape> argument.
- Parameters
new_dims_shape (int or tuple(int)) – shape of the added dimensions; they will be appended to the shape of the input, for instance an input shape (2,) and new_dims_shape=(6, 8) will produce an output shape (2, 6, 8)
- property new_dims_shape: Tuple[int, ...]
Return the <new_dims_shape> attribute
- Return type
Tuple
[int
,...
]
- class lava.lib.dnf.operations.shape_handlers.FlipShapeHandler(dims=None)
Bases:
KeepShapeShapeHandler
Shape handler for the Flip operation that flips specified dimensions.
- Parameters
dims (tuple(int) or int) – indices of the dimensions that are to be flipped
- property dims: Tuple[int, ...]
Return the <dims> that are to be flipped
- Return type
Tuple
[int
,...
]
- class lava.lib.dnf.operations.shape_handlers.KeepShapeShapeHandler
Bases:
AbstractShapeHandler
Shape handler for operations that do not change the shape of the input.
- class lava.lib.dnf.operations.shape_handlers.ReduceAlongDiagonalShapeHandler
Bases:
AbstractShapeHandler
Shape handler for the ReduceAlongDiagonal operation, which projects diagonally from a multi-dimensional population.
- class lava.lib.dnf.operations.shape_handlers.ReduceDimsShapeHandler(reduce_dims)
Bases:
AbstractShapeHandler
Shape handler for operations that reduce the dimensionality of the input.
- Parameters
reduce_dims (int or tuple(int)) – indices of the dimensions to remove
- property reduce_dims: Tuple[int, ...]
Return the output shape of the handler
- Return type
Tuple
[int
,...
]
- class lava.lib.dnf.operations.shape_handlers.ReorderDimsShapeHandler(order)
Bases:
AbstractShapeHandler
Shape handler for operations that reorder the input shape.
- Parameters
order (tuple(int)) – order of the dimensions of the output; for instance if the input shape is (1, 2, 3) and order=(0, 2, 1), the output shape will be (1, 3, 2); must have the same number of elements as the input and output shape
- property order: Tuple[int, ...]
Return the order of the handler
- Return type
Tuple
[int
,...
]
- class lava.lib.dnf.operations.shape_handlers.ReshapeShapeHandler(output_shape)
Bases:
AbstractShapeHandler
Shape handler for operations that reshape the input, changing the shape but keeping the number of elements constant.
- Parameters
output_shape (tuple(int)) – output shape of an operation