AsCovarianceMatrix#
- class bayesflow.adapters.transforms.AsCovarianceMatrix(*, cholesky: bool = False, diag_kwargs: dict = None)[source]#
Bases:
ElementwiseTransformConstrains 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
Constraintransform 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
Constraintransform that constrains the diagonal to be positive. The lower bound is always fixed to 0.0. All other arguments use the default ofConstrain.
Examples
>>> adapter = bf.Adapter().as_covariance_matrix("cov_x", diag_kwargs={"method": "exp"})