From 89ff8afe13ce86a4e4bae194ec73e36638a18800 Mon Sep 17 00:00:00 2001 From: Theo Steininger Date: Mon, 14 Aug 2017 13:58:42 +0200 Subject: [PATCH] Added limitted_exp to basic_arithmetics.py --- nifty/basic_arithmetics.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nifty/basic_arithmetics.py b/nifty/basic_arithmetics.py index 44a53151..f81540cb 100644 --- a/nifty/basic_arithmetics.py +++ b/nifty/basic_arithmetics.py @@ -23,7 +23,7 @@ from nifty.field import Field __all__ = ['cos', 'sin', 'cosh', 'sinh', 'tan', 'tanh', 'arccos', 'arcsin', 'arccosh', 'arcsinh', 'arctan', 'arctanh', 'sqrt', 'exp', 'log', - 'conjugate', 'clipped_exp'] + 'conjugate', 'clipped_exp', 'limitted_exp'] def _math_helper(x, function): @@ -99,6 +99,19 @@ def clipped_exp(x): return _math_helper(x, lambda z: np.exp(np.minimum(200, z))) +def limitted_exp(x): + thr = 200 + expthr = np.exp(thr) + return _math_helper(x, lambda z: _limitted_exp_helper(z, thr, expthr)) + + +def _limitted_exp_helper(x, thr, expthr): + mask = (x > thr) + result = np.exp(x) + result[mask] = ((1-thr) + x[mask])*expthr + return result + + def log(x, base=None): result = _math_helper(x, np.log) if base is not None: -- GitLab