IsotropicGaussianNode

class IsotropicGaussianNode(*shape: int | None, variance: float | Tensor = 1.0)[source]

Bases: AbstractGaussianNode

Gaussian predictive coding node with scalar variance.

Assumes the covariance matrix is a scalar matrix.

\[\boldsymbol{\Sigma} = \sigma\mathbf{I}\]
Parameters:
  • *shape (int | None) – shape of the node’s learned state.

  • variance (float | Tensor, optional) – initial variance. Defaults to 1.0.

value

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

Type:

Parameter

logvar

log of the distribution variance \(\log{\sigma}\).

Type:

Parameter

property covariance: Tensor

Covariance matrix of the Gaussian distribution.

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

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

Returns:

covariance of the distribution.

Return type:

Tensor

Note

Assigment of variances is performed as follows:

  • 0D-Tensor (or float): single variance is used.

  • 1D-Tensor: vector of variances are averaged.

  • 2D-Tensor: diagonal of the covariance matrix is averaged.

energy(pred: Tensor) Tensor[source]

Variational free energy with respect to the prediction.

\[\begin{split}\begin{aligned} \mathcal{F} &= \frac{1}{2} \left((\mathbf{z} - \boldsymbol{\mu}) ((\mathbf{z} - \boldsymbol{\mu}) \sigma^{-1})^\intercal + N \log \sigma\right) \\ &= \frac{1}{2} \left(\frac{\lVert\mathbf{z} - \boldsymbol{\mu}\rVert_2^2}{\sigma} + N \log \sigma\right) \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} = \frac{\mathbf{z} - \boldsymbol{\mu}}{\sigma}\]
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