Top Description Fields Constructors Methods
org.apache.commons.math3.analysis.solvers

public abstract Class BaseAbstractUnivariateSolver<FUNC extends UnivariateFunction>

extends Object
implements BaseUnivariateSolver<FUNC extends UnivariateFunction>
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver
Known Direct Subclasses
org.apache.commons.math3.analysis.solvers.AbstractDifferentiableUnivariateSolver, org.apache.commons.math3.analysis.solvers.AbstractPolynomialSolver, org.apache.commons.math3.analysis.solvers.AbstractUnivariateDifferentiableSolver, org.apache.commons.math3.analysis.solvers.AbstractUnivariateSolver
Type Parameters
<FUNC>
Type of function to solve.
Imports
org.apache.commons.math3.analysis.UnivariateFunction, org.apache.commons.math3.exception.MaxCountExceededException, .NoBracketingException, .TooManyEvaluationsException, .NumberIsTooLargeException, .NullArgumentException, org.apache.commons.math3.util.IntegerSequence, .MathUtils

Provide a default implementation for several functions useful to generic solvers. The default values for relative and function tolerances are 1e-14 and 1e-15, respectively. It is however highly recommended to not rely on the default, but rather carefully consider values that match user's expectations, as well as the specifics of each implementation.
Since
2.0

Field Summary

Modifier and TypeField and Description
private final double
absoluteAccuracy

Absolute accuracy.

private static final double
DEFAULT_FUNCTION_VALUE_ACCURACY

Default function value accuracy.

private static final double
DEFAULT_RELATIVE_ACCURACY

Default relative accuracy.

private IntegerSequence.Incrementor
evaluations

Evaluations counter.

private FUNC
function

Function to solve.

private final double
functionValueAccuracy

Function value accuracy.

private final double
relativeAccuracy

Relative accuracy.

private double
searchMax

Higher end of search interval.

private double
searchMin

Lower end of search interval.

private double
searchStart

Initial guess.

Constructor Summary

AccessConstructor and Description
protected
BaseAbstractUnivariateSolver(final double
Maximum absolute error.
absoluteAccuracy
)

Construct a solver with given absolute accuracy.

protected
BaseAbstractUnivariateSolver(final double
Maximum relative error.
relativeAccuracy
,
final double
Maximum absolute error.
absoluteAccuracy
)

Construct a solver with given accuracies.

protected
BaseAbstractUnivariateSolver(final double
Maximum relative error.
relativeAccuracy
,
final double
Maximum absolute error.
absoluteAccuracy
,
final double
Maximum function value error.
functionValueAccuracy
)

Construct a solver with given accuracies.

Method Summary

Modifier and TypeMethod and Description
protected double

Returns:

the objective function value at specified point.
computeObjectiveValue
(double
Point at which the objective function must be evaluated.
point
)

Compute the objective function value.

protected abstract double

Returns:

the root.
doSolve
()

Method for implementing actual optimization algorithms in derived classes.

public double
public int
getEvaluations()

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.getEvaluations.

Get the number of evaluations of the objective function.

public double
public double

Returns:

the higher end of the search interval.
getMax
()

public int
public double

Returns:

the lower end of the search interval.
getMin
()

public double
public double

Returns:

the initial guess.
getStartValue
()

protected void
incrementEvaluationCount()

Increment the evaluation count by one.

protected boolean

Returns:

true if the function values have opposite signs at the given points.
isBracketing
(final double
Lower endpoint.
lower
,
final double
Upper endpoint.
upper
)

Check whether the function takes opposite signs at the endpoints.

protected boolean

Returns:

true if the arguments form an increasing sequence.
isSequence
(final double
First number.
start
,
final double
Second number.
mid
,
final double
Third number.
end
)

Check whether the arguments form a (strictly) increasing sequence.

protected void
setup(int
Maximum number of evaluations.
maxEval
,
FUNC
Function to solve.
f
,
double
Lower bound for the interval.
min
,
double
Upper bound for the interval.
max
,
double
Start value to use.
startValue
)

Prepare for computation.

public double
solve(int
Maximum number of evaluations.
maxEval
,
FUNC
Function to solve.
f
,
double
Lower bound for the interval.
min
,
double
Upper bound for the interval.
max
,
double
Start value to use.
startValue
)

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.solve.

Solve for a zero in the given interval, start at startValue.

