{ } Raw JSON

bundles / scipy latest / scipy / stats / _covariance / Covariance / from_cholesky

staticmethod

scipy.stats._covariance:Covariance.from_cholesky

source: /scipy/stats/_covariance.py :194

Signature

staticmethod def   from_cholesky ( cholesky )

Summary

Representation of a covariance provided via the (lower) Cholesky factor

Parameters

cholesky : array_like

The lower triangular Cholesky factor of the covariance matrix.

Notes

Let the covariance matrix be and be the lower Cholesky factor such that . Whitening of a data point is performed by computing . is calculated as , where the operation is performed element-wise.

This Covariance class does not support singular covariance matrices because the Cholesky decomposition does not exist for a singular covariance matrix.

Examples

Prepare a symmetric positive definite covariance matrix ``A`` and a data point ``x``.
import numpy as np
from scipy import stats
rng = np.random.default_rng()
n = 5
A = rng.random(size=(n, n))
A = A @ A.T  # make the covariance symmetric positive definite
x = rng.random(size=n)
Perform the Cholesky decomposition of ``A`` and create the `Covariance` object.
L = np.linalg.cholesky(A)
cov = stats.Covariance.from_cholesky(L)
Compare the functionality of the `Covariance` object against reference implementation.
from scipy.linalg import solve_triangular
res = cov.whiten(x)
ref = solve_triangular(L, x, lower=True)
np.allclose(res, ref)
res = cov.log_pdet
ref = np.linalg.slogdet(A)[-1]
np.allclose(res, ref)

Aliases

  • scipy.stats.Covariance.from_cholesky