Package org.hipparchus.optim
Class BaseOptimizer<P>
- java.lang.Object
-
- org.hipparchus.optim.BaseOptimizer<P>
-
- Type Parameters:
P
- Type of the point/value pair returned by the optimization algorithm.
- Direct Known Subclasses:
BaseMultivariateOptimizer
,UnivariateOptimizer
public abstract class BaseOptimizer<P> extends Object
Base class for implementing optimizers. It contains the boiler-plate code for counting the number of evaluations of the objective function and the number of iterations of the algorithm, and storing the convergence checker. It is not a "user" class.
-
-
Field Summary
Fields Modifier and Type Field Description protected Incrementor
evaluations
Evaluations counter.protected Incrementor
iterations
Iterations counter.
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseOptimizer(ConvergenceChecker<P> checker)
Simple constructor.protected
BaseOptimizer(ConvergenceChecker<P> checker, int maxEval, int maxIter)
Simple constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract P
doOptimize()
Performs the bulk of the optimization algorithm.ConvergenceChecker<P>
getConvergenceChecker()
Gets the convergence checker.int
getEvaluations()
Gets the number of evaluations of the objective function.int
getIterations()
Gets the number of iterations performed by the algorithm.int
getMaxEvaluations()
Gets the maximal number of function evaluations.int
getMaxIterations()
Gets the maximal number of iterations.protected void
incrementEvaluationCount()
Increment the evaluation count.protected void
incrementIterationCount()
Increment the iteration count.P
optimize()
Performs the optimization.P
optimize(OptimizationData... optData)
Stores data and performs the optimization.protected void
parseOptimizationData(OptimizationData... optData)
Scans the list of (required and optional) optimization data that characterize the problem.
-
-
-
Field Detail
-
evaluations
protected Incrementor evaluations
Evaluations counter.
-
iterations
protected Incrementor iterations
Iterations counter.
-
-
Constructor Detail
-
BaseOptimizer
protected BaseOptimizer(ConvergenceChecker<P> checker)
Simple constructor.- Parameters:
checker
- Convergence checker.
-
BaseOptimizer
protected BaseOptimizer(ConvergenceChecker<P> checker, int maxEval, int maxIter)
Simple constructor.- Parameters:
checker
- Convergence checker.maxEval
- Maximum number of objective function evaluations.maxIter
- Maximum number of algorithm iterations.
-
-
Method Detail
-
getMaxEvaluations
public int getMaxEvaluations()
Gets the maximal number of function evaluations.- Returns:
- the maximal number of function evaluations.
-
getEvaluations
public int getEvaluations()
Gets the number of evaluations of the objective function. The number of evaluations corresponds to the last call to theoptimize
method. It is 0 if the method has not been called yet.- Returns:
- the number of evaluations of the objective function.
-
getMaxIterations
public int getMaxIterations()
Gets the maximal number of iterations.- Returns:
- the maximal number of iterations.
-
getIterations
public int getIterations()
Gets the number of iterations performed by the algorithm. The number iterations corresponds to the last call to theoptimize
method. It is 0 if the method has not been called yet.- Returns:
- the number of evaluations of the objective function.
-
getConvergenceChecker
public ConvergenceChecker<P> getConvergenceChecker()
Gets the convergence checker.- Returns:
- the object used to check for convergence.
-
optimize
public P optimize(OptimizationData... optData) throws MathIllegalStateException
Stores data and performs the optimization.The list of parameters is open-ended so that sub-classes can extend it with arguments specific to their concrete implementations.
When the method is called multiple times, instance data is overwritten only when actually present in the list of arguments: when not specified, data set in a previous call is retained (and thus is optional in subsequent calls).
Important note: Subclasses must override
parseOptimizationData(OptimizationData[])
if they need to register their own options; but then, they must also callsuper.parseOptimizationData(optData)
within that method.- Parameters:
optData
- Optimization data. This method will register the following data:- Returns:
- a point/value pair that satisfies the convergence criteria.
- Throws:
MathIllegalStateException
- if the maximal number of evaluations is exceeded.MathIllegalStateException
- if the maximal number of iterations is exceeded.
-
optimize
public P optimize() throws MathIllegalStateException
Performs the optimization.- Returns:
- a point/value pair that satisfies the convergence criteria.
- Throws:
MathIllegalStateException
- if the maximal number of evaluations is exceeded.MathIllegalStateException
- if the maximal number of iterations is exceeded.
-
doOptimize
protected abstract P doOptimize()
Performs the bulk of the optimization algorithm.- Returns:
- the point/value pair giving the optimal value of the objective function.
-
incrementEvaluationCount
protected void incrementEvaluationCount() throws MathIllegalStateException
Increment the evaluation count.- Throws:
MathIllegalStateException
- if the allowed evaluations have been exhausted.
-
incrementIterationCount
protected void incrementIterationCount() throws MathIllegalStateException
Increment the iteration count.- Throws:
MathIllegalStateException
- if the allowed iterations have been exhausted.
-
parseOptimizationData
protected void parseOptimizationData(OptimizationData... optData)
Scans the list of (required and optional) optimization data that characterize the problem.
-
-