Create the barrier function for the Phase I.
It is an instance of this class for the constraint:
<br>G + Sum[x_i * F_i(x),i] < t * I
@see "S.Boyd and L.Vandenberghe, Convex Optimization, 11.6.2"
764368
@Override
	public BarrierFunction createPhase1BarrierFunction(){
		List<double[][]> FiPh1MatrixList = new ArrayList<double[][]>();
		for(int i=0; i<this.Fi.length; i++){
			FiPh1MatrixList.add(FiPh1MatrixList.size(), this.Fi[i].getData());
		}
		FiPh1MatrixList.add(FiPh1MatrixList.size(), MatrixUtils.createRealIdentityMatrix(p).scalarMultiply(-1).getData());
		return new SDPLogarithmicBarrier(FiPh1MatrixList, this.G.getData());
	}
1226139
private Vector<Vector<HashMap<FuzzyAllenIntervalConstraint.Type, Double>>> createFuzzyCompleteNetwork(Constraint[] cns) {	
		
		if(subs != null){
			if(subs.size() > 0) 
				isSubGraph = true;
		}
		Constraint[] c = extractSubGraphCons(cns);
		
/*		if(isSubGraph){
			
			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
			for (int i = 0; i < cns.length; i++) {
				System.out.println("cns: " + cns[i]);	
			}
			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
			for (int i = 0; i < subs.size(); i++) {
				System.out.println("sb: " + subs.get(i));
			}
			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
			for (int i = 0; i < c.length; i++) {
				System.out.println("c: " + c[i]);	
			}
		} //Iran
*/
		setNumVars(c);
		
		Vector<Vector<HashMap<FuzzyAllenIntervalConstraint.Type, Double>>> frelations = new Vector<Vector<HashMap<FuzzyAllenIntervalConstraint.Type, Double>>>();
		
		final class Coord {
			public int x, y;
			public Coord(int x, int y) { this.x = x; this.y = y; }
			public boolean equals(Object o) {
				if (!(o instanceof Coord)) return false;
				Coord oc = (Coord)o;
				return ((oc.x == x) && (oc.y == y));
			}
			public int hashCode() {
				return (x*31)^y;
			}
		}
		
		HashMap<Coord, Vector<FuzzyAllenIntervalConstraint>> multiple = new HashMap<Coord, Vector<FuzzyAllenIntervalConstraint>>();
		
		FuzzyAllenIntervalConstraint[][] tmp = new FuzzyAllenIntervalConstraint[getNumVars()][getNumVars()];
		
		int row = 0 , col = 0;
		for(int i = 0; i < c.length; i++){
			if(!isSubGraph){
				row = this.getID(c[i].getScope()[0]);
				col = this.getID(c[i].getScope()[1]);
			}
			else{
				row = (int)varIndex.get(c[i].getScope()[0].getID());
				col = (int)varIndex.get(c[i].getScope()[1].getID());
			}
			if (tmp[row][col] == null)
				tmp[row][col] = ((FuzzyAllenIntervalConstraint)c[i]);
			else {
				Coord coord = new Coord(row,col);
				Vector<FuzzyAllenIntervalConstraint> vec = multiple.get(coord);
				if (vec == null) {
					vec = new Vector<FuzzyAllenIntervalConstraint>();
					vec.add(tmp[row][col]);
					multiple.put(coord, vec);
				}
				vec.add((FuzzyAllenIntervalConstraint)c[i]);
			}
		}
		boolean isACrispCons = false;
		for(int i = 0; i < tmp.length; i++){
			Vector<HashMap<FuzzyAllenIntervalConstraint.Type, Double>> con = new Vector<HashMap<FuzzyAllenIntervalConstraint.Type, Double>>(); 
			for(int j = 0; j < tmp.length; j++){
				if(crispCons != null && tmp[i][j] != null){
					if(isACrispConstrint(tmp[i][j])) isACrispCons = true;
				}
				if(tmp[i][j] != null) {
					//add poss (i,j)
					/*
					System.out.println("----------------------------------");
					System.out.println("LOOKING AT " + tmpToConstraints.get(new Coords(i,j)) + ":\n" + (tmpToConstraints.get(new Coords(i,j))).getPossibilities());
					System.out.println("----------------------------------");
					*/
					Coord coord = new Coord(i,j);
					if (!multiple.containsKey(coord)) {
						if(!isACrispCons)
							con.add(tmp[i][j].getPossibilities());
						else
							con.add(tmp[i][j].makeCrispRel());
					}
					else {
						if(!isACrispCons){
							HashMap<FuzzyAllenIntervalConstraint.Type, Double> poss = multiple.get(coord).get(0).getPossibilities();
							for (int h = 1; h < multiple.get(coord).size(); h++) {
								updateRelation(poss, multiple.get(coord).get(h).getPossibilities());
							}
							con.add(poss);
						}
						else{
							HashMap<FuzzyAllenIntervalConstraint.Type, Double> poss = multiple.get(coord).get(0).makeCrispRel();
							for (int h = 1; h < multiple.get(coord).size(); h++) {
								updateRelation(poss, multiple.get(coord).get(h).makeCrispRel());
							}
							con.add(poss);
						}
					}
				}
				else if (tmp[j][i] != null) {
					//add inverse of (i,j)
					/*
					System.out.println("----------------------------------");
					System.out.println("LOOKING AT (I) " + tmpToConstraints.get(new Coords(j,i)) + ":\n" + (tmpToConstraints.get(new Coords(j,i))).getInversePossibilities());
					System.out.println("----------------------------------");
					*/
					Coord coord = new Coord(j,i);
					if(!isACrispCons){
						if (!multiple.containsKey(coord)) {
							con.add(tmp[j][i].getInversePossibilities());
						}
						else {
							HashMap<FuzzyAllenIntervalConstraint.Type, Double> poss = multiple.get(coord).get(0).getInversePossibilities();
							for (int h = 1; h < multiple.get(coord).size(); h++) {
								updateRelation(poss, multiple.get(coord).get(h).getInversePossibilities());
							}
							con.add(poss);
						}
					}
					else{
						if (!multiple.containsKey(coord)) {
							con.add(tmp[j][i].getCrispInverse());
						}
						else {
							HashMap<FuzzyAllenIntervalConstraint.Type, Double> poss = multiple.get(coord).get(0).getCrispInverse();
							for (int h = 1; h < multiple.get(coord).size(); h++) {
								updateRelation(poss, multiple.get(coord).get(h).getCrispInverse());
							}
							con.add(poss);
						}
					}
				}
				
				//if no relation exists, add [all possibilities <-- 1.0]
				else con.add(createAllFuzzyAllenRelation());
			}
			isACrispCons = false;
			frelations.add(con);
		}	
		
		return frelations;
	}
