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

public Class BracketingNthOrderBrentSolver

extends AbstractUnivariateSolver
implements BracketedUnivariateSolver<UnivariateFunction>
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.analysis.solvers.BracketedUnivariateSolver, org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver
Imports
org.apache.commons.math3.analysis.UnivariateFunction, org.apache.commons.math3.exception.MathInternalError, .NoBracketingException, .NumberIsTooLargeException, .NumberIsTooSmallException, .TooManyEvaluationsException, org.apache.commons.math3.util.FastMath, .Precision

This class implements a modification of the Brent algorithm.

The changes with respect to the original Brent algorithm are:

The given interval must bracket the root.

Field Summary

Modifier and TypeField and Description
private AllowedSolution
allowed

The kinds of solutions that the algorithm may accept.

private static final double
DEFAULT_ABSOLUTE_ACCURACY

Default absolute accuracy.

private static final int
DEFAULT_MAXIMAL_ORDER

Default maximal order.

private static final int
MAXIMAL_AGING

Maximal aging triggering an attempt to balance the bracketing interval.

private final int
maximalOrder

Maximal order.

private static final double
REDUCTION_FACTOR

Reduction factor for attempts to balance the bracketing interval.

Constructor Summary

AccessConstructor and Description
public
BracketingNthOrderBrentSolver()

Construct a solver with default accuracy and maximal order (1e-6 and 5 respectively)

public
BracketingNthOrderBrentSolver(final double
Absolute accuracy.
absoluteAccuracy
,
final int
maximal order.
maximalOrder
)

Construct a solver.

public
BracketingNthOrderBrentSolver(final double
Relative accuracy.
relativeAccuracy
,
final double
Absolute accuracy.
absoluteAccuracy
,
final int
maximal order.
maximalOrder
)

Construct a solver.

public
BracketingNthOrderBrentSolver(final double
Relative accuracy.
relativeAccuracy
,
final double
Absolute accuracy.
absoluteAccuracy
,
final double
Function value accuracy.
functionValueAccuracy
,
final int
maximal order.
maximalOrder
)

Construct a solver.

Method Summary

Modifier and TypeMethod and Description
protected double
doSolve()

Implements abstract org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver.doSolve.

Method for implementing actual optimization algorithms in derived classes.

public int

Returns:

maximal order
getMaximalOrder
()

Get the maximal order.

private double

Returns:

guessed root (will be a NaN if two points share the same y)
guessX
(final double
target value for y
targetY
,
final double[]
reference points abscissas for interpolation, note that this array is modified during computation
x
,
final double[]
reference points ordinates for interpolation
y
,
final int
start index of the points to consider (inclusive)
start
,
final int
end index of the points to consider (exclusive)
end
)

Guess an x value by nth order inverse polynomial interpolation.

public double
solve(int
Maximum number of evaluations.
maxEval
,
UnivariateFunction
Function to solve.
f
,
double
Lower bound for the interval.
min
,
double
Upper bound for the interval.
max
,
AllowedSolution
The kind of solutions that the root-finding algorithm may accept as solutions.
allowedSolution
)

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

Solve for a zero in the given interval.

public double
solve(int
Maximum number of evaluations.
maxEval
,
UnivariateFunction
Function to solve.
f
,
double
Lower bound for the interval.
min
,
double
Upper bound for the interval.
max
,
double
Start value to use.
startValue
,
AllowedSolution
The kind of solutions that the root-finding algorithm may accept as solutions.
allowedSolution
)

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

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

Field Detail

allowedback to summary
private AllowedSolution allowed

The kinds of solutions that the algorithm may accept.

DEFAULT_ABSOLUTE_ACCURACYback to summary
private static final double DEFAULT_ABSOLUTE_ACCURACY

Default absolute accuracy.

DEFAULT_MAXIMAL_ORDERback to summary
private static final int DEFAULT_MAXIMAL_ORDER

Default maximal order.

MAXIMAL_AGINGback to summary
private static final int MAXIMAL_AGING

