/** * {@inheritDoc} * * @throws MathIllegalStateException if {@code optData} does not contain an * instance of {@link MaxEval} or {@link SearchInterval}. */ @Override public UnivariatePointValuePair optimize(OptimizationData... optData) { // Store arguments in order to pass them to the internal optimizer. optimData = optData; // Set up base class and perform computations. return super.optimize(optData); }
double initialBracketingRange) { mainOptimizer = optimizer; lineOptimizer = new BrentOptimizer(REL_TOL_UNUSED, ABS_TOL_UNUSED, new SimpleUnivariateValueChecker(relativeTolerance, absoluteTolerance)); this.initialBracketingRange = initialBracketingRange;
/** * Selects the best of two points. * * @param a Point and value. * @param b Point and value. * @param isMinim {@code true} if the selected point must be the one with * the lowest value. * @return the best point, or {@code null} if {@code a} and {@code b} are * both {@code null}. When {@code a} and {@code b} have the same function * value, {@code a} is returned. */ private UnivariatePointValuePair best(UnivariatePointValuePair a, UnivariatePointValuePair b, boolean isMinim) { if (a == null) { return b; } if (b == null) { return a; } if (isMinim) { return a.getValue() <= b.getValue() ? a : b; } else { return a.getValue() >= b.getValue() ? a : b; } } }
/** * Maximum likelihood estimate (MLE) of examinee ability. * * @param thetaMin smallest possible ability estimate (lower bound on BrentOptimizer) * @param thetaMax largest possible ability estimate (upper bound on BrentOptimizer) * @return MLE of examinee ability */ public double maximumLikelihoodEstimate(double thetaMin, double thetaMax, int maxIter, double tolerance){ method = EstimationMethod.ML; UnivariateOptimizer optimizer = new BrentOptimizer(tolerance, 1e-14); UnivariatePointValuePair pair = optimizer.optimize(new MaxEval(maxIter), new UnivariateObjectiveFunction(this), GoalType.MAXIMIZE, new SearchInterval(thetaMin, thetaMax)); estimatedTheta = pair.getPoint(); return estimatedTheta; }
totalEvaluations = 0; final int maxEval = getMaxEvaluations(); final double min = getMin(); final double max = getMax(); final double startValue = getStartValue(); startValue : min + generator.nextDouble() * (max - min); optimData[searchIntervalIndex] = new SearchInterval(min, max, s); optima[i] = optimizer.optimize(optimData); } catch (RuntimeException mue) { lastException = mue; totalEvaluations += optimizer.getEvaluations(); sortPairs(getGoalType());
bracket.search(f, goal, 0, initialBracketingRange); return lineOptimizer.optimize(new MaxEval(Integer.MAX_VALUE), new UnivariateObjectiveFunction(f), goal, new SearchInterval(bracket.getLo(), bracket.getHi(), bracket.getMid()));
final boolean isMinim = getGoalType() == GoalType.MINIMIZE; final double lo = getMin(); final double mid = getStartValue(); final double hi = getMax(); = getConvergenceChecker(); double d = 0; double e = 0; double fx = computeObjectiveValue(x); if (!isMinim) { fx = -fx; = new UnivariatePointValuePair(x, isMinim ? fx : -fx); double fu = computeObjectiveValue(u); if (!isMinim) { fu = -fu; current = new UnivariatePointValuePair(u, isMinim ? fu : -fu); best = best(best, best(previous, current, isMinim), isMinim); if (checker != null && checker.converged(getIterations(), previous, current)) { return best;
if (data instanceof SearchInterval) { final SearchInterval interval = (SearchInterval) data; min = interval.getMin(); max = interval.getMax(); start = interval.getStartValue(); continue; function = ((UnivariateObjectiveFunction) data).getObjectiveFunction(); continue;
final double p = previous.getValue(); final double c = current.getValue(); final double difference = FastMath.abs(p - c); final double size = FastMath.max(FastMath.abs(p), FastMath.abs(c)); return difference <= size * getRelativeThreshold() || difference <= getAbsoluteThreshold();
final double step = line.search(point, searchDirection).getPoint();
/** * Default constructor. */ public ExtreumumFinderBrent() { this.brentOptimizer = new BrentOptimizer(Kernel.STANDARD_PRECISION, Kernel.MAX_PRECISION); }
/** * Create a multi-start optimizer from a single-start optimizer. * * @param optimizer Single-start optimizer to wrap. * @param starts Number of starts to perform. If {@code starts == 1}, * the {@code optimize} methods will return the same solution as * {@code optimizer} would. * @param generator Random generator to use for restarts. * @throws NotStrictlyPositiveException if {@code starts < 1}. */ public MultiStartUnivariateOptimizer(final UnivariateOptimizer optimizer, final int starts, final RandomGenerator generator) { super(optimizer.getConvergenceChecker()); if (starts < 1) { throw new NotStrictlyPositiveException(starts); } this.optimizer = optimizer; this.starts = starts; this.generator = generator; }
final boolean isMinim = goal == GoalType.MINIMIZE; double fA = eval(func, xA); double fB = eval(func, xB); if (isMinim ? fA < fB : double fC = eval(func, xC); fW = eval(func, w); if (isMinim ? fW < fC : fW = eval(func, w); } else if ((w - wLim) * (wLim - xC) >= 0) { w = wLim; fW = eval(func, w); } else if ((w - wLim) * (xC - w) > 0) { fW = eval(func, w); if (isMinim ? fW < fC : fB = fC; fC =fW; fW = eval(func, w); fW = eval(func, w);
/** * Maximum a Posteriori (MAP) estimate of examinee ability using a normal prior * quadrature. * * @param mean mean of normal prior quadrature * @param sd standard deviation of prior quadrature * @param thetaMin smallest possible ability estimate (lower bound on BrentOptimizer) * @param thetaMax largest possible ability estimate (upper bound on BrentOptimizer) * @return MAP estimate of examinee ability */ public double mapEstimate(double mean, double sd, double thetaMin, double thetaMax, int maxIter, double tolerance){ mapPrior = new NormalDistribution(mean, sd); method = EstimationMethod.MAP; UnivariateOptimizer optimizer = new BrentOptimizer(tolerance, 1e-14); UnivariatePointValuePair pair = optimizer.optimize(new MaxEval(maxIter), new UnivariateObjectiveFunction(this), GoalType.MAXIMIZE, new SearchInterval(thetaMin, thetaMax)); estimatedTheta = pair.getPoint(); return estimatedTheta; }
/** {@inheritDoc} */ public int compare(final UnivariatePointValuePair o1, final UnivariatePointValuePair o2) { if (o1 == null) { return (o2 == null) ? 0 : 1; } else if (o2 == null) { return -1; } final double v1 = o1.getValue(); final double v2 = o2.getValue(); return (goal == GoalType.MINIMIZE) ? Double.compare(v1, v2) : Double.compare(v2, v1); } });
/** * {@inheritDoc} * * @throws MathIllegalStateException if {@code optData} does not contain an * instance of {@link MaxEval} or {@link SearchInterval}. */ @Override public UnivariatePointValuePair optimize(OptimizationData... optData) { // Store arguments in order to pass them to the internal optimizer. optimData = optData; // Set up base class and perform computations. return super.optimize(optData); }
/** {@inheritDoc} */ public int compare(final UnivariatePointValuePair o1, final UnivariatePointValuePair o2) { if (o1 == null) { return (o2 == null) ? 0 : 1; } else if (o2 == null) { return -1; } final double v1 = o1.getValue(); final double v2 = o2.getValue(); return (goal == GoalType.MINIMIZE) ? Double.compare(v1, v2) : Double.compare(v2, v1); } });
/** * {@inheritDoc} * * @throws MathIllegalStateException if {@code optData} does not contain an * instance of {@link MaxEval} or {@link SearchInterval}. */ @Override public UnivariatePointValuePair optimize(OptimizationData... optData) { // Store arguments in order to pass them to the internal optimizer. optimData = optData; // Set up base class and perform computations. return super.optimize(optData); }
/** {@inheritDoc} */ public int compare(final UnivariatePointValuePair o1, final UnivariatePointValuePair o2) { if (o1 == null) { return (o2 == null) ? 0 : 1; } else if (o2 == null) { return -1; } final double v1 = o1.getValue(); final double v2 = o2.getValue(); return (goal == GoalType.MINIMIZE) ? Double.compare(v1, v2) : Double.compare(v2, v1); } });