bisection_method#
- sionna.phy.utils.bisection_method(f: Callable, left: torch.Tensor, right: torch.Tensor, regula_falsi: bool = False, expand_to_left: bool = True, expand_to_right: bool = True, step_expand: float = 2.0, eps_x: float = 1e-05, eps_y: float = 0.0001, max_n_iter: int = 100, return_brackets: bool = False, precision: str | None = None, **kwargs) torch.Tensor | Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor][source]#
Implements the classic bisection method for estimating the root of batches of decreasing univariate functions
- Parameters:
f (Callable) – Generic function handle that takes batched inputs and returns batched outputs. Applies a different decreasing univariate function to each of its inputs. Must accept input batches of the same shape as
leftandright.left (torch.Tensor) – […], torch.float. Left end point of the initial search interval, for each batch. The root is guessed to be contained within [
left,right].right (torch.Tensor) – […], torch.float. Right end point of the initial search interval, for each batch.
regula_falsi (bool) – If True, then the regula falsi method is employed to determine the next root guess. This guess is computed as the x-intercept of the line passing through the two points formed by the function evaluated at the current search interval endpoints. Else, the next root guess is computed as the middle point of the current search interval. Defaults to False.
expand_to_left (bool) – If True and
f(left)is negative, thenleftis decreased by a geometric progression ofstep_expanduntilfbecomes positive, for each batch. If False, thenleftis not decreased. Defaults to True.expand_to_right (bool) – If True and
f(left)is positive, thenrightis increased by a geometric progression ofstep_expanduntilfbecomes negative, for each batch. If False, thenrightis not increased. Defaults to True.step_expand (float) – See
expand_to_leftandexpand_to_right. Defaults to 2.0.eps_x (float) – Convergence criterion. Search terminates after
max_n_iteriterations or if, for each batch, either the search interval length is smaller thaneps_xor the function absolute value is smaller thaneps_y. Defaults to 1e-5.eps_y (float) – Convergence criterion. See
eps_x. Defaults to 1e-4.max_n_iter (int) – Maximum number of iterations. Defaults to 100.
return_brackets (bool) – If True, the final values of search interval
leftandrightend point are returned. Defaults to False.precision (str | None) – Precision used for internal calculations and outputs. If set to None,
precisionis used.kwargs – Additional arguments for function
f.
- Outputs:
x_opt – […], torch.float. Estimated roots of the input batch of functions
f.f_opt – […], torch.float. Value of function
fevaluated atx_opt.left – […], torch.float. Final value of left end points of the search intervals. Only returned if
return_bracketsis True.right – […], torch.float. Final value of right end points of the search intervals. Only returned if
return_bracketsis True.
Examples
import torch from sionna.phy.utils import bisection_method # Define a decreasing univariate function of x def f(x, a): return - torch.pow(x - a, 3) # Initial search interval left, right = 0., 2. # Input parameter for function a a = 3 # Perform bisection method x_opt, _ = bisection_method(f, left, right, eps_x=1e-4, eps_y=0, a=a) print(x_opt.numpy()) # 2.9999084