MultivariateGaussianNode

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

Bases: AbstractGaussianNode

Gaussian predictive coding node with full covariance.

The covariances of the distribution are represented as a full covariance matrix, that is, a matrix that is symmetric and positive-definite.

Internally, the covariance matrix is stored as two parts that can be combined into the Cholesky factor \(\mathbf{L}\) of the covariance matrix \(\boldsymbol{\Sigma}\).

\[\boldsymbol{\Sigma} = \mathbf{L}\mathbf{L}^\ast\]
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

covar_cf_logdiag

log of the diagonal of the Cholesky factor for the distribution covariance.

Type:

Parameter

covar_cf_offtril

Cholesky factor for the distribution covariances, with the diagonal zeroed.

Type:

Parameter

property covariance: Tensor

Covariance matrix of the Gaussian distribution.

\[\begin{split}\boldsymbol{\Sigma} = \begin{bmatrix} \sigma_{1,1} & \sigma_{1,2} & \cdots & \sigma_{1,N} \\ \sigma_{2,1} & \sigma_{2,2} & \cdots & \sigma_{2,N} \\ \vdots & \vdots & \ddots & \vdots \\ \sigma_{N,1} & \sigma_{N,2} & \cdots & \sigma_{N,N} \\ \end{bmatrix}\end{split}\]
Parameters:

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

Returns:

covariance of the distribution.

Return type:

Tensor

Note

Assigment of covariances is performed as follows:

  • 0D-Tensor (or float): single variance is used, with zero covariance.

  • 1D-Tensor: vector of variances is used, with zero covariance.

  • 2D-Tensor: 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}) \boldsymbol{\Sigma}^{-1} (\mathbf{z} - \boldsymbol{\mu})^\intercal + \log \lvert\boldsymbol{\Sigma}\rvert \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} = \boldsymbol{\Sigma}^{-1} (\mathbf{z} - \boldsymbol{\mu})^\intercal\]
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 (torch.Generator | None, optional) – pseudorandom number generator for sampling. Defaults to None.

Returns:

samples from the variational distribution.

Return type:

Tensor