/** * Creates a Cholesky decomposition of the symmetric positive definite * matrix A. The result is a Cholesky factor R, such that * R.transpose().times( R ) equals the original symmetirc PD matrix A. * * @param A * Symmetric positive definite matrix A to decompose * @return * Cholesky decomposition of the given matrix A. */ public static CholeskyDecompositionMTJ create( final DenseMatrix A ) { DenseCholesky cholesky = DenseCholesky.factorize( A.getInternalMatrix() ); if( !cholesky.isSPD() ) { throw new IllegalArgumentException( "Matrix must be symmetric and positive definite!" ); } DenseMatrix R = DenseMatrixFactoryMTJ.INSTANCE.createWrapper( new no.uib.cipr.matrix.DenseMatrix( cholesky.getU() ) ); return new CholeskyDecompositionMTJ( R ); }
/** * Creates a Cholesky decomposition of the symmetric positive definite * matrix A. The result is a Cholesky factor R, such that * R.transpose().times( R ) equals the original symmetirc PD matrix A. * * @param A * Symmetric positive definite matrix A to decompose * @return * Cholesky decomposition of the given matrix A. */ public static CholeskyDecompositionMTJ create( final DenseMatrix A ) { DenseCholesky cholesky = DenseCholesky.factorize( A.getInternalMatrix() ); if( !cholesky.isSPD() ) { throw new IllegalArgumentException( "Matrix must be symmetric and positive definite!" ); } DenseMatrix R = DenseMatrixFactoryMTJ.INSTANCE.createWrapper( new no.uib.cipr.matrix.DenseMatrix( cholesky.getU() ) ); return new CholeskyDecompositionMTJ( R ); }
/** * Creates a Cholesky decomposition of the symmetric positive definite * matrix A. The result is a Cholesky factor R, such that * R.transpose().times( R ) equals the original symmetirc PD matrix A. * * @param A * Symmetric positive definite matrix A to decompose * @return * Cholesky decomposition of the given matrix A. */ public static CholeskyDecompositionMTJ create( final DenseMatrix A ) { DenseCholesky cholesky = DenseCholesky.factorize( A.getInternalMatrix() ); if( !cholesky.isSPD() ) { throw new IllegalArgumentException( "Matrix must be symmetric and positive definite!" ); } DenseMatrix R = DenseMatrixFactoryMTJ.INSTANCE.createWrapper( new no.uib.cipr.matrix.DenseMatrix( cholesky.getU() ) ); return new CholeskyDecompositionMTJ( R ); }
/** * Generates the estimator based on the given observations and weight vector. * Equal weights are assumed if the weight vector is null. */ @Override public void estimate(double[][] observations, double[] weights) { if (weights == null) { weights = new double[observations.length]; for (int i = 0; i < weights.length; i++) { weights[i] = 1.0; } } DenseVector weightVector = new DenseVector(weights); weightVector = weightVector.scale(1.0 / weightVector.norm(Vector.Norm.One)); mean = weightedMean(observations, weightVector); Matrix cov = weightedCovariance(observations, weightVector, mean); // Compute inverse of covariance matrix DenseCholesky chol = new DenseCholesky(observations[0].length, true).factor((UpperSPDDenseMatrix)cov); covarianceInverse = new UpperSPDDenseMatrix(chol.solve(Matrices.identity(observations[0].length))); double logDeterminant = 0; for (int i = 0; i < observations[0].length; i++) { logDeterminant += Math.log(chol.getU().get(i, i)); } logDeterminant *= 2; lnconstant = -(Log2PI * observations[0].length + logDeterminant) * 0.5; }
/** * Generates the estimator based on the given observations and weight vector. * Equal weights are assumed if the weight vector is null. */ @Override public void estimate(double[][] observations, double[] weights) { if (weights == null) { weights = new double[observations.length]; for (int i = 0; i < weights.length; i++) { weights[i] = 1.0; } } DenseVector weightVector = new DenseVector(weights); weightVector = weightVector.scale(1.0 / weightVector.norm(Vector.Norm.One)); mean = weightedMean(observations, weightVector); Matrix cov = weightedCovariance(observations, weightVector, mean); // Compute inverse of covariance matrix DenseCholesky chol = new DenseCholesky(observations[0].length, true).factor((UpperSPDDenseMatrix)cov); covarianceInverse = new UpperSPDDenseMatrix(chol.solve(Matrices.identity(observations[0].length))); double logDeterminant = 0; for (int i = 0; i < observations[0].length; i++) { logDeterminant += Math.log(chol.getU().get(i, i)); } logDeterminant *= 2; lnconstant = -(Log2PI * observations[0].length + logDeterminant) * 0.5; }
logDeterminant += Math.log(chol.getU().get(i, i));
logDeterminant += Math.log(chol.getU().get(i, i));