diff --git a/GPy/core/parameterization/__init__.py b/GPy/core/parameterization/__init__.py index ec9944e8..ff62a493 100644 --- a/GPy/core/parameterization/__init__.py +++ b/GPy/core/parameterization/__init__.py @@ -3,7 +3,7 @@ from .param import Param from .parameterized import Parameterized -from paramz import transformations +from . import transformations from paramz.core import lists_and_dicts, index_operations, observable_array, observable from paramz import ties_and_remappings, ObsAr diff --git a/GPy/testing/util_tests.py b/GPy/testing/util_tests.py new file mode 100644 index 00000000..6fcf838e --- /dev/null +++ b/GPy/testing/util_tests.py @@ -0,0 +1,49 @@ +#=============================================================================== +# Copyright (c) 2016, Max Zwiessele +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of GPy.testing.util_tests nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#=============================================================================== + +import unittest, numpy as np + +class TestDebug(unittest.TestCase): + def test_checkFinite(self): + from GPy.util.debug import checkFinite + array = np.random.normal(0, 1, 100).reshape(25,4) + self.assertTrue(checkFinite(array, name='test')) + + array[np.random.binomial(1, .3, array.shape).astype(bool)] = np.nan + self.assertFalse(checkFinite(array)) + + def test_checkFullRank(self): + from GPy.util.debug import checkFullRank + from GPy.util.linalg import tdot + array = np.random.normal(0, 1, 100).reshape(25,4) + self.assertFalse(checkFullRank(tdot(array), name='test')) + + array = np.random.normal(0, 1, (25,25)) + self.assertTrue(checkFullRank(tdot(array))) \ No newline at end of file diff --git a/GPy/util/debug.py b/GPy/util/debug.py index d691ad82..e09f162c 100644 --- a/GPy/util/debug.py +++ b/GPy/util/debug.py @@ -22,7 +22,7 @@ def checkFullRank(m, tol=1e-10, name=None, force_check=False): name = 'Matrix with ID['+str(id(m))+']' assert len(m.shape)==2 and m.shape[0]==m.shape[1], 'The input of checkFullRank has to be a square matrix!' - if not force_check and m.shape[0]>=10000: + if not force_check and m.shape[0]>=10000: # pragma: no cover print('The size of '+name+'is too big to check (>=10000)!') return True diff --git a/GPy/util/functions.py b/GPy/util/functions.py index be024aeb..a7e8584c 100644 --- a/GPy/util/functions.py +++ b/GPy/util/functions.py @@ -1,27 +1,31 @@ # Copyright (c) 2012, GPy authors (see AUTHORS.txt). # Licensed under the BSD 3-clause license (see LICENSE.txt) import numpy as np -from scipy.special import erf, erfc, erfcx +from scipy import special +from scipy.special import erfcx import sys epsilon = sys.float_info.epsilon lim_val = -np.log(epsilon) -def logisticln(x): +def logisticln(x): # pragma: no cover return np.where(x-lim_val, -np.log(1+np.exp(-x)), -x), -np.log(1+epsilon)) -def logistic(x): - return np.where(x-lim_val, 1/(1+np.exp(-x)), epsilon/(epsilon+1)), 1/(1+epsilon)) +def logistic(x): # pragma: no cover + return special.expit(x) + #return np.where(x-lim_val, 1/(1+np.exp(-x)), epsilon/(epsilon+1)), 1/(1+epsilon)) -def normcdf(x): - g=0.5*erfc(-x/np.sqrt(2)) - return np.where(g==0, epsilon, np.where(g==1, 1-epsilon, g)) +def normcdf(x): # pragma: no cover + return special.ndtr(x) + #g=0.5*erfc(-x/np.sqrt(2)) + #return np.where(g==0, epsilon, np.where(g==1, 1-epsilon, g)) -def normcdfln(x): - return np.where(x < 0, -.5*x*x + np.log(.5) + np.log(erfcx(-x/np.sqrt(2))), np.log(normcdf(x))) +def normcdfln(x): # pragma: no cover + return special.log_ndtr(x) + #return np.where(x < 0, -.5*x*x + np.log(.5) + np.log(erfcx(-x/np.sqrt(2))), np.log(normcdf(x))) -def clip_exp(x): +def clip_exp(x): # pragma: no cover return np.where(x-lim_val, np.exp(x), epsilon), 1/epsilon) -def differfln(x0, x1): +def differfln(x0, x1): # pragma: no cover # this is a, hopefully!, a numerically more stable variant of log(erf(x0)-erf(x1)) = log(erfc(x1)-erfc(x0)). return np.where(x0>x1, -x1*x1 + np.log(erfcx(x1)-np.exp(-x0**2+x1**2)*erfcx(x0)), -x0*x0 + np.log(np.exp(-x1**2+x0**2)*erfcx(x1) - erfcx(x0)))