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
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximal number of iterations allowed. -
Method Summary
Modifier and TypeMethodDescriptionGet the convergence checker.intGet the number of evaluations of the objective function.intGet the number of evaluations of the objective function gradient.intGet the number of iterations realized by the algorithm.intGet the maximal number of functions evaluations.intGet the maximal number of iterations of the algorithm.optimize(DifferentiableMultivariateRealFunction f, GoalType goalType, double[] startPoint) Optimizes an objective function.voidsetConvergenceChecker(RealConvergenceChecker convergenceChecker) Set the convergence checker.voidsetMaxEvaluations(int maxEvaluations) Set the maximal number of functions evaluations.voidsetMaxIterations(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:
-
-
Method Details
-
setMaxIterations
public void setMaxIterations(int maxIterations) Set the maximal number of iterations of the algorithm.- Specified by:
setMaxIterationsin interfaceDifferentiableMultivariateRealOptimizer- Parameters:
maxIterations- maximal number of function calls
-
getMaxIterations
public int getMaxIterations()Get the maximal number of iterations of the algorithm.- Specified by:
getMaxIterationsin 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
optimizemethod. It is 0 if the method has not been called yet.- Specified by:
getIterationsin interfaceDifferentiableMultivariateRealOptimizer- Returns:
- number of iterations
-
setMaxEvaluations
public void setMaxEvaluations(int maxEvaluations) Set the maximal number of functions evaluations.- Specified by:
setMaxEvaluationsin interfaceDifferentiableMultivariateRealOptimizer- Parameters:
maxEvaluations- maximal number of function evaluations
-
getMaxEvaluations
public int getMaxEvaluations()Get the maximal number of functions evaluations.- Specified by:
getMaxEvaluationsin 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
optimizemethod. It is 0 if the method has not been called yet.- Specified by:
getEvaluationsin 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
optimizemethod. It is 0 if the method has not been called yet.- Specified by:
getGradientEvaluationsin interfaceDifferentiableMultivariateRealOptimizer- Returns:
- number of evaluations of the objective function gradient
-
setConvergenceChecker
Set the convergence checker.- Specified by:
setConvergenceCheckerin interfaceDifferentiableMultivariateRealOptimizer- Parameters:
convergenceChecker- object to use to check for convergence
-
getConvergenceChecker
Get the convergence checker.- Specified by:
getConvergenceCheckerin interfaceDifferentiableMultivariateRealOptimizer- Returns:
- object used to check for convergence
-
optimize
public RealPointValuePair optimize(DifferentiableMultivariateRealFunction f, GoalType goalType, double[] startPoint) throws FunctionEvaluationException, OptimizationException, IllegalArgumentException Optimizes an objective function.- Specified by:
optimizein interfaceDifferentiableMultivariateRealOptimizer- Parameters:
f- objective functiongoalType- type of optimization goal: eitherGoalType.MAXIMIZEorGoalType.MINIMIZEstartPoint- 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
-