public class MultiStartUnivariateRealOptimizer extends java.lang.Object implements UnivariateRealOptimizer
UnivariateRealOptimizer
interface adding
multi-start features to an existing optimizer.
This class wraps a classical optimizer to use it several times in turn with different starting points in order to avoid being trapped into a local extremum when looking for a global one.
Constructor and Description |
---|
MultiStartUnivariateRealOptimizer(UnivariateRealOptimizer optimizer,
int starts,
RandomGenerator generator)
Create a multi-start optimizer from a single-start optimizer
|
Modifier and Type | Method and Description |
---|---|
double |
getAbsoluteAccuracy()
Get the actual absolute accuracy.
|
int |
getEvaluations()
Get the number of evaluations of the objective function.
|
double |
getFunctionValue()
Get the result of the last run of the optimizer.
|
int |
getIterationCount()
Get the number of iterations in the last run of the algorithm.
|
int |
getMaxEvaluations()
Get the maximal number of functions evaluations.
|
int |
getMaximalIterationCount()
Get the upper limit for the number of iterations.
|
double[] |
getOptima()
Get all the optima found during the last call to
optimize . |
double[] |
getOptimaValues()
Get all the function values at optima found during the last call to
optimize . |
double |
getRelativeAccuracy()
Get the actual relative accuracy.
|
double |
getResult()
Get the result of the last run of the optimizer.
|
double |
optimize(UnivariateRealFunction f,
GoalType goalType,
double min,
double max)
Find an optimum in the given interval.
|
double |
optimize(UnivariateRealFunction f,
GoalType goalType,
double min,
double max,
double startValue)
Find an optimum in the given interval, start at startValue.
|
void |
resetAbsoluteAccuracy()
Reset the absolute accuracy to the default.
|
void |
resetMaximalIterationCount()
Reset the upper limit for the number of iterations to the default.
|
void |
resetRelativeAccuracy()
Reset the relative accuracy to the default.
|
void |
setAbsoluteAccuracy(double accuracy)
Set the absolute accuracy.
|
void |
setMaxEvaluations(int maxEvaluations)
Set the maximal number of functions evaluations.
|
void |
setMaximalIterationCount(int count)
Set the upper limit for the number of iterations.
|
void |
setRelativeAccuracy(double accuracy)
Set the relative accuracy.
|
public MultiStartUnivariateRealOptimizer(UnivariateRealOptimizer optimizer, int starts, RandomGenerator generator)
optimizer
- single-start optimizer to wrapstarts
- number of starts to perform (including the
first one), multi-start is disabled if value is less than or
equal to 1generator
- random generator to use for restartspublic double getFunctionValue()
getFunctionValue
in interface UnivariateRealOptimizer
public double getResult()
getResult
in interface UnivariateRealOptimizer
public double getAbsoluteAccuracy()
getAbsoluteAccuracy
in interface ConvergingAlgorithm
public int getIterationCount()
This is mainly meant for testing purposes. It may occasionally help track down performance problems: if the iteration count is notoriously high, check whether the problem is evaluated properly, and whether another algorithm is more amenable to the problem.
getIterationCount
in interface ConvergingAlgorithm
public int getMaximalIterationCount()
getMaximalIterationCount
in interface ConvergingAlgorithm
public int getMaxEvaluations()
getMaxEvaluations
in interface UnivariateRealOptimizer
public int getEvaluations()
The number of evaluations corresponds to the last call to the
optimize
method. It is 0 if the method has not been called yet.
getEvaluations
in interface UnivariateRealOptimizer
public double getRelativeAccuracy()
getRelativeAccuracy
in interface ConvergingAlgorithm
public void resetAbsoluteAccuracy()
The default value is provided by the algorithm implementation.
resetAbsoluteAccuracy
in interface ConvergingAlgorithm
public void resetMaximalIterationCount()
The default value is supplied by the algorithm implementation.
resetMaximalIterationCount
in interface ConvergingAlgorithm
ConvergingAlgorithm.setMaximalIterationCount(int)
public void resetRelativeAccuracy()
resetRelativeAccuracy
in interface ConvergingAlgorithm
public void setAbsoluteAccuracy(double accuracy)
The default is usually chosen so that results in the interval -10..-0.1 and +0.1..+10 can be found with a reasonable accuracy. If the expected absolute value of your results is of much smaller magnitude, set this to a smaller value.
Algorithms are advised to do a plausibility check with the relative accuracy, but clients should not rely on this.
setAbsoluteAccuracy
in interface ConvergingAlgorithm
accuracy
- the accuracy.public void setMaximalIterationCount(int count)
Usually a high iteration count indicates convergence problems. However, the "reasonable value" varies widely for different algorithms. Users are advised to use the default value supplied by the algorithm.
A ConvergenceException
will be thrown if this number
is exceeded.
setMaximalIterationCount
in interface ConvergingAlgorithm
count
- maximum number of iterationspublic void setMaxEvaluations(int maxEvaluations)
setMaxEvaluations
in interface UnivariateRealOptimizer
maxEvaluations
- maximal number of function evaluationspublic void setRelativeAccuracy(double accuracy)
This is used to stop iterations if the absolute accuracy can't be achieved due to large values or short mantissa length.
If this should be the primary criterion for convergence rather then a
safety measure, set the absolute accuracy to a ridiculously small value,
like MathUtils.SAFE_MIN
.
setRelativeAccuracy
in interface ConvergingAlgorithm
accuracy
- the relative accuracy.public double[] getOptima() throws java.lang.IllegalStateException
optimize
.
The optimizer stores all the optima found during a set of
restarts. The optimize
method returns the best point only. This
method returns all the points found at the end of each starts,
including the best one already returned by the optimize
method.
The returned array as one element for each start as specified
in the constructor. It is ordered with the results from the
runs that did converge first, sorted from best to worst
objective value (i.e in ascending order if minimizing and in
descending order if maximizing), followed by Double.NaN elements
corresponding to the runs that did not converge. This means all
elements will be NaN if the optimize
method did throw a ConvergenceException
). This also means that
if the first element is not NaN, it is the best point found across
all starts.
java.lang.IllegalStateException
- if optimize
has not been calledgetOptimaValues()
public double[] getOptimaValues() throws java.lang.IllegalStateException
optimize
.
The returned array as one element for each start as specified
in the constructor. It is ordered with the results from the
runs that did converge first, sorted from best to worst
objective value (i.e in ascending order if minimizing and in
descending order if maximizing), followed by Double.NaN elements
corresponding to the runs that did not converge. This means all
elements will be NaN if the optimize
method did throw a ConvergenceException
). This also means that
if the first element is not NaN, it is the best point found across
all starts.
java.lang.IllegalStateException
- if optimize
has not been calledgetOptima()
public double optimize(UnivariateRealFunction f, GoalType goalType, double min, double max) throws ConvergenceException, FunctionEvaluationException
An optimizer may require that the interval brackets a single optimum.
optimize
in interface UnivariateRealOptimizer
f
- the function to optimize.goalType
- type of optimization goal: either GoalType.MAXIMIZE
or GoalType.MINIMIZE
.min
- the lower bound for the interval.max
- the upper bound for the interval.ConvergenceException
- if the maximum iteration count is exceeded
or the optimizer detects convergence problems otherwise.FunctionEvaluationException
- if an error occurs evaluating the function.public double optimize(UnivariateRealFunction f, GoalType goalType, double min, double max, double startValue) throws ConvergenceException, FunctionEvaluationException
An optimizer may require that the interval brackets a single optimum.
optimize
in interface UnivariateRealOptimizer
f
- the function to optimize.goalType
- type of optimization goal: either GoalType.MAXIMIZE
or GoalType.MINIMIZE
.min
- the lower bound for the interval.max
- the upper bound for the interval.startValue
- the start value to use.ConvergenceException
- if the maximum iteration count is exceeded
or the optimizer detects convergence problems otherwise.FunctionEvaluationException
- if an error occurs evaluating the function."Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"