Node

class Node(*shape: int | None)[source]

Bases: Module, ABC

Base class for predictive coding nodes.

Parameters:

*shape (int | None) – base shape of the node’s state.

Important

A placeholder \(\text{0}^\text{th}\) dimension is automatically added to shape.

property bshape: tuple[int, ...]

Shape of the node state, safe for tensor construction.

Returns:

shape of the node state.

Return type:

tuple[int, …]

Note

Placeholder dimensions represented with unit length dimensions. Use shape() for a version to use that preserves placeholders.

abstractmethod forward(inputs: Tensor, **kwargs) Tensor[source]

Computes a forward pass on the node.

Parameters:

inputs (Tensor) – input to the node.

Returns:

value of the node.

Return type:

Tensor

Raises:

NotImplementedError – must be implemented by subclasses.

Important

Subclasses implementing this method should perform the following operations: - Initialize the value of the node based on inputs if self.training is True. - Return the value of the node.

Most subclasses should inherit from PredictiveNode instead, although special cases may inherit from this class instead (see BiasNode for an example of this).

abstractmethod reset() None[source]

Resets transient node state.

Raises:

NotImplementedError – must be implemented by subclasses.

property shape: tuple[int | None, ...]

Shape of the node state.

Returns:

shape of the node state.

Return type:

tuple[int | None, …]

Note

Placeholder dimensions represented with None values. Use bshape() for a version to use when constructing broadcastable tensors.

property shapeobj: Shape

Object storing the node shape.

Returns:

object storing the node shape.

Return type:

Shape

property size: int

Size of the node state.

Returns:

size of the node state.

Return type:

int