F
- Type of function to solve.public abstract class BaseAbstractUnivariateSolver<F extends UnivariateFunction> extends Object implements BaseUnivariateSolver<F>, Serializable
Modifier | Constructor and Description |
---|---|
protected |
BaseAbstractUnivariateSolver(double absoluteAccuracyIn)
Construct a solver with given absolute accuracy.
|
protected |
BaseAbstractUnivariateSolver(double relativeAccuracyIn,
double absoluteAccuracyIn)
Construct a solver with given accuracies.
|
protected |
BaseAbstractUnivariateSolver(double relativeAccuracyIn,
double absoluteAccuracyIn,
double functionValueAccuracyIn)
Construct a solver with given accuracies.
|
Modifier and Type | Method and Description |
---|---|
protected double |
computeObjectiveValue(double point)
Compute the objective function value.
|
protected abstract double |
doSolve()
Method for implementing actual optimization algorithms in derived
classes.
|
double |
getAbsoluteAccuracy()
Get the absolute accuracy of the solver.
|
int |
getEvaluations()
Get the number of evaluations of the objective function.
|
double |
getFunctionValueAccuracy()
Get the function value accuracy of the solver.
|
double |
getMax() |
int |
getMaxEvaluations()
Get the maximum number of function evaluations.
|
double |
getMin() |
double |
getRelativeAccuracy()
Get the relative accuracy of the solver.
|
double |
getStartValue() |
protected void |
incrementEvaluationCount()
Increment the evaluation count by one.
|
protected boolean |
isBracketing(double lower,
double upper)
Check whether the function takes opposite signs at the endpoints.
|
protected boolean |
isSequence(double start,
double mid,
double end)
Check whether the arguments form a (strictly) increasing sequence.
|
protected void |
setup(int maxEval,
F f,
double min,
double max,
double startValue)
Prepare for computation.
|
double |
solve(int maxEval,
F f,
double startValue)
Solve for a zero in the vicinity of
startValue . |
double |
solve(int maxEval,
F f,
double min,
double max)
Solve for a zero root in the given interval.
|
double |
solve(int maxEval,
F f,
double min,
double max,
double startValue)
Solve for a zero in the given interval, start at
startValue . |
protected void |
verifyBracketing(double lower,
double upper)
Check that the endpoints specify an interval and the function takes
opposite signs at the endpoints.
|
protected void |
verifyInterval(double lower,
double upper)
Check that the endpoints specify an interval.
|
protected void |
verifySequence(double lower,
double initial,
double upper)
Check that
lower < initial < upper . |
protected void |
verifySequenceStrict(double lower,
double initial,
double upper)
Check that
lower <= initial <= upper & lower < upper . |
protected BaseAbstractUnivariateSolver(double absoluteAccuracyIn)
absoluteAccuracyIn
- Maximum absolute error.protected BaseAbstractUnivariateSolver(double relativeAccuracyIn, double absoluteAccuracyIn)
relativeAccuracyIn
- Maximum relative error.absoluteAccuracyIn
- Maximum absolute error.protected BaseAbstractUnivariateSolver(double relativeAccuracyIn, double absoluteAccuracyIn, double functionValueAccuracyIn)
relativeAccuracyIn
- Maximum relative error.absoluteAccuracyIn
- Maximum absolute error.functionValueAccuracyIn
- Maximum function value error.public int getMaxEvaluations()
getMaxEvaluations
in interface BaseUnivariateSolver<F extends UnivariateFunction>
public int getEvaluations()
optimize
method. It is 0 if the method has
not been
called yet.getEvaluations
in interface BaseUnivariateSolver<F extends UnivariateFunction>
public double getMin()
public double getMax()
public double getStartValue()
public double getAbsoluteAccuracy()
v
is a value returned by
one of the solve
methods, then a root of the function should
exist somewhere in the interval (v
- ε, v
+ ε).getAbsoluteAccuracy
in interface BaseUnivariateSolver<F extends UnivariateFunction>
public double getRelativeAccuracy()
BaseUnivariateSolver.getAbsoluteAccuracy()
, but using
relative, rather than absolute error. If ρ is the relative accuracy
configured for a solver and v
is a value returned, then a root
of the function should exist somewhere in the interval
(v
- ρ v
, v
+ ρ v
).getRelativeAccuracy
in interface BaseUnivariateSolver<F extends UnivariateFunction>
public double getFunctionValueAccuracy()
v
is
a value returned by the solver for a function f
,
then by contract, |f(v)|
should be less than or equal to
the function value accuracy configured for the solver.getFunctionValueAccuracy
in interface BaseUnivariateSolver<F extends UnivariateFunction>
protected double computeObjectiveValue(double point)
point
- Point at which the objective function must be evaluated.TooManyEvaluationsException
- if the maximal number of evaluations
is exceeded.protected void setup(int maxEval, F f, double min, double max, double startValue)
solve
methods.f
- Function to solve.min
- Lower bound for the interval.max
- Upper bound for the interval.startValue
- Start value to use.maxEval
- Maximum number of evaluations.public double solve(int maxEval, F f, double min, double max, double startValue)
startValue
.
A solver may require that the interval brackets a single zero root.
Solvers that do require bracketing should be able to handle the case
where one of the endpoints is itself a root.solve
in interface BaseUnivariateSolver<F extends UnivariateFunction>
maxEval
- Maximum number of evaluations.f
- Function to solve.min
- Lower bound for the interval.max
- Upper bound for the interval.startValue
- Start value to use.public double solve(int maxEval, F f, double min, double max)
solve
in interface BaseUnivariateSolver<F extends UnivariateFunction>
maxEval
- Maximum number of evaluations.f
- Function to solve.min
- Lower bound for the interval.max
- Upper bound for the interval.public double solve(int maxEval, F f, double startValue)
startValue
.solve
in interface BaseUnivariateSolver<F extends UnivariateFunction>
maxEval
- Maximum number of evaluations.f
- Function to solve.startValue
- Start value to use.protected abstract double doSolve()
TooManyEvaluationsException
- if the maximal number of evaluations
is exceeded.NoBracketingException
- if the initial search interval does not bracket
a root and the solver requires it.protected boolean isBracketing(double lower, double upper)
lower
- Lower endpoint.upper
- Upper endpoint.true
if the function values have opposite signs at the
given points.protected boolean isSequence(double start, double mid, double end)
start
- First number.mid
- Second number.end
- Third number.true
if the arguments form an increasing sequence.protected void verifyInterval(double lower, double upper)
lower
- Lower endpoint.upper
- Upper endpoint.NumberIsTooLargeException
- if lower >= upper
.protected void verifySequence(double lower, double initial, double upper)
lower < initial < upper
.lower
- Lower endpoint.initial
- Initial value.upper
- Upper endpoint.NumberIsTooLargeException
- if lower >= initial
or initial >= upper
.protected void verifySequenceStrict(double lower, double initial, double upper)
lower <= initial <= upper & lower < upper
.lower
- Lower endpoint.initial
- Initial value.upper
- Upper endpoint.NumberIsTooLargeException
- if lower > initial
or initial > upper
or lower >= upper
.protected void verifyBracketing(double lower, double upper)
lower
- Lower endpoint.upper
- Upper endpoint.NullArgumentException
- if the function has not been set.NoBracketingException
- if the function has the same sign at
the endpoints.protected void incrementEvaluationCount()
computeObjectiveValue(double)
calls this method internally.
It is provided for subclasses that do not exclusively use computeObjectiveValue
to solve the function.
See e.g. AbstractUnivariateDifferentiableSolver
.TooManyEvaluationsException
- when the allowed number of function
evaluations has been exhausted.Copyright © 2023 CNES. All rights reserved.