751588
def create(lr, weight_decay=0, momentum=0, layer_groups=False):
    
    return SgdFactory(lr=lr, weight_decay=weight_decay, momentum=momentum, layer_groups=layer_groups)
1162081
def create(max_kl, cg_iters, line_search_iters, cg_damping, entropy_coef, vf_iters, discount_factor,
           gae_lambda=1.0, improvement_acceptance_ratio=0.1, max_grad_norm=0.5):
    
    return TrpoPolicyGradient(
        max_kl, int(cg_iters), int(line_search_iters), cg_damping, entropy_coef, vf_iters,
        discount_factor=discount_factor,
        gae_lambda=gae_lambda,
        improvement_acceptance_ratio=improvement_acceptance_ratio,
        max_grad_norm=max_grad_norm
    )
378204
function (fn) { var cache = {}  // barrier-enabled impl, eliminates redundant fetches
                                                    // in this version, any subsequent calls join at barrier (which opens when result is fetched)
        switch (_.numArgs (fn)) {
            case 1:
                return function (then) {             
                    if (!cache.already) {
                        fn.call (this, (cache = _.barrier ())) }
                    cache (then) }
            case 2:
                cache = {}
                return function (value, then) {    
                    if (!(value in cache)) {
                        fn.call (this, value, (cache[value] = _.barrier ())) }
                    cache[value] (then) }
            default:
                throw new Error ('_.cps.memoize: unsupported number of arguments') } }
1365855
def convex_conj(self):
        """"""
        if isinstance(self.domain, ProductSpace):
            norm = GroupL1Norm(self.domain, 2)
        else:
            norm = L1Norm(self.domain)

        return FunctionalQuadraticPerturb(norm.convex_conj,
                                          quadratic_coeff=self.gamma / 2)
445828
def solve_minimize(
        self,
        func,
        weights,
        constraints,
        lower_bound=0.0,
        upper_bound=1.0,
        func_deriv=False
    ):
        

        bounds = ((lower_bound, upper_bound), ) * len(self.SUPPORTED_COINS)
        return minimize(
            fun=func, x0=weights, jac=func_deriv, bounds=bounds,
            constraints=constraints, method='SLSQP', options={'disp': False}
        )
