Calculates the initial value for the s parameter in Phase I.
Return s = max(||Ai.x+bi|| - (ci.x+di))
@see "S.Boyd and L.Vandenberghe, Convex Optimization, 11.6.2"
8303
@Override
	public double calculatePhase1InitialFeasiblePoint(double[] originalNotFeasiblePoint, double tolerance){
		double s = -Double.MAX_VALUE;
		RealVector x = new ArrayRealVector(originalNotFeasiblePoint); 
		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();
 			s = Math.max(s, (A.operate(x).subtract(b).getNorm() - (c.dotProduct(x)+d))*Math.pow(tolerance,-0.5));
		}
		if(Double.compare(0., s)==0){
			//for the point to be feasible, we must have s<0.
			//s==0 is an ambiguous value the is better to avoid
			s = 2 * tolerance;
		}
		return s;
	}
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));
        }
544952
synchronized Weight getMaximumStart() {
        if (calcMaxStart == null) {
            // Find the longest distance from time zero to a start.
            Weight result = WeightFactory.POS_INFINITY;
            if (shortestDistancesFromTimeZeroSource == null) {
                shortestDistancesFromTimeZeroSource = BellmanFord.calcShortestDistances(timeZero, directedGraph,
                        BellmanFord.Mode.SOURCE);

                if (shortestDistancesFromTimeZeroSource == null) {
                    throw new IllegalStateException("Negative cycle detected!");
                }
            }
            for (int i = 0, n = intervals.size(); i < n; i++) {
                Object start = intervals.get(i).getStart();
                result = Weight.min(result,
                        (Weight) shortestDistancesFromTimeZeroSource.get(start));
            }
            calcMaxStart = result;
        }

        return calcMaxStart;
    }
1269914
function(first, second) {
			var start = 0;
			var max = 0;

			for (var i = 0; i < first.length; i++) {
				for (var j = 0; j < second.length; j++) {
					var x = 0;
					while (first[i + x] === second[j + x]) {
						x++;
						if ((i + x >= first.length) || (j + x >= second.length)) {
							break;
						}
					}
					if (x > max) {
						max = x;
						start = i;
					}
				}
			}

			return first.slice(start, start + max);
		}
1196325
public int maxValue()
    {
        final int initialValue = this.initialValue;
        int max = size == 0 ? initialValue : Integer.MIN_VALUE;

        final int[] entries = this.entries;
        @DoNotSub final int length = entries.length;

        for (@DoNotSub int i = 1; i < length; i += 2)
        {
            final int value = entries[i];
            if (value != initialValue)
            {
                max = Math.max(max, value);
            }
        }

        return max;
    }
1188647
public static int whichMax(float[] x) {
        float m = Float.NEGATIVE_INFINITY;
        int which = 0;

        for (int i = 0; i < x.length; i++) {
            if (x[i] > m) {
                m = x[i];
                which = i;
            }
        }

        return which;
    }
275324
private void minmax() {
        gmin = Double.MAX_VALUE;
        gmax = -Double.MAX_VALUE;

        for (SupportVector v : sv) {
            double g = -v.g[0];
            double a = v.alpha[0];
            if (g < gmin && a > 0.0) {
                svmin = v;
                gmin = g;
                gminindex = 0;
            }
            if (g > gmax && a < v.C) {
                svmax = v;
                gmax = g;
                gmaxindex = 0;
            }

            g = v.g[1];
            a = v.alpha[1];
            if (g < gmin && a < v.C) {
                svmin = v;
                gmin = g;
                gminindex = 1;
            }
            if (g > gmax && a > 0.0) {
                svmax = v;
                gmax = g;
                gmaxindex = 1;
            }
        }
    }
55411
protected function getMaxValue()
    {
        $maxValue = $this->getFilter()->getMaxValue() + 1;

        if ($this->isManualCalculation() && ($this->getStepValue() > 0)) {
            $stepValue = $this->getStepValue();
            $maxValue  = ceil($maxValue / $stepValue) * $stepValue;
        }

        return $maxValue;
    }
