Derivation of Whitening Transformation
To transform a dataset so that its features are uncorrelated and each has unit variance, you use a process called whitening. Whitening is especially useful in machine learning and statistics, as many algorithms assume that input features are uncorrelated and standardized. The whitening transformation can be derived step by step using eigenvalue decomposition of the data's covariance matrix.
Suppose your data matrix X is of shape (nsβamples,nfβeatures) and is already mean-centered (each feature has mean zero). The first step is to compute the covariance matrix Ξ£ (sigma) of the data. This is given by:
Ξ£=n1βXβ€Xwhere n is the number of samples.
Next, you perform eigenvalue decomposition on the covariance matrix Ξ£. This means you find a matrix of eigenvectors U and a diagonal matrix of eigenvalues Ξ (lambda) such that:
Ξ£=UΞUβ€The matrix U contains the eigenvectors as columns, and Ξ is a diagonal matrix with the corresponding eigenvalues.
The whitening transformation seeks a matrix W such that the transformed data Xwhiteβ=XW has a covariance matrix equal to the identity matrix (i.e., uncorrelated features with unit variance). The transformation matrix W is derived as follows:
- Rotate the data using the eigenvectors: XU;
- Scale each component by the inverse square root of its eigenvalue: XUΞβ1/2.
Thus, the full whitening transformation is:
Xwhiteβ=XUΞβ1/2Uβ€Here, Ξβ1/2 means taking the reciprocal of the square root of each eigenvalue on the diagonal of Ξ. This operation scales each principal component to have unit variance.
In summary, the whitening transformation is constructed by first diagonalizing the covariance matrix via eigenvalue decomposition, then scaling the principal components, and finally rotating the data back to the original feature space. This ensures that the resulting features are both uncorrelated and standardized.
Whitening transforms data so that all features are uncorrelated (covariances are zero) and each has unit variance (variance equals one). This is achieved by scaling and rotating the data based on the eigenvalues and eigenvectors of its covariance matrix.
12345678910111213141516171819202122232425262728import numpy as np # Generate a simple 2D mean-centered dataset X = np.array([ [2.0, 0.0], [0.0, 2.0], [-2.0, 0.0], [0.0, -2.0] ]) # Step 1: Compute the covariance matrix cov = np.cov(X, rowvar=False) # Step 2: Eigenvalue decomposition eigvals, eigvecs = np.linalg.eigh(cov) # Step 3: Construct the whitening matrix # Lambda^{-1/2}: inverse square root of eigenvalues D_inv_sqrt = np.diag(1.0 / np.sqrt(eigvals)) # Whitening matrix: eigvecs @ D_inv_sqrt @ eigvecs.T whitening_matrix = eigvecs @ D_inv_sqrt @ eigvecs.T # Step 4: Apply the whitening transformation X_white = X @ whitening_matrix print("Whitened data:\n", X_white) print("Covariance of whitened data:\n", np.cov(X_white, rowvar=False))
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you explain why whitening is important in machine learning?
How does eigenvalue decomposition help in the whitening process?
Can you walk me through the steps of the whitening code example?
Awesome!
Completion rate improved to 5.26
Derivation of Whitening Transformation
Swipe to show menu
To transform a dataset so that its features are uncorrelated and each has unit variance, you use a process called whitening. Whitening is especially useful in machine learning and statistics, as many algorithms assume that input features are uncorrelated and standardized. The whitening transformation can be derived step by step using eigenvalue decomposition of the data's covariance matrix.
Suppose your data matrix X is of shape (nsβamples,nfβeatures) and is already mean-centered (each feature has mean zero). The first step is to compute the covariance matrix Ξ£ (sigma) of the data. This is given by:
Ξ£=n1βXβ€Xwhere n is the number of samples.
Next, you perform eigenvalue decomposition on the covariance matrix Ξ£. This means you find a matrix of eigenvectors U and a diagonal matrix of eigenvalues Ξ (lambda) such that:
Ξ£=UΞUβ€The matrix U contains the eigenvectors as columns, and Ξ is a diagonal matrix with the corresponding eigenvalues.
The whitening transformation seeks a matrix W such that the transformed data Xwhiteβ=XW has a covariance matrix equal to the identity matrix (i.e., uncorrelated features with unit variance). The transformation matrix W is derived as follows:
- Rotate the data using the eigenvectors: XU;
- Scale each component by the inverse square root of its eigenvalue: XUΞβ1/2.
Thus, the full whitening transformation is:
Xwhiteβ=XUΞβ1/2Uβ€Here, Ξβ1/2 means taking the reciprocal of the square root of each eigenvalue on the diagonal of Ξ. This operation scales each principal component to have unit variance.
In summary, the whitening transformation is constructed by first diagonalizing the covariance matrix via eigenvalue decomposition, then scaling the principal components, and finally rotating the data back to the original feature space. This ensures that the resulting features are both uncorrelated and standardized.
Whitening transforms data so that all features are uncorrelated (covariances are zero) and each has unit variance (variance equals one). This is achieved by scaling and rotating the data based on the eigenvalues and eigenvectors of its covariance matrix.
12345678910111213141516171819202122232425262728import numpy as np # Generate a simple 2D mean-centered dataset X = np.array([ [2.0, 0.0], [0.0, 2.0], [-2.0, 0.0], [0.0, -2.0] ]) # Step 1: Compute the covariance matrix cov = np.cov(X, rowvar=False) # Step 2: Eigenvalue decomposition eigvals, eigvecs = np.linalg.eigh(cov) # Step 3: Construct the whitening matrix # Lambda^{-1/2}: inverse square root of eigenvalues D_inv_sqrt = np.diag(1.0 / np.sqrt(eigvals)) # Whitening matrix: eigvecs @ D_inv_sqrt @ eigvecs.T whitening_matrix = eigvecs @ D_inv_sqrt @ eigvecs.T # Step 4: Apply the whitening transformation X_white = X @ whitening_matrix print("Whitened data:\n", X_white) print("Covariance of whitened data:\n", np.cov(X_white, rowvar=False))
Thanks for your feedback!