mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-10 04:22:38 +02:00
[merge] into new devel
This commit is contained in:
commit
dc9a67ad74
16 changed files with 1158 additions and 3 deletions
|
|
@ -8,6 +8,7 @@ from . import parameterization
|
|||
from .gp import GP
|
||||
from .svgp import SVGP
|
||||
from .sparse_gp import SparseGP
|
||||
from .gp_grid import GpGrid
|
||||
from .mapping import *
|
||||
|
||||
|
||||
|
|
|
|||
116
GPy/core/gp_grid.py
Normal file
116
GPy/core/gp_grid.py
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
# Copyright (c) 2012-2014, GPy authors (see AUTHORS.txt).
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
# Kurt Cutajar
|
||||
|
||||
#This implementation of converting GPs to state space models is based on the article:
|
||||
|
||||
#@article{Gilboa:2015,
|
||||
# title={Scaling multidimensional inference for structured Gaussian processes},
|
||||
# author={Gilboa, Elad and Saat{\c{c}}i, Yunus and Cunningham, John P},
|
||||
# journal={Pattern Analysis and Machine Intelligence, IEEE Transactions on},
|
||||
# volume={37},
|
||||
# number={2},
|
||||
# pages={424--436},
|
||||
# year={2015},
|
||||
# publisher={IEEE}
|
||||
#}
|
||||
|
||||
import numpy as np
|
||||
import scipy.linalg as sp
|
||||
from .gp import GP
|
||||
from .parameterization.param import Param
|
||||
from ..inference.latent_function_inference import gaussian_grid_inference
|
||||
from .. import likelihoods
|
||||
|
||||
import logging
|
||||
from GPy.inference.latent_function_inference.posterior import Posterior
|
||||
logger = logging.getLogger("gp grid")
|
||||
|
||||
class GpGrid(GP):
|
||||
"""
|
||||
A GP model for Grid inputs
|
||||
|
||||
:param X: inputs
|
||||
:type X: np.ndarray (num_data x input_dim)
|
||||
:param likelihood: a likelihood instance, containing the observed data
|
||||
:type likelihood: GPy.likelihood.(Gaussian | EP | Laplace)
|
||||
:param kernel: the kernel (covariance function). See link kernels
|
||||
:type kernel: a GPy.kern.kern instance
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, X, Y, kernel, likelihood, inference_method=None,
|
||||
name='gp grid', Y_metadata=None, normalizer=False):
|
||||
#pick a sensible inference method
|
||||
|
||||
inference_method = gaussian_grid_inference.GaussianGridInference()
|
||||
|
||||
GP.__init__(self, X, Y, kernel, likelihood, inference_method=inference_method, name=name, Y_metadata=Y_metadata, normalizer=normalizer)
|
||||
self.posterior = None
|
||||
|
||||
def parameters_changed(self):
|
||||
"""
|
||||
Method that is called upon any changes to :class:`~GPy.core.parameterization.param.Param` variables within the model.
|
||||
In particular in the GP class this method reperforms inference, recalculating the posterior and log marginal likelihood and gradients of the model
|
||||
|
||||
.. warning::
|
||||
This method is not designed to be called manually, the framework is set up to automatically call this method upon changes to parameters, if you call
|
||||
this method yourself, there may be unexpected consequences.
|
||||
"""
|
||||
self.posterior, self._log_marginal_likelihood, self.grad_dict = self.inference_method.inference(self.kern, self.X, self.likelihood, self.Y_normalized, self.Y_metadata)
|
||||
self.likelihood.update_gradients(self.grad_dict['dL_dthetaL'])
|
||||
self.kern.update_gradients_direct(self.grad_dict['dL_dVar'], self.grad_dict['dL_dLen'])
|
||||
|
||||
def kron_mmprod(self, A, B):
|
||||
count = 0
|
||||
D = len(A)
|
||||
for b in (B.T):
|
||||
x = b
|
||||
N = 1
|
||||
G = np.zeros(D)
|
||||
for d in range(D):
|
||||
G[d] = len(A[d])
|
||||
N = np.prod(G)
|
||||
for d in range(D-1, -1, -1):
|
||||
X = np.reshape(x, (G[d], np.round(N/G[d])), order='F')
|
||||
Z = np.dot(A[d], X)
|
||||
Z = Z.T
|
||||
x = np.reshape(Z, (-1, 1), order='F')
|
||||
if (count == 0):
|
||||
result = x
|
||||
else:
|
||||
result = np.column_stack((result, x))
|
||||
count+=1
|
||||
return result
|
||||
|
||||
def _raw_predict(self, Xnew, full_cov=False, kern=None):
|
||||
"""
|
||||
Make a prediction for the latent function values
|
||||
"""
|
||||
if kern is None:
|
||||
kern = self.kern
|
||||
|
||||
# compute mean predictions
|
||||
Kmn = kern.K(Xnew, self.X)
|
||||
alpha_kron = self.posterior.alpha
|
||||
mu = np.dot(Kmn, alpha_kron)
|
||||
mu = mu.reshape(-1,1)
|
||||
|
||||
# compute variance of predictions
|
||||
Knm = Kmn.T
|
||||
noise = self.likelihood.variance
|
||||
V_kron = self.posterior.V_kron
|
||||
Qs = self.posterior.Qs
|
||||
QTs = self.posterior.QTs
|
||||
A = self.kron_mmprod(QTs, Knm)
|
||||
V_kron = V_kron.reshape(-1, 1)
|
||||
A = A / (V_kron + noise)
|
||||
A = self.kron_mmprod(Qs, A)
|
||||
|
||||
Kmm = kern.K(Xnew)
|
||||
var = np.diag(Kmm - np.dot(Kmn, A)).copy()
|
||||
#var = np.zeros((Xnew.shape[0]))
|
||||
var = var.reshape(-1, 1)
|
||||
|
||||
return mu, var
|
||||
|
|
@ -69,6 +69,8 @@ from .dtc import DTC
|
|||
from .fitc import FITC
|
||||
from .var_dtc_parallel import VarDTC_minibatch
|
||||
from .var_gauss import VarGauss
|
||||
from .gaussian_grid_inference import GaussianGridInference
|
||||
|
||||
|
||||
# class FullLatentFunctionData(object):
|
||||
#
|
||||
|
|
|
|||
|
|
@ -0,0 +1,114 @@
|
|||
# Copyright (c) 2012-2014, GPy authors (see AUTHORS.txt).
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
# Kurt Cutajar
|
||||
|
||||
# This implementation of converting GPs to state space models is based on the article:
|
||||
|
||||
#@article{Gilboa:2015,
|
||||
# title={Scaling multidimensional inference for structured Gaussian processes},
|
||||
# author={Gilboa, Elad and Saat{\c{c}}i, Yunus and Cunningham, John P},
|
||||
# journal={Pattern Analysis and Machine Intelligence, IEEE Transactions on},
|
||||
# volume={37},
|
||||
# number={2},
|
||||
# pages={424--436},
|
||||
# year={2015},
|
||||
# publisher={IEEE}
|
||||
#}
|
||||
|
||||
from .grid_posterior import GridPosterior
|
||||
import numpy as np
|
||||
from . import LatentFunctionInference
|
||||
log_2_pi = np.log(2*np.pi)
|
||||
|
||||
class GaussianGridInference(LatentFunctionInference):
|
||||
"""
|
||||
An object for inference when the likelihood is Gaussian and inputs are on a grid.
|
||||
|
||||
The function self.inference returns a GridPosterior object, which summarizes
|
||||
the posterior.
|
||||
|
||||
"""
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def kron_mvprod(self, A, b):
|
||||
x = b
|
||||
N = 1
|
||||
D = len(A)
|
||||
G = np.zeros((D,1))
|
||||
for d in range(0, D):
|
||||
G[d] = len(A[d])
|
||||
N = np.prod(G)
|
||||
for d in range(D-1, -1, -1):
|
||||
X = np.reshape(x, (G[d], np.round(N/G[d])), order='F')
|
||||
Z = np.dot(A[d], X)
|
||||
Z = Z.T
|
||||
x = np.reshape(Z, (-1, 1), order='F')
|
||||
return x
|
||||
|
||||
def inference(self, kern, X, likelihood, Y, Y_metadata=None):
|
||||
|
||||
"""
|
||||
Returns a GridPosterior class containing essential quantities of the posterior
|
||||
"""
|
||||
N = X.shape[0] #number of training points
|
||||
D = X.shape[1] #number of dimensions
|
||||
|
||||
Kds = np.zeros(D, dtype=object) #vector for holding covariance per dimension
|
||||
Qs = np.zeros(D, dtype=object) #vector for holding eigenvectors of covariance per dimension
|
||||
QTs = np.zeros(D, dtype=object) #vector for holding transposed eigenvectors of covariance per dimension
|
||||
V_kron = 1 # kronecker product of eigenvalues
|
||||
|
||||
# retrieve the one-dimensional variation of the designated kernel
|
||||
oneDkernel = kern.get_one_dimensional_kernel(D)
|
||||
|
||||
for d in range(D):
|
||||
xg = list(set(X[:,d])) #extract unique values for a dimension
|
||||
xg = np.reshape(xg, (len(xg), 1))
|
||||
oneDkernel.lengthscale = kern.lengthscale[d]
|
||||
Kds[d] = oneDkernel.K(xg)
|
||||
[V, Q] = np.linalg.eig(Kds[d])
|
||||
V_kron = np.kron(V_kron, V)
|
||||
Qs[d] = Q
|
||||
QTs[d] = Q.T
|
||||
|
||||
noise = likelihood.variance + 1e-8
|
||||
|
||||
alpha_kron = self.kron_mvprod(QTs, Y)
|
||||
V_kron = V_kron.reshape(-1, 1)
|
||||
alpha_kron = alpha_kron / (V_kron + noise)
|
||||
alpha_kron = self.kron_mvprod(Qs, alpha_kron)
|
||||
|
||||
log_likelihood = -0.5 * (np.dot(Y.T, alpha_kron) + np.sum((np.log(V_kron + noise))) + N*log_2_pi)
|
||||
|
||||
# compute derivatives wrt parameters Thete
|
||||
derivs = np.zeros(D+2, dtype='object')
|
||||
for t in range(len(derivs)):
|
||||
dKd_dTheta = np.zeros(D, dtype='object')
|
||||
gamma = np.zeros(D, dtype='object')
|
||||
gam = 1
|
||||
for d in range(D):
|
||||
xg = list(set(X[:,d]))
|
||||
xg = np.reshape(xg, (len(xg), 1))
|
||||
oneDkernel.lengthscale = kern.lengthscale[d]
|
||||
if t < D:
|
||||
dKd_dTheta[d] = oneDkernel.dKd_dLen(xg, (t==d), lengthscale=kern.lengthscale[t]) #derivative wrt lengthscale
|
||||
elif (t == D):
|
||||
dKd_dTheta[d] = oneDkernel.dKd_dVar(xg) #derivative wrt variance
|
||||
else:
|
||||
dKd_dTheta[d] = np.identity(len(xg)) #derivative wrt noise
|
||||
gamma[d] = np.diag(np.dot(np.dot(QTs[d], dKd_dTheta[d].T), Qs[d]))
|
||||
gam = np.kron(gam, gamma[d])
|
||||
|
||||
gam = gam.reshape(-1,1)
|
||||
kappa = self.kron_mvprod(dKd_dTheta, alpha_kron)
|
||||
derivs[t] = 0.5*np.dot(alpha_kron.T,kappa) - 0.5*np.sum(gam / (V_kron + noise))
|
||||
|
||||
# separate derivatives
|
||||
dL_dLen = derivs[:D]
|
||||
dL_dVar = derivs[D]
|
||||
dL_dThetaL = derivs[D+1]
|
||||
|
||||
return GridPosterior(alpha_kron=alpha_kron, QTs=QTs, Qs=Qs, V_kron=V_kron), \
|
||||
log_likelihood, {'dL_dLen':dL_dLen, 'dL_dVar':dL_dVar, 'dL_dthetaL':dL_dThetaL}
|
||||
62
GPy/inference/latent_function_inference/grid_posterior.py
Normal file
62
GPy/inference/latent_function_inference/grid_posterior.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# Copyright (c) 2012-2014, GPy authors (see AUTHORS.txt).
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
# Kurt Cutajar
|
||||
|
||||
import numpy as np
|
||||
|
||||
class GridPosterior(object):
|
||||
"""
|
||||
Specially intended for the Grid Regression case
|
||||
An object to represent a Gaussian posterior over latent function values, p(f|D).
|
||||
|
||||
The purpose of this class is to serve as an interface between the inference
|
||||
schemes and the model classes.
|
||||
|
||||
"""
|
||||
def __init__(self, alpha_kron=None, QTs=None, Qs=None, V_kron=None):
|
||||
"""
|
||||
alpha_kron :
|
||||
QTs : transpose of eigen vectors resulting from decomposition of single dimension covariance matrices
|
||||
Qs : eigen vectors resulting from decomposition of single dimension covariance matrices
|
||||
V_kron : kronecker product of eigenvalues reulting decomposition of single dimension covariance matrices
|
||||
"""
|
||||
|
||||
if ((alpha_kron is not None) and (QTs is not None)
|
||||
and (Qs is not None) and (V_kron is not None)):
|
||||
pass # we have sufficient to compute the posterior
|
||||
else:
|
||||
raise ValueError("insufficient information for predictions")
|
||||
|
||||
self._alpha_kron = alpha_kron
|
||||
self._qTs = QTs
|
||||
self._qs = Qs
|
||||
self._v_kron = V_kron
|
||||
|
||||
@property
|
||||
def alpha(self):
|
||||
"""
|
||||
"""
|
||||
return self._alpha_kron
|
||||
|
||||
@property
|
||||
def QTs(self):
|
||||
"""
|
||||
array of transposed eigenvectors resulting for single dimension covariance
|
||||
"""
|
||||
return self._qTs
|
||||
|
||||
@property
|
||||
def Qs(self):
|
||||
"""
|
||||
array of eigenvectors resulting for single dimension covariance
|
||||
"""
|
||||
return self._qs
|
||||
|
||||
@property
|
||||
def V_kron(self):
|
||||
"""
|
||||
kronecker product of eigenvalues s
|
||||
"""
|
||||
return self._v_kron
|
||||
|
||||
|
|
@ -33,6 +33,7 @@ from .src.splitKern import SplitKern,DEtime
|
|||
from .src.splitKern import DEtime as DiffGenomeKern
|
||||
from .src.spline import Spline
|
||||
from .src.basis_funcs import LogisticBasisFuncKernel, LinearSlopeBasisFuncKernel, BasisFuncKernel, ChangePointBasisFuncKernel, DomainKernel
|
||||
from .src.grid_kerns import GridRBF
|
||||
|
||||
from .src.sde_matern import sde_Matern32
|
||||
from .src.sde_matern import sde_Matern52
|
||||
|
|
|
|||
76
GPy/kern/src/grid_kerns.py
Normal file
76
GPy/kern/src/grid_kerns.py
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# Copyright (c) 2012-2014, GPy authors (see AUTHORS.txt).
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
# Kurt Cutajar
|
||||
|
||||
import numpy as np
|
||||
from .stationary import Stationary
|
||||
from paramz.caching import Cache_this
|
||||
|
||||
|
||||
class GridKern(Stationary):
|
||||
|
||||
def __init__(self, input_dim, variance, lengthscale, ARD, active_dims, name, originalDimensions, useGPU=False):
|
||||
super(GridKern, self).__init__(input_dim, variance, lengthscale, ARD, active_dims, name, useGPU=useGPU)
|
||||
self.originalDimensions = originalDimensions
|
||||
|
||||
@Cache_this(limit=3, ignore_args=())
|
||||
def dKd_dVar(self, X, X2=None):
|
||||
"""
|
||||
Derivative of Kernel function wrt variance applied on inputs X and X2.
|
||||
In the stationary case there is an inner function depending on the
|
||||
distances from X to X2, called r.
|
||||
|
||||
dKd_dVar(X, X2) = dKdVar_of_r((X-X2)**2)
|
||||
"""
|
||||
r = self._scaled_dist(X, X2)
|
||||
return self.dKdVar_of_r(r)
|
||||
|
||||
@Cache_this(limit=3, ignore_args=())
|
||||
def dKd_dLen(self, X, dimension, lengthscale, X2=None):
|
||||
"""
|
||||
Derivate of Kernel function wrt lengthscale applied on inputs X and X2.
|
||||
In the stationary case there is an inner function depending on the
|
||||
distances from X to X2, called r.
|
||||
|
||||
dKd_dLen(X, X2) = dKdLen_of_r((X-X2)**2)
|
||||
"""
|
||||
r = self._scaled_dist(X, X2)
|
||||
return self.dKdLen_of_r(r, dimension, lengthscale)
|
||||
|
||||
class GridRBF(GridKern):
|
||||
"""
|
||||
Similar to regular RBF but supplemented with methods required for Gaussian grid regression
|
||||
Radial Basis Function kernel, aka squared-exponential, exponentiated quadratic or Gaussian kernel:
|
||||
|
||||
.. math::
|
||||
|
||||
k(r) = \sigma^2 \exp \\bigg(- \\frac{1}{2} r^2 \\bigg)
|
||||
|
||||
"""
|
||||
_support_GPU = True
|
||||
def __init__(self, input_dim, variance=1., lengthscale=None, ARD=False, active_dims=None, name='gridRBF', originalDimensions=1, useGPU=False):
|
||||
super(GridRBF, self).__init__(input_dim, variance, lengthscale, ARD, active_dims, name, originalDimensions, useGPU=useGPU)
|
||||
|
||||
def K_of_r(self, r):
|
||||
return (self.variance**(float(1)/self.originalDimensions)) * np.exp(-0.5 * r**2)
|
||||
|
||||
def dKdVar_of_r(self, r):
|
||||
"""
|
||||
Compute derivative of kernel wrt variance
|
||||
"""
|
||||
return np.exp(-0.5 * r**2)
|
||||
|
||||
def dKdLen_of_r(self, r, dimCheck, lengthscale):
|
||||
"""
|
||||
Compute derivative of kernel for dimension wrt lengthscale
|
||||
Computation of derivative changes when lengthscale corresponds to
|
||||
the dimension of the kernel whose derivate is being computed.
|
||||
"""
|
||||
if (dimCheck == True):
|
||||
return (self.variance**(float(1)/self.originalDimensions)) * np.exp(-0.5 * r**2) * (r**2) / (lengthscale**(float(1)/self.originalDimensions))
|
||||
else:
|
||||
return (self.variance**(float(1)/self.originalDimensions)) * np.exp(-0.5 * r**2) / (lengthscale**(float(1)/self.originalDimensions))
|
||||
|
||||
def dK_dr(self, r):
|
||||
return -r*self.K_of_r(r)
|
||||
|
|
@ -7,6 +7,7 @@ from .stationary import Stationary
|
|||
from .psi_comp import PSICOMP_RBF, PSICOMP_RBF_GPU
|
||||
from ...core import Param
|
||||
from paramz.transformations import Logexp
|
||||
from .grid_kerns import GridRBF
|
||||
|
||||
class RBF(Stationary):
|
||||
"""
|
||||
|
|
@ -60,6 +61,14 @@ class RBF(Stationary):
|
|||
if self.use_invLengthscale: self.lengthscale[:] = 1./np.sqrt(self.inv_l+1e-200)
|
||||
super(RBF,self).parameters_changed()
|
||||
|
||||
|
||||
def get_one_dimensional_kernel(self, dim):
|
||||
"""
|
||||
Specially intended for Grid regression.
|
||||
"""
|
||||
oneDkernel = GridRBF(input_dim=1, variance=self.variance.copy(), originalDimensions=dim)
|
||||
return oneDkernel
|
||||
|
||||
#---------------------------------------#
|
||||
# PSI statistics #
|
||||
#---------------------------------------#
|
||||
|
|
|
|||
|
|
@ -198,6 +198,16 @@ class Stationary(Kern):
|
|||
self.lengthscale.gradient = -np.sum(dL_dr*r)/self.lengthscale
|
||||
|
||||
|
||||
def update_gradients_direct(self, dL_dVar, dL_dLen):
|
||||
"""
|
||||
Specially intended for the Grid regression case.
|
||||
Given the computed log likelihood derivates, update the corresponding
|
||||
kernel and likelihood gradients.
|
||||
Useful for when gradients have been computed a priori.
|
||||
"""
|
||||
self.variance.gradient = dL_dVar
|
||||
self.lengthscale.gradient = dL_dLen
|
||||
|
||||
def _inv_dist(self, X, X2=None):
|
||||
"""
|
||||
Compute the elementwise inverse of the distance matrix, expecpt on the
|
||||
|
|
@ -319,6 +329,15 @@ class Stationary(Kern):
|
|||
def input_sensitivity(self, summarize=True):
|
||||
return self.variance*np.ones(self.input_dim)/self.lengthscale**2
|
||||
|
||||
def get_one_dimensional_kernel(self, dimensions):
|
||||
"""
|
||||
Specially intended for the grid regression case
|
||||
For a given covariance kernel, this method returns the corresponding kernel for
|
||||
a single dimension. The resulting values can then be used in the algorithm for
|
||||
reconstructing the full covariance matrix.
|
||||
"""
|
||||
raise NotImplementedError("implement one dimensional variation of kernel")
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,9 +22,7 @@ from .gp_var_gauss import GPVariationalGaussianApproximation
|
|||
from .one_vs_all_classification import OneVsAllClassification
|
||||
from .one_vs_all_sparse_classification import OneVsAllSparseClassification
|
||||
from .dpgplvm import DPBayesianGPLVM
|
||||
|
||||
from .state_space_model import StateSpace
|
||||
|
||||
from .ibp_lfm import IBPLFM
|
||||
|
||||
from .gp_offset_regression import GPOffsetRegression
|
||||
from .gp_grid_regression import GPRegressionGrid
|
||||
|
|
|
|||
36
GPy/models/gp_grid_regression.py
Normal file
36
GPy/models/gp_grid_regression.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# Copyright (c) 2012-2014, GPy authors (see AUTHORS.txt).
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
# Kurt Cutajar
|
||||
|
||||
from ..core import GpGrid
|
||||
from .. import likelihoods
|
||||
from .. import kern
|
||||
|
||||
class GPRegressionGrid(GpGrid):
|
||||
"""
|
||||
Gaussian Process model for grid inputs using Kronecker products
|
||||
|
||||
This is a thin wrapper around the models.GpGrid class, with a set of sensible defaults
|
||||
|
||||
:param X: input observations
|
||||
:param Y: observed values
|
||||
:param kernel: a GPy kernel, defaults to the kron variation of SqExp
|
||||
:param Norm normalizer: [False]
|
||||
|
||||
Normalize Y with the norm given.
|
||||
If normalizer is False, no normalization will be done
|
||||
If it is None, we use GaussianNorm(alization)
|
||||
|
||||
.. Note:: Multiple independent outputs are allowed using columns of Y
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, X, Y, kernel=None, Y_metadata=None, normalizer=None):
|
||||
|
||||
if kernel is None:
|
||||
kernel = kern.RBF(1) # no other kernels implemented so far
|
||||
|
||||
likelihood = likelihoods.Gaussian()
|
||||
super(GPRegressionGrid, self).__init__(X, Y, kernel, likelihood, name='GP Grid regression', Y_metadata=Y_metadata, normalizer=normalizer)
|
||||
|
||||
51
GPy/testing/grid_tests.py
Normal file
51
GPy/testing/grid_tests.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# Copyright (c) 2012-2014, GPy authors (see AUTHORS.txt).
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
# Kurt Cutajar
|
||||
|
||||
import unittest
|
||||
import numpy as np
|
||||
import GPy
|
||||
|
||||
class GridModelTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
######################################
|
||||
# # 3 dimensional example
|
||||
|
||||
# sample inputs and outputs
|
||||
self.X = np.array([[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]])
|
||||
self.Y = np.random.randn(8, 1) * 100
|
||||
self.dim = self.X.shape[1]
|
||||
|
||||
def test_alpha_match(self):
|
||||
kernel = GPy.kern.RBF(input_dim=self.dim, variance=1, ARD=True)
|
||||
m = GPy.models.GPRegressionGrid(self.X, self.Y, kernel)
|
||||
|
||||
kernel2 = GPy.kern.RBF(input_dim=self.dim, variance=1, ARD=True)
|
||||
m2 = GPy.models.GPRegression(self.X, self.Y, kernel2)
|
||||
|
||||
np.testing.assert_almost_equal(m.posterior.alpha, m2.posterior.woodbury_vector)
|
||||
|
||||
def test_gradient_match(self):
|
||||
kernel = GPy.kern.RBF(input_dim=self.dim, variance=1, ARD=True)
|
||||
m = GPy.models.GPRegressionGrid(self.X, self.Y, kernel)
|
||||
|
||||
kernel2 = GPy.kern.RBF(input_dim=self.dim, variance=1, ARD=True)
|
||||
m2 = GPy.models.GPRegression(self.X, self.Y, kernel2)
|
||||
|
||||
np.testing.assert_almost_equal(kernel.variance.gradient, kernel2.variance.gradient)
|
||||
np.testing.assert_almost_equal(kernel.lengthscale.gradient, kernel2.lengthscale.gradient)
|
||||
np.testing.assert_almost_equal(m.likelihood.variance.gradient, m2.likelihood.variance.gradient)
|
||||
|
||||
|
||||
def test_prediction_match(self):
|
||||
kernel = GPy.kern.RBF(input_dim=self.dim, variance=1, ARD=True)
|
||||
m = GPy.models.GPRegressionGrid(self.X, self.Y, kernel)
|
||||
|
||||
kernel2 = GPy.kern.RBF(input_dim=self.dim, variance=1, ARD=True)
|
||||
m2 = GPy.models.GPRegression(self.X, self.Y, kernel2)
|
||||
|
||||
test = np.array([[0,0,2],[-1,3,-4]])
|
||||
|
||||
np.testing.assert_almost_equal(m.predict(test), m2.predict(test))
|
||||
|
||||
93
doc/source/GPy.core.rst
Normal file
93
doc/source/GPy.core.rst
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
GPy.core package
|
||||
================
|
||||
|
||||
Subpackages
|
||||
-----------
|
||||
|
||||
.. toctree::
|
||||
|
||||
GPy.core.parameterization
|
||||
|
||||
Submodules
|
||||
----------
|
||||
|
||||
GPy.core.gp module
|
||||
------------------
|
||||
|
||||
.. automodule:: GPy.core.gp
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.core.mapping module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.core.mapping
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.core.model module
|
||||
---------------------
|
||||
|
||||
.. automodule:: GPy.core.model
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.core.sparse_gp module
|
||||
-------------------------
|
||||
|
||||
.. automodule:: GPy.core.sparse_gp
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.core.sparse_gp_mpi module
|
||||
-----------------------------
|
||||
|
||||
.. automodule:: GPy.core.sparse_gp_mpi
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.core.svgp module
|
||||
--------------------
|
||||
|
||||
.. automodule:: GPy.core.svgp
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.core.gp_grid module
|
||||
------------------------
|
||||
|
||||
.. automodule:: GPy.core.gp_grid
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.core.symbolic module
|
||||
------------------------
|
||||
|
||||
.. automodule:: GPy.core.symbolic
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.core.verbose_optimization module
|
||||
------------------------------------
|
||||
|
||||
.. automodule:: GPy.core.verbose_optimization
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
Module contents
|
||||
---------------
|
||||
|
||||
.. automodule:: GPy.core
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
118
doc/source/GPy.inference.latent_function_inference.rst
Normal file
118
doc/source/GPy.inference.latent_function_inference.rst
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
GPy.inference.latent_function_inference package
|
||||
===============================================
|
||||
|
||||
Submodules
|
||||
----------
|
||||
|
||||
GPy.inference.latent_function_inference.dtc module
|
||||
--------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.dtc
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.exact_gaussian_inference module
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.exact_gaussian_inference
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.expectation_propagation module
|
||||
----------------------------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.expectation_propagation
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.fitc module
|
||||
---------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.fitc
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.inferenceX module
|
||||
---------------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.inferenceX
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.laplace module
|
||||
------------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.laplace
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.posterior module
|
||||
--------------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.posterior
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.grid_posterior module
|
||||
--------------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.grid_posterior
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.svgp module
|
||||
---------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.svgp
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.var_dtc module
|
||||
------------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.var_dtc
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.var_dtc_parallel module
|
||||
---------------------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.var_dtc_parallel
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.var_gauss module
|
||||
--------------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.var_gauss
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.inference.latent_function_inference.gaussian_grid_inference module
|
||||
--------------------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference.gaussian_grid_inference
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
Module contents
|
||||
---------------
|
||||
|
||||
.. automodule:: GPy.inference.latent_function_inference
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
245
doc/source/GPy.kern.src.rst
Normal file
245
doc/source/GPy.kern.src.rst
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
GPy.kern.src package
|
||||
====================
|
||||
|
||||
Subpackages
|
||||
-----------
|
||||
|
||||
.. toctree::
|
||||
|
||||
GPy.kern.src.psi_comp
|
||||
|
||||
Submodules
|
||||
----------
|
||||
|
||||
GPy.kern.src.ODE_UY module
|
||||
--------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.ODE_UY
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.ODE_UYC module
|
||||
---------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.ODE_UYC
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.ODE_st module
|
||||
--------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.ODE_st
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.ODE_t module
|
||||
-------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.ODE_t
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.add module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.add
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.basis_funcs module
|
||||
-------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.basis_funcs
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.brownian module
|
||||
----------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.brownian
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.coregionalize module
|
||||
---------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.coregionalize
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.coregionalize_cython module
|
||||
----------------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.coregionalize_cython
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.eq_ode2 module
|
||||
---------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.eq_ode2
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.independent_outputs module
|
||||
---------------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.independent_outputs
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.kern module
|
||||
------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.kern
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.kernel_slice_operations module
|
||||
-------------------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.kernel_slice_operations
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.linear module
|
||||
--------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.linear
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.mlp module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.mlp
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.periodic module
|
||||
----------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.periodic
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.poly module
|
||||
------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.poly
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.prod module
|
||||
------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.prod
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.rbf module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.rbf
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.spline module
|
||||
--------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.spline
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.grid_kerns module
|
||||
-----------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.grid_kerns
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.splitKern module
|
||||
-----------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.splitKern
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.standard_periodic module
|
||||
-------------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.standard_periodic
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.static module
|
||||
--------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.static
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.stationary module
|
||||
------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.stationary
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.stationary_cython module
|
||||
-------------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.stationary_cython
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.symbolic module
|
||||
----------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.symbolic
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.kern.src.trunclinear module
|
||||
-------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.src.trunclinear
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
Module contents
|
||||
---------------
|
||||
|
||||
.. automodule:: GPy.kern.src
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
214
doc/source/GPy.testing.rst
Normal file
214
doc/source/GPy.testing.rst
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
GPy.testing package
|
||||
===================
|
||||
|
||||
Submodules
|
||||
----------
|
||||
|
||||
GPy.testing.bgplvm_minibatch_tests module
|
||||
-----------------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.bgplvm_minibatch_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.cacher_tests module
|
||||
-------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.cacher_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.cython_tests module
|
||||
-------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.cython_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.examples_tests module
|
||||
---------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.examples_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.fitc module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.testing.fitc
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.gp_tests module
|
||||
---------------------------
|
||||
|
||||
.. automodule:: GPy.testing.gp_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.index_operations_tests module
|
||||
-----------------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.index_operations_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.inference_tests module
|
||||
----------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.inference_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.kernel_tests module
|
||||
-------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.kernel_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.likelihood_tests module
|
||||
-----------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.likelihood_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.linalg_test module
|
||||
------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.linalg_test
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.link_function_tests module
|
||||
--------------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.link_function_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.mapping_tests module
|
||||
--------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.mapping_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.meanfunc_tests module
|
||||
---------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.meanfunc_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.misc_tests module
|
||||
-----------------------------
|
||||
|
||||
.. automodule:: GPy.testing.misc_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.model_tests module
|
||||
------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.model_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.mpi_tests module
|
||||
----------------------------
|
||||
|
||||
.. automodule:: GPy.testing.mpi_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.observable_tests module
|
||||
-----------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.observable_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.parameterized_tests module
|
||||
--------------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.parameterized_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.pickle_tests module
|
||||
-------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.pickle_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.plotting_tests module
|
||||
---------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.plotting_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.prior_tests module
|
||||
------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.prior_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.rv_transformation_tests module
|
||||
------------------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.rv_transformation_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
GPy.testing.svgp_tests module
|
||||
-----------------------------
|
||||
|
||||
.. automodule:: GPy.testing.svgp_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
GPy.testing.grid_tests module
|
||||
-----------------------------
|
||||
|
||||
.. automodule:: GPy.testing.grid_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
Module contents
|
||||
---------------
|
||||
|
||||
.. automodule:: GPy.testing
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
Loading…
Add table
Add a link
Reference in a new issue