1187450
private int getPlateStartIndex(int plateNum) {
    Preconditions.checkArgument(plateNum >= 0 && plateNum < plateNames.size());
    int startOffset = fixedVariableMaxInd + 1;
    for (int i = 0; i < plateNum; i++) {
      startOffset += plates.get(i).getMaximumPlateSize() * maximumReplications[i];
    }
    return startOffset;
  }
514145
public function x()
    {
        // Load file
        $file = new \SplFileObject($this->storage('finals.all'));

        // Get instance MJD, and MJD at line 0
        $mjdQ = $this->mjd;
        $mjd0 = (int)substr($file->getCurrentLine(), 7, 8);

        // Check for requested MJD before first date
        if ($mjdQ < $mjd0) {
            return false;
        }

        // Determine nearest center pointer
        $p = $mjdQ - $mjd0 - 1;

        // Fix for values within |n| of lower bound
        if ($p < static::INTERP_C && $p > -static::INTERP_C) {
            $p = static::INTERP_C;
        }

        // Compile dataset
        $ds = [];
        for ($i = $p - static::INTERP_C; $i < $p + static::INTERP_C; $i++) {
            $file->seek($i);
            $line = $file->getCurrentLine();

            // Parse data from line
            $mjd = substr($line, 7, 8);
            $xf  = substr($line, 136, 9);
            $xp  = substr($line, 18, 9);

            // Use final value first, if not present use prediction
            $x = trim($xf) ? $xf : $xp;

            // Check if no dut1 data, error
            if (trim($x) == '') {
                return false;
            }

            // Add the data
            $ds[$i - $p + static::INTERP_C]['x'] = (float)$mjd;
            $ds[$i - $p + static::INTERP_C]['y'] = (float)$x;
        }

        // Interpolate pole x
        return $this->lagrangeInterp($mjdQ, $ds);
    }
794824
public double getSolution(double targetValue, double initGuess) {
    double rMax = 1.0;
    double oldValue = -1;
    for (int i = 0; i < MAXIMUM_ITERATION; ++i) {
      double value = targetFunction(rMax);
      if (value >= targetValue) {
        break;
      }
      if (equals(value, oldValue)) {
        return rMax; // Target value is not feasible. Just return rMax
      }
      rMax *= 2;
    }
    double left = 0;
    double right = rMax;
    double mid = initGuess > left && initGuess < right ?
        initGuess : (left + right) / 2.0;
    for (int i = 0; i < MAXIMUM_ITERATION; ++i) {
      double value = targetFunction(mid);
      if (equals(value, targetValue)) {
        return mid;
      }
      if (value < targetValue) {
        left = mid;
      } else {
        right = mid;
      }
      mid = (left + right) / 2.0;
    }
    return right;
  }
1139420
public static /*@pure@*/ int maxIndex(int[] ints) {

    int maximum = 0;
    int maxIndex = 0;

    for (int i = 0; i < ints.length; i++) {
      if ((i == 0) || (ints[i] > maximum)) {
	maxIndex = i;
	maximum = ints[i];
      }
    }

    return maxIndex;
  }
1026516
public static double I(int n, double x) {
        if (n < 0)
            throw new IllegalArgumentException("the variable n out of range.");
        else if (n == 0)
            return I0(x);
        else if (n == 1)
            return I(x);

        if (x == 0.0)
            return 0.0;

        double ACC = 40.0;
        double BIGNO = 1.0e+10;
        double BIGNI = 1.0e-10;

        double tox = 2.0 / Math.abs(x);
        double bip = 0, ans = 0.0;
        double bi = 1.0;

        for (int j = 2 * (n + (int) Math.sqrt(ACC * n)); j > 0; j--) {
            double bim = bip + j * tox * bi;
            bip = bi;
            bi = bim;

            if (Math.abs(bi) > BIGNO) {
                ans *= BIGNI;
                bi *= BIGNI;
                bip *= BIGNI;
            }

            if (j == n)
                ans = bip;
        }

        ans *= I0(x) / bi;
        return x < 0.0 && n % 2 == 1 ? -ans : ans;
    }
