Bisect#

Perform bisection on a function whose range is not known.

pfl.internal.bisect.bisect_range(function, start, end, num_steps)#

Use bisection to find where the output of a function crosses 0, and return a lower bound and a higher bound.

Parameters:
  • function (Callable[[float], float]) – The function for which the root is to be found.

  • start (float) – A point on one side of the root.

  • end (float) – A point on the other side of the root.

  • num_steps (int) – The number of bisection steps to take before returning.

Return type:

Tuple[float, float]

Returns:

A tuple of the final lower and upper bounds.

pfl.internal.bisect.bisect_automatic_range(function, start, initial_distance, num_steps=50)#

Use bisection to find where the output of a function crosses 0. But first, increase the step size to find the search area.

Parameters:
  • function (Callable[[float], float]) – The function for which the root is to be found.

  • start (float) – A point on one side of the root.

  • initial_distance (float) – A distance from start which is an initial guess of where the sign of the function might be different. If the sign is not different between start and start+initial_distance, then increase the distance exponentially until the signs are different.

  • num_steps (int) – The number of bisection steps to take before returning.

Return type:

Tuple[float, float]

Returns:

A tuple of the final lower and upper bounds.