@Override public long process(BenchmarkMatrix[] inputs, BenchmarkMatrix[] outputs, long numTrials) { DenseMatrix matA = inputs[0].getOriginal(); DenseMatrix I = Matrices.identity(matA.numColumns()); DenseMatrix inv = new DenseMatrix(matA.numColumns(),matA.numColumns()); long prev = System.nanoTime(); for( long i = 0; i < numTrials; i++ ) { matA.solve(I,inv); } long elapsedTime = System.nanoTime()-prev; if( outputs != null ) { outputs[0] = new MtjBenchmarkMatrix(inv); } return elapsedTime; } }
public Matrix invSPD() { DenseCholesky chol = DenseCholesky.factorize(getWrappedObject()); return new MTJDenseDoubleMatrix2D(chol.solve(Matrices.identity(matrix.numRows()))); }
public Matrix invSPD() { DenseCholesky chol = DenseCholesky.factorize(getWrappedObject()); return new MTJDenseDoubleMatrix2D(chol.solve(Matrices.identity(matrix.numRows()))); }
@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; } }
public double getDouble(long... coordinates) { if (inv == null) { DenseMatrix A = new MTJDenseDoubleMatrix2D(getSource()).getWrappedObject(); DenseMatrix I = Matrices.identity((int) getSource().getColumnCount()); DenseMatrix AI = I.copy(); inv = new MTJDenseDoubleMatrix2D((DenseMatrix) A.solve(I, AI)); } return inv.getAsDouble(coordinates); }
public double getDouble(long... coordinates) { if (inv == null) { DenseMatrix A = new MTJDenseDoubleMatrix2D(getSource()).getWrappedObject(); DenseMatrix I = Matrices.identity((int) getSource().getColumnCount()); DenseMatrix AI = I.copy(); inv = new MTJDenseDoubleMatrix2D((DenseMatrix) A.solve(I, AI)); } return inv.getAsDouble(coordinates); }
/** * 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; }
DenseMatrix I = Matrices.identity(m); DenseMatrix CwInverse = I.copy(); System.err.println("CwInverse : \n" + Cw.solve(I, CwInverse));
covarianceInverse = new UpperSPDDenseMatrix(chol.solve(Matrices.identity(m)));
covarianceInverse = new UpperSPDDenseMatrix(chol.solve(Matrices.identity(m)));
m_L = new DenseCholesky(n, true).factor((UpperSPDDenseMatrix)m_L).solve(Matrices.identity(n)); m_L = new UpperSPDDenseMatrix(m_L); // Convert from DenseMatrix
m_L = new DenseCholesky(n, true).factor((UpperSPDDenseMatrix)m_L).solve(Matrices.identity(n)); m_L = new UpperSPDDenseMatrix(m_L); // Convert from DenseMatrix