PredictiveNode

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

Bases: Node, ABC

Base class for predictive coding nodes that generate predictions.

Parameters:

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

value

current value of the node.

Type:

Parameter

abstractmethod energy(pred: Tensor) Tensor[source]

Computes variational free energy for a prediction of the node state.

Parameters:

pred (Tensor) – prediction of the node state.

Raises:

NotImplementedError – must be implemented by subclasses.

Returns:

variational free energy between the state and a prediction.

Return type:

Tensor

abstractmethod error(pred: Tensor) Tensor[source]

Computes elementwise error for a prediction of the node state.

Parameters:

pred (Tensor) – prediction of the node state.

Raises:

NotImplementedError – must be implemented by subclasses.

Returns:

elementwise error between the state and a prediction.

Return type:

Tensor

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

Computes a forward pass on the node.

When self.training is True, the prediction is assigned to the value and then value is returned. When self.training is False, the prediction is directly returned (i.e. this acts as the identity operation).

Parameters:

inputs (Tensor) – prediction of the value.

Returns:

value of the node.

Return type:

Tensor

init(value: Tensor) Parameter[source]

Initializes the node’s state to a new value.

Parameters:

value (Tensor) – value to initialize to.

Returns:

the reinitialized value.

Return type:

Parameter

Raises:

ValueError – shape of value is incompatible with the node.

reset() None[source]

Resets the node state.

This operation is typically executed after each new batch. With inference learning, this is done after M-step. With incremental inference learning, this is done after the final M-step.