public MTJDenseDoubleMatrix2D(DenseMatrix m) { super(m.numRows(), m.numColumns()); this.matrix = m; }
public MTJDenseDoubleMatrix2D(DenseMatrix m) { super(m.numRows(), m.numColumns()); this.matrix = m; }
@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; } }
/** * Convert a {@link DenseMatrix} to a {@link Matrix}. * * @param mjt * {@link DenseMatrix} to convert * @return converted matrix. */ public static Matrix convert(DenseMatrix mjt) { return convert(mjt, mjt.numRows(), mjt.numColumns()); }
@Override public long process(BenchmarkMatrix[] inputs, BenchmarkMatrix[] outputs, long numTrials) { DenseMatrix matA = inputs[0].getOriginal(); DenseMatrix matB = inputs[1].getOriginal(); DenseMatrix result = new DenseMatrix(matA.numColumns(),matB.numColumns()); long prev = System.nanoTime(); for( long i = 0; i < numTrials; i++ ) { matA.transBmult(matB,result); } long elapsedTime = System.nanoTime()-prev; if( outputs != null ) { outputs[0] = new MtjBenchmarkMatrix(result); } return elapsedTime; } }
@Override public long process(BenchmarkMatrix[] inputs, BenchmarkMatrix[] outputs, long numTrials) { DenseMatrix matA = inputs[0].getOriginal(); DenseMatrix result = new DenseMatrix(matA.numColumns(),matA.numRows()); long prev = System.nanoTime(); for( long i = 0; i < numTrials; i++ ) { matA.transpose(result); } long elapsedTime = System.nanoTime()-prev; if( outputs != null ) { outputs[0] = new MtjBenchmarkMatrix(result); } return elapsedTime; } }
private final static int sygvd(int itype, String jobz, String uplo, DenseMatrix A, DenseMatrix B, DenseVector W) { int info = dsygvd(itype, jobz, uplo, A.numColumns(), A.getData(), A.numRows(), B.getData(), B.numRows(), W.getData()); if (info == 0) { return 0; } else { if (info < 0) throw new IllegalArgumentException("LAPACK ERROR: DSYGVD returned " + info); throw new RuntimeException("LAPACK ERROR: DSYGVD returned " + info); } }
@Override public long process(BenchmarkMatrix[] inputs, BenchmarkMatrix[] outputs, long numTrials) { DenseMatrix matA = inputs[0].getOriginal(); DenseMatrix matB = inputs[1].getOriginal(); DenseMatrix result = new DenseMatrix(matA.numRows(),matB.numColumns()); long prev = System.nanoTime(); for( long i = 0; i < numTrials; i++ ) { matA.mult(matB,result); } long elapsedTime = System.nanoTime()-prev; if( outputs != null ) { outputs[0] = new MtjBenchmarkMatrix(result); } return elapsedTime; } }
@Override public VectorParameters derivative(Model model, double[] data) { final double[][] as = model.getLayerActivations(data); final double[] d2 = new double[as[1].length]; for (int i = 0; i < d2.length; i++) { d2[i] = -(data[i] - as[1][i]) * (as[1][i] * (1 - as[1][i])); } final DenseVector wd = (DenseVector) model.w1.transMult(new DenseVector(d2), new DenseVector(model.w1.numColumns())); final double[] d1 = wd.getData(); for (int i = 0; i < d1.length; i++) { d1[i] *= (as[0][i] * (1 - as[0][i])); } return null; }
private DenseMatrix solve(DenseMatrix B, Transpose trans) throws MatrixSingularException { if (singular) throw new MatrixSingularException(); if (B.numRows() != n) throw new IllegalArgumentException("B.numRows() != n"); intW info = new intW(0); LAPACK.getInstance().dgbtrs(trans.netlib(), n, kl, ku, B.numColumns(), LU.getData(), 2 * kl + ku + 1, ipiv, B.getData(), Matrices.ld(n), info); if (info.val < 0) throw new IllegalArgumentException(); return B; } }
@Override public VectorParameters derivative(Model model, double[] data) { final double[][] as = model.getLayerActivations(data); final double[] d2 = new double[as[1].length]; for (int i = 0; i < d2.length; i++) { d2[i] = -(data[i] - as[1][i]) * (as[1][i] * (1 - as[1][i])); } final DenseVector wd = (DenseVector) model.w1.transMult(new DenseVector(d2), new DenseVector(model.w1.numColumns())); final double[] d1 = wd.getData(); for (int i = 0; i < d1.length; i++) { d1[i] *= (as[0][i] * (1 - as[0][i])); } return null; }
private DenseMatrix solve(DenseMatrix B, Transpose trans) throws MatrixSingularException { if (singular) throw new MatrixSingularException(); if (B.numRows() != n) throw new IllegalArgumentException("B.numRows() != n"); intW info = new intW(0); LAPACK.getInstance().dgbtrs(trans.netlib(), n, kl, ku, B.numColumns(), LU.getData(), 2 * kl + ku + 1, ipiv, B.getData(), Matrices.ld(n), info); if (info.val < 0) throw new IllegalArgumentException(); return B; } }
/** * Creates an LU decomposition of the given matrix * * @param A * Matrix to decompose. Overwritten with the decomposition * @return The current decomposition */ public DenseLU factor(DenseMatrix A) { singular = false; intW info = new intW(0); LAPACK.getInstance().dgetrf(A.numRows(), A.numColumns(), A.getData(), Matrices.ld(A.numRows()), piv, info); if (info.val > 0) singular = true; else if (info.val < 0) throw new IllegalArgumentException(); LU.set(A); return this; }
public Matrix transAmult(Matrix B, DenseMatrix C) { if (pivots == null) return super.transAmult(B, C); checkTransAmultAdd(B, C); C.set(B); LAPACK.getInstance().dlaswp(C.numColumns(), C.getData(), Matrices.ld(C.numRows()), 1, pivots.length, pivots, transposed ? 1 : -1); return C; }
public Matrix mult(Matrix B, DenseMatrix C) { if (pivots == null) return super.mult(B, C); checkMultAdd(B, C); C.set(B); LAPACK.getInstance().dlaswp(C.numColumns(), C.getData(), Matrices.ld(C.numRows()), 1, pivots.length, pivots, transposed ? -1 : 1); return C; }
public Matrix transAmult(Matrix B, DenseMatrix C) { if (pivots == null) return super.transAmult(B, C); checkTransAmultAdd(B, C); C.set(B); LAPACK.getInstance().dlaswp(C.numColumns(), C.getData(), Matrices.ld(C.numRows()), 1, pivots.length, pivots, transposed ? 1 : -1); return C; }
private DenseMatrix solve(DenseMatrix B, Transpose trans) throws MatrixSingularException { if (singular) throw new MatrixSingularException(); if (B.numRows() != LU.numRows()) throw new IllegalArgumentException("B.numRows() != LU.numRows()"); intW info = new intW(0); LAPACK.getInstance().dgetrs(trans.netlib(), LU.numRows(), B.numColumns(), LU.getData(), Matrices.ld(LU.numRows()), piv, B.getData(), Matrices.ld(LU.numRows()), info); if (info.val < 0) throw new IllegalArgumentException(); return B; }
private DenseMatrix solve(DenseMatrix B, Transpose trans) throws MatrixSingularException { if (singular) throw new MatrixSingularException(); if (B.numRows() != LU.numRows()) throw new IllegalArgumentException("B.numRows() != LU.numRows()"); intW info = new intW(0); LAPACK.getInstance().dgetrs(trans.netlib(), LU.numRows(), B.numColumns(), LU.getData(), Matrices.ld(LU.numRows()), piv, B.getData(), Matrices.ld(LU.numRows()), info); if (info.val < 0) throw new IllegalArgumentException(); return B; }
public Matrix mult(Matrix B, DenseMatrix C) { if (pivots == null) return super.mult(B, C); checkMultAdd(B, C); C.set(B); LAPACK.getInstance().dlaswp(C.numColumns(), C.getData(), Matrices.ld(C.numRows()), 1, pivots.length, pivots, transposed ? -1 : 1); return C; }
private void estimate_internal(Matrix y, Matrix x) { try { final no.uib.cipr.matrix.DenseMatrix mjtX = new no.uib.cipr.matrix.DenseMatrix(x.getArray()); no.uib.cipr.matrix.SVD svd; svd = no.uib.cipr.matrix.SVD.factorize(mjtX); final Matrix u = MatrixUtils.convert(svd.getU(), svd.getU().numRows(), svd.getS().length); final Matrix v = MatrixUtils.convert(svd.getVt(), svd.getS().length, svd.getVt().numColumns()).transpose(); final Matrix d = MatrixUtils.diag(svd.getS()); weights = v.times(MatrixUtils.pseudoInverse(d)).times(u.transpose()).times(y); } catch (final NotConvergedException e) { throw new RuntimeException(e.getMessage()); } }