ternary_search#
- mlquantify.solvers.ternary_search(left, right, objective, tol=1e-06)[source]#
Find the minimum of a unimodal function via ternary search.
Iteratively narrows the interval
[left, right]by comparing the objective at two interior probe points until the interval width falls belowtol.- Parameters:
- leftfloat
Left bound of the search interval.
- rightfloat
Right bound of the search interval.
- objectivecallable
Scalar function to minimize over
[left, right]. Must be unimodal on the interval.- tolfloat, default=1e-6
Convergence criterion: the search stops when
right - left <= tol.
- Returns:
- minimumfloat
Approximate location of the minimum.
Examples
>>> from mlquantify.solvers._binary import ternary_search >>> minimum = ternary_search(0.0, 1.0, lambda x: (x - 0.3) ** 2) >>> round(minimum, 4) 0.3