31317
def create_projected_dual(self):
    
    # TODO: consider whether we can use shallow copy of the lists without
    # using tf.identity
    projected_nu = tf.placeholder(tf.float32, shape=[])
    min_eig_h = tf.placeholder(tf.float32, shape=[])
    projected_lambda_pos = [tf.identity(x) for x in self.lambda_pos]
    projected_lambda_neg = [tf.identity(x) for x in self.lambda_neg]
    projected_lambda_quad = [
        tf.identity(x) for x in self.lambda_quad
    ]
    projected_lambda_lu = [tf.identity(x) for x in self.lambda_lu]

    for i in range(self.nn_params.num_hidden_layers + 1):
      # Making H PSD
      projected_lambda_lu[i] = self.lambda_lu[i] + 0.5*tf.maximum(-min_eig_h, 0) + TOL
      # Adjusting the value of \lambda_neg to make change in g small
      projected_lambda_neg[i] = self.lambda_neg[i] + tf.multiply(
          (self.lower[i] + self.upper[i]),
          (self.lambda_lu[i] - projected_lambda_lu[i]))
      projected_lambda_neg[i] = (tf.multiply(self.negative_indices[i],
                                             projected_lambda_neg[i]) +
                                 tf.multiply(self.switch_indices[i],
                                             tf.maximum(projected_lambda_neg[i], 0)))

    projected_dual_var = {
        'lambda_pos': projected_lambda_pos,
        'lambda_neg': projected_lambda_neg,
        'lambda_lu': projected_lambda_lu,
        'lambda_quad': projected_lambda_quad,
        'nu': projected_nu,
    }
    projected_dual_object = DualFormulation(
        self.sess, projected_dual_var, self.nn_params,
        self.test_input, self.true_class,
        self.adv_class, self.input_minval,
        self.input_maxval, self.epsilon,
        self.lzs_params,
        project_dual=False)
    projected_dual_object.min_eig_val_h = min_eig_h
    return projected_dual_object
890644
@Override
	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;
	}
1135882
def solve_sdr(prob, *args, **kwargs):
    

    # lifted variables and semidefinite constraint
    X = cvx.Semidef(prob.n + 1)

    W = prob.f0.homogeneous_form()
    rel_obj = cvx.Minimize(cvx.sum_entries(cvx.mul_elemwise(W, X)))
    rel_constr = [X[-1, -1] == 1]

    for f in prob.fs:
        W = f.homogeneous_form()
        lhs = cvx.sum_entries(cvx.mul_elemwise(W, X))
        if f.relop == '==':
            rel_constr.append(lhs == 0)
        else:
            rel_constr.append(lhs <= 0)

    rel_prob = cvx.Problem(rel_obj, rel_constr)
    rel_prob.solve(*args, **kwargs)

    if rel_prob.status not in [cvx.OPTIMAL, cvx.OPTIMAL_INACCURATE]:
        raise Exception("Relaxation problem status: %s" % rel_prob.status)

    return X.value, rel_prob.value
907149
def add_constraint(self, func, variables, default_values=None):
        
        self._constraints.append((func, variables, default_values or ()))
55504
def convex_conj(self):
        
        convex_conjs = [func.convex_conj for func in self.functionals]
        return SeparableSum(*convex_conjs)
253757
function _gpfClassSuperCreate (superMember) {
    var superMethod;
    if (typeof superMember === "function") {
        superMethod = superMember;
    } else {
        superMethod = _gpfClassNoSuper;
    }
    return _gpfClassSuperCreateWithSameSignature(superMethod);
}
935491
def create_function_f_i(self):
        """"""
        return ca.Function(
            'f_i',
            [self.t, self.x, self.y, self.m, self.p, self.c, self.pre_c, self.ng, self.nu],
            [self.f_i],
            ['t', 'x', 'y', 'm', 'p', 'c', 'pre_c', 'ng', 'nu'], ['x_n'], self.func_opt)
814544
def build(self, x, h, mask=None):
        '''
        
        '''
        xw = tf.split(tf.matmul(x, self.w_matrix) + self.bias, 3, 1)
        hu = tf.split(tf.matmul(h, self.U), 3, 1)
        r = tf.sigmoid(xw[0] + hu[0])
        z = tf.sigmoid(xw[1] + hu[1])
        h1 = tf.tanh(xw[2] + r * hu[2])
        next_h = h1 * (1 - z) + h * z
        if mask is not None:
            next_h = next_h * mask + h * (1 - mask)
        return next_h