public double
solve(int
Maximum number of evaluations.
maxEval
,
FUNC
Function to solve.
f
,
double
Lower bound for the interval.
min
,
double
Upper bound for the interval.
max
)

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.solve.

Solve for a zero root in the given interval.

public double
solve(int
Maximum number of evaluations.
maxEval
,
FUNC
Function to solve.
f
,
double
Start value to use.
startValue
)

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.solve.

Solve for a zero in the vicinity of startValue.

protected void
verifyBracketing(final double
Lower endpoint.
lower
,
final double
Upper endpoint.
upper
)

Check that the endpoints specify an interval and the function takes opposite signs at the endpoints.

protected void
verifyInterval(final double
Lower endpoint.
lower
,
final double
Upper endpoint.
upper
)

Check that the endpoints specify an interval.

protected void
verifySequence(final double
Lower endpoint.
lower
,
final double
Initial value.
initial
,
final double
Upper endpoint.
upper
)

Check that lower < initial < upper.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

absoluteAccuracyback to summary
private final double absoluteAccuracy

Absolute accuracy.

DEFAULT_FUNCTION_VALUE_ACCURACYback to summary
private static final double DEFAULT_FUNCTION_VALUE_ACCURACY

Default function value accuracy.

DEFAULT_RELATIVE_ACCURACYback to summary
private static final double DEFAULT_RELATIVE_ACCURACY

Default relative accuracy.

evaluationsback to summary
private IntegerSequence.Incrementor evaluations

Evaluations counter.

functionback to summary
private FUNC function

Function to solve.

functionValueAccuracyback to summary
private final double functionValueAccuracy

Function value accuracy.

relativeAccuracyback to summary
private final double relativeAccuracy

Relative accuracy.

searchMaxback to summary
private double searchMax

Higher end of search interval.

searchMinback to summary
private double searchMin

Lower end of search interval.

searchStartback to summary
private double searchStart

Initial guess.

Constructor Detail

BaseAbstractUnivariateSolverback to summary
protected BaseAbstractUnivariateSolver(final double absoluteAccuracy)

Construct a solver with given absolute accuracy.

Parameters
absoluteAccuracy:double

Maximum absolute error.

BaseAbstractUnivariateSolverback to summary
protected BaseAbstractUnivariateSolver(final double relativeAccuracy, final double absoluteAccuracy)

Construct a solver with given accuracies.

Parameters
relativeAccuracy:double

Maximum relative error.

absoluteAccuracy:double

Maximum absolute error.

BaseAbstractUnivariateSolverback to summary
protected BaseAbstractUnivariateSolver(final double relativeAccuracy, final double absoluteAccuracy, final double functionValueAccuracy)

Construct a solver with given accuracies.

Parameters
relativeAccuracy:double

Maximum relative error.

absoluteAccuracy:double

Maximum absolute error.

functionValueAccuracy:double

Maximum function value error.

Method Detail

computeObjectiveValueback to summary
protected double computeObjectiveValue(double point) throws TooManyEvaluationsException

Compute the objective function value.

Parameters
point:double

Point at which the objective function must be evaluated.

Returns:double

the objective function value at specified point.

Exceptions
TooManyEvaluationsException:
if the maximal number of evaluations is exceeded.
doSolveback to summary
protected abstract double doSolve() throws TooManyEvaluationsException, NoBracketingException

Method for implementing actual optimization algorithms in derived classes.

Returns:double

the root.

Exceptions
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.
getAbsoluteAccuracyback to summary
public double getAbsoluteAccuracy()

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.getAbsoluteAccuracy.

Doc from org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.getAbsoluteAccuracy.

Get the absolute accuracy of the solver. Solutions returned by the solver should be accurate to this tolerance, i.e., if ε is the absolute accuracy of the solver and 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 + ε).

Returns:double

the absolute accuracy.

getEvaluationsback to summary
public int getEvaluations()

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.getEvaluations.

Doc from org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.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.

Returns:int

the number of evaluations of the objective function.

getFunctionValueAccuracyback to summary
public double getFunctionValueAccuracy()

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.getFunctionValueAccuracy.

Doc from org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.getFunctionValueAccuracy.

Get the function value accuracy of the solver. If 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.

Returns:double

the function value accuracy.

getMaxback to summary
public double getMax()
Returns:double

the higher end of the search interval.

getMaxEvaluationsback to summary
public int getMaxEvaluations()

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.getMaxEvaluations.