1077753
@Override
	public double getQuantileExpectation(double quantileStart, double quantileEnd) {
		if(isDeterministic()) {
			return valueIfNonStochastic;
		}
		if(size() == 0) {
			return Double.NaN;
		}
		if(quantileStart > quantileEnd) {
			return getQuantileExpectation(quantileEnd, quantileStart);
		}

		float[] realizationsSorted = realizations.clone();
		java.util.Arrays.sort(realizationsSorted);

		int indexOfQuantileValueStart	= Math.min(Math.max((int)Math.round((size()+1) * quantileStart - 1), 0), size()-1);
		int indexOfQuantileValueEnd		= Math.min(Math.max((int)Math.round((size()+1) * quantileEnd - 1), 0), size()-1);

		double quantileExpectation = 0.0;
		for (int i=indexOfQuantileValueStart; i<=indexOfQuantileValueEnd;i++) {
			quantileExpectation += realizationsSorted[i];
		}
		quantileExpectation /= indexOfQuantileValueEnd-indexOfQuantileValueStart+1;

		return quantileExpectation;
	}
889805
private void findStartingPoint() {
    // Well, we already know the best Y value...
    final double bestY = minmaxY.getMin();
    double bestX = Double.POSITIVE_INFINITY;
    int bestI = -1;
    Iterator<double[]> iter = this.points.iterator();
    for(int i = 0; iter.hasNext(); i++) {
      double[] vec = iter.next();
      if(vec[1] == bestY && vec[0] < bestX) {
        bestX = vec[0];
        bestI = i;
      }
    }
    assert (bestI >= 0);
    // Bring the reference object to the head.
    if(bestI > 0) {
      points.add(0, points.remove(bestI));
    }
  }
899703
public boolean optimize(ResidualFunction function, DMatrixRMaj parameters )
    {
        configure(function,parameters.getNumElements());

        // save the cost of the initial parameters so that it knows if it improves or not
        double previousCost = initialCost = cost(parameters);

        // iterate until the difference between the costs is insignificant
        double lambda = initialLambda;

        // if it should recompute the Jacobian in this iteration or not
        boolean computeHessian = true;

        for( int iter = 0; iter < maxIterations; iter++ ) {
            if( computeHessian ) {
                // compute some variables based on the gradient
                computeGradientAndHessian(parameters);
                computeHessian = false;

                // check for convergence using gradient test
                boolean converged = true;
                for (int i = 0; i < g.getNumElements(); i++) {
                    if( Math.abs(g.data[i]) > gtol ) {
                        converged = false;
                        break;
                    }
                }
                if( converged )
                    return true;
            }

            // H = H + lambda*I
            for (int i = 0; i < H.numRows; i++) {
                H.set(i,i, Hdiag.get(i) + lambda);
            }

            // In robust implementations failure to solve is handled much better
            if( !CommonOps_DDRM.solve(H, g, negativeStep) ) {
                return false;
            }

            // compute the candidate parameters
            CommonOps_DDRM.subtract(parameters, negativeStep, candidateParameters);

            double cost = cost(candidateParameters);
            if( cost <= previousCost ) {
                // the candidate parameters produced better results so use it
                computeHessian = true;
                parameters.set(candidateParameters);

                // check for convergence
                // ftol <= (cost(k) - cost(k+1))/cost(k)
                boolean converged = ftol*previousCost >= previousCost-cost;

                previousCost = cost;
                lambda /= 10.0;

                if( converged ) {
                    return true;
                }
            } else {
                lambda *= 10.0;
            }

        }
        finalCost = previousCost;
        return true;
    }
880561
def value(self, t):
        """"""
        fraction = min(float(t) / max(1, self.schedule_timesteps), 1.0)
        return self.initial_p + fraction * (self.final_p - self.initial_p)