lava.lib.dnf.operations

lava.lib.dnf.operations.enums

digraph inheritance44ca4d646e { bgcolor=transparent; rankdir=TB; size=""; "BorderType" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.enums.BorderType",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="An enumeration."]; "Enum" -> "BorderType" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Enum" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Generic enumeration."]; "ReduceMethod" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.enums.ReduceMethod",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Enum for reduce methods of ReduceDims operation"]; "Enum" -> "ReduceMethod" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class lava.lib.dnf.operations.enums.BorderType(value)

Bases: Enum

An enumeration.

CIRCULAR = 2
PADDED = 1
classmethod validate(border_type)

Validate type of <border_type>

Return type:

None

class lava.lib.dnf.operations.enums.ReduceMethod(value)

Bases: Enum

Enum for reduce methods of ReduceDims operation

MEAN = 2
SUM = 1
classmethod validate(reduce_method)

Validate type of <reduce_op>

Return type:

None

lava.lib.dnf.operations.exceptions

digraph inheritance3347ca1c38 { bgcolor=transparent; rankdir=TB; size=""; "MisconfiguredOpError" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.exceptions.MisconfiguredOpError",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Exception that is raised when an operation is misconfigured."]; }
exception lava.lib.dnf.operations.exceptions.MisconfiguredOpError(msg=None)

Bases: Exception

Exception that is raised when an operation is misconfigured.

Parameters:

msgstr (optional)

custom exception message that overwrites the default

lava.lib.dnf.operations.operations

digraph inheritance7e1e3182b3 { bgcolor=transparent; rankdir=TB; size=""; "ABC" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Helper class that provides a standard way to create an ABC using"]; "AbstractOperation" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.operations.AbstractOperation",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Abstract Operation, subclasses of which can be used to parameterize the"]; "ABC" -> "AbstractOperation" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Convolution" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.operations.Convolution",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Creates connectivity that resembles a convolution with a kernel."]; "AbstractOperation" -> "Convolution" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ExpandAlongDiagonal" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.operations.ExpandAlongDiagonal",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Creates connectivity that projects the output of a source population"]; "AbstractOperation" -> "ExpandAlongDiagonal" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ExpandDims" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.operations.ExpandDims",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Operation that expands the dimensionality of the input by projecting"]; "AbstractOperation" -> "ExpandDims" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Flip" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.operations.Flip",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Creates connectivity that flips all specified dimensions."]; "AbstractOperation" -> "Flip" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ReduceAlongDiagonal" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.operations.ReduceAlongDiagonal",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Creates connectivity that projects the output of a source population"]; "AbstractOperation" -> "ReduceAlongDiagonal" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ReduceDims" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.operations.ReduceDims",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Operation that reduces the dimensionality of the input by projecting"]; "AbstractOperation" -> "ReduceDims" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ReorderDims" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.operations.ReorderDims",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Operation that reorders the dimensions in the input to a specified new"]; "AbstractOperation" -> "ReorderDims" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Weights" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.operations.Weights",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Operation that generates one-to-one connectivity with given weights for"]; "AbstractOperation" -> "Weights" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
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

property output_shape: Tuple[int, ...]

Return the output shape of the operation

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

property kernel: Kernel

Returns the kernel

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

digraph inheritance8abf6fd3c5 { bgcolor=transparent; rankdir=TB; size=""; "ABC" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Helper class that provides a standard way to create an ABC using"]; "AbstractShapeHandler" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.shape_handlers.AbstractShapeHandler",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Abstract class for handling input and output shape of the"]; "ABC" -> "AbstractShapeHandler" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ExpandAlongDiagonalShapeHandler" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.shape_handlers.ExpandAlongDiagonalShapeHandler",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Shape handler for the ExpandAlongDiagonal operation, which projects"]; "AbstractShapeHandler" -> "ExpandAlongDiagonalShapeHandler" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ExpandDimsShapeHandler" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.shape_handlers.ExpandDimsShapeHandler",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Shape handler for operations that expand the dimensionality. New"]; "AbstractShapeHandler" -> "ExpandDimsShapeHandler" [arrowsize=0.5,style="setlinewidth(0.5)"]; "FlipShapeHandler" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.shape_handlers.FlipShapeHandler",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Shape handler for the Flip operation that flips specified dimensions."]; "KeepShapeShapeHandler" -> "FlipShapeHandler" [arrowsize=0.5,style="setlinewidth(0.5)"]; "KeepShapeShapeHandler" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.shape_handlers.KeepShapeShapeHandler",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Shape handler for operations that do not change the shape of the"]; "AbstractShapeHandler" -> "KeepShapeShapeHandler" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ReduceAlongDiagonalShapeHandler" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.shape_handlers.ReduceAlongDiagonalShapeHandler",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Shape handler for the ReduceAlongDiagonal operation, which projects"]; "AbstractShapeHandler" -> "ReduceAlongDiagonalShapeHandler" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ReduceDimsShapeHandler" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.shape_handlers.ReduceDimsShapeHandler",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Shape handler for operations that reduce the dimensionality of the"]; "AbstractShapeHandler" -> "ReduceDimsShapeHandler" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ReorderDimsShapeHandler" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.shape_handlers.ReorderDimsShapeHandler",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Shape handler for operations that reorder the input shape."]; "AbstractShapeHandler" -> "ReorderDimsShapeHandler" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ReshapeShapeHandler" [URL="../lava-lib-dnf/lava.lib.dnf.operations.html#lava.lib.dnf.operations.shape_handlers.ReshapeShapeHandler",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Shape handler for operations that reshape the input, changing"]; "AbstractShapeHandler" -> "ReshapeShapeHandler" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
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

property output_shape: Tuple[int, ...]

Return the output shape of the handler

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

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

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

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

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