public void factorize ( boolean checkSymmetry ) throws Exception { if ( checkSymmetry && ! Property . TWELVE . isSymmetric ( Q ) ) { throw new Exception ( "Matrix is not symmetric" ) ; } double threshold = Utils . getDoubleMachineEpsilon ( ) ; this . LData = new double [ ( dim + 1 ) * dim / 2 ] ; for ( int i = 0 ; i < dim ; i ++ ) { int iShift = ( i + 1 ) * i / 2 ; for ( int j = 0 ; j < i + 1 ; j ++ ) { int jShift = ( j + 1 ) * j / 2 ; double sum = 0.0 ; for ( int k = 0 ; k < j ; k ++ ) { sum += LData [ jShift + k ] * LData [ iShift + k ] ; } if ( i == j ) { double d = Q . getQuick ( i , i ) - sum ; if ( ! ( d > threshold ) ) { throw new Exception ( "not positive definite matrix" ) ; } LData [ iShift + i ] = Math . sqrt ( d ) ; } else { LData [ iShift + j ] = 1.0 / LData [ jShift + j ] * ( Q . getQuick ( i , j ) - sum ) ; } } } }
Cholesky factorization L of psd matrix Q = L . LT