diff --git a/GPy/kern/constructors.py b/GPy/kern/constructors.py index 083960b4..4ab06bba 100644 --- a/GPy/kern/constructors.py +++ b/GPy/kern/constructors.py @@ -292,7 +292,6 @@ except ImportError: if sympy_available: from parts.sympykern import spkern from sympy.parsing.sympy_parser import parse_expr - from GPy.util.symbolic import sinc def rbf_sympy(input_dim, ARD=False, variance=1., lengthscale=1.): """ @@ -337,27 +336,6 @@ if sympy_available: f = scale_i*scale_j*sp.exp(-dist/(2*(lengthscale_i**2 + lengthscale_j**2 + shared_lengthscale**2))) return kern(input_dim, [spkern(input_dim, f, output_dim=output_dim, name='eq_sympy')]) - def sinc(input_dim, ARD=False, variance=1., lengthscale=1.): - """ - TODO: Not clear why this isn't working, suggests argument of sinc is not a number. - sinc covariance funciton - """ - X = sp.symbols('x_:' + str(input_dim)) - Z = sp.symbols('z_:' + str(input_dim)) - variance = sp.var('variance',positive=True) - if ARD: - lengthscales = [sp.var('lengthscale_%i' % i, positive=True) for i in range(input_dim)] - dist_string = ' + '.join(['(x_%i-z_%i)**2/lengthscale_%i**2' % (i, i, i) for i in range(input_dim)]) - dist = parse_expr(dist_string) - f = variance*sinc(sp.pi*sp.sqrt(dist)) - else: - lengthscale = sp.var('lengthscale',positive=True) - dist_string = ' + '.join(['(x_%i-z_%i)**2' % (i, i) for i in range(input_dim)]) - dist = parse_expr(dist_string) - f = variance*sinc(sp.pi*sp.sqrt(dist)/lengthscale) - - return kern(input_dim, [spkern(input_dim, f, name='sinc')]) - def sympykern(input_dim, k=None, output_dim=1, name=None, param=None): """ A base kernel object, where all the hard work in done by sympy. diff --git a/GPy/kern/parts/sympykern.py b/GPy/kern/parts/sympykern.py index 7f7fba11..d109fea7 100644 --- a/GPy/kern/parts/sympykern.py +++ b/GPy/kern/parts/sympykern.py @@ -11,6 +11,7 @@ import tempfile import pdb import ast from kernpart import Kernpart +from ...util.config import config class spkern(Kernpart): """ @@ -110,8 +111,9 @@ class spkern(Kernpart): 'headers':['"sympy_helpers.h"'], 'sources':[os.path.join(current_dir,"parts/sympy_helpers.cpp")], 'extra_compile_args':extra_compile_args, - 'extra_link_args':['-lgomp'], + 'extra_link_args':[], 'verbose':True} + if config.getboolean('parallel', 'openmp'): self.weave_kwargs.append('-lgomp') def __add__(self,other): return spkern(self._sp_k+other._sp_k) @@ -343,9 +345,9 @@ class spkern(Kernpart): # Code to use when only X is provided. self._dK_dtheta_code_X = self._dK_dtheta_code.replace('Z[', 'X[') - self._dK_dX_code_X = self._dK_dX_code.replace('Z[', 'X[').replace('+= partial[', '+= 2*partial[') + self._dK_dX_code_X = self._dK_dX_code.replace('Z[', 'X[').replace('+= partial[', '+= 2*partial[') self._dK_dtheta_code_X = self._dK_dtheta_code.replace('Z2(', 'X2(') - self._dK_dX_code_X = self._dK_dX_code.replace('Z2(', 'X2(') + self._dK_dX_code_X = self._dK_dX_code_X.replace('Z2(', 'X2(') #TODO: insert multiple functions here via string manipulation diff --git a/GPy/testing/kernel_tests.py b/GPy/testing/kernel_tests.py index f64dac2b..301fa54f 100644 --- a/GPy/testing/kernel_tests.py +++ b/GPy/testing/kernel_tests.py @@ -34,11 +34,7 @@ class KernelTests(unittest.TestCase): self.assertTrue(GPy.kern.kern_test(kern, verbose=verbose)) def test_eq_sympykernel(self): - kern = GPy.kern.eq_sympy(5, 3, output_ind=4) - self.assertTrue(GPy.kern.kern_test(kern, verbose=verbose)) - - def test_sinckernel(self): - kern = GPy.kern.sinc(5) + kern = GPy.kern.eq_sympy(5, 3) self.assertTrue(GPy.kern.kern_test(kern, verbose=verbose)) def test_rbf_invkernel(self): diff --git a/GPy/util/symbolic.py b/GPy/util/symbolic.py index 395f9e3e..4b660c7f 100644 --- a/GPy/util/symbolic.py +++ b/GPy/util/symbolic.py @@ -237,52 +237,3 @@ class erfcx(Function): def eval(cls, arg): return erfc(arg)*exp(arg*arg) -class sinc_grad(Function): - nargs = 1 - - def fdiff(self, argindex=1): - if argindex==1: - # Strictly speaking this should be computed separately, as it won't work when x=0. See http://calculus.subwiki.org/wiki/Sinc_function - return ((2-x*x)*sin(self.args[0]) - 2*x*cos(x))/(x*x*x) - else: - raise ArgumentIndexError(self, argindex) - - - @classmethod - def eval(cls, x): - if x.is_Number: - if x is S.NaN: - return S.NaN - elif x is S.Zero: - return S.Zero - else: - return (x*cos(x) - sin(x))/(x*x) - -class sinc(Function): - - nargs = 1 - - def fdiff(self, argindex=1): - if argindex==1: - return sinc_grad(self.args[0]) - else: - raise ArgumentIndexError(self, argindex) - - - @classmethod - def eval(cls, arg): - if arg.is_Number: - if arg is S.NaN: - return S.NaN - elif arg is S.Zero: - return S.One - else: - return sin(arg)/arg - - if arg.func is asin: - x = arg.args[0] - return x / arg - - def _eval_is_real(self): - return self.args[0].is_real -