/** {@inheritDoc} */ public UnivariatePointValuePair optimize(int maxEval, UnivariateFunction f, GoalType goalType, double min, double max, double startValue) { // Checks. if (f == null) { throw new NullArgumentException(); } if (goalType == null) { throw new NullArgumentException(); } // Reset. searchMin = min; searchMax = max; searchStart = startValue; goal = goalType; function = f; evaluations.setMaximalCount(maxEval); evaluations.resetCount(); // Perform computation. return doOptimize(); }
/** {@inheritDoc} */ public Incrementor getIterationCounter() { return new Incrementor(this.maxIterations, MAX_ITER_CALLBACK); }
/** * Gets the number of evaluations of the objective function. * The number of evaluations corresponds to the last call to the * {@code optimize} method. It is 0 if the method has not been * called yet. * * @return the number of evaluations of the objective function. */ public int getEvaluations() { return evaluations.getCount(); }
super.setMaximalCount(delegate.getMaximalCount()); super.incrementCount(delegate.getCount());
iterationCounter.incrementCount(); evaluationCounter.incrementCount(); current = lsp.evaluate(currentPoint); final RealVector currentResiduals = current.getResiduals(); checker.converged(iterationCounter.getCount(), previous, current)) { return new OptimumImpl(current, evaluationCounter.getCount(), iterationCounter.getCount());
/** * Performs multiple increments. * See the other {@link #incrementCount() incrementCount} method). * * @param value Number of increments. * @throws MaxCountExceededException at counter exhaustion. */ public void incrementCount(int value) throws MaxCountExceededException { for (int i = 0; i < value; i++) { incrementCount(); } }
/** {@inheritDoc} */ @Override public void setMaximalCount(int max) { super.setMaximalCount(max); delegate = delegate.withMaximalCount(max); }
/** * Gets the maximal number of iterations. * * @return the maximal number of iterations. */ public int getMaxIterations() { return iterations.getMaximalCount(); }
/** * Performs the optimization. * * @return a point/value pair that satisfies the convergence criteria. * @throws TooManyEvaluationsException if the maximal number of * evaluations is exceeded. * @throws TooManyIterationsException if the maximal number of * iterations is exceeded. */ public PAIR optimize() throws TooManyEvaluationsException, TooManyIterationsException { // Reset counters. evaluations.resetCount(); iterations.resetCount(); // Perform optimization. return doOptimize(); }
/** Get the evaluations counter. * @return evaluations counter * @since 3.2 * @deprecated as of 3.6 replaced with {@link #getCounter()} */ @Deprecated protected org.apache.commons.math3.util.Incrementor getEvaluationsCounter() { return org.apache.commons.math3.util.Incrementor.wrap(evaluations); }
evaluationCounter.incrementCount(); iterationCounter.incrementCount(); evaluationCounter.getCount(), iterationCounter.getCount()); evaluationCounter.incrementCount(); current = problem.evaluate(new ArrayRealVector(currentPoint)); currentResiduals = current.getResiduals().toArray(); if (checker != null && checker.converged(iterationCounter.getCount(), previous, current)) { return new OptimumImpl(current, evaluationCounter.getCount(), iterationCounter.getCount()); ratio <= 2.0) || delta <= parRelativeTolerance * xNorm) { return new OptimumImpl(current, evaluationCounter.getCount(), iterationCounter.getCount());
/** * Increment the evaluation count. * * @throws TooManyEvaluationsException if the allowed evaluations * have been exhausted. */ protected void incrementEvaluationCount() throws TooManyEvaluationsException { evaluations.incrementCount(); }
/** * Scans the list of (required and optional) optimization data that * characterize the problem. * * @param optData Optimization data. * The following data will be looked for: * <ul> * <li>{@link MaxEval}</li> * <li>{@link MaxIter}</li> * </ul> */ protected void parseOptimizationData(OptimizationData... optData) { // The existing values (as set by the previous call) are reused if // not provided in the argument list. for (OptimizationData data : optData) { if (data instanceof MaxEval) { evaluations.setMaximalCount(((MaxEval) data).getMaxEval()); continue; } if (data instanceof MaxIter) { iterations.setMaximalCount(((MaxIter) data).getMaxIter()); continue; } } }
super.setMaximalCount(delegate.getMaximalCount()); super.incrementCount(delegate.getCount());
/** * @return the number of evalutations. */ public int getMaxEvaluations() { return evaluations.getMaximalCount(); }
/** {@inheritDoc} */ @Override public void resetCount() { super.resetCount(); delegate = delegate.withStart(0); }
org.apache.commons.math3.util.Incrementor.wrap(count); this.iterations = wrapped;
throws TooManyEvaluationsException { evaluations.setMaximalCount(maxEval); evaluations.resetCount(); function = f; goal = goalType;
iterationCounter.incrementCount(); evaluationCounter.incrementCount(); current = lsp.evaluate(currentPoint); final RealVector currentResiduals = current.getResiduals(); checker.converged(iterationCounter.getCount(), previous, current)) { return new OptimumImpl(current, evaluationCounter.getCount(), iterationCounter.getCount());
/** * Increment the iteration count. * * @throws TooManyIterationsException if the allowed iterations * have been exhausted. */ protected void incrementIterationCount() throws TooManyIterationsException { iterations.incrementCount(); }