org.apache.commons.math.optimization.general
public abstract class AbstractScalarDifferentiableOptimizer extends Object implements DifferentiableMultivariateRealOptimizer
This base class handles the boilerplate methods associated to thresholds settings, iterations and evaluations counting.
Modifier and Type | Field and Description |
---|---|
protected RealConvergenceChecker |
checker
Deprecated.
|
static int |
DEFAULT_MAX_ITERATIONS
Default maximal number of iterations allowed.
|
private int |
evaluations
Number of evaluations already performed.
|
private DifferentiableMultivariateRealFunction |
function
Objective function.
|
protected GoalType |
goal
Deprecated.
|
private MultivariateVectorialFunction |
gradient
Objective function gradient.
|
private int |
gradientEvaluations
Number of gradient evaluations.
|
private int |
iterations
Number of iterations already performed.
|
private int |
maxEvaluations
Maximal number of evaluations allowed.
|
private int |
maxIterations
Maximal number of iterations allowed.
|
protected double[] |
point
Deprecated.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractScalarDifferentiableOptimizer()
Simple constructor with default settings.
|
Modifier and Type | Method and Description |
---|---|
protected double[] |
computeObjectiveGradient(double[] evaluationPoint)
Compute the gradient vector.
|
protected double |
computeObjectiveValue(double[] evaluationPoint)
Compute the objective function value.
|
protected abstract RealPointValuePair |
doOptimize()
Perform the bulk of optimization algorithm.
|
RealConvergenceChecker |
getConvergenceChecker()
Get the convergence checker.
|
int |
getEvaluations()
Get the number of evaluations of the objective function.
|
int |
getGradientEvaluations()
Get the number of evaluations of the objective function gradient.
|
int |
getIterations()
Get the number of iterations realized by the algorithm.
|
int |
getMaxEvaluations()
Get the maximal number of functions evaluations.
|
int |
getMaxIterations()
Get the maximal number of iterations of the algorithm.
|
protected void |
incrementIterationsCounter()
Increment the iterations counter by 1.
|
RealPointValuePair |
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.
|
public static final int DEFAULT_MAX_ITERATIONS
@Deprecated protected RealConvergenceChecker checker
@Deprecated protected GoalType goal
@Deprecated protected double[] point
private int maxIterations
private int iterations
private int maxEvaluations
private int evaluations
private int gradientEvaluations
private DifferentiableMultivariateRealFunction function
private MultivariateVectorialFunction gradient
protected AbstractScalarDifferentiableOptimizer()
The convergence check is set to a SimpleScalarValueChecker
and the maximal number of evaluation is set to its default value.
public void setMaxIterations(int maxIterations)
setMaxIterations
in interface DifferentiableMultivariateRealOptimizer
maxIterations
- maximal number of function callspublic int getMaxIterations()
getMaxIterations
in interface DifferentiableMultivariateRealOptimizer
public int getIterations()
The number of evaluations corresponds to the last call to the
optimize
method. It is 0 if the method has not been called yet.
getIterations
in interface DifferentiableMultivariateRealOptimizer
public void setMaxEvaluations(int maxEvaluations)
setMaxEvaluations
in interface DifferentiableMultivariateRealOptimizer
maxEvaluations
- maximal number of function evaluationspublic int getMaxEvaluations()
getMaxEvaluations
in interface DifferentiableMultivariateRealOptimizer
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 DifferentiableMultivariateRealOptimizer
public int getGradientEvaluations()
The number of evaluations corresponds to the last call to the
optimize
method. It is 0 if the method has not been called yet.
getGradientEvaluations
in interface DifferentiableMultivariateRealOptimizer
public void setConvergenceChecker(RealConvergenceChecker convergenceChecker)
setConvergenceChecker
in interface DifferentiableMultivariateRealOptimizer
convergenceChecker
- object to use to check for convergencepublic RealConvergenceChecker getConvergenceChecker()
getConvergenceChecker
in interface DifferentiableMultivariateRealOptimizer
protected void incrementIterationsCounter() throws OptimizationException
OptimizationException
- if the maximal number
of iterations is exceededprotected double[] computeObjectiveGradient(double[] evaluationPoint) throws FunctionEvaluationException
evaluationPoint
- point at which the gradient must be evaluatedFunctionEvaluationException
- if the function gradientprotected double computeObjectiveValue(double[] evaluationPoint) throws FunctionEvaluationException
evaluationPoint
- point at which the objective function must be evaluatedFunctionEvaluationException
- if the function cannot be evaluated
or its dimension doesn't match problem dimension or the maximal number
of iterations is exceededpublic RealPointValuePair optimize(DifferentiableMultivariateRealFunction f, GoalType goalType, double[] startPoint) throws FunctionEvaluationException, OptimizationException, IllegalArgumentException
optimize
in interface DifferentiableMultivariateRealOptimizer
f
- objective functiongoalType
- type of optimization goal: either GoalType.MAXIMIZE
or GoalType.MINIMIZE
startPoint
- the start point for optimizationFunctionEvaluationException
- if the objective function throws one during
the searchOptimizationException
- if the algorithm failed to convergeIllegalArgumentException
- if the start point dimension is wrongprotected abstract RealPointValuePair doOptimize() throws FunctionEvaluationException, OptimizationException, IllegalArgumentException
FunctionEvaluationException
- if the objective function throws one during
the searchOptimizationException
- if the algorithm failed to convergeIllegalArgumentException
- if the start point dimension is wrongCopyright (c) 2003-2013 Apache Software Foundation