{ } Raw JSON

bundles / scipy latest / scipy / stats / _covariance / Covariance / whiten

function

scipy.stats._covariance:Covariance.whiten

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

Signature

def   whiten ( self x )

Summary

Perform a whitening transformation on data.

Extended Summary

"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.

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_ : array_like

The transformed array of points.

Examples

import numpy as np
from scipy import stats
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 = stats.Covariance.from_precision(precision)
x = rng.multivariate_normal(np.zeros(n), cov_array, size=(10000))
x_ = cov_object.whiten(x)
np.cov(x_, rowvar=False)  # near-identity covariance

Aliases

  • scipy.stats.Covariance.whiten