Class Searches
java.lang.Object
org.apache.commons.statistics.inference.Searches
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intRange threshold to use a binary search. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static intsearchAscending(int a, int b, double x, IntToDoubleFunction value) Conduct a search betweenainclusive andbinclusive to find the highest index wherevalue <= x.(package private) static intsearchDescending(int a, int b, double x, IntToDoubleFunction value) Conduct a search betweenainclusive andbinclusive to find the lowest index wherevalue <= x.
-
Field Details
-
BINARY_SEARCH
private static final int BINARY_SEARCHRange threshold to use a binary search. The binary search takes O(log(n)) so is used when n is large and a sequential search is slower.- See Also:
-
-
Constructor Details
-
Searches
private Searches()No instances.
-
-
Method Details
-
searchDescending
Conduct a search betweenainclusive andbinclusive to find the lowest index wherevalue <= x. The values must be in descending order. The method is functionally equivalent to:i = b + 1 while (i > a AND value(i - 1) <= x) i = i - 1 return iThe function is only evaluated between the closed interval
[a, b]. Special cases:- If
value(a) <= xthe returned index isa. - If
value(b) > xthe returned index isb + 1.
- Parameters:
a- Lower limit (inclusive).b- Upper limit (inclusive).x- Target value.value- Function to evaluate the value at an index.- Returns:
- the minimum index where
value(i) <= x.
- If
-
searchAscending
Conduct a search betweenainclusive andbinclusive to find the highest index wherevalue <= x. The values must be in ascending order. The method is functionally equivalent to:i = a - 1 while (i < b AND value(i + 1) <= x) i = i + 1 return iThe function is only evaluated between the closed interval
[a, b]. Special cases:- If
value(a) > xthe returned index isa - 1. - If
value(b) <= xthe returned index isb.
- Parameters:
a- Lower limit (inclusive).b- Upper limit (inclusive).x- Target value.value- Function to evaluate the value at an index.- Returns:
- the maximum index where
value(i) <= x.
- If
-