List of usage examples for org.apache.commons.math3.linear RealVector setSubVector
public abstract void setSubVector(int index, RealVector v) throws OutOfRangeException;
From source file:com.joptimizer.functions.SOCPLogarithmicBarrier.java
public double[] gradient(double[] X) { RealVector x = new ArrayRealVector(X); RealVector ret = new ArrayRealVector(dim); for (int i = 0; i < socpConstraintParametersList.size(); i++) { SOCPConstraintParameters param = socpConstraintParametersList.get(i); double t = this.buildT(param, x); RealVector u = this.buildU(param, x); double t2uu = t * t - u.dotProduct(u); RealMatrix Jacob = this.buildJ(param, x); int k = u.getDimension(); RealVector G = new ArrayRealVector(k + 1); G.setSubVector(0, u); G.setEntry(k, -t);/*from ww w .jav a2s . c o m*/ RealVector ret_i = Jacob.operate(G).mapMultiply((2. / t2uu)); ret = ret.add(ret_i); } return ret.toArray(); }
From source file:com.joptimizer.functions.SOCPLogarithmicBarrier.java
/** * Create the barrier function for the Phase I. * It is an instance of this class for the constraints: * <br>||Ai.x+bi|| < ci.x+di+t, i=1,...,m * @see "S.Boyd and L.Vandenberghe, Convex Optimization, 11.6.2" */// www . j a v a2 s.com public BarrierFunction createPhase1BarrierFunction() { final int dimPh1 = dim + 1; List<SOCPConstraintParameters> socpConstraintParametersPh1List = new ArrayList<SOCPConstraintParameters>(); SOCPLogarithmicBarrier bfPh1 = new SOCPLogarithmicBarrier(socpConstraintParametersPh1List, dimPh1); for (int i = 0; i < socpConstraintParametersList.size(); i++) { SOCPConstraintParameters param = socpConstraintParametersList.get(i); RealMatrix A = param.getA(); RealVector b = param.getB(); RealVector c = param.getC(); double d = param.getD(); RealMatrix APh1 = MatrixUtils.createRealMatrix(A.getRowDimension(), dimPh1); APh1.setSubMatrix(A.getData(), 0, 0); RealVector bPh1 = b; RealVector cPh1 = new ArrayRealVector(c.getDimension() + 1); cPh1.setSubVector(0, c); cPh1.setEntry(c.getDimension(), 1); double dPh1 = d; SOCPConstraintParameters paramsPh1 = new SOCPConstraintParameters(APh1.getData(), bPh1.toArray(), cPh1.toArray(), dPh1); socpConstraintParametersPh1List.add(socpConstraintParametersPh1List.size(), paramsPh1); } return bfPh1; }