public CholeskyDecomposition regularizedCholesky(double[][] gram, int max_attempts, boolean throw_exception) { int attempts = 0; double addedL2 = 0; Matrix gmat = new Matrix(gram); CholeskyDecomposition chol = new CholeskyDecomposition(gmat); while (!chol.isSPD() && attempts < max_attempts) { if (addedL2 == 0) addedL2 = 1e-5; else addedL2 *= 10; ++attempts; for (int i = 0; i < gram.length; i++) gmat.set(i,i,addedL2); // try to add L2 penalty to make the Gram SPD Log.info("Added L2 regularization = " + addedL2 + " to diagonal of Gram matrix"); chol = new CholeskyDecomposition(gmat); } if (!chol.isSPD() && throw_exception) throw new Gram.NonSPDMatrixException(); return chol; }
/** Cholesky Decomposition @return CholeskyDecomposition @see CholeskyDecomposition */ public CholeskyDecomposition chol () { return new CholeskyDecomposition(this); }
public Matrix chol() { CholeskyDecomposition chol = new CholeskyDecomposition(matrix); Matrix r = new JamaDenseDoubleMatrix2D(chol.getL()); return r; }
public Matrix chol() { CholeskyDecomposition chol = new CholeskyDecomposition(matrix); Matrix r = new JamaDenseDoubleMatrix2D(chol.getL()); return r; }
public static CholeskyDecomposition cholesky(double[][] v) { return new CholeskyDecomposition(new Matrix(v)); }
public Matrix solveSPD(Matrix b) { if (b instanceof JamaDenseDoubleMatrix2D) { JamaDenseDoubleMatrix2D b2 = (JamaDenseDoubleMatrix2D) b; CholeskyDecomposition chol = new CholeskyDecomposition(matrix); return new JamaDenseDoubleMatrix2D(chol.solve(b2.matrix)); } else { return super.solve(b); } }
public Matrix solveSPD(Matrix b) { if (b instanceof JamaDenseDoubleMatrix2D) { JamaDenseDoubleMatrix2D b2 = (JamaDenseDoubleMatrix2D) b; CholeskyDecomposition chol = new CholeskyDecomposition(matrix); return new JamaDenseDoubleMatrix2D(chol.solve(b2.matrix)); } else { return super.solve(b); } }
public CholeskyDecomposition regularizedCholesky(double[][] gram, int max_attempts, boolean throw_exception) { int attempts = 0; double addedL2 = 0; Matrix gmat = new Matrix(gram); CholeskyDecomposition chol = new CholeskyDecomposition(gmat); while (!chol.isSPD() && attempts < max_attempts) { if (addedL2 == 0) addedL2 = 1e-5; else addedL2 *= 10; ++attempts; for (int i = 0; i < gram.length; i++) gmat.set(i,i,addedL2); // try to add L2 penalty to make the Gram SPD Log.info("Added L2 regularization = " + addedL2 + " to diagonal of Gram matrix"); chol = new CholeskyDecomposition(gmat); } if (!chol.isSPD() && throw_exception) throw new Gram.NonSPDMatrixException(); return chol; }
public Matrix invSPD() { CholeskyDecomposition chol = new CholeskyDecomposition(matrix); return new JamaDenseDoubleMatrix2D(chol.solve(Jama.Matrix.identity(matrix.getRowDimension(), matrix.getRowDimension()))); }
public Matrix invSPD() { CholeskyDecomposition chol = new CholeskyDecomposition(matrix); return new JamaDenseDoubleMatrix2D(chol.solve(Jama.Matrix.identity(matrix.getRowDimension(), matrix.getRowDimension()))); }