/** Constructs and returns a 1-dimensional array containing the cell values. The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. The returned array <tt>values</tt> has the form <br> <tt>for (int i=0; i < size(); i++) values[i] = get(i);</tt> @return an array filled with the values of the cells. */ public double[] toArray() { double[] values = new double[size]; toArray(values); return values; } /**
/** Fills the cell values into the specified 1-dimensional array. The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. After this call returns the array <tt>values</tt> has the form <br> <tt>for (int i=0; i < size(); i++) values[i] = get(i);</tt> @throws IllegalArgumentException if <tt>values.length < size()</tt>. */ public void toArray(double[] values) { if (values.length < size) throw new IllegalArgumentException("values too small"); if (this.isNoView) System.arraycopy(this.elements,0,values,0,this.elements.length); else super.toArray(values); } /**
public double[][] getCentersArray() { DoubleMatrix1D[] centersMat = new DoubleMatrix1D[centers.size()]; double[][] centerArray = new double[centers.size()][]; for (int i = 0; i < centers.size(); ++i) { centerArray[i] = centers.get(i).toArray(); } return centerArray; }
public double[][] toVector(){ double[][] outArr = new double[1][]; outArr[0] = toMatrix1D().toArray(); return outArr; } }
public void add (DoubleMatrix1D x) { x.toArray (tempArray); add (tempArray); }
/** * Objective function domain. */ protected boolean isInDomainF0(DoubleMatrix1D X) { double F0X = request.getF0().value(X.toArray()); return !Double.isInfinite(F0X) && !Double.isNaN(F0X); }
private double rms(DoubleMatrix1D w) { double ssq = Descriptive.sumOfSquares(new DoubleArrayList(w.toArray())); return Math.sqrt(ssq); }
/** * Objective function value at X. */ protected double getF0(DoubleMatrix1D X) { return request.getF0().value(X.toArray()); }
/** * Objective function gradient at X. */ protected DoubleMatrix1D getGradF0(DoubleMatrix1D X) { return F1.make(request.getF0().gradient(X.toArray())); }
@Override public double[] gradient(double[] Y) { DoubleMatrix1D y = DoubleFactory1D.dense.make(Y); DoubleMatrix1D X = y.viewPart(0, originalDim); DoubleMatrix1D origGrad = F1.make(originalFi.gradient(X.toArray())); DoubleMatrix1D ret = F1.make(1, -1); ret = F1.append(origGrad, ret); return ret.toArray(); }
@Override public double value(double[] Y) { DoubleMatrix1D y = DoubleFactory1D.dense.make(Y); DoubleMatrix1D X = y.viewPart(0, dim); return originalFi.value(X.toArray()) - y.get(dimPh1-1); }
@Override public double value(double[] Y) { DoubleMatrix1D y = DoubleFactory1D.dense.make(Y); DoubleMatrix1D X = y.viewPart(0, originalDim); return originalFi.value(X.toArray()) - y.get(dim-1); }
@Override public double[] gradient(double[] X) { DoubleMatrix1D x = DoubleFactory1D.dense.make(X); DoubleMatrix1D D = x.assign(C, Functions.minus); return D.assign(Mult.mult(2)).toArray(); }
private double logsumexp(DoubleMatrix1D x){ DoubleMatrix1D myX = x.copy(); double maxX = StatUtils.max(myX.toArray()); return Math.log(myX.assign(Functions.minus(maxX)).assign(Functions.exp).zSum()) + maxX; }
@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(); } }
/** * Objective function hessian at X. */ protected DoubleMatrix2D getHessF0(DoubleMatrix1D X) { double[][] hess = request.getF0().hessian(X.toArray()); if(hess == FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER){ return F2.make(X.size(), X.size()); }else{ return F2.make(hess); } }
@Override public double[] gradient(double[] X) { DoubleMatrix1D x = F1.make(X); DoubleMatrix1D phiGrad = F1.make(barrierFunction.gradient(X)); return getGradF0(x).assign(Mult.mult(tIter)).assign(phiGrad, Functions.plus).toArray(); }
/** * Inequality functions gradients values at X. */ protected DoubleMatrix2D getGradFi(DoubleMatrix1D X) { DoubleMatrix2D ret = F2.make(request.getFi().length, X.size()); double[] x = X.toArray(); for(int i=0; i<request.getFi().length; i++){ ret.viewRow(i).assign(request.getFi()[i].gradient(x)); } return ret; }
@Override public double[] gradient(double[] X) { DoubleMatrix1D gradFiSum = F1.make(getDim()); for(int j=0; j<fi.length; j++){ double ineqValuejX = fi[j].value(X); DoubleMatrix1D ineqGradjX = F1.make(fi[j].gradient(X)); gradFiSum.assign(ineqGradjX.assign(Mult.mult(-1./ineqValuejX)), Functions.plus); } return gradFiSum.toArray(); }