public static double [ ] [ ] factorReductionUsingCommonsMath ( double [ ] [ ] correlationMatrix , int numberOfFactors ) { // Extract factors corresponding to the largest eigenvalues double [ ] [ ] factorMatrix = getFactorMatrix ( correlationMatrix , numberOfFactors ) ; // Renormalize rows for ( int row = 0 ; row < correlationMatrix . length ; row ++ ) { double sumSquared = 0 ; for ( int factor = 0 ; factor < numberOfFactors ; factor ++ ) { sumSquared += factorMatrix [ row ] [ factor ] * factorMatrix [ row ] [ factor ] ; } if ( sumSquared != 0 ) { for ( int factor = 0 ; factor < numberOfFactors ; factor ++ ) { factorMatrix [ row ] [ factor ] = factorMatrix [ row ] [ factor ] / Math . sqrt ( sumSquared ) ; } } else { // This is a rare case: The factor reduction of a completely decorrelated system to 1 factor for ( int factor = 0 ; factor < numberOfFactors ; factor ++ ) { factorMatrix [ row ] [ factor ] = 1.0 ; } } } // Orthogonalized again double [ ] [ ] reducedCorrelationMatrix = ( new Array2DRowRealMatrix ( factorMatrix ) . multiply ( new Array2DRowRealMatrix ( factorMatrix ) . transpose ( ) ) ) . getData ( ) ; return getFactorMatrix ( reducedCorrelationMatrix , numberOfFactors ) ; }
Returns a correlation matrix which has rank &lt ; n and for which the first n factors agree with the factors of correlationMatrix .