covmats.CovarianceMatrix.whiten#
- CovarianceMatrix.whiten(x)[source]#
Perform a whitening transformation on data.
“Whitening” (“white” as in “white noise”, in which each frequency has equal magnitude) transforms a set of random variables into a new set of random variables with unit-diagonal covariance. When a whitening transform is applied to a sample of points distributed according to a multivariate normal distribution with zero mean, the covariance of the transformed sample is approximately the identity matrix [Wikipedia, 2025, Novak and Vorechovsky, 2019].
- Parameters:
x (array_like) – An array of points. The last dimension must correspond with the dimensionality of the space, i.e., the number of columns in the covariance matrix.
- Returns:
x_ – The transformed array of points.
- Return type:
array_like
References
Wikipedia. Whitening transformation. Wikipedia, August 2025.
Lukas Novak and Miroslav Vorechovsky. Generalization of Coloring Linear Transformation. Transactions of the VŠB – Technical University of Ostrava, Civil Engineering Series, 2019. doi:10.31490/tces-2018-0013.
Examples
>>> import numpy as np >>> import covmats >>> rng = np.random.default_rng() >>> n = 3 >>> A = rng.random(size=(n, n)) >>> cov_array = A @ A.T # make matrix symmetric positive definite >>> precision = np.linalg.inv(cov_array) >>> cov_object = covmats.CovViaPrecisionCholesky( .. sp.linalg.cholesky(precision, lower=True)) >>> x = rng.multivariate_normal(np.zeros(n), cov_array, size=(10000)) >>> x_ = cov_object.whiten(x) >>> np.cov(x_, rowvar=False) # near-identity covariance array([[0.97862122, 0.00893147, 0.02430451], [0.00893147, 0.96719062, 0.02201312], [0.02430451, 0.02201312, 0.99206881]])