StandardGaussianNode

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

Bases: AbstractGaussianNode

Gaussian predictive coding node with unit variance.

Assumes the covariance matrix is an identity matrix.

\[\boldsymbol{\Sigma} = \mathbf{I}\]
Parameters:

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

value

value of the node \(\mathbf{z}\).

Type:

Parameter

property covariance: Tensor

Covariance matrix of the Gaussian distribution.

\[\boldsymbol{\Sigma} = \mathbf{I}\]
Parameters:

value (float | Tensor) – new covariance for the distribution.

Raises:

RuntimeError – covariance is a fixed value.

Returns:

covariance of the distribution.

Return type:

Tensor

energy(pred: Tensor) Tensor[source]

Variational free energy with respect to the prediction.

\[\begin{split}\begin{aligned} \mathcal{F} &= \frac{1}{2} (\mathbf{z} - \boldsymbol{\mu}) (\mathbf{z} - \boldsymbol{\mu})^\intercal \\ &= \frac{1}{2} \lVert\mathbf{z} - \boldsymbol{\mu}\rVert_2^2 \end{aligned}\end{split}\]
Parameters:

pred (Tensor) – predicted distribution mean \(\boldsymbol{\mu}\).

Returns:

variational free energy \(\mathcal{F}\).

Return type:

Tensor

error(pred: Tensor) Tensor[source]

Error between the prediction and node state.

\[\boldsymbol{\varepsilon} = \mathbf{z} - \boldsymbol{\mu}\]
Parameters:

pred (Tensor) – predicted distribution mean \(\boldsymbol{\mu}\).

Returns:

elementwise error \(\boldsymbol{\varepsilon}\).

Return type:

Tensor

sample(value: Tensor, generator: Generator | None = None) Tensor[source]

Samples from the learned variational distribution.

Parameters:
  • value (Tensor) – location parameter of the variational distribution for sampling.

  • generator (Generator | None, optional) – pseudorandom number generator for sampling. Defaults to None.

Returns:

samples from the variational distribution.

Return type:

Tensor