Normalizations |
Normalizations allow to center or standardize data collection.
Hereinafter the following convention is used:
x denotes matrix column.
For matrix, columns corresponds to variables, rows corresponds to observations. Thus, the resulting centered or standardized matrix consists of centered/standardized columns, which are calculated analogically to vector case.
Centered column is calculated using the following formula:
Standardized column is calculated using the following formula:
Ensuring boundaries involves replacing values below left boundary/above right boundary with boundary value.
The whitening transformation is a decorrelation method that converts the covariance matrix of a set of samples into the identity matrix I. This effectively linearly transforms random variables such that the resulting variables are uncorrelated and have the same variances as the original random variables. this transformation is invertible. The method is called the whitening transform because it transforms the input matrix closer towards white noise.
Provided methods white series in specified data matrix. They use user specified covariance matrix instead of actual calculation. We transform matrix of observations X linearly so that we obtain a new matrix ˜X which is white, i.e. its components are uncorrelated and their variances equal unity. In other words, the covariance matrix of ˜X equals the identity matrix:
where
Whitening transformation can be obtained through SVD decomposition of covariance matrix of X:
where U is a unitary matrix, S is a diagonal matrix with the singular values of the covariance matrix on the diagonal, and the transpose of V is a unitary matrix.
Whitening transformation can now be done by:
Cholesky whitening involves Cholesky decomposition of the covariance matrix:
where U is an upper triangular matrix. Then the transformation can be defined as:
Matrix normalizations sample:
1using System; 2using FinMath.LinearAlgebra; 3using FinMath.Statistics.Distributions; 4using FinMath.Statistics; 5 6namespace FinMath.Samples 7{ 8 class MatrixNormalizationsSample 9 { 10 static Matrix matrix; 11 12 static void Main() 13 { 14 // Input parameters: 15 const Int32 observationsCount = 10; 16 const Int32 seriesCount = 3; 17 const Double trimmingQuantile = 0.25; 18 19 Normal normalDistribution = new Normal(); 20 matrix = Matrix.Random(observationsCount, seriesCount, normalDistribution); 21 22 // Output input matrix and their covariance. 23 Console.WriteLine("Transposed input matrix:"); 24 Console.WriteLine(matrix.GetTransposed().ToString("0.000")); 25 Console.WriteLine("Input covariance matrix:"); 26 Console.WriteLine(matrix.Covariance().ToString("0.000")); 27 28 // Trim values smaller than specified quantile. 29 Double quantile = matrix.ToColumnWiseArray().Quantile(trimmingQuantile); 30 Matrix trimmed = matrix.GetEnsuredLeftBoundary(quantile); 31 Console.WriteLine(); 32 Console.WriteLine($"Transposed trimmed matrix (smallest value will be {quantile:0.000}):"); 33 Console.WriteLine(trimmed.GetTransposed().ToString("0.000")); 34 35 // Center input matrix and print it and their means. 36 Matrix cetnered = matrix.GetCentered(); 37 Console.WriteLine(); 38 Console.WriteLine("Transposed centerd matrix:"); 39 Console.WriteLine(cetnered.GetTransposed().ToString("0.000")); 40 Console.WriteLine("Centerd matrix mean:"); 41 Console.WriteLine(cetnered.Mean().ToString("0.000")); 42 43 // Standardize input matrix and print it and their covariance. 44 Matrix standardized = matrix.GetStandardized(); 45 Console.WriteLine(); 46 Console.WriteLine("Transposed standardized matrix:"); 47 Console.WriteLine(standardized.GetTransposed().ToString("0.000")); 48 Console.WriteLine("Standardized matrix covariance:"); 49 Console.WriteLine(standardized.Covariance().ToString("0.000")); 50 51 // White input matrix and print it and their covariance. 52 Matrix whited = matrix.GetWhited(); 53 Console.WriteLine(); 54 Console.WriteLine("Transposed whited matrix:"); 55 Console.WriteLine(whited.GetTransposed().ToString("0.000")); 56 Console.WriteLine("Whited matrix covariance:"); 57 Console.WriteLine(whited.Covariance().ToString("0.000")); 58 } 59 } 60}