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 doubleTolerance to avoid division by zero.private intNumber of function evaluations performed in the last search.private doubleFunction value athi.private doubleFunction value atlo.private doubleFunction value atmid.private static final doubleGolden section.private final doubleFactor for expanding the interval.private doubleHigher bound of the bracket.private doubleLower bound of the bracket.private final intNumber of allowed function evaluations.private doublePoint 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) doublegetFHi()Get function value atgetHi().(package private) doublegetFLo()Get function value atgetLo().(package private) doublegetFMid()Get function value atgetMid().(package private) doublegetHi()(package private) doublegetLo()(package private) doublegetMid()(package private) booleansearch(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 doublevalue(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 thegrowLimitormaxEvalutationsare 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
-
getHi
double getHi()- Returns:
- the higher bound of the bracket.
- See Also:
-
getFHi
-
getMid
double getMid()- Returns:
- a point in the middle of the bracket.
- See Also:
-
getFMid
-
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.
-