Class SearchClosestValueMonoticallyIncreasing
Object
org.anchoranalysis.math.optimization.SearchClosestValueMonoticallyIncreasing
public class SearchClosestValueMonoticallyIncreasing extends Object
Given a monotonically
increasing function of an integer, determine the input value that provides an output value as
close to
target as possible.
The input-values must be integers, and have a minimum bound.
It begins at the minimum-bound, and in a similar manner to exponential search, successively doubles, until a lower and upper bound are found.
It then proceeds with a binary-search-style recursive
evaluation to find the integer value that produces the exact closest value to target.
An upper bound on the input-values may also be optionally imposed via boundUpper.
- Author:
- Owen Feehan
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSearchClosestValueMonoticallyIncreasing.ValueFunctionThe function that calculates the output value for a particular inputint. -
Constructor Summary
Constructors Constructor Description SearchClosestValueMonoticallyIncreasing(double target, SearchClosestValueMonoticallyIncreasing.ValueFunction function)Create without an upper bound.SearchClosestValueMonoticallyIncreasing(double target, SearchClosestValueMonoticallyIncreasing.ValueFunction function, IntPredicate boundUpper) -
Method Summary
Modifier and Type Method Description intfindOptimalInput(int boundLower)Finds the input value that produces a calculated-value that is closest totarget.
-
Constructor Details
-
SearchClosestValueMonoticallyIncreasing
public SearchClosestValueMonoticallyIncreasing(double target, SearchClosestValueMonoticallyIncreasing.ValueFunction function)Create without an upper bound.- Parameters:
target- the target value to try and be closest to when evaluatingfunctionon differing inputs.function- calculates an output value for a particular input integer.
-
SearchClosestValueMonoticallyIncreasing
public SearchClosestValueMonoticallyIncreasing(double target, SearchClosestValueMonoticallyIncreasing.ValueFunction function, IntPredicate boundUpper)
-
-
Method Details
-
findOptimalInput
public int findOptimalInput(int boundLower)Finds the input value that produces a calculated-value that is closest totarget.- Parameters:
boundLower- a lower bound on the input range, inclusive.- Returns:
- the input-value that is optimal to produce the closest value to
targetwhen evaluated usingcalculateValue.
-