AsCovarianceMatrix#

class bayesflow.adapters.transforms.AsCovarianceMatrix(*, cholesky: bool = False, diag_kwargs: dict = None)[source]#

Bases: ElementwiseTransform

Constrains neural network predictions of a variable to a valid (symmetric, positive definite) K x K covariance (or precision) matrix.

The unconstrained representation is a flat vector of K * (K + 1) / 2 entries of the lower Cholesky factor of the covariance matrix. First, the K diagonal entries, passed through a lower-bounded Constrain transform to keep them positive, followed by the K * (K - 1) / 2 entries from the lower triangular.

Parameters:
choleskybool, optional

Whether the constrained side of the transform is the Cholesky factor, rather than the full covariance matrix. Default is False (use the full covariance matrix).

diag_kwargsdict, optional

Keyword arguments forwarded to the Constrain transform that constrains the diagonal to be positive. The lower bound is always fixed to 0.0. All other arguments use the default of Constrain.

Examples

>>> adapter = bf.Adapter().as_covariance_matrix("cov_x", diag_kwargs={"method": "exp"})
forward(data: Tensor, **kwargs) → Tensor[source]#
inverse(data: Tensor, **kwargs) → Tensor[source]#
get_config() → dict[source]#
log_det_jac(data: Tensor, inverse: bool = False, **kwargs) → Tensor[source]#
__call__(data: Tensor, inverse: bool = False, **kwargs) → Tensor#

Call self as a function.

classmethod from_config(config: dict, custom_objects=None)#