/** * Compacts the vector */ public void compact() { int nz = Matrices.cardinality(this); // catches zero entries if (nz < data.length) { int[] newIndex = new int[nz]; double[] newData = new double[nz]; // Copy only non-zero entries for (int i = 0, j = 0; i < data.length; ++i) if (data[i] != 0.) { newIndex[j] = index[i]; newData[j] = data[i]; j++; } data = newData; index = newIndex; used = data.length; } }
/** * Return the correlation/covariance matrix * * @return the correlation or covariance matrix */ public double[][] getCorrelationMatrix() { return Matrices.getArray(m_correlation); }
Matrix LUsolve(Matrix B, Matrix X) { if (!(X instanceof DenseMatrix)) throw new UnsupportedOperationException("X must be a DenseMatrix"); double[] Xd = ((DenseMatrix) X).getData(); X.set(B); int[] piv = new int[numRows]; intW info = new intW(0); LAPACK.getInstance().dgesv(numRows, B.numColumns(), data.clone(), Matrices.ld(numRows), piv, Xd, Matrices.ld(numRows), info); if (info.val > 0) throw new MatrixSingularException(); else if (info.val < 0) throw new IllegalArgumentException(); return X; }
@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; } }
DenseMatrix I = Matrices.identity(m); DenseMatrix CwInverse = I.copy(); System.err.println("CwInverse : \n" + Cw.solve(I, CwInverse)); rows[i] = i; Matrix reducedMatrix = Matrices.getSubMatrix(evd.getEigenvectors(), rows, cols);
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()))); }
/** * Compacts the vector */ public void compact() { int nz = Matrices.cardinality(this); // catches zero entries if (nz < data.length) { int[] newIndex = new int[nz]; double[] newData = new double[nz]; // Copy only non-zero entries for (int i = 0, j = 0; i < data.length; ++i) if (data[i] != 0.) { newIndex[j] = index[i]; newData[j] = data[i]; j++; } data = newData; index = newIndex; used = data.length; } }
private SymmBandEVD factor(Matrix A, double[] data, int kd) throws NotConvergedException { if (A.numRows() != n) throw new IllegalArgumentException("A.numRows() != n"); intW info = new intW(0); LAPACK.getInstance().dsbevd(job.netlib(), uplo.netlib(), n, kd, data, Matrices.ld(kd + 1), w, job == JobEig.All ? Z.getData() : new double[0], Matrices.ld(n), work, work.length, iwork, iwork.length, info); if (info.val > 0) throw new NotConvergedException( NotConvergedException.Reason.Iterations); else if (info.val < 0) throw new IllegalArgumentException(); return this; }
/** * Return the correlation/covariance matrix * * @return the correlation or covariance matrix */ public double[][] getCorrelationMatrix() { return Matrices.getArray(m_correlation); }
/** * Creates a random matrix. Numbers are drawn from a uniform distribution * between 0 and 1 * * @param numRows * Number of rows * @param numColumns * Number of columns */ public static Matrix random(int numRows, int numColumns) { return random(new DenseMatrix(numRows, numColumns)); }
@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; } }
@Override public String toString() { // Output into coordinate format. Indices start from 1 instead of 0 Formatter out = new Formatter(); out.format("%10d %19d\n", size, Matrices.cardinality(this)); int i = 0; for (VectorEntry e : this) { if (e.get() != 0) out.format("%10d % .12e\n", e.index() + 1, e.get()); if (++i == 100) { out.format("...\n"); break; } } return out.toString(); }
private SymmBandEVD factor(Matrix A, double[] data, int kd) throws NotConvergedException { if (A.numRows() != n) throw new IllegalArgumentException("A.numRows() != n"); intW info = new intW(0); LAPACK.getInstance().dsbevd(job.netlib(), uplo.netlib(), n, kd, data, Matrices.ld(kd + 1), w, job == JobEig.All ? Z.getData() : new double[0], Matrices.ld(n), work, work.length, iwork, iwork.length, info); if (info.val > 0) throw new NotConvergedException( NotConvergedException.Reason.Iterations); else if (info.val < 0) throw new IllegalArgumentException(); return this; }
.append(corrCov + "matrix\n" + matrixToString(Matrices.getArray(m_correlation)) + "\n\n"); result.append("eigenvalue\tproportion\tcumulative\n"); for (int i = m_numAttribs - 1; i > (m_numAttribs - numVectors - 1); i--) {
/** * Creates a random matrix. Numbers are drawn from a uniform distribution * between 0 and 1 * * @param numRows * Number of rows * @param numColumns * Number of columns */ public static Matrix random(int numRows, int numColumns) { return random(new DenseMatrix(numRows, numColumns)); }
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); }
@Override public String toString() { // Output into coordinate format. Indices start from 1 instead of 0 Formatter out = new Formatter(); out.format("%10d %19d\n", size, Matrices.cardinality(this)); int i = 0; for (VectorEntry e : this) { if (e.get() != 0) out.format("%10d % .12e\n", e.index() + 1, e.get()); if (++i == 100) { out.format("...\n"); break; } } return out.toString(); }