public double trace() { return apacheData.getTrace(); }
@Override public double getTrace(Matrix m) { ArgChecker.notNull(m, "m"); if (m instanceof DoubleMatrix) { RealMatrix temp = CommonsMathWrapper.wrap((DoubleMatrix) m); return temp.getTrace(); } throw new IllegalArgumentException("Can only find trace of DoubleMatrix; have " + m.getClass()); }
/** * @see "S.Boyd and L.Vandenberghe, Convex Optimization, p. 618" */ @Override public double[] gradient(double[] X) { double[] ret = new double[dim]; RealMatrix S = buildS(X); CholeskyDecomposition cFact = new CholeskyDecomposition(S); RealMatrix SInv = cFact.getSolver().getInverse(); for (int i = 0; i < dim; i++) { ret[i] = SInv.multiply(this.Fi[i]).getTrace(); } return ret; }
/** * @see "S.Boyd and L.Vandenberghe, Convex Optimization, p. 618" */ @Override public double[][] hessian(double[] X) { RealMatrix S = buildS(X); CholeskyDecomposition cFact = new CholeskyDecomposition(S); RealMatrix SInv = cFact.getSolver().getInverse(); double[][] ret = new double[dim][dim]; for (int i = 0; i < dim; i++) { for (int j = i; j < dim; j++) { double h = SInv.multiply(this.Fi[i]) .multiply(SInv.multiply(this.Fi[j])).getTrace(); ret[i][j] = h; ret[j][i] = h; } } return ret; }
double sum = B.getTrace(); functionValue = -sum/4.0;
S = S.scalarMultiply(0.5); RealMatrix Gp = G.subtract(Tmat.multiply(S)); s = Math.sqrt((Gp.transpose().multiply(Gp)).getTrace()); s2 = Math.pow(s,2);
RealMatrix diagP = new DiagonalMatrix(V1.multiply(M).getRow(0)); RealMatrix Gp = G.subtract(Tmat.multiply(diagP)); s = Math.sqrt(Gp.transpose().multiply(Gp).getTrace()); s2 = Math.pow(s,2);