Return x such that f(x) ≈ y within the specified tolerance.
(y)
| 874 | |
| 875 | def _newton_raphson(f_inv_estimate, f, f_prime, tolerance=1e-12): |
| 876 | def f_inv(y): |
| 877 | "Return x such that f(x) ≈ y within the specified tolerance." |
| 878 | x = f_inv_estimate(y) |
| 879 | while abs(diff := f(x) - y) > tolerance: |
| 880 | x -= diff / f_prime(x) |
| 881 | return x |
| 882 | return f_inv |
| 883 | |
| 884 | def _quartic_invcdf_estimate(p): |