public abstract class AbstractUnivariateRealOptimizer extends ConvergingAlgorithmImpl implements UnivariateRealOptimizer
Modifier and Type | Field and Description |
---|---|
private int |
evaluations
Number of evaluations already performed.
|
private UnivariateRealFunction |
function
Function to optimize.
|
protected double |
functionValue
Value of the function at the last computed result.
|
private int |
maxEvaluations
Maximal number of evaluations allowed.
|
private GoalType |
optimizationGoal
Optimization type
|
protected double |
result
The last computed root.
|
protected boolean |
resultComputed
Indicates where a root has been computed.
|
private double |
searchMax
Higher end of search interval.
|
private double |
searchMin
Lower end of search interval.
|
private double |
searchStart
Initial guess .
|
absoluteAccuracy, defaultAbsoluteAccuracy, defaultMaximalIterationCount, defaultRelativeAccuracy, iterationCount, maximalIterationCount, relativeAccuracy
Modifier | Constructor and Description |
---|---|
protected |
AbstractUnivariateRealOptimizer()
Default constructor.
|
protected |
AbstractUnivariateRealOptimizer(int defaultMaximalIterationCount,
double defaultAbsoluteAccuracy)
Deprecated.
in 2.2. Please use the "setter" methods to assign meaningful
values to the maximum numbers of iterations and evaluations, and to the
absolute and relative accuracy thresholds.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkResultComputed()
Deprecated.
in 2.2 (no alternative).
|
protected void |
clearResult()
Deprecated.
in 2.2 (no alternative).
|
protected double |
computeObjectiveValue(double point)
Compute the objective function value.
|
protected double |
computeObjectiveValue(UnivariateRealFunction f,
double point)
Deprecated.
in 2.2. Use this
replacement instead. |
protected double |
doOptimize()
Method for implementing actual optimization algorithms in derived
classes.
|
int |
getEvaluations()
Get the number of evaluations of the objective function.
|
double |
getFunctionValue()
Get the result of the last run of the optimizer.
|
GoalType |
getGoalType() |
double |
getMax() |
int |
getMaxEvaluations()
Get the maximal number of functions evaluations.
|
double |
getMin() |
double |
getResult()
Get the result of the last run of the optimizer.
|
double |
getStartValue() |
double |
optimize(UnivariateRealFunction f,
GoalType goal,
double min,
double max)
Find an optimum in the given interval.
|
double |
optimize(UnivariateRealFunction f,
GoalType goal,
double min,
double max,
double startValue)
Find an optimum in the given interval, start at startValue.
|
protected void |
setFunctionValue(double functionValue)
Set the value at the optimum.
|
void |
setMaxEvaluations(int maxEvaluations)
Set the maximal number of functions evaluations.
|
protected void |
setResult(double x,
double fx,
int iterationCount)
Deprecated.
in 2.2 (no alternative).
|
getAbsoluteAccuracy, getIterationCount, getMaximalIterationCount, getRelativeAccuracy, incrementIterationsCounter, resetAbsoluteAccuracy, resetIterationsCounter, resetMaximalIterationCount, resetRelativeAccuracy, setAbsoluteAccuracy, setMaximalIterationCount, setRelativeAccuracy
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAbsoluteAccuracy, getIterationCount, getMaximalIterationCount, getRelativeAccuracy, resetAbsoluteAccuracy, resetMaximalIterationCount, resetRelativeAccuracy, setAbsoluteAccuracy, setMaximalIterationCount, setRelativeAccuracy
protected boolean resultComputed
protected double result
protected double functionValue
private int maxEvaluations
private int evaluations
private GoalType optimizationGoal
private double searchMin
private double searchMax
private double searchStart
private UnivariateRealFunction function
@Deprecated protected AbstractUnivariateRealOptimizer(int defaultMaximalIterationCount, double defaultAbsoluteAccuracy)
defaultAbsoluteAccuracy
- maximum absolute errordefaultMaximalIterationCount
- maximum number of iterationsjava.lang.IllegalArgumentException
- if f is null or the
defaultAbsoluteAccuracy is not validprotected AbstractUnivariateRealOptimizer()
@Deprecated protected void checkResultComputed()
NoDataException
- if no result has been computedpublic double getResult()
getResult
in interface UnivariateRealOptimizer
public double getFunctionValue() throws FunctionEvaluationException
getFunctionValue
in interface UnivariateRealOptimizer
FunctionEvaluationException
- if an error occurs evaluating the function.@Deprecated protected final void setResult(double x, double fx, int iterationCount)
x
- the result to setfx
- the result to setiterationCount
- the iteration count to set@Deprecated protected final void clearResult()
public void setMaxEvaluations(int maxEvaluations)
setMaxEvaluations
in interface UnivariateRealOptimizer
maxEvaluations
- maximal number of function evaluationspublic 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 GoalType getGoalType()
public double getMin()
public double getMax()
public double getStartValue()
@Deprecated protected double computeObjectiveValue(UnivariateRealFunction f, double point) throws FunctionEvaluationException
replacement
instead.f
- objective functionpoint
- point at which the objective function must be evaluatedFunctionEvaluationException
- if the function cannot be evaluated
or the maximal number of iterations is exceededprotected double computeObjectiveValue(double point) throws FunctionEvaluationException
point
- Point at which the objective function must be evaluated.FunctionEvaluationException
- if the function cannot be evaluated
or the maximal number of iterations is exceeded.public double optimize(UnivariateRealFunction f, GoalType goal, double min, double max, double startValue) throws MaxIterationsExceededException, FunctionEvaluationException
An optimizer may require that the interval brackets a single optimum.
optimize
in interface UnivariateRealOptimizer
f
- the function to optimize.goal
- 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.FunctionEvaluationException
- if an error occurs evaluating the function.MaxIterationsExceededException
protected void setFunctionValue(double functionValue)
functionValue
- Value of the objective function at the optimum.public double optimize(UnivariateRealFunction f, GoalType goal, double min, double max) throws MaxIterationsExceededException, FunctionEvaluationException
An optimizer may require that the interval brackets a single optimum.
optimize
in interface UnivariateRealOptimizer
f
- the function to optimize.goal
- type of optimization goal: either GoalType.MAXIMIZE
or GoalType.MINIMIZE
.min
- the lower bound for the interval.max
- the upper bound for the interval.FunctionEvaluationException
- if an error occurs evaluating the function.MaxIterationsExceededException
protected double doOptimize() throws MaxIterationsExceededException, FunctionEvaluationException
optimize(UnivariateRealFunction, GoalType, double, double)
.MaxIterationsExceededException
- if the maximum iteration count
is exceeded.FunctionEvaluationException
- if an error occurs evaluating
the function.Copyright (c) 2003-2014 Apache Software Foundation