From 1a253ff82a9b244866a0e20fe06444dda6c0bcd4 Mon Sep 17 00:00:00 2001 From: Alan Saul Date: Fri, 27 Mar 2015 15:14:52 +0000 Subject: [PATCH] Added safe_exp and tests --- GPy/likelihoods/likelihood.py | 2 +- GPy/testing/misc_tests.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 GPy/testing/misc_tests.py diff --git a/GPy/likelihoods/likelihood.py b/GPy/likelihoods/likelihood.py index 022670a5..2e55ddb9 100644 --- a/GPy/likelihoods/likelihood.py +++ b/GPy/likelihoods/likelihood.py @@ -5,7 +5,7 @@ import numpy as np from scipy import stats,special import scipy as sp import link_functions -from ..util.misc import chain_1, chain_2, chain_3, blockify_dhess_dtheta, blockify_third, blockify_hessian +from ..util.misc import chain_1, chain_2, chain_3, blockify_dhess_dtheta, blockify_third, blockify_hessian, safe_exp from scipy.integrate import quad import warnings from ..core.parameterization import Parameterized diff --git a/GPy/testing/misc_tests.py b/GPy/testing/misc_tests.py new file mode 100644 index 00000000..e620fa7e --- /dev/null +++ b/GPy/testing/misc_tests.py @@ -0,0 +1,18 @@ +import numpy as np +import scipy as sp +import GPy + +class MiscTests(np.testing.TestCase): + """ + Testing some utilities of misc + """ + def setUp(self): + self._lim_val = np.finfo(np.float64).max + self._lim_val_exp = np.log(self._lim_val) + + def test_safe_exp_upper(self): + assert np.exp(self._lim_val_exp + 1) == np.inf + assert GPy.util.misc.safe_exp(self._lim_val_exp + 1) < np.inf + + def test_safe_exp_lower(self): + assert GPy.util.misc.safe_exp(1e-10) < np.inf