Class BracketFinder
optimize.py
v0.5).
This class has been extracted from o.a.c.math4.optim.univariate
and modified to: remove support for bracketing a maximum; support bounds
on the bracket; correct the sign of the denominator when the magnitude is small;
and return true/false if there is a minimum strictly inside the bounds.
- Since:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
Tolerance to avoid division by zero.private int
Number of function evaluations performed in the last search.private double
Function value athi
.private double
Function value atlo
.private double
Function value atmid
.private static final double
Golden section.private final double
Factor for expanding the interval.private double
Higher bound of the bracket.private double
Lower bound of the bracket.private final int
Number of allowed function evaluations.private double
Point inside the bracket. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with default values100, 100000
(see theother constructor
).BracketFinder
(double growLimit, int maxEvaluations) Create a bracketing interval finder. -
Method Summary
Modifier and TypeMethodDescription(package private) int
(package private) double
getFHi()
Get function value atgetHi()
.(package private) double
getFLo()
Get function value atgetLo()
.(package private) double
getFMid()
Get function value atgetMid()
.(package private) double
getHi()
(package private) double
getLo()
(package private) double
getMid()
(package private) boolean
search
(DoubleUnaryOperator func, double a, double b, double min, double max) Search downhill from the initial points to obtain new points that bracket a local minimum of the function.private double
value
(DoubleUnaryOperator func, double x) Get the value of the function.
-
Field Details
-
EPS_MIN
private static final double EPS_MINTolerance to avoid division by zero.- See Also:
-
GOLD
private static final double GOLDGolden section.- See Also:
-
growLimit
private final double growLimitFactor for expanding the interval. -
maxEvaluations
private final int maxEvaluationsNumber of allowed function evaluations. -
evaluations
private int evaluationsNumber of function evaluations performed in the last search. -
lo
private double loLower bound of the bracket. -
hi
private double hiHigher bound of the bracket. -
mid
private double midPoint inside the bracket. -
fLo
private double fLoFunction value atlo
. -
fHi
private double fHiFunction value athi
. -
fMid
private double fMidFunction value atmid
.
-
-
Constructor Details
-
BracketFinder
BracketFinder()Constructor with default values100, 100000
(see theother constructor
). -
BracketFinder
BracketFinder(double growLimit, int maxEvaluations) Create a bracketing interval finder.- Parameters:
growLimit
- Expanding factor.maxEvaluations
- Maximum number of evaluations allowed for finding a bracketing interval.- Throws:
IllegalArgumentException
- if thegrowLimit
ormaxEvalutations
are not strictly positive.
-
-
Method Details
-
search
Search downhill from the initial points to obtain new points that bracket a local minimum of the function. Note that the initial points do not have to bracket a minimum. An exception is raised if a minimum cannot be found within the configured number of function evaluations.The bracket is limited to the provided bounds if they create a positive interval
min < max
. It is possible that the middle of the bracket is at the bounds as the final bracket isf(mid) <= min(f(lo), f(hi))
andlo <= mid <= hi
.No exception is raised if the initial points are not within the bounds; the points are updated to be within the bounds.
No exception is raised if the initial points are equal; the bracket will be returned as a single point
lo == mid == hi
.- Parameters:
func
- Function whose optimum should be bracketed.a
- Initial point.b
- Initial point.min
- Minimum bound of the bracket (inclusive).max
- Maximum bound of the bracket (inclusive).- Returns:
- true if the mid-point is strictly within the final bracket
[lo, hi]
; false if there is no local minima. - Throws:
IllegalStateException
- if the maximum number of evaluations is exceeded.
-
getEvaluations
int getEvaluations()- Returns:
- the number of evaluations.
-
getLo
double getLo()- Returns:
- the lower bound of the bracket.
- See Also:
-
getFLo
double getFLo()Get function value atgetLo()
.- Returns:
- function value at
getLo()
-
getHi
double getHi()- Returns:
- the higher bound of the bracket.
- See Also:
-
getFHi
double getFHi()Get function value atgetHi()
.- Returns:
- function value at
getHi()
-
getMid
double getMid()- Returns:
- a point in the middle of the bracket.
- See Also:
-
getFMid
double getFMid()Get function value atgetMid()
.- Returns:
- function value at
getMid()
-
value
Get the value of the function.- Parameters:
func
- Function.x
- Point.- Returns:
- the value
- Throws:
IllegalStateException
- if the maximal number of evaluations is exceeded.
-