@Override public long process(BenchmarkMatrix[] inputs, BenchmarkMatrix[] outputs, long numTrials) { DenseMatrix matA = inputs[0].getOriginal(); DenseCholesky cholesky = new DenseCholesky(matA.numRows(),false); LowerSPDDenseMatrix uspd = new LowerSPDDenseMatrix(matA); DenseMatrix result = null; long prev = System.nanoTime(); for( long i = 0; i < numTrials; i++ ) { // the input matrix is over written uspd.set(matA); if( !cholesky.factor(uspd).isSPD() ) { throw new RuntimeException("Is not SPD"); } result = cholesky.solve(Matrices.identity(matA.numColumns())); } long elapsedTime = System.nanoTime()-prev; if( outputs != null ) { outputs[0] = new MtjBenchmarkMatrix(result); } return elapsedTime; } }
/** * 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 ); }
@Override public long process(BenchmarkMatrix[] inputs, BenchmarkMatrix[] outputs, long numTrials) { DenseMatrix matA = inputs[0].getOriginal(); DenseCholesky cholesky = new DenseCholesky(matA.numRows(),false); LowerSPDDenseMatrix uspd = new LowerSPDDenseMatrix(matA); LowerTriangDenseMatrix L = null; long prev = System.nanoTime(); for( long i = 0; i < numTrials; i++ ) { // the input matrix is over written uspd.set(matA); if( !cholesky.factor(uspd).isSPD() ) { throw new DetectedException("Is not SPD"); } L = cholesky.getL(); } long elapsedTime = System.nanoTime()-prev; if( outputs != null ) { outputs[0] = new MtjBenchmarkMatrix(L); } return elapsedTime; } }
/** * Calculates a Cholesky decomposition * * @param A * Matrix to decompose. Not modified * @return The current decomposition */ public static DenseCholesky factorize(Matrix A) { return new DenseCholesky(A.numRows(), true) .factor(new UpperSPDDenseMatrix(A)); }
/** * 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; }
m_L = new DenseCholesky(n, true).factor((UpperSPDDenseMatrix)m_L).solve(Matrices.identity(n)); m_L = new UpperSPDDenseMatrix(m_L); // Convert from DenseMatrix
/** * 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; }
m_L = new DenseCholesky(n, true).factor((UpperSPDDenseMatrix)m_L).solve(Matrices.identity(n)); m_L = new UpperSPDDenseMatrix(m_L); // Convert from DenseMatrix
/** * Calculates a Cholesky decomposition * * @param A * Matrix to decompose. Not modified * @return The current decomposition */ public static DenseCholesky factorize(Matrix A) { return new DenseCholesky(A.numRows(), true) .factor(new UpperSPDDenseMatrix(A)); }
DenseCholesky chol = new DenseCholesky(m, true).factor((UpperSPDDenseMatrix)cov); covarianceInverse = new UpperSPDDenseMatrix(chol.solve(Matrices.identity(m))); logDeterminant += Math.log(chol.getU().get(i, i));
/** * 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 ); }
DenseCholesky chol = new DenseCholesky(m, true).factor((UpperSPDDenseMatrix)cov); covarianceInverse = new UpperSPDDenseMatrix(chol.solve(Matrices.identity(m))); logDeterminant += Math.log(chol.getU().get(i, i));
/** * 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 ); }