1343269
function() {

            var start = this.start;
            var controlPoint1 = this.controlPoint1;
            var controlPoint2 = this.controlPoint2;
            var end = this.end;

            var x0 = start.x;
            var y0 = start.y;
            var x1 = controlPoint1.x;
            var y1 = controlPoint1.y;
            var x2 = controlPoint2.x;
            var y2 = controlPoint2.y;
            var x3 = end.x;
            var y3 = end.y;

            var points = new Array(); // local extremes
            var tvalues = new Array(); // t values of local extremes
            var bounds = [new Array(), new Array()];

            var a, b, c, t;
            var t1, t2;
            var b2ac, sqrtb2ac;

            for (var i = 0; i < 2; ++i) {

                if (i === 0) {
                    b = 6 * x0 - 12 * x1 + 6 * x2;
                    a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
                    c = 3 * x1 - 3 * x0;

                } else {
                    b = 6 * y0 - 12 * y1 + 6 * y2;
                    a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
                    c = 3 * y1 - 3 * y0;
                }

                if (abs(a) < 1e-12) { // Numerical robustness
                    if (abs(b) < 1e-12) { // Numerical robustness
                        continue;
                    }

                    t = -c / b;
                    if ((0 < t) && (t < 1)) tvalues.push(t);

                    continue;
                }

                b2ac = b * b - 4 * c * a;
                sqrtb2ac = sqrt(b2ac);

                if (b2ac < 0) continue;

                t1 = (-b + sqrtb2ac) / (2 * a);
                if ((0 < t1) && (t1 < 1)) tvalues.push(t1);

                t2 = (-b - sqrtb2ac) / (2 * a);
                if ((0 < t2) && (t2 < 1)) tvalues.push(t2);
            }

            var j = tvalues.length;
            var jlen = j;
            var mt;
            var x, y;

            while (j--) {
                t = tvalues[j];
                mt = 1 - t;

                x = (mt * mt * mt * x0) + (3 * mt * mt * t * x1) + (3 * mt * t * t * x2) + (t * t * t * x3);
                bounds[0][j] = x;

                y = (mt * mt * mt * y0) + (3 * mt * mt * t * y1) + (3 * mt * t * t * y2) + (t * t * t * y3);
                bounds[1][j] = y;

                points[j] = { X: x, Y: y };
            }

            tvalues[jlen] = 0;
            tvalues[jlen + 1] = 1;

            points[jlen] = { X: x0, Y: y0 };
            points[jlen + 1] = { X: x3, Y: y3 };

            bounds[0][jlen] = x0;
            bounds[1][jlen] = y0;

            bounds[0][jlen + 1] = x3;
            bounds[1][jlen + 1] = y3;

            tvalues.length = jlen + 2;
            bounds[0].length = jlen + 2;
            bounds[1].length = jlen + 2;
            points.length = jlen + 2;

            var left = min.apply(null, bounds[0]);
            var top = min.apply(null, bounds[1]);
            var right = max.apply(null, bounds[0]);
            var bottom = max.apply(null, bounds[1]);

            return new Rect(left, top, (right - left), (bottom - top));
        }
1113302
function(a, b, r1, r2, k1, k2)
{
    // calculate mass matrix
    // If I wasn't lazy and wrote a proper matrix class, this wouldn't be so gross...
    var k11, k12, k21, k22;
    var m_sum = a.m_inv + b.m_inv;
    
    // start with I*m_sum
    k11 = m_sum; k12 = 0;
    k21 = 0;     k22 = m_sum;
    
    // add the influence from r1
    var a_i_inv = a.i_inv;
    var r1xsq =  r1.x * r1.x * a_i_inv;
    var r1ysq =  r1.y * r1.y * a_i_inv;
    var r1nxy = -r1.x * r1.y * a_i_inv;
    k11 += r1ysq; k12 += r1nxy;
    k21 += r1nxy; k22 += r1xsq;
    
    // add the influnce from r2
    var b_i_inv = b.i_inv;
    var r2xsq =  r2.x * r2.x * b_i_inv;
    var r2ysq =  r2.y * r2.y * b_i_inv;
    var r2nxy = -r2.x * r2.y * b_i_inv;
    k11 += r2ysq; k12 += r2nxy;
    k21 += r2nxy; k22 += r2xsq;
    
    // invert
    var determinant = k11*k22 - k12*k21;
    assertSoft(determinant !== 0, "Unsolvable constraint.");
    
    var det_inv = 1/determinant;

    k1.x =  k22*det_inv; k1.y = -k12*det_inv;
    k2.x = -k21*det_inv; k2.y =  k11*det_inv;
}