From e32afa11e5b437ef5db6bfd015f4f87936723bd0 Mon Sep 17 00:00:00 2001 From: Nicolo Fusi Date: Mon, 11 Mar 2013 12:33:03 +0000 Subject: [PATCH 1/7] added GPy.tests(), removed some useless tests --- GPy/__init__.py | 5 +++++ GPy/testing/bgplvm_tests.py | 5 ++++- GPy/testing/kernel_tests.py | 1 - GPy/testing/unit_tests.py | 11 ----------- setup.py | 6 ++---- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/GPy/__init__.py b/GPy/__init__.py index c0772c27..6c43e471 100644 --- a/GPy/__init__.py +++ b/GPy/__init__.py @@ -9,3 +9,8 @@ import util import examples from core import priors import likelihoods +import testing +from numpy.testing import Tester + +def tests(): + Tester(testing).test(verbose=10) diff --git a/GPy/testing/bgplvm_tests.py b/GPy/testing/bgplvm_tests.py index c49bdfda..e3bd2b36 100644 --- a/GPy/testing/bgplvm_tests.py +++ b/GPy/testing/bgplvm_tests.py @@ -12,6 +12,7 @@ class BGPLVMTests(unittest.TestCase): k = GPy.kern.rbf(Q) + GPy.kern.white(Q, 0.00001) K = k.K(X) Y = np.random.multivariate_normal(np.zeros(N),K,D).T + Y -= Y.mean(axis=0) k = GPy.kern.bias(Q) + GPy.kern.white(Q, 0.00001) m = GPy.models.Bayesian_GPLVM(Y, Q, kernel = k, M=M) m.constrain_positive('(rbf|bias|noise|white|S)') @@ -24,6 +25,7 @@ class BGPLVMTests(unittest.TestCase): k = GPy.kern.rbf(Q) + GPy.kern.white(Q, 0.00001) K = k.K(X) Y = np.random.multivariate_normal(np.zeros(N),K,D).T + Y -= Y.mean(axis=0) k = GPy.kern.linear(Q) + GPy.kern.white(Q, 0.00001) m = GPy.models.Bayesian_GPLVM(Y, Q, kernel = k, M=M) m.constrain_positive('(linear|bias|noise|white|S)') @@ -36,13 +38,14 @@ class BGPLVMTests(unittest.TestCase): k = GPy.kern.rbf(Q) + GPy.kern.white(Q, 0.00001) K = k.K(X) Y = np.random.multivariate_normal(np.zeros(N),K,D).T + Y -= Y.mean(axis=0) k = GPy.kern.rbf(Q) + GPy.kern.white(Q, 0.00001) m = GPy.models.Bayesian_GPLVM(Y, Q, kernel = k, M=M) m.constrain_positive('(rbf|bias|noise|white|S)') m.randomize() self.assertTrue(m.checkgrad()) - + if __name__ == "__main__": print "Running unit tests, please be (very) patient..." unittest.main() diff --git a/GPy/testing/kernel_tests.py b/GPy/testing/kernel_tests.py index 3d738106..bb809ea6 100644 --- a/GPy/testing/kernel_tests.py +++ b/GPy/testing/kernel_tests.py @@ -13,7 +13,6 @@ class KernelTests(unittest.TestCase): X = np.random.rand(5,5) Y = np.ones((5,1)) m = GPy.models.GP_regression(X,Y,K) - print m self.assertTrue(m.checkgrad()) def test_coregionalisation(self): diff --git a/GPy/testing/unit_tests.py b/GPy/testing/unit_tests.py index 61fb15bb..55963805 100644 --- a/GPy/testing/unit_tests.py +++ b/GPy/testing/unit_tests.py @@ -177,17 +177,6 @@ class GradientTests(unittest.TestCase): m.approximate_likelihood() self.assertTrue(m.checkgrad()) - def test_warped_GP(self): - xmin, xmax = 1, 2.5*np.pi - b, C, SNR = 1, 0, 0.1 - X = np.linspace(xmin, xmax, 500) - y = b*X + C + 1*np.sin(X) - y += 0.05*np.random.randn(len(X)) - X, y = X[:, None], y[:, None] - m = GPy.models.warpedGP(X, y, warping_terms = 3) - m.constrain_positive('(tanh_a|tanh_b|rbf|white|bias)') - self.assertTrue(m.checkgrad()) - if __name__ == "__main__": print "Running unit tests, please be (very) patient..." diff --git a/setup.py b/setup.py index d24171e2..b701b74d 100644 --- a/setup.py +++ b/setup.py @@ -3,8 +3,6 @@ import os from setuptools import setup -#from numpy.distutils.core import Extension, setup -#from sphinx.setup_command import BuildDoc # Version number version = '0.1.3' @@ -14,12 +12,12 @@ def read(fname): setup(name = 'GPy', version = version, - author = 'James Hensman, Nicolo Fusi, Ricardo Andrade, Nicolas Durrande, Alan Saul, Neil D. Lawrence', + author = read('AUTHORS.txt'), author_email = "james.hensman@gmail.com", description = ("The Gaussian Process Toolbox"), license = "BSD 3-clause", keywords = "machine-learning gaussian-processes kernels", - url = "http://ml.sheffield.ac.uk/GPy/", + url = "http://sheffieldml.github.com/GPy/", packages = ['GPy', 'GPy.core', 'GPy.kern', 'GPy.util', 'GPy.models', 'GPy.inference', 'GPy.examples', 'GPy.likelihoods'], package_dir={'GPy': 'GPy'}, package_data = {'GPy': ['GPy/examples']}, From a86676016247b222664c177bfc4e9dc834500c00 Mon Sep 17 00:00:00 2001 From: Alan Saul Date: Mon, 11 Mar 2013 12:39:44 +0000 Subject: [PATCH 2/7] Removed unused partial1 --- GPy/kern/kern.py | 2 +- GPy/models/sparse_GP.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GPy/kern/kern.py b/GPy/kern/kern.py index f1a5bd45..87e67f33 100644 --- a/GPy/kern/kern.py +++ b/GPy/kern/kern.py @@ -399,7 +399,7 @@ class kern(parameterised): return target - def dpsi2_dtheta(self,dL_dpsi2,partial1,Z,mu,S,slices1=None,slices2=None): + def dpsi2_dtheta(self,dL_dpsi2,Z,mu,S,slices1=None,slices2=None): """Returns shape (N,M,M,Ntheta)""" slices1, slices2 = self._process_slices(slices1,slices2) target = np.zeros(self.Nparam) diff --git a/GPy/models/sparse_GP.py b/GPy/models/sparse_GP.py index ff00faea..e2019d99 100644 --- a/GPy/models/sparse_GP.py +++ b/GPy/models/sparse_GP.py @@ -208,7 +208,7 @@ class sparse_GP(GP): if self.has_uncertain_inputs: dL_dtheta += self.kern.dpsi0_dtheta(self.dL_dpsi0, self.Z,self.X,self.X_uncertainty) dL_dtheta += self.kern.dpsi1_dtheta(self.dL_dpsi1.T,self.Z,self.X, self.X_uncertainty) - dL_dtheta += self.kern.dpsi2_dtheta(self.dL_dpsi2,self.dL_dpsi1.T, self.Z,self.X, self.X_uncertainty) + dL_dtheta += self.kern.dpsi2_dtheta(self.dL_dpsi2, self.Z,self.X, self.X_uncertainty) else: dL_dtheta += self.kern.dK_dtheta(self.dL_dpsi1,self.Z,self.X) dL_dtheta += self.kern.dKdiag_dtheta(self.dL_dpsi0, self.X) From f98e52ffe8cd5678b178eb69fa771b23af55125f Mon Sep 17 00:00:00 2001 From: Nicolo Fusi Date: Mon, 11 Mar 2013 12:40:14 +0000 Subject: [PATCH 3/7] now running nosetest doesn't run unittests twice --- GPy/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GPy/__init__.py b/GPy/__init__.py index 6c43e471..fa69dac3 100644 --- a/GPy/__init__.py +++ b/GPy/__init__.py @@ -11,6 +11,8 @@ from core import priors import likelihoods import testing from numpy.testing import Tester +from nose.tools import nottest +@nottest def tests(): Tester(testing).test(verbose=10) From e511bb69cf25cfa3c6c8aea946a85fcdf3f437d2 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Mon, 11 Mar 2013 12:40:29 +0000 Subject: [PATCH 4/7] added in documentation the current status of kernel implementation --- doc/Figures/tick.png | Bin 0 -> 175 bytes doc/GPy.examples.rst | 16 +++++++++++++ doc/GPy.kern.rst | 28 ++++++++++++++++++----- doc/kernel_implementation.rst | 41 +++++++++++++++++++++++++--------- doc/tuto_kernel_overview.rst | 2 +- 5 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 doc/Figures/tick.png diff --git a/doc/Figures/tick.png b/doc/Figures/tick.png new file mode 100644 index 0000000000000000000000000000000000000000..1175c8021717199329a79061bbf1e02c49f677fc GIT binary patch literal 175 zcmeAS@N?(olHy`uVBq!ia0vp@K+MO&3?$hCyB`86tpJ}8*Z=?j1DW&Y%?k(!NJ>g_ zaBwIoDcQDd8xIeUl9Cb&3rkm5*O@bCo;`ae#qL%PRO;aA;uyklJvo7aQH|B$Xadv1 z2w{a1iIyb8h6|zsT?;v#4E-4`_ . The following figure gives a summary of most of them: +Many kernels are already implemented in GPy. A comprehensive list can be found `here `_ and the following figure gives a summary of most of them: .. figure:: Figures/tuto_kern_overview_allkern.png :align: center From da219a66e811767303f858d59d37fbde96c7eb76 Mon Sep 17 00:00:00 2001 From: Nicolo Fusi Date: Mon, 11 Mar 2013 12:40:53 +0000 Subject: [PATCH 5/7] added init --- GPy/testing/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 GPy/testing/__init__.py diff --git a/GPy/testing/__init__.py b/GPy/testing/__init__.py new file mode 100644 index 00000000..e69de29b From 25d73b13e99ecf6471063573d3ab4f2d02b6f587 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Mon, 11 Mar 2013 12:59:39 +0000 Subject: [PATCH 6/7] update in the documentation on kernel implementation --- doc/kernel_implementation.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/kernel_implementation.rst b/doc/kernel_implementation.rst index 888d1ee5..99ee006b 100644 --- a/doc/kernel_implementation.rst +++ b/doc/kernel_implementation.rst @@ -35,4 +35,13 @@ spline |tick| |tick| |tick| |tick| |tick| white |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick| ==================== =========== ====== ======= =========== =============== ======= =========== ====== ====== ======= +Depending on the use, all functions may not be required + + * ``get/set, K, Kdiag``: compulsory + * ``dK_dtheta``: necessary to optimize the model + * ``dKdiag_dtheta``: sparse models, BGPLVM, GPs with uncertain inputs + * ``dK_dX``: sparse models, GPLVM, BGPLVM, GPs with uncertain inputs + * ``dKdiag_dX``: sparse models, BGPLVM, GPs with uncertain inputs + * ``psi0, psi1, psi2``: BGPLVM, GPs with uncertain inputs + .. |tick| image:: Figures/tick.png From 16a23758c6f64b568c2ce985ef98454932ed3350 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Mon, 11 Mar 2013 13:13:18 +0000 Subject: [PATCH 7/7] example files for tutorials are now in Neil's format --- GPy/examples/__init__.py | 1 + GPy/examples/tuto_GP_regression.py | 56 -------- GPy/examples/tuto_kernel_overview.py | 139 ------------------ GPy/examples/tutorials.py | 201 +++++++++++++++++++++++++++ doc/tuto_GP_regression.rst | 2 +- doc/tuto_kernel_overview.rst | 2 +- 6 files changed, 204 insertions(+), 197 deletions(-) delete mode 100644 GPy/examples/tuto_GP_regression.py delete mode 100644 GPy/examples/tuto_kernel_overview.py create mode 100644 GPy/examples/tutorials.py diff --git a/GPy/examples/__init__.py b/GPy/examples/__init__.py index 2f3cf0f4..ce4618ac 100644 --- a/GPy/examples/__init__.py +++ b/GPy/examples/__init__.py @@ -6,3 +6,4 @@ import classification import regression import unsupervised +import tutorials diff --git a/GPy/examples/tuto_GP_regression.py b/GPy/examples/tuto_GP_regression.py deleted file mode 100644 index b3953de0..00000000 --- a/GPy/examples/tuto_GP_regression.py +++ /dev/null @@ -1,56 +0,0 @@ -# The detailed explanations of the commands used in this file can be found in the tutorial section - -import pylab as pb -pb.ion() -import numpy as np -import GPy - -X = np.random.uniform(-3.,3.,(20,1)) -Y = np.sin(X) + np.random.randn(20,1)*0.05 - -kernel = GPy.kern.rbf(D=1, variance=1., lengthscale=1.) - -m = GPy.models.GP_regression(X,Y,kernel) - -print m -m.plot() - -m.constrain_positive('') - -m.unconstrain('') # Required to remove the previous constrains -m.constrain_positive('rbf_variance') -m.constrain_bounded('lengthscale',1.,10. ) -m.constrain_fixed('noise',0.0025) - -m.optimize() - -m.optimize_restarts(Nrestarts = 10) - -########################### -# 2-dimensional example # -########################### - -import pylab as pb -pb.ion() -import numpy as np -import GPy - -# sample inputs and outputs -X = np.random.uniform(-3.,3.,(50,2)) -Y = np.sin(X[:,0:1]) * np.sin(X[:,1:2])+np.random.randn(50,1)*0.05 - -# define kernel -ker = GPy.kern.Matern52(2,ARD=True) + GPy.kern.white(2) - -# create simple GP model -m = GPy.models.GP_regression(X,Y,ker) - -# contrain all parameters to be positive -m.constrain_positive('') - -# optimize and plot -pb.figure() -m.optimize('tnc', max_f_eval = 1000) - -m.plot() -print(m) diff --git a/GPy/examples/tuto_kernel_overview.py b/GPy/examples/tuto_kernel_overview.py deleted file mode 100644 index ebd19d76..00000000 --- a/GPy/examples/tuto_kernel_overview.py +++ /dev/null @@ -1,139 +0,0 @@ -# The detailed explanations of the commands used in this file can be found in the tutorial section - -import pylab as pb -import numpy as np -import GPy -pb.ion() - -ker1 = GPy.kern.rbf(1) # Equivalent to ker1 = GPy.kern.rbf(D=1, variance=1., lengthscale=1.) -ker2 = GPy.kern.rbf(D=1, variance = .75, lengthscale=2.) -ker3 = GPy.kern.rbf(1, .5, .5) - -print ker2 -ker1.plot() -ker2.plot() -ker3.plot() - -k1 = GPy.kern.rbf(1,1.,2.) -k2 = GPy.kern.Matern32(1, 0.5, 0.2) - -# Product of kernels -k_prod = k1.prod(k2) -k_prodorth = k1.prod_orthogonal(k2) - -# Sum of kernels -k_add = k1.add(k2) -k_addorth = k1.add_orthogonal(k2) - -pb.figure(figsize=(8,8)) -pb.subplot(2,2,1) -k_prod.plot() -pb.title('prod') -pb.subplot(2,2,2) -k_prodorth.plot() -pb.title('prod_orthogonal') -pb.subplot(2,2,3) -k_add.plot() -pb.title('add') -pb.subplot(2,2,4) -k_addorth.plot() -pb.title('add_orthogonal') -pb.subplots_adjust(wspace=0.3, hspace=0.3) - -k1 = GPy.kern.rbf(1,1.,2) -k2 = GPy.kern.periodic_Matern52(1,variance=1e3, lengthscale=1, period = 1.5, lower=-5., upper = 5) - -k = k1 * k2 # equivalent to k = k1.prod(k2) -print k - -# Simulate sample paths -X = np.linspace(-5,5,501)[:,None] -Y = np.random.multivariate_normal(np.zeros(501),k.K(X),1) - -# plot -pb.figure(figsize=(10,4)) -pb.subplot(1,2,1) -k.plot() -pb.subplot(1,2,2) -pb.plot(X,Y.T) -pb.ylabel("Sample path") -pb.subplots_adjust(wspace=0.3) - -k = (k1+k2)*(k1+k2) -print k.parts[0].name, '\n', k.parts[1].name, '\n', k.parts[2].name, '\n', k.parts[3].name - -k1 = GPy.kern.rbf(1) -k2 = GPy.kern.Matern32(1) -k3 = GPy.kern.white(1) - -k = k1 + k2 + k3 -print k - -k.constrain_positive('var') -k.constrain_fixed(np.array([1]),1.75) -k.tie_param('len') -k.unconstrain('white') -k.constrain_bounded('white',lower=1e-5,upper=.5) -print k - -k_cst = GPy.kern.bias(1,variance=1.) -k_mat = GPy.kern.Matern52(1,variance=1., lengthscale=3) -Kanova = (k_cst + k_mat).prod_orthogonal(k_cst + k_mat) -print Kanova - -# sample inputs and outputs -X = np.random.uniform(-3.,3.,(40,2)) -Y = 0.5*X[:,:1] + 0.5*X[:,1:] + 2*np.sin(X[:,:1]) * np.sin(X[:,1:]) - -# Create GP regression model -m = GPy.models.GP_regression(X,Y,Kanova) -pb.figure(figsize=(5,5)) -m.plot() - -pb.figure(figsize=(20,3)) -pb.subplots_adjust(wspace=0.5) -pb.subplot(1,5,1) -m.plot() -pb.subplot(1,5,2) -pb.ylabel("= ",rotation='horizontal',fontsize='30') -pb.subplot(1,5,3) -m.plot(which_functions=[False,True,False,False]) -pb.ylabel("cst +",rotation='horizontal',fontsize='30') -pb.subplot(1,5,4) -m.plot(which_functions=[False,False,True,False]) -pb.ylabel("+ ",rotation='horizontal',fontsize='30') -pb.subplot(1,5,5) -pb.ylabel("+ ",rotation='horizontal',fontsize='30') -m.plot(which_functions=[False,False,False,True]) - -import pylab as pb -import numpy as np -import GPy -pb.ion() - -ker1 = GPy.kern.rbf(D=1) # Equivalent to ker1 = GPy.kern.rbf(D=1, variance=1., lengthscale=1.) -ker2 = GPy.kern.rbf(D=1, variance = .75, lengthscale=3.) -ker3 = GPy.kern.rbf(1, .5, .25) - -ker1.plot() -ker2.plot() -ker3.plot() -#pb.savefig("Figures/tuto_kern_overview_basicdef.png") - -kernels = [GPy.kern.rbf(1), GPy.kern.exponential(1), GPy.kern.Matern32(1), GPy.kern.Matern52(1), GPy.kern.Brownian(1), GPy.kern.bias(1), GPy.kern.linear(1), GPy.kern.spline(1), GPy.kern.periodic_exponential(1), GPy.kern.periodic_Matern32(1), GPy.kern.periodic_Matern52(1), GPy.kern.white(1)] -kernel_names = ["GPy.kern.rbf", "GPy.kern.exponential", "GPy.kern.Matern32", "GPy.kern.Matern52", "GPy.kern.Brownian", "GPy.kern.bias", "GPy.kern.linear", "GPy.kern.spline", "GPy.kern.periodic_exponential", "GPy.kern.periodic_Matern32", "GPy.kern.periodic_Matern52", "GPy.kern.white"] - -pb.figure(figsize=(16,12)) -pb.subplots_adjust(wspace=.5, hspace=.5) -for i, kern in enumerate(kernels): - pb.subplot(3,4,i+1) - kern.plot(x=7.5,plot_limits=[0.00001,15.]) - pb.title(kernel_names[i]+ '\n') - -# actual plot for the noise -i = 11 -X = np.linspace(0.,15.,201) -WN = 0*X -WN[100] = 1. -pb.subplot(3,4,i+1) -pb.plot(X,WN,'b') diff --git a/GPy/examples/tutorials.py b/GPy/examples/tutorials.py new file mode 100644 index 00000000..be550e01 --- /dev/null +++ b/GPy/examples/tutorials.py @@ -0,0 +1,201 @@ +# Copyright (c) 2012, GPy authors (see AUTHORS.txt). +# Licensed under the BSD 3-clause license (see LICENSE.txt) + + +""" +Code of Tutorials +""" + +def tuto_GP_regression(): + """The detailed explanations of the commands used in this file can be found in the tutorial section""" + + import pylab as pb + pb.ion() + import numpy as np + import GPy + + X = np.random.uniform(-3.,3.,(20,1)) + Y = np.sin(X) + np.random.randn(20,1)*0.05 + + kernel = GPy.kern.rbf(D=1, variance=1., lengthscale=1.) + + m = GPy.models.GP_regression(X,Y,kernel) + + print m + m.plot() + + m.constrain_positive('') + + m.unconstrain('') # Required to remove the previous constrains + m.constrain_positive('rbf_variance') + m.constrain_bounded('lengthscale',1.,10. ) + m.constrain_fixed('noise',0.0025) + + m.optimize() + + m.optimize_restarts(Nrestarts = 10) + + ########################### + # 2-dimensional example # + ########################### + + import pylab as pb + pb.ion() + import numpy as np + import GPy + + # sample inputs and outputs + X = np.random.uniform(-3.,3.,(50,2)) + Y = np.sin(X[:,0:1]) * np.sin(X[:,1:2])+np.random.randn(50,1)*0.05 + + # define kernel + ker = GPy.kern.Matern52(2,ARD=True) + GPy.kern.white(2) + + # create simple GP model + m = GPy.models.GP_regression(X,Y,ker) + + # contrain all parameters to be positive + m.constrain_positive('') + + # optimize and plot + pb.figure() + m.optimize('tnc', max_f_eval = 1000) + + m.plot() + print(m) + + +def tuto_kernel_overview(): + """The detailed explanations of the commands used in this file can be found in the tutorial section""" + import pylab as pb + import numpy as np + import GPy + pb.ion() + + ker1 = GPy.kern.rbf(1) # Equivalent to ker1 = GPy.kern.rbf(D=1, variance=1., lengthscale=1.) + ker2 = GPy.kern.rbf(D=1, variance = .75, lengthscale=2.) + ker3 = GPy.kern.rbf(1, .5, .5) + + print ker2 + ker1.plot() + ker2.plot() + ker3.plot() + + k1 = GPy.kern.rbf(1,1.,2.) + k2 = GPy.kern.Matern32(1, 0.5, 0.2) + + # Product of kernels + k_prod = k1.prod(k2) + k_prodorth = k1.prod_orthogonal(k2) + + # Sum of kernels + k_add = k1.add(k2) + k_addorth = k1.add_orthogonal(k2) + + pb.figure(figsize=(8,8)) + pb.subplot(2,2,1) + k_prod.plot() + pb.title('prod') + pb.subplot(2,2,2) + k_prodorth.plot() + pb.title('prod_orthogonal') + pb.subplot(2,2,3) + k_add.plot() + pb.title('add') + pb.subplot(2,2,4) + k_addorth.plot() + pb.title('add_orthogonal') + pb.subplots_adjust(wspace=0.3, hspace=0.3) + + k1 = GPy.kern.rbf(1,1.,2) + k2 = GPy.kern.periodic_Matern52(1,variance=1e3, lengthscale=1, period = 1.5, lower=-5., upper = 5) + + k = k1 * k2 # equivalent to k = k1.prod(k2) + print k + + # Simulate sample paths + X = np.linspace(-5,5,501)[:,None] + Y = np.random.multivariate_normal(np.zeros(501),k.K(X),1) + + # plot + pb.figure(figsize=(10,4)) + pb.subplot(1,2,1) + k.plot() + pb.subplot(1,2,2) + pb.plot(X,Y.T) + pb.ylabel("Sample path") + pb.subplots_adjust(wspace=0.3) + + k = (k1+k2)*(k1+k2) + print k.parts[0].name, '\n', k.parts[1].name, '\n', k.parts[2].name, '\n', k.parts[3].name + + k1 = GPy.kern.rbf(1) + k2 = GPy.kern.Matern32(1) + k3 = GPy.kern.white(1) + + k = k1 + k2 + k3 + print k + + k.constrain_positive('var') + k.constrain_fixed(np.array([1]),1.75) + k.tie_param('len') + k.unconstrain('white') + k.constrain_bounded('white',lower=1e-5,upper=.5) + print k + + k_cst = GPy.kern.bias(1,variance=1.) + k_mat = GPy.kern.Matern52(1,variance=1., lengthscale=3) + Kanova = (k_cst + k_mat).prod_orthogonal(k_cst + k_mat) + print Kanova + + # sample inputs and outputs + X = np.random.uniform(-3.,3.,(40,2)) + Y = 0.5*X[:,:1] + 0.5*X[:,1:] + 2*np.sin(X[:,:1]) * np.sin(X[:,1:]) + + # Create GP regression model + m = GPy.models.GP_regression(X,Y,Kanova) + pb.figure(figsize=(5,5)) + m.plot() + + pb.figure(figsize=(20,3)) + pb.subplots_adjust(wspace=0.5) + pb.subplot(1,5,1) + m.plot() + pb.subplot(1,5,2) + pb.ylabel("= ",rotation='horizontal',fontsize='30') + pb.subplot(1,5,3) + m.plot(which_functions=[False,True,False,False]) + pb.ylabel("cst +",rotation='horizontal',fontsize='30') + pb.subplot(1,5,4) + m.plot(which_functions=[False,False,True,False]) + pb.ylabel("+ ",rotation='horizontal',fontsize='30') + pb.subplot(1,5,5) + pb.ylabel("+ ",rotation='horizontal',fontsize='30') + m.plot(which_functions=[False,False,False,True]) + + ker1 = GPy.kern.rbf(D=1) # Equivalent to ker1 = GPy.kern.rbf(D=1, variance=1., lengthscale=1.) + ker2 = GPy.kern.rbf(D=1, variance = .75, lengthscale=3.) + ker3 = GPy.kern.rbf(1, .5, .25) + + ker1.plot() + ker2.plot() + ker3.plot() + #pb.savefig("Figures/tuto_kern_overview_basicdef.png") + + kernels = [GPy.kern.rbf(1), GPy.kern.exponential(1), GPy.kern.Matern32(1), GPy.kern.Matern52(1), GPy.kern.Brownian(1), GPy.kern.bias(1), GPy.kern.linear(1), GPy.kern.spline(1), GPy.kern.periodic_exponential(1), GPy.kern.periodic_Matern32(1), GPy.kern.periodic_Matern52(1), GPy.kern.white(1)] + kernel_names = ["GPy.kern.rbf", "GPy.kern.exponential", "GPy.kern.Matern32", "GPy.kern.Matern52", "GPy.kern.Brownian", "GPy.kern.bias", "GPy.kern.linear", "GPy.kern.spline", "GPy.kern.periodic_exponential", "GPy.kern.periodic_Matern32", "GPy.kern.periodic_Matern52", "GPy.kern.white"] + + pb.figure(figsize=(16,12)) + pb.subplots_adjust(wspace=.5, hspace=.5) + for i, kern in enumerate(kernels): + pb.subplot(3,4,i+1) + kern.plot(x=7.5,plot_limits=[0.00001,15.]) + pb.title(kernel_names[i]+ '\n') + + # actual plot for the noise + i = 11 + X = np.linspace(0.,15.,201) + WN = 0*X + WN[100] = 1. + pb.subplot(3,4,i+1) + pb.plot(X,WN,'b') diff --git a/doc/tuto_GP_regression.rst b/doc/tuto_GP_regression.rst index 9de79a8c..24e10528 100644 --- a/doc/tuto_GP_regression.rst +++ b/doc/tuto_GP_regression.rst @@ -2,7 +2,7 @@ Gaussian process regression tutorial ************************************* -We will see in this tutorial the basics for building a 1 dimensional and a 2 dimensional Gaussian process regression model, also known as a kriging model. The code shown in this tutorial can be found without the comments at GPy/examples/tuto_GP_regression.py. +We will see in this tutorial the basics for building a 1 dimensional and a 2 dimensional Gaussian process regression model, also known as a kriging model. The code shown in this tutorial can be obtained at GPy/examples/tutorials.py, or by running ``GPy.examples.tutorials.tuto_GP_regression()``. We first import the libraries we will need: :: diff --git a/doc/tuto_kernel_overview.rst b/doc/tuto_kernel_overview.rst index e410696a..dfb7fb3f 100644 --- a/doc/tuto_kernel_overview.rst +++ b/doc/tuto_kernel_overview.rst @@ -2,7 +2,7 @@ **************************** tutorial : A kernel overview **************************** -The aim of this tutorial is to give a better understanding of the kernel objects in GPy and to list the ones that are already implemented. The code shown in this tutorial can be found without the comments at GPy/examples/tuto_kernel_overview.py. +The aim of this tutorial is to give a better understanding of the kernel objects in GPy and to list the ones that are already implemented. The code shown in this tutorial can be obtained at GPy/examples/tutorials.py or by running ``GPy.examples.tutorials.tuto_kernel_overview()``. First we import the libraries we will need ::