mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-18 13:55:14 +02:00
Merge branch 'master' of github.com:SheffieldML/GPy
This commit is contained in:
commit
7bdf01da10
18 changed files with 296 additions and 231 deletions
|
|
@ -9,3 +9,10 @@ import util
|
||||||
import examples
|
import examples
|
||||||
from core import priors
|
from core import priors
|
||||||
import likelihoods
|
import likelihoods
|
||||||
|
import testing
|
||||||
|
from numpy.testing import Tester
|
||||||
|
from nose.tools import nottest
|
||||||
|
|
||||||
|
@nottest
|
||||||
|
def tests():
|
||||||
|
Tester(testing).test(verbose=10)
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,4 @@
|
||||||
import classification
|
import classification
|
||||||
import regression
|
import regression
|
||||||
import unsupervised
|
import unsupervised
|
||||||
|
import tutorials
|
||||||
|
|
|
||||||
|
|
@ -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)
|
|
||||||
|
|
@ -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')
|
|
||||||
201
GPy/examples/tutorials.py
Normal file
201
GPy/examples/tutorials.py
Normal file
|
|
@ -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')
|
||||||
|
|
@ -399,7 +399,7 @@ class kern(parameterised):
|
||||||
|
|
||||||
return target
|
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)"""
|
"""Returns shape (N,M,M,Ntheta)"""
|
||||||
slices1, slices2 = self._process_slices(slices1,slices2)
|
slices1, slices2 = self._process_slices(slices1,slices2)
|
||||||
target = np.zeros(self.Nparam)
|
target = np.zeros(self.Nparam)
|
||||||
|
|
|
||||||
|
|
@ -208,7 +208,7 @@ class sparse_GP(GP):
|
||||||
if self.has_uncertain_inputs:
|
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.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.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:
|
else:
|
||||||
dL_dtheta += self.kern.dK_dtheta(self.dL_dpsi1,self.Z,self.X)
|
dL_dtheta += self.kern.dK_dtheta(self.dL_dpsi1,self.Z,self.X)
|
||||||
dL_dtheta += self.kern.dKdiag_dtheta(self.dL_dpsi0, self.X)
|
dL_dtheta += self.kern.dKdiag_dtheta(self.dL_dpsi0, self.X)
|
||||||
|
|
|
||||||
0
GPy/testing/__init__.py
Normal file
0
GPy/testing/__init__.py
Normal file
|
|
@ -12,6 +12,7 @@ class BGPLVMTests(unittest.TestCase):
|
||||||
k = GPy.kern.rbf(Q) + GPy.kern.white(Q, 0.00001)
|
k = GPy.kern.rbf(Q) + GPy.kern.white(Q, 0.00001)
|
||||||
K = k.K(X)
|
K = k.K(X)
|
||||||
Y = np.random.multivariate_normal(np.zeros(N),K,D).T
|
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)
|
k = GPy.kern.bias(Q) + GPy.kern.white(Q, 0.00001)
|
||||||
m = GPy.models.Bayesian_GPLVM(Y, Q, kernel = k, M=M)
|
m = GPy.models.Bayesian_GPLVM(Y, Q, kernel = k, M=M)
|
||||||
m.constrain_positive('(rbf|bias|noise|white|S)')
|
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 = GPy.kern.rbf(Q) + GPy.kern.white(Q, 0.00001)
|
||||||
K = k.K(X)
|
K = k.K(X)
|
||||||
Y = np.random.multivariate_normal(np.zeros(N),K,D).T
|
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)
|
k = GPy.kern.linear(Q) + GPy.kern.white(Q, 0.00001)
|
||||||
m = GPy.models.Bayesian_GPLVM(Y, Q, kernel = k, M=M)
|
m = GPy.models.Bayesian_GPLVM(Y, Q, kernel = k, M=M)
|
||||||
m.constrain_positive('(linear|bias|noise|white|S)')
|
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 = GPy.kern.rbf(Q) + GPy.kern.white(Q, 0.00001)
|
||||||
K = k.K(X)
|
K = k.K(X)
|
||||||
Y = np.random.multivariate_normal(np.zeros(N),K,D).T
|
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)
|
k = GPy.kern.rbf(Q) + GPy.kern.white(Q, 0.00001)
|
||||||
m = GPy.models.Bayesian_GPLVM(Y, Q, kernel = k, M=M)
|
m = GPy.models.Bayesian_GPLVM(Y, Q, kernel = k, M=M)
|
||||||
m.constrain_positive('(rbf|bias|noise|white|S)')
|
m.constrain_positive('(rbf|bias|noise|white|S)')
|
||||||
m.randomize()
|
m.randomize()
|
||||||
self.assertTrue(m.checkgrad())
|
self.assertTrue(m.checkgrad())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print "Running unit tests, please be (very) patient..."
|
print "Running unit tests, please be (very) patient..."
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ class KernelTests(unittest.TestCase):
|
||||||
X = np.random.rand(5,5)
|
X = np.random.rand(5,5)
|
||||||
Y = np.ones((5,1))
|
Y = np.ones((5,1))
|
||||||
m = GPy.models.GP_regression(X,Y,K)
|
m = GPy.models.GP_regression(X,Y,K)
|
||||||
print m
|
|
||||||
self.assertTrue(m.checkgrad())
|
self.assertTrue(m.checkgrad())
|
||||||
|
|
||||||
def test_coregionalisation(self):
|
def test_coregionalisation(self):
|
||||||
|
|
|
||||||
|
|
@ -192,17 +192,6 @@ class GradientTests(unittest.TestCase):
|
||||||
m.approximate_likelihood()
|
m.approximate_likelihood()
|
||||||
self.assertTrue(m.checkgrad())
|
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__":
|
if __name__ == "__main__":
|
||||||
print "Running unit tests, please be (very) patient..."
|
print "Running unit tests, please be (very) patient..."
|
||||||
|
|
|
||||||
BIN
doc/Figures/tick.png
Normal file
BIN
doc/Figures/tick.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 175 B |
|
|
@ -73,6 +73,22 @@ examples Package
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
|
:mod:`tuto_GP_regression` Module
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
.. automodule:: GPy.examples.tuto_GP_regression
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
|
:mod:`tuto_kernel_overview` Module
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
.. automodule:: GPy.examples.tuto_kernel_overview
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
:mod:`uncertain_input_GP_regression_demo` Module
|
:mod:`uncertain_input_GP_regression_demo` Module
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,14 @@ kern Package
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
|
:mod:`coregionalise` Module
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
.. automodule:: GPy.kern.coregionalise
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
:mod:`exponential` Module
|
:mod:`exponential` Module
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
|
|
@ -113,18 +121,18 @@ kern Package
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
:mod:`product` Module
|
:mod:`prod` Module
|
||||||
---------------------
|
------------------
|
||||||
|
|
||||||
.. automodule:: GPy.kern.product
|
.. automodule:: GPy.kern.prod
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
:mod:`product_orthogonal` Module
|
:mod:`prod_orthogonal` Module
|
||||||
--------------------------------
|
-----------------------------
|
||||||
|
|
||||||
.. automodule:: GPy.kern.product_orthogonal
|
.. automodule:: GPy.kern.prod_orthogonal
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
@ -145,6 +153,14 @@ kern Package
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
|
:mod:`symmetric` Module
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
.. automodule:: GPy.kern.symmetric
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
:mod:`sympykern` Module
|
:mod:`sympykern` Module
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,45 @@
|
||||||
List of implemented kernels
|
List of implemented kernels
|
||||||
***************************
|
***************************
|
||||||
|
|
||||||
The :math:`\checkmark` symbol represents the functions that have been implemented for each kernel.
|
The following table shows the implemented kernels in GPy and gives the details of the implemented function for each kernel.
|
||||||
|
|
||||||
.. |tick|
|
==================== =========== ====== ======= =========== =============== ======= =========== ====== ====== =======
|
||||||
|
NAME get/set K Kdiag dK_dtheta dKdiag_dtheta dK_dX dKdiag_dX psi0 psi1 psi2
|
||||||
|
==================== =========== ====== ======= =========== =============== ======= =========== ====== ====== =======
|
||||||
|
bias |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
Brownian |tick| |tick| |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
exponential |tick| |tick| |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
finite_dimensional |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
linear |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
Matern32 |tick| |tick| |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
Matern52 |tick| |tick| |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
periodic_exponential |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
periodic_Matern32 |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
periodic_Matern52 |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
rbf |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
spline |tick| |tick| |tick| |tick| |tick| |tick|
|
||||||
|
-------------------- ----------- ------ ------- ----------- --------------- ------- ----------- ------ ------ -------
|
||||||
|
white |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick| |tick|
|
||||||
|
==================== =========== ====== ======= =========== =============== ======= =========== ====== ====== =======
|
||||||
|
|
||||||
.. |tick| image:: tick.png
|
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
|
||||||
NAME get/set K Kdiag dK_dtheta dKdiag_dtheta dK_dX dKdiag_dX psi0 psi1 psi2
|
|
||||||
====== =========== === ======= =========== =============== ======= =========== ====== ====== =======
|
|
||||||
rbf \\checkmark y
|
|
||||||
====== =========== === ======= =========== =============== ======= =========== ====== ====== =======
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
Gaussian process regression tutorial
|
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: ::
|
We first import the libraries we will need: ::
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
****************************
|
****************************
|
||||||
tutorial : A kernel overview
|
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 ::
|
First we import the libraries we will need ::
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ return::
|
||||||
Implemented kernels
|
Implemented kernels
|
||||||
===================
|
===================
|
||||||
|
|
||||||
Many kernels are already implemented in GPy. A comprehensive list can be found `here <kernel_implementation.html>`_ . The following figure gives a summary of most of them:
|
Many kernels are already implemented in GPy. A comprehensive list can be found `here <kernel_implementation.html>`_ and the following figure gives a summary of most of them:
|
||||||
|
|
||||||
.. figure:: Figures/tuto_kern_overview_allkern.png
|
.. figure:: Figures/tuto_kern_overview_allkern.png
|
||||||
:align: center
|
:align: center
|
||||||
|
|
|
||||||
6
setup.py
6
setup.py
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
#from numpy.distutils.core import Extension, setup
|
|
||||||
#from sphinx.setup_command import BuildDoc
|
|
||||||
|
|
||||||
# Version number
|
# Version number
|
||||||
version = '0.1.3'
|
version = '0.1.3'
|
||||||
|
|
@ -14,12 +12,12 @@ def read(fname):
|
||||||
|
|
||||||
setup(name = 'GPy',
|
setup(name = 'GPy',
|
||||||
version = version,
|
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",
|
author_email = "james.hensman@gmail.com",
|
||||||
description = ("The Gaussian Process Toolbox"),
|
description = ("The Gaussian Process Toolbox"),
|
||||||
license = "BSD 3-clause",
|
license = "BSD 3-clause",
|
||||||
keywords = "machine-learning gaussian-processes kernels",
|
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'],
|
packages = ['GPy', 'GPy.core', 'GPy.kern', 'GPy.util', 'GPy.models', 'GPy.inference', 'GPy.examples', 'GPy.likelihoods'],
|
||||||
package_dir={'GPy': 'GPy'},
|
package_dir={'GPy': 'GPy'},
|
||||||
package_data = {'GPy': ['GPy/examples']},
|
package_data = {'GPy': ['GPy/examples']},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue