diff --git a/GPy/examples/tutorials.py b/GPy/examples/tutorials.py index be550e01..9d892b8e 100644 --- a/GPy/examples/tutorials.py +++ b/GPy/examples/tutorials.py @@ -90,7 +90,7 @@ def tuto_kernel_overview(): # Sum of kernels k_add = k1.add(k2) - k_addorth = k1.add_orthogonal(k2) + k_addorth = k1.add_orthogonal(k2) pb.figure(figsize=(8,8)) pb.subplot(2,2,1) @@ -199,3 +199,10 @@ def tuto_kernel_overview(): WN[100] = 1. pb.subplot(3,4,i+1) pb.plot(X,WN,'b') + +def model_interaction(): + X = np.random.randn(20,1) + Y = np.sin(X) + np.random.randn(*X.shape)*0.01 + 5. + k = GPy.kern.rbf(1) + GPy.kern.bias(1) + return GPy.models.GP_regression(X,Y,kernel=k) + diff --git a/GPy/kern/kern.py b/GPy/kern/kern.py index 8cadf662..b2970674 100644 --- a/GPy/kern/kern.py +++ b/GPy/kern/kern.py @@ -389,6 +389,11 @@ class kern(parameterised): target += p1.variance*(p2._psi1[:,:,None]+p2._psi1[:,None,:]) elif p2.name=='bias' and p1.name=='rbf': target += p2.variance*(p1._psi1[:,:,None]+p1._psi1[:,None,:]) + #linear X bias + elif p1.name=='bias' and p2.name=='linear': + raise NotImplementedError + elif p2.name=='bias' and p1.name=='linear': + raise NotImplementedError #rbf X linear elif p1.name=='linear' and p2.name=='rbf': raise NotImplementedError #TODO @@ -396,7 +401,6 @@ class kern(parameterised): raise NotImplementedError #TODO else: raise NotImplementedError, "psi2 cannot be computed for this kernel" - return target def dpsi2_dtheta(self,dL_dpsi2,Z,mu,S,slices1=None,slices2=None): @@ -417,11 +421,11 @@ class kern(parameterised): pass #rbf X bias elif p1.name=='bias' and p2.name=='rbf': - p2.dpsi1_dtheta(dL_dpsi2.sum(1)*p1.variance,Z,mu,S,target[ps2]) - p1.dpsi1_dtheta(dL_dpsi2.sum(1)*p2._psi1,Z,mu,S,target[ps1]) + p2.dpsi1_dtheta(dL_dpsi2.sum(1)*p1.variance*2.,Z,mu,S,target[ps2]) + p1.dpsi1_dtheta(dL_dpsi2.sum(1)*p2._psi1*2.,Z,mu,S,target[ps1]) elif p2.name=='bias' and p1.name=='rbf': - p1.dpsi1_dtheta(dL_dpsi2.sum(1)*p2.variance,Z,mu,S,target[ps1]) - p2.dpsi1_dtheta(dL_dpsi2.sum(1)*p1._psi1,Z,mu,S,target[ps2]) + p1.dpsi1_dtheta(dL_dpsi2.sum(1)*p2.variance*2.,Z,mu,S,target[ps1]) + p2.dpsi1_dtheta(dL_dpsi2.sum(1)*p1._psi1*2.,Z,mu,S,target[ps2]) #rbf X linear elif p1.name=='linear' and p2.name=='rbf': raise NotImplementedError #TODO @@ -444,9 +448,9 @@ class kern(parameterised): pass #rbf X bias elif p1.name=='bias' and p2.name=='rbf': - p2.dpsi1_dX(dL_dpsi2.sum(1)*p1.variance,Z,mu,S,target) + p2.dpsi1_dX(dL_dpsi2.sum(1).T*p1.variance,Z,mu,S,target) elif p2.name=='bias' and p1.name=='rbf': - p1.dpsi1_dZ(dL_dpsi2.sum(2)*p2.variance,Z,mu,S,target) + p1.dpsi1_dZ(dL_dpsi2.sum(1).T*p2.variance,Z,mu,S,target) #rbf X linear elif p1.name=='linear' and p2.name=='rbf': raise NotImplementedError #TODO @@ -471,9 +475,9 @@ class kern(parameterised): pass #rbf X bias elif p1.name=='bias' and p2.name=='rbf': - p2.dpsi1_dmuS(partial.sum(1)*p1.variance,Z,mu,S,target_mu,target_S) + p2.dpsi1_dmuS(dL_dpsi2.sum(1).T*p1.variance*2.,Z,mu,S,target_mu,target_S) elif p2.name=='bias' and p1.name=='rbf': - p1.dpsi1_dmuS(partial.sum(2)*p2.variance,Z,mu,S,target_mu,target_S) + p1.dpsi1_dmuS(dL_dpsi2.sum(1).T*p2.variance*2.,Z,mu,S,target_mu,target_S) #rbf X linear elif p1.name=='linear' and p2.name=='rbf': raise NotImplementedError #TODO diff --git a/GPy/kern/linear.py b/GPy/kern/linear.py index 7d817f62..ef6b72bb 100644 --- a/GPy/kern/linear.py +++ b/GPy/kern/linear.py @@ -81,6 +81,13 @@ class linear(kernpart): self._K_computations(X, X2) target += np.sum(self._dot_product*dL_dK) + def dKdiag_dtheta(self,dL_dKdiag, X, target): + tmp = dL_dKdiag[:,None]*X**2 + if self.ARD: + target += tmp.sum(0) + else: + target += tmp.sum() + def dK_dX(self,dL_dK,X,X2,target): target += (((X2[:, None, :] * self.variances)) * dL_dK[:,:, None]).sum(0) @@ -92,13 +99,6 @@ class linear(kernpart): self._psi_computations(Z,mu,S) target += np.sum(self.variances*self.mu2_S,1) - def dKdiag_dtheta(self,dL_dKdiag, X, target): - tmp = dL_dKdiag[:,None]*X**2 - if self.ARD: - target += tmp.sum(0) - else: - target += tmp.sum() - def dpsi0_dtheta(self,dL_dpsi0,Z,mu,S,target): self._psi_computations(Z,mu,S) tmp = dL_dpsi0[:, None] * self.mu2_S @@ -134,6 +134,7 @@ class linear(kernpart): self._psi_computations(Z,mu,S) psi2 = self.ZZ*np.square(self.variances)*self.mu2_S[:, None, None, :] target += psi2.sum(-1) + #TODO: this could be faster using np.tensordot def dpsi2_dtheta(self,dL_dpsi2,Z,mu,S,target): self._psi_computations(Z,mu,S) diff --git a/GPy/models/sparse_GP.py b/GPy/models/sparse_GP.py index f1439f76..f70938c9 100644 --- a/GPy/models/sparse_GP.py +++ b/GPy/models/sparse_GP.py @@ -103,8 +103,12 @@ class sparse_GP(GP): self.psi1V = np.dot(self.psi1, self.V) self.psi1VVpsi1 = np.dot(self.psi1V, self.psi1V.T) - self.C = mdot(self.Lmi.T, self.Bi, self.Lmi) - self.E = mdot(self.C, self.psi1VVpsi1/sf2, self.C.T) + tmp = np.dot(self.Lmi.T, self.LBi.T) + self.C = np.dot(tmp,tmp.T) + #self.C = mdot(self.Lmi.T, self.Bi, self.Lmi) + #self.E = mdot(self.C, self.psi1VVpsi1/sf2, self.C.T) + tmp = np.dot(self.C,self.psi1V/sf) + self.E = np.dot(tmp,tmp.T) # Compute dL_dpsi # FIXME: this is untested for the heterscedastic + uncertin inputs case self.dL_dpsi0 = - 0.5 * self.D * (self.likelihood.precision * np.ones([self.N,1])).flatten() diff --git a/GPy/testing/bgplvm_tests.py b/GPy/testing/bgplvm_tests.py index 80e6fecd..dda92b90 100644 --- a/GPy/testing/bgplvm_tests.py +++ b/GPy/testing/bgplvm_tests.py @@ -58,6 +58,7 @@ class BGPLVMTests(unittest.TestCase): m.randomize() self.assertTrue(m.checkgrad()) + @unittest.skip('psi2 cross terms are NotImplemented for this combination') def test_linear_bias_kern(self): N, M, Q, D = 10, 3, 2, 4 X = np.random.rand(N, Q) diff --git a/doc/GPy.examples.rst b/doc/GPy.examples.rst index ec283d21..d369de41 100644 --- a/doc/GPy.examples.rst +++ b/doc/GPy.examples.rst @@ -73,18 +73,10 @@ examples Package :undoc-members: :show-inheritance: -:mod:`tuto_GP_regression` Module --------------------------------- +:mod:`tutorials` Module +----------------------- -.. automodule:: GPy.examples.tuto_GP_regression - :members: - :undoc-members: - :show-inheritance: - -:mod:`tuto_kernel_overview` Module ----------------------------------- - -.. automodule:: GPy.examples.tuto_kernel_overview +.. automodule:: GPy.examples.tutorials :members: :undoc-members: :show-inheritance: diff --git a/doc/GPy.rst b/doc/GPy.rst index 3fd4bcfd..242a22bc 100644 --- a/doc/GPy.rst +++ b/doc/GPy.rst @@ -9,6 +9,14 @@ GPy Package :undoc-members: :show-inheritance: +:mod:`test_coreg` Module +------------------------ + +.. automodule:: GPy.test_coreg + :members: + :undoc-members: + :show-inheritance: + Subpackages ----------- @@ -20,5 +28,6 @@ Subpackages GPy.kern GPy.likelihoods GPy.models + GPy.testing GPy.util diff --git a/doc/index.rst b/doc/index.rst index b62ff6a7..5066278f 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -8,9 +8,10 @@ Welcome to GPy's documentation! For a quick start, you can have a look at one of the tutorials: * `Basic Gaussian process regression `_ +* `Interacting with models `_ * `A kernel overview `_ * Advanced GP regression (Forthcoming) -* Writting kernels (Forthcoming) +* Writing kernels (Forthcoming) You may also be interested by some examples in the GPy/examples folder. diff --git a/setup.py b/setup.py index ca193fbc..b14c907e 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ setup(name = 'GPy', long_description=read('README.md'), #ext_modules = [Extension(name = 'GPy.kern.lfmUpsilonf2py', # sources = ['GPy/kern/src/lfmUpsilonf2py.f90'])], - install_requires=['sympy', 'numpy>=1.6', 'scipy>=0.9','matplotlib>=1.1'], + install_requires=['sympy', 'numpy>=1.6', 'scipy>=0.9','matplotlib>=1.1', 'nose'], extras_require = { 'docs':['Sphinx', 'ipython'], },