From 654115338ddc4cbf57eb68fb33a13393f704a0cd Mon Sep 17 00:00:00 2001 From: peppelauro Date: Wed, 21 Nov 2018 14:44:12 +0100 Subject: [PATCH 1/3] Added erfcinv Add function erfcinv (Inverse Complementary Error Function) --- pyerf/pyerf.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pyerf/pyerf.py b/pyerf/pyerf.py index 941f788..f54dc81 100644 --- a/pyerf/pyerf.py +++ b/pyerf/pyerf.py @@ -342,6 +342,43 @@ def erfinv(z): # otherwise calculate things. return _ndtri((z + 1) / 2.0) / math.sqrt(2) +def erfcinv(z): + """ + Calculate the inverse complementary error function at point ``z``. + + Parameters + ---------- + z : numeric + + Returns + ------- + float + + References + ---------- + + https://en.wikipedia.org/wiki/Error_function#Inverse_functions + + http://functions.wolfram.com/GammaBetaErf/InverseErfc/ + + Examples + -------- + >>> round(erfcinv(0.1), 12) + 1.163087153677 + >>> round(erfcinv(0.5), 12) + 0.476936276204 + >>> round(erfcinv(0.95), 12) + 0.04434038791 + >>> round(erfc(erfcinv(1.9)), 12) + -1.163087153677 + """ + if abs(z) > 1: + raise ValueError("`z` must be between 0 and 2") + + # Shortcut special cases + if z == 0: + return 0 + + # otherwise calculate things. + return -_ndtri(0.5 * z) / math.sqrt(2) # bring the built-ins into this namespace for conveinence. try: From 3e38ecef3356ed91884103a161952494565b5007 Mon Sep 17 00:00:00 2001 From: peppelauro Date: Wed, 21 Nov 2018 17:18:57 +0100 Subject: [PATCH 2/3] Update pyerf.py --- pyerf/pyerf.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyerf/pyerf.py b/pyerf/pyerf.py index f54dc81..023fe2c 100644 --- a/pyerf/pyerf.py +++ b/pyerf/pyerf.py @@ -370,11 +370,13 @@ def erfcinv(z): >>> round(erfc(erfcinv(1.9)), 12) -1.163087153677 """ - if abs(z) > 1: - raise ValueError("`z` must be between 0 and 2") + if z < 0 or z > 2: + raise ValueError("`z` must be between 0 and 2 inclusive") # Shortcut special cases if z == 0: + return inf + if z == 1: return 0 # otherwise calculate things. From a8cd206786e5a97f4de5058fd6f91c287062fcff Mon Sep 17 00:00:00 2001 From: peppelauro Date: Wed, 21 Nov 2018 17:22:48 +0100 Subject: [PATCH 3/3] Update pyerf.py --- pyerf/pyerf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyerf/pyerf.py b/pyerf/pyerf.py index 023fe2c..7bd6d8b 100644 --- a/pyerf/pyerf.py +++ b/pyerf/pyerf.py @@ -368,7 +368,7 @@ def erfcinv(z): >>> round(erfcinv(0.95), 12) 0.04434038791 >>> round(erfc(erfcinv(1.9)), 12) - -1.163087153677 + 1.9 """ if z < 0 or z > 2: raise ValueError("`z` must be between 0 and 2 inclusive")