# pulse2percept.utils.optimize¶

bisect

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 gives y_target

For a function y = func(x, *args, **kwargs), returns x_opt for which func(x_opt, *args, **kwargs) is approximately equal to y_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 than x_tol y_tol (float, optional) – Search will stop if y is within y_tol of y_target max_iter (int, optional) – Maximum number of iterations to run x_opt (float) – The x value such that func(x_opt) $approx$ y_target

Notes

• Assumes func is a monotonously increasing function of x.
• Does not require x_lo and x_hi to have opposite signs as in the conventional bisection method.