List of usage examples for org.apache.commons.math3.optim MaxIter unlimited
public static MaxIter unlimited()
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static UnivariatePointValuePair runBrent(BrentOptimizer optimizer, BaseObjectiveFunction objective, double[] startPoint) throws TooManyEvaluationsException { UnivariatePointValuePair outcome;/*w w w . j a v a 2 s .co m*/ outcome = optimizer.optimize(GoalType.MINIMIZE, new UnivariateObjectiveFunction(objective), new MaxEval(objective.getMaxEvaluations()), MaxIter.unlimited(), new SearchInterval(objective.getLowerBounds()[0], objective.getUpperBounds()[0], startPoint[0])); return outcome; }
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair runBobyqa(BOBYQAOptimizer optimizer, BaseObjectiveFunction objective, double[] startPoint, int maxEvaluations) throws TooManyEvaluationsException { PointValuePair outcome;//www. j ava2 s . c o m EvaluatorInterface originalEvaluator = objective.getEvaluator(); if (objective.isRunTwoStageOptimization()) { objective.setEvaluator(objective.getFirstStageEvaluator()); outcome = optimizer.optimize(GoalType.MINIMIZE, new ObjectiveFunction(objective), new MaxEval(maxEvaluations), MaxIter.unlimited(), new InitialGuess(startPoint), new SimpleBounds(objective.getLowerBounds(), objective.getUpperBounds())); objective.setGeometryPoint(outcome.getPoint()); startPoint = objective.getInitialPoint(); } objective.setEvaluator(originalEvaluator); outcome = optimizer.optimize(GoalType.MINIMIZE, new ObjectiveFunction(objective), new MaxEval(maxEvaluations - optimizer.getEvaluations()), MaxIter.unlimited(), new InitialGuess(startPoint), new SimpleBounds(objective.getLowerBounds(), objective.getUpperBounds())); return outcome; }
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair runPowell(BaseObjectiveFunction objective, double[] startPoint) throws TooManyEvaluationsException { PowellOptimizer optimizer = new PowellOptimizer(1.e-6, 1.e-14); return optimizer.optimize(GoalType.MINIMIZE, new ObjectiveFunction(objective), new MaxEval(objective.getMaxEvaluations()), MaxIter.unlimited(), new InitialGuess(startPoint)); }
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. ja va2 s .c o m }
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair runCmaes(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); MultivariateOptimizer optimizer = new CMAESOptimizer(objective.getMaxEvaluations(), 0.0001 * initialNorm, true, 0, 0, new MersenneTwister(), false, convergenceChecker); return optimizer.optimize(GoalType.MINIMIZE, new ObjectiveFunction(objective), new MaxEval(objective.getMaxEvaluations()), MaxIter.unlimited(), new InitialGuess(startPoint), new SimpleBounds(objective.getLowerBounds(), objective.getUpperBounds()), new CMAESOptimizer.PopulationSize(objective.getNrInterpolations()), new CMAESOptimizer.Sigma(objective.getStdDev())); }
From source file:com.wwidesigner.modelling.PlayingRange.java
/** * Find fmin for a playing range, given fmax. * fmin is the highest frequency <= fmax that satisfies * either gain(fmin) == MinimumGain/*from w w w .j a va2s .c om*/ * or fmin is a local minimum of Im(Z)/Re(Z). * @param fmax - maximum frequency, as returned by findFmax(). */ public double findFmin(double fmax) { final double stepSize = fmax * Granularity; // Step size for search. // Upper bound on fmin is fmax. // findFmax ensures Im(Z(fmax)) == 0.0. double lowerFreq = fmax; Complex z_lo = calculator.calcZ(fmax, fingering); double g_lo = calculator.calcGain(lowerFreq, z_lo); double ratio = z_lo.getImaginary() / z_lo.getReal(); double minRatio = ratio + 1.0; if (g_lo < MinimumGain) { // Loop gain is too small, even at fmax. // There is no playing range here. throw new NoPlayingRange(fmax); } // Lower bound on fmin either has gain < MinimumGain // or is past a local minimum of Im(Z)/Re(Z). while (g_lo >= MinimumGain && ratio < minRatio) { minRatio = ratio; lowerFreq -= stepSize; if (lowerFreq < fmax / SearchBoundRatio) { throw new NoPlayingRange(fmax); } z_lo = calculator.calcZ(lowerFreq, fingering); g_lo = calculator.calcGain(lowerFreq, z_lo); ratio = z_lo.getImaginary() / z_lo.getReal(); } double freqGain; // Frequency at which gain == MinimumGain. double freqRatio; // Frequency of local minimum of Im(Z)/Re(Z). if (g_lo < MinimumGain) { // Find the point at which gain == MinimumGain. try { freqGain = solver.solve(50, gainOne, lowerFreq, fmax); } catch (Exception e) { System.out.println("Exception solving for fmin (gain): " + e.getMessage()); // e.printStackTrace(); throw new NoPlayingRange(fmax); } } else { freqGain = lowerFreq; } // Find the local minimum of Im(Z)/Re(Z). try { UnivariatePointValuePair minimum; minimum = optimizer.optimize(GoalType.MINIMIZE, new UnivariateObjectiveFunction(zRatio), new MaxEval(50), MaxIter.unlimited(), new SearchInterval(lowerFreq, fmax, 0.5 * (lowerFreq + fmax))); freqRatio = minimum.getPoint(); } catch (Exception e) { System.out.println("Exception solving for fmin (ratio): " + e.getMessage()); // e.printStackTrace(); throw new NoPlayingRange(fmax); } if (freqRatio > freqGain) { return freqRatio; } return freqGain; }
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair runDirect(MultivariateOptimizer optimizer, BaseObjectiveFunction objective, double[] startPoint) throws TooManyEvaluationsException { PointValuePair outcome;// w w w .j a v a 2s .co m // Run optimization first with the first-stage evaluator, if // specified EvaluatorInterface originalEvaluator = objective.getEvaluator(); if (objective.isRunTwoStageOptimization()) { objective.setEvaluator(objective.getFirstStageEvaluator()); } // Specify a target function value, to guard against // underconstrained // optimizations. Value here should be suitable for // CentsDeviationEvaluator, // and adequate for most other evaluators. outcome = optimizer.optimize(GoalType.MINIMIZE, new ObjectiveFunction(objective), new MaxEval(2 * objective.getMaxEvaluations()), MaxIter.unlimited(), new InitialGuess(startPoint), new DIRECTOptimizer.TargetFunctionValue(0.001), new SimpleBounds(objective.getLowerBounds(), objective.getUpperBounds())); objective.setEvaluator(originalEvaluator); return outcome; }