Class AbstractScalarDifferentiableOptimizer
java.lang.Object
org.apache.commons.math.optimization.general.AbstractScalarDifferentiableOptimizer
- All Implemented Interfaces:
DifferentiableMultivariateRealOptimizer
- Direct Known Subclasses:
NonLinearConjugateGradientOptimizer
,PowellOptimizer
public abstract class AbstractScalarDifferentiableOptimizer
extends Object
implements DifferentiableMultivariateRealOptimizer
Base class for implementing optimizers for multivariate scalar functions.
This base class handles the boilerplate methods associated to thresholds settings, iterations and evaluations counting.
- Since:
- 2.0
- Version:
- $Revision: 1069567 $ $Date: 2011-02-10 22:07:26 +0100 (jeu. 10 févr. 2011) $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected RealConvergenceChecker
Deprecated.static final int
Default maximal number of iterations allowed.protected GoalType
Deprecated.protected double[]
Deprecated. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Simple constructor with default settings. -
Method Summary
Modifier and TypeMethodDescriptionprotected double[]
computeObjectiveGradient
(double[] evaluationPoint) Compute the gradient vector.protected double
computeObjectiveValue
(double[] evaluationPoint) Compute the objective function value.protected abstract RealPointValuePair
Perform the bulk of optimization algorithm.Get the convergence checker.int
Get the number of evaluations of the objective function.int
Get the number of evaluations of the objective function gradient.int
Get the number of iterations realized by the algorithm.int
Get the maximal number of functions evaluations.int
Get the maximal number of iterations of the algorithm.protected void
Increment the iterations counter by 1.optimize
(DifferentiableMultivariateRealFunction f, GoalType goalType, double[] startPoint) Optimizes an objective function.void
setConvergenceChecker
(RealConvergenceChecker convergenceChecker) Set the convergence checker.void
setMaxEvaluations
(int maxEvaluations) Set the maximal number of functions evaluations.void
setMaxIterations
(int maxIterations) Set the maximal number of iterations of the algorithm.
-
Field Details
-
DEFAULT_MAX_ITERATIONS
public static final int DEFAULT_MAX_ITERATIONSDefault maximal number of iterations allowed.- See Also:
-
checker
Deprecated.Convergence checker. -
goal
Deprecated.Type of optimization.- Since:
- 2.1
-
point
Deprecated.Current point set.
-
-
Constructor Details
-
AbstractScalarDifferentiableOptimizer
protected AbstractScalarDifferentiableOptimizer()Simple constructor with default settings.The convergence check is set to a
SimpleScalarValueChecker
and the maximal number of evaluation is set to its default value.
-
-
Method Details
-
setMaxIterations
public void setMaxIterations(int maxIterations) Set the maximal number of iterations of the algorithm.- Specified by:
setMaxIterations
in interfaceDifferentiableMultivariateRealOptimizer
- Parameters:
maxIterations
- maximal number of function calls
-
getMaxIterations
public int getMaxIterations()Get the maximal number of iterations of the algorithm.- Specified by:
getMaxIterations
in interfaceDifferentiableMultivariateRealOptimizer
- Returns:
- maximal number of iterations
-
getIterations
public int getIterations()Get the number of iterations realized by the algorithm.The number of evaluations corresponds to the last call to the
optimize
method. It is 0 if the method has not been called yet.- Specified by:
getIterations
in interfaceDifferentiableMultivariateRealOptimizer
- Returns:
- number of iterations
-
setMaxEvaluations
public void setMaxEvaluations(int maxEvaluations) Set the maximal number of functions evaluations.- Specified by:
setMaxEvaluations
in interfaceDifferentiableMultivariateRealOptimizer
- Parameters:
maxEvaluations
- maximal number of function evaluations
-
getMaxEvaluations
public int getMaxEvaluations()Get the maximal number of functions evaluations.- Specified by:
getMaxEvaluations
in interfaceDifferentiableMultivariateRealOptimizer
- Returns:
- maximal number of functions evaluations
-
getEvaluations
public int getEvaluations()Get the number of evaluations of the objective function.The number of evaluations corresponds to the last call to the
optimize
method. It is 0 if the method has not been called yet.- Specified by:
getEvaluations
in interfaceDifferentiableMultivariateRealOptimizer
- Returns:
- number of evaluations of the objective function
-
getGradientEvaluations
public int getGradientEvaluations()Get the number of evaluations of the objective function gradient.The number of evaluations corresponds to the last call to the
optimize
method. It is 0 if the method has not been called yet.- Specified by:
getGradientEvaluations
in interfaceDifferentiableMultivariateRealOptimizer
- Returns:
- number of evaluations of the objective function gradient
-
setConvergenceChecker
Set the convergence checker.- Specified by:
setConvergenceChecker
in interfaceDifferentiableMultivariateRealOptimizer
- Parameters:
convergenceChecker
- object to use to check for convergence
-
getConvergenceChecker
Get the convergence checker.- Specified by:
getConvergenceChecker
in interfaceDifferentiableMultivariateRealOptimizer
- Returns:
- object used to check for convergence
-
incrementIterationsCounter
Increment the iterations counter by 1.- Throws:
OptimizationException
- if the maximal number of iterations is exceeded
-
computeObjectiveGradient
protected double[] computeObjectiveGradient(double[] evaluationPoint) throws FunctionEvaluationException Compute the gradient vector.- Parameters:
evaluationPoint
- point at which the gradient must be evaluated- Returns:
- gradient at the specified point
- Throws:
FunctionEvaluationException
- if the function gradient
-
computeObjectiveValue
Compute the objective function value.- Parameters:
evaluationPoint
- point at which the objective function must be evaluated- Returns:
- objective function value at specified point
- Throws:
FunctionEvaluationException
- if the function cannot be evaluated or its dimension doesn't match problem dimension or the maximal number of iterations is exceeded
-
optimize
public RealPointValuePair optimize(DifferentiableMultivariateRealFunction f, GoalType goalType, double[] startPoint) throws FunctionEvaluationException, OptimizationException, IllegalArgumentException Optimizes an objective function.- Specified by:
optimize
in interfaceDifferentiableMultivariateRealOptimizer
- Parameters:
f
- objective functiongoalType
- type of optimization goal: eitherGoalType.MAXIMIZE
orGoalType.MINIMIZE
startPoint
- the start point for optimization- Returns:
- the point/value pair giving the optimal value for objective function
- Throws:
FunctionEvaluationException
- if the objective function throws one during the searchOptimizationException
- if the algorithm failed to convergeIllegalArgumentException
- if the start point dimension is wrong
-
doOptimize
protected abstract RealPointValuePair doOptimize() throws FunctionEvaluationException, OptimizationException, IllegalArgumentExceptionPerform the bulk of optimization algorithm.- Returns:
- the point/value pair giving the optimal value for objective function
- Throws:
FunctionEvaluationException
- if the objective function throws one during the searchOptimizationException
- if the algorithm failed to convergeIllegalArgumentException
- if the start point dimension is wrong
-