whiten {ForeCA} | R Documentation |
whitens multivariate data
Description
whiten
transforms a multivariate K-dimensional signal with mean
and covariance matrix
to a whitened
signal
with mean
and
.
Thus it centers the signal and makes it contemporaneously uncorrelated.
See Details.
check_whitened
checks if data has been whitened; i.e., if it has
zero mean, unit variance, and is uncorrelated.
sqrt_matrix
computes the square root of a square matrix
. The matrix
satisfies
.
Usage
whiten(data)
check_whitened(data, check.attribute.only = TRUE)
sqrt_matrix(mat, return.sqrt.only = TRUE, symmetric = FALSE)
Arguments
data |
|
check.attribute.only |
logical; if |
mat |
a square |
return.sqrt.only |
logical; if |
symmetric |
logical; if |
Details
whiten
uses zero component analysis (ZCA) (aka zero-phase whitening filters)
to whiten the data; i.e., it uses the
inverse square root of the covariance matrix of (see
sqrt_matrix
) as the whitening transformation.
This means that on top of PCA, the uncorrelated principal components are
back-transformed to the original space using the
transpose of the eigenvectors. The advantage is that this makes them comparable
to the original . See References for details.
The square root of a quadratic matrix
can be computed by using the eigen-decomposition of
where is an
matrix with the eigenvalues
in the diagonal.
The square root is simply
where
.
Similarly, the inverse square root is defined as
, where
(provided that
).
Value
whiten
returns a list with the whitened data, the transformation,
and other useful quantities.
check_whitened
throws an error if the input is not
whiten
ed, and returns (invisibly) the data with an attribute 'whitened'
equal to TRUE
. This allows to simply update data to have the
attribute and thus only check it once on the actual data (slow) but then
use the attribute lookup (fast).
sqrt_matrix
returns an matrix. If
is not semi-positive definite it returns a complex-valued
(since square root of negative eigenvalues are complex).
If return.sqrt.only = FALSE
then it returns a list with:
values |
eigenvalues of |
vectors |
eigenvectors of |
sqrt |
square root matrix |
sqrt.inverse |
inverse of |
References
See appendix in http://www.cs.toronto.edu/~kriz/learning-features-2009-TR.pdf.
See http://ufldl.stanford.edu/wiki/index.php/Implementing_PCA/Whitening.
Examples
## Not run:
XX <- matrix(rnorm(100), ncol = 2) %*% matrix(runif(4), ncol = 2)
cov(XX)
UU <- whiten(XX)$U
cov(UU)
## End(Not run)