List of usage examples for org.apache.commons.math3.optim.nonlinear.scalar.noderiv SimplexOptimizer SimplexOptimizer
public SimplexOptimizer(ConvergenceChecker<PointValuePair> checker)
From source file:de.bund.bfr.math.MultivariateOptimization.java
@Override public Result optimize(int nParameterSpace, int nOptimizations, boolean stopWhenSuccessful, Map<String, Double> minStartValues, Map<String, Double> maxStartValues, int maxIterations, DoubleConsumer progessListener, ExecutionContext exec) throws CanceledExecutionException { if (exec != null) { exec.checkCanceled();//from w w w . jav a2s.co m } progessListener.accept(0.0); List<ParamRange> ranges = MathUtils.getParamRanges(parameters, minStartValues, maxStartValues, nParameterSpace); ranges.set(parameters.indexOf(sdParam), new ParamRange(1.0, 1, 1.0)); List<StartValues> startValuesList = MathUtils.createStartValuesList(ranges, nOptimizations, values -> optimizerFunction.value(Doubles.toArray(values)), progress -> progessListener.accept(0.5 * progress), exec); Result result = new Result(); AtomicInteger currentIteration = new AtomicInteger(); SimplexOptimizer optimizer = new SimplexOptimizer(new SimpleValueChecker(1e-10, 1e-10) { @Override public boolean converged(int iteration, PointValuePair previous, PointValuePair current) { if (super.converged(iteration, previous, current)) { return true; } return currentIteration.incrementAndGet() >= maxIterations; } }); int count = 0; for (StartValues startValues : startValuesList) { if (exec != null) { exec.checkCanceled(); } progessListener.accept(0.5 * count++ / startValuesList.size() + 0.5); try { PointValuePair optimizerResults = optimizer.optimize(new MaxEval(Integer.MAX_VALUE), new MaxIter(maxIterations), new InitialGuess(Doubles.toArray(startValues.getValues())), new ObjectiveFunction(optimizerFunction), GoalType.MAXIMIZE, new NelderMeadSimplex(parameters.size())); double logLikelihood = optimizerResults.getValue() != null ? optimizerResults.getValue() : Double.NaN; if (result.logLikelihood == null || logLikelihood > result.logLikelihood) { result = getResults(optimizerResults); if (result.logLikelihood == 0.0 || stopWhenSuccessful) { break; } } } catch (TooManyEvaluationsException | TooManyIterationsException | ConvergenceException e) { } } return result; }
From source file:com.insightml.math.optimization.AbstractOptimizable.java
private PointValuePair simplex(final AbstractSimplex simplex, final double[] initialValues) { return optimize(new SimplexOptimizer(conv()), initialValues, simplex); }
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair runSimplex(BaseObjectiveFunction objective, double[] startPoint) throws TooManyEvaluationsException { // Rely on relative difference to test convergence, // to allow for vast differences in absolute error scale // between objective functions. ConvergenceChecker<PointValuePair> convergenceChecker = new SimpleValueChecker(1.e-6, 1.e-14); SimplexOptimizer optimizer = new SimplexOptimizer(convergenceChecker); MultiDirectionalSimplex simplex = new MultiDirectionalSimplex(objective.getSimplexStepSize()); return optimizer.optimize(GoalType.MINIMIZE, new ObjectiveFunction(objective), new MaxEval(objective.getMaxEvaluations()), MaxIter.unlimited(), new InitialGuess(startPoint), simplex);/*from w w w . jav a2s. c o m*/ }
From source file:uk.ac.diamond.scisoft.analysis.diffraction.FittingUtils.java
/** * @param opt// w w w .j a va 2 s .co m * @param n * @return optimizer */ public static MultivariateOptimizer createOptimizer(Optimizer opt, int n) { switch (opt) { case BOBYQA: return new BOBYQAOptimizer(n + 2); case CMAES: return new CMAESOptimizer(MAX_ITER, 0., true, 0, 10, seed == null ? new Well19937c() : new Well19937c(seed), false, new SimplePointChecker<PointValuePair>(REL_TOL, ABS_TOL)); case Simplex: default: return new SimplexOptimizer(new SimplePointChecker<PointValuePair>(REL_TOL * 1e3, ABS_TOL * 1e3)); } }
From source file:uk.ac.diamond.scisoft.analysis.optimize.ApacheOptimizer.java
private MultivariateOptimizer createOptimizer() { SimplePointChecker<PointValuePair> checker = new SimplePointChecker<PointValuePair>(REL_TOL, ABS_TOL); switch (optimizer) { case CONJUGATE_GRADIENT: return new NonLinearConjugateGradientOptimizer(Formula.POLAK_RIBIERE, checker); case BOBYQA:// w ww .ja v a 2 s . c o m return new BOBYQAOptimizer(n + 2); case CMAES: return new CMAESOptimizer(MAX_ITER, 0., true, 0, 10, seed == null ? new Well19937c() : new Well19937c(seed), false, new SimplePointChecker<PointValuePair>(REL_TOL, ABS_TOL)); case POWELL: return new PowellOptimizer(REL_TOL, ABS_TOL, checker); case SIMPLEX_MD: case SIMPLEX_NM: return new SimplexOptimizer(checker); default: throw new IllegalStateException("Should not be called"); } }