pulse2percept.utils.optimize¶
Functions
bisect (y_target, func[, args, kwargs, x_lo, …]) |
Binary search (bisection method) to find x value that gives y_target |
-
pulse2percept.utils.optimize.
bisect
(y_target, func, args=None, kwargs=None, x_lo=0, x_hi=1, x_tol=1e-06, y_tol=0.001, max_iter=100)[source]¶ Binary search (bisection method) to find
x
value that givesy_target
For a function
y = func(x, *args, **kwargs)
, returnsx_opt
for whichfunc(x_opt, *args, **kwargs)
is approximately equal toy_target
.New in version 0.7.
Parameters: - y_target (float) – Target y value
- args, kwargs (func,) – The function to call along with its positional and keyword arguments
- x_hi (x_lo,) – Lower and upper bounds on
x
- x_tol (float, optional) – Search will stop if the range of candidate
x
values is smaller thanx_tol
- y_tol (float, optional) – Search will stop if
y
is withiny_tol
ofy_target
- max_iter (int, optional) – Maximum number of iterations to run
Returns: x_opt (float) – The x value such that func(x_opt) $approx$ y_target
Notes
- Assumes
func
is a monotonously increasing function ofx
. - Does not require
x_lo
andx_hi
to have opposite signs as in the conventional bisection method.