Doc from org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.getMaxEvaluations.

Get the maximum number of function evaluations.

Returns:int

the maximum number of function evaluations.

getMinback to summary
public double getMin()
Returns:double

the lower end of the search interval.

getRelativeAccuracyback to summary
public double getRelativeAccuracy()

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.getRelativeAccuracy.

Doc from org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.getRelativeAccuracy.

Get the relative accuracy of the solver. The contract for relative accuracy is the same as 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).

Returns:double

the relative accuracy.

getStartValueback to summary
public double getStartValue()
Returns:double

the initial guess.

incrementEvaluationCountback to summary
protected void incrementEvaluationCount() throws TooManyEvaluationsException

Increment the evaluation count by one. Method 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.

Exceptions
TooManyEvaluationsException:
when the allowed number of function evaluations has been exhausted.
isBracketingback to summary
protected boolean isBracketing(final double lower, final double upper)

Check whether the function takes opposite signs at the endpoints.

Parameters
lower:double

Lower endpoint.

upper:double

Upper endpoint.

Returns:boolean

true if the function values have opposite signs at the given points.

isSequenceback to summary
protected boolean isSequence(final double start, final double mid, final double end)

Check whether the arguments form a (strictly) increasing sequence.

Parameters
start:double

First number.

mid:double

Second number.

end:double

Third number.

Returns:boolean

true if the arguments form an increasing sequence.

setupback to summary
protected void setup(int maxEval, FUNC f, double min, double max, double startValue) throws NullArgumentException

Prepare for computation. Subclasses must call this method if they override any of the solve methods.

Parameters
maxEval:int

Maximum number of evaluations.

f:FUNC

Function to solve.

min:double

Lower bound for the interval.

max:double

Upper bound for the interval.

startValue:double

Start value to use.

Exceptions
NullArgumentException:
if f is null
solveback to summary
public double solve(int maxEval, FUNC f, double min, double max, double startValue) throws TooManyEvaluationsException, NoBracketingException

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.solve.

Doc from org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.solve.

Solve for a zero in the given interval, start at 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.

Parameters
maxEval:int

Maximum number of evaluations.

f:FUNC

Function to solve.

min:double

Lower bound for the interval.

max:double

Upper bound for the interval.

startValue:double

Start value to use.

Returns:double

a value where the function is zero.

Exceptions
TooManyEvaluationsException:
if the allowed number of evaluations is exceeded.
solveback to summary
public double solve(int maxEval, FUNC f, double min, double max)

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.solve.

Doc from org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.solve.

Solve for a zero root in the given interval. 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.

Parameters
maxEval:int

Maximum number of evaluations.

f:FUNC

Function to solve.

min:double

Lower bound for the interval.

max:double

Upper bound for the interval.

Returns:double

a value where the function is zero.

solveback to summary
public double solve(int maxEval, FUNC f, double startValue) throws TooManyEvaluationsException, NoBracketingException

Implements org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.solve.

Doc from org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver.solve.

Solve for a zero in the vicinity of startValue.

Parameters
maxEval:int

Maximum number of evaluations.

f:FUNC

Function to solve.

startValue:double

Start value to use.

Returns:double

a value where the function is zero.

Exceptions
TooManyEvaluationsException:
if the allowed number of evaluations is exceeded.
verifyBracketingback to summary
protected void verifyBracketing(final double lower, final double upper) throws NullArgumentException, NoBracketingException

Check that the endpoints specify an interval and the function takes opposite signs at the endpoints.

Parameters
lower:double

Lower endpoint.

upper:double

Upper endpoint.

Exceptions
NullArgumentException:
if the function has not been set.
NoBracketingException:
if the function has the same sign at the endpoints.
verifyIntervalback to summary
protected void verifyInterval(final double lower, final double upper) throws NumberIsTooLargeException

Check that the endpoints specify an interval.

Parameters
lower:double

Lower endpoint.

upper:double

Upper endpoint.

Exceptions
NumberIsTooLargeException:
if lower >= upper.
verifySequenceback to summary
protected void verifySequence(final double lower, final double initial, final double upper) throws NumberIsTooLargeException

Check that lower < initial < upper.

Parameters
lower:double

Lower endpoint.

initial:double

Initial value.

upper:double

Upper endpoint.

Exceptions
NumberIsTooLargeException:
if lower >= initial or initial >= upper.