/** * Returns the parameter * <SPAN CLASS="MATH"><I><B>Σ</B></I></SPAN> of this object. * */ public double[][] getSigma() { return sigma.toArray(); }
private final double[][] hessianSlow() { DoubleMatrix2D ret = null; if(P!=null){ ret = P; }else{ return FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER; } return ret.toArray(); }
public double[][] getCovariance() { return sigma.toArray(); }
public double[][] getCorrelation () { return getCorrelation_ (mu, sigma.toArray()); }
@Override public double[][] hessian(double[] X) { double[] d = new double[dim]; Arrays.fill(d, 2); return F2.diagonal(F1.make(d)).toArray(); }
/** * Similar to {@link #exp((DoubleMatrix2D)) exp}<TT>(A)</TT>. * * @param A input matrix * * @return the exponential of <SPAN CLASS="MATH"><I>A</I></SPAN> * */ public static double[][] exp (double[][] A) { DoubleMatrix2D V = new DenseDoubleMatrix2D(A); DoubleMatrix2D R = exp(V); return R.toArray(); }
public static TetradMatrix identity(int rows) { return new TetradMatrix(DoubleFactory2D.dense.identity(rows).toArray()); } }
public String toString() { return "\nSigma hat\n" + MatrixUtils.toStringSquare(getShat().toArray(), new DecimalFormat("0.0000"), covMatrix.getVariableNames()) + "\n\nLambda hat\n" + MatrixUtils.toStringSquare(getLhat().toArray(), new DecimalFormat("0.0000"), covMatrix.getVariableNames()) + "\n\nBeta hat\n" + MatrixUtils.toStringSquare(getBhat().toArray(), new DecimalFormat("0.0000"), covMatrix.getVariableNames()) + "\n\nOmega hat\n" + MatrixUtils.toStringSquare(getOhat().toArray(), new DecimalFormat("0.0000"), covMatrix.getVariableNames()) + "\n\nIterations\n" + getIterations() + "\n\ndiff = " + diff; }
public ColtDenseDoubleMatrix2D(DoubleMatrix2D m) { super(m.rows(), m.columns()); if (m instanceof DenseDoubleMatrix2D) { this.matrix = (DenseDoubleMatrix2D) m; } else { this.matrix = new DenseDoubleMatrix2D(m.toArray()); } }
public ColtDenseDoubleMatrix2D(DoubleMatrix2D m) { super(m.rows(), m.columns()); if (m instanceof DenseDoubleMatrix2D) { this.matrix = (DenseDoubleMatrix2D) m; } else { this.matrix = new DenseDoubleMatrix2D(m.toArray()); } }
@Override public double[][] hessian(double[] X) { DoubleMatrix1D x = F1.make(X); DoubleMatrix2D hessF0X = getHessF0(x); double[][] hessX = barrierFunction.hessian(X); if(hessX == FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER){ return hessF0X.assign(Mult.mult(tIter)).toArray(); }else{ DoubleMatrix2D phiHess = F2.make(hessX); return hessF0X.assign(Mult.mult(tIter)).assign(phiHess, Functions.plus).toArray(); } }
public static double[][] cholesky(double[][] covar) { return new CholeskyDecomposition( new DenseDoubleMatrix2D(covar)).getL().toArray(); }
public static TetradMatrix multOuter(TetradVector v1, TetradVector v2) { DoubleMatrix2D m = new Algebra().multOuter(new DenseDoubleMatrix1D(v1.toArray()), new DenseDoubleMatrix1D(v2.toArray()), null); return new TetradMatrix(m.toArray()); }
@Override public double[][] hessian(double[] Y) { DoubleMatrix1D y = DoubleFactory1D.dense.make(Y); DoubleMatrix1D X = y.viewPart(0, dim); DoubleMatrix2D origHess; double[][] origFiHessX = originalFi.hessian(X.toArray()); if(origFiHessX == FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER){ return FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER; }else{ origHess = F2.make(origFiHessX); DoubleMatrix2D[][] parts = new DoubleMatrix2D[][]{{origHess, null},{null,F2.make(1, 1)}}; return F2.compose(parts).toArray(); } }
public double[][] decompPCA (double[][] sigma){ // L'objet SingularValueDecomposition permet de recuperer la matrice // des valeurs propres en ordre decroissant et celle des vecteurs propres de // sigma (pour une matrice symetrique et definie-positive seulement). SingularValueDecomposition sv = new SingularValueDecomposition (new DenseDoubleMatrix2D (sigma)); DoubleMatrix2D D = sv.getS (); // diagonal // Calculer la racine carree des valeurs propres for (int i = 0; i < D.rows(); i++){ sortedEigenvalues[i] = D.getQuick (i, i); D.setQuick (i, i, Math.sqrt (D.getQuick (i, i))); } DoubleMatrix2D P = sv.getV(); // right factor matrix return P.zMult (D, null).toArray (); }
public static TetradMatrix solve(TetradMatrix a, TetradMatrix b) { DoubleMatrix2D _a = new DenseDoubleMatrix2D(a.toArray()); DoubleMatrix2D _b = new DenseDoubleMatrix2D(b.toArray()); return new TetradMatrix(new Algebra().solve(_a, _b).toArray()); }
@Override public double[][] hessian(double[] Y) { DoubleMatrix1D y = DoubleFactory1D.dense.make(Y); DoubleMatrix1D X = y.viewPart(0, originalDim); double[][] originalFiHess = originalFi.hessian(X.toArray()); if(originalFiHess==FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER){ return FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER; }else{ DoubleMatrix2D origHess = (originalFiHess!=FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER)? F2.make(originalFi.hessian(X.toArray())) : F2.make(X.size(), X.size()); DoubleMatrix2D[][] parts = new DoubleMatrix2D[][]{{origHess, null},{null,F2.make(1, 1)}}; return F2.compose(parts).toArray(); } }
public void execute() { Object dataModel = getDataModel(); Parameters params = getParams(); if (dataModel instanceof DataSet) { DataSet dataSet = (DataSet) dataModel; DoubleMatrix2D cov = new DenseDoubleMatrix2D(dataSet.getCovarianceMatrix().toArray()); Glasso glasso = new Glasso(cov); glasso.setMaxit((int) params.get("maxit", 10000)); glasso.setIa(params.getBoolean("ia", false)); glasso.setIs(params.getBoolean("is", false)); glasso.setItr(params.getBoolean("itr", false)); glasso.setIpen(params.getBoolean("ipen", false)); glasso.setThr(params.getDouble("thr", 1e-4)); glasso.setRhoAllEqual(1.0); Glasso.Result result = glasso.search(); TetradMatrix wwi = new TetradMatrix(result.getWwi().toArray()); List<Node> variables = dataSet.getVariables(); Graph resultGraph = new EdgeListGraph(variables); for (int i = 0; i < variables.size(); i++) { for (int j = i + 1; j < variables.size(); j++) { if (wwi.get(i, j) != 0.0 && wwi.get(i, j) != 0.0) { resultGraph.addUndirectedEdge(variables.get(i), variables.get(j)); } } } setResultGraph(resultGraph); } }
@Override public double[][] hessian(double[] X) { DoubleMatrix2D HessSum = F2.make(new double[getDim()][getDim()]); DoubleMatrix2D GradSum = F2.make(new double[getDim()][getDim()]); for (int j = 0; j < fi.length; j++) { double ineqValuejX = fi[j].value(X); double[][] fijHessianX = fi[j].hessian(X); DoubleMatrix2D ineqHessjX = (fijHessianX!=FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER)? F2.make(fijHessianX) : FunctionsUtils.ZEROES_MATRIX_PLACEHOLDER; DoubleMatrix1D ineqGradjX = F1.make(fi[j].gradient(X)); if(ineqHessjX!=FunctionsUtils.ZEROES_MATRIX_PLACEHOLDER){ HessSum.assign(ineqHessjX.assign(Mult.mult(-1./ineqValuejX)), Functions.plus); } GradSum.assign(ALG.multOuter(ineqGradjX, ineqGradjX, null).assign(Mult.mult(1. / Math.pow(ineqValuejX, 2))), Functions.plus); } return HessSum.assign(GradSum, Functions.plus).toArray(); }
@Override public double[][] hessian(double[] X) { DoubleMatrix1D x = DoubleFactory1D.dense.make(X); DoubleMatrix1D g = ALG.mult(A, x).assign(b, Functions.plus).assign(Functions.exp); double den = g.zSum(); DoubleMatrix1D r = DoubleFactory1D.dense.make(dim); for(int i=0; i<dim; i++){ double d = 0d; for(int k=0; k<A.rows(); k++){ d += g.get(k) * A.get(k, i); } r.set(i, d); } DoubleMatrix2D ret = DoubleFactory2D.dense.make(dim, dim); ret.assign(ALG.multOuter(r, r, null).assign(Mult.mult(-1d/Math.pow(den, 2))), Functions.plus); for(int k=0; k<A.rows(); k++){ ret.assign(ALG.multOuter(A.viewRow(k), A.viewRow(k), null).assign(Mult.mult(g.get(k))).assign(Mult.mult(1d/den)), Functions.plus); } return ret.toArray(); }