Maximal aging triggering an attempt to balance the bracketing interval.

maximalOrderback to summary
private final int maximalOrder

Maximal order.

REDUCTION_FACTORback to summary
private static final double REDUCTION_FACTOR

Reduction factor for attempts to balance the bracketing interval.

Constructor Detail

BracketingNthOrderBrentSolverback to summary
public BracketingNthOrderBrentSolver()

Construct a solver with default accuracy and maximal order (1e-6 and 5 respectively)

BracketingNthOrderBrentSolverback to summary
public BracketingNthOrderBrentSolver(final double absoluteAccuracy, final int maximalOrder) throws NumberIsTooSmallException

Construct a solver.

Parameters
absoluteAccuracy:double

Absolute accuracy.

maximalOrder:int

maximal order.

Exceptions
NumberIsTooSmallException:
if maximal order is lower than 2
BracketingNthOrderBrentSolverback to summary
public BracketingNthOrderBrentSolver(final double relativeAccuracy, final double absoluteAccuracy, final int maximalOrder) throws NumberIsTooSmallException

Construct a solver.

Parameters
relativeAccuracy:double

Relative accuracy.

absoluteAccuracy:double

Absolute accuracy.

maximalOrder:int

maximal order.

Exceptions
NumberIsTooSmallException:
if maximal order is lower than 2
BracketingNthOrderBrentSolverback to summary
public BracketingNthOrderBrentSolver(final double relativeAccuracy, final double absoluteAccuracy, final double functionValueAccuracy, final int maximalOrder) throws NumberIsTooSmallException

Construct a solver.

Parameters
relativeAccuracy:double

Relative accuracy.

absoluteAccuracy:double

Absolute accuracy.

functionValueAccuracy:double

Function value accuracy.

maximalOrder:int

maximal order.

Exceptions
NumberIsTooSmallException:
if maximal order is lower than 2

Method Detail

doSolveback to summary
protected double doSolve() throws TooManyEvaluationsException, NumberIsTooLargeException, NoBracketingException

Implements abstract org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver.doSolve.

Doc from org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver.doSolve.

Method for implementing actual optimization algorithms in derived classes.

Returns:double

the root.

Annotations
@Override
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.
getMaximalOrderback to summary
public int getMaximalOrder()

Get the maximal order.

Returns:int

maximal order

guessXback to summary
private double guessX(final double targetY, final double[] x, final double[] y, final int start, final int end)

Guess an x value by nth order inverse polynomial interpolation.

The x value is guessed by evaluating polynomial Q(y) at y = targetY, where Q is built such that for all considered points (xi, yi), Q(yi) = xi.

Parameters
targetY:double

target value for y

x:double[]

reference points abscissas for interpolation, note that this array is modified during computation

y:double[]

reference points ordinates for interpolation

start:int

start index of the points to consider (inclusive)

end:int

end index of the points to consider (exclusive)

Returns:double

guessed root (will be a NaN if two points share the same y)

solveback to summary
public double solve(int maxEval, UnivariateFunction f, double min, double max, AllowedSolution allowedSolution) throws TooManyEvaluationsException, NumberIsTooLargeException, NoBracketingException

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

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

Solve for a zero 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:UnivariateFunction

Function to solve.

min:double

Lower bound for the interval.

max:double

Upper bound for the interval.

allowedSolution:AllowedSolution

The kind of solutions that the root-finding algorithm may accept as solutions.

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, UnivariateFunction f, double min, double max, double startValue, AllowedSolution allowedSolution) throws TooManyEvaluationsException, NumberIsTooLargeException, NoBracketingException

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

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

Function to solve.

min:double

Lower bound for the interval.

max:double

Upper bound for the interval.

startValue:double

Start value to use.

allowedSolution:AllowedSolution

The kind of solutions that the root-finding algorithm may accept as solutions.

Returns:double

A value where the function is zero.

Exceptions
TooManyEvaluationsException:
if the allowed number of evaluations is exceeded.