Merge branch 'master' of github.com:SheffieldML/GPy

This commit is contained in:
Ricardo Andrade 2013-03-11 14:54:41 +00:00
commit 4b9064bb0e
9 changed files with 51 additions and 32 deletions

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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()

View file

@ -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)

View file

@ -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:

View file

@ -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

View file

@ -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 <tuto_GP_regression.html>`_
* `Interacting with models <tuto_interacting_with_models.html>`_
* `A kernel overview <tuto_kernel_overview.html>`_
* Advanced GP regression (Forthcoming)
* Writting kernels (Forthcoming)
* Writing kernels (Forthcoming)
You may also be interested by some examples in the GPy/examples folder.

View file

@ -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'],
},