FactorizedGaussianNode

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

Bases: AbstractGaussianNode

Gaussian predictive coding node with diagonal variances.

Assumes the covariance matrix is a diagonal matrix.

\[\begin{split}\boldsymbol{\Sigma} = \begin{bmatrix} \sigma_1 & 0 & \cdots & 0 \\ 0 & \sigma_2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \sigma_N \end{bmatrix}\end{split}\]
Parameters:
  • *shape (int | None) – shape of the node’s learned state.

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

value

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

Type:

Parameter

logvar

log of the distribution variances \(\log{\boldsymbol{\sigma}}\).

Type:

Parameter

property covariance: Tensor

Covariance matrix of the Gaussian distribution.

\[\boldsymbol{\Sigma} = \operatorname{diag}(\sigma_1, \sigma_2, \ldots, \sigma_N)\]
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 is used.

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

energy(pred: Tensor) Tensor[source]

Variational free energy with respect to the prediction.

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