mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-15 06:52:39 +02:00
Merge branch 'devel' of github.com:SheffieldML/GPy into devel
This commit is contained in:
commit
9deb1fc1c2
28 changed files with 463 additions and 289 deletions
|
|
@ -2,7 +2,7 @@
|
|||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
from model import *
|
||||
from parameterised import *
|
||||
from parameterized import *
|
||||
import priors
|
||||
from gp import GP
|
||||
from sparse_gp import SparseGP
|
||||
|
|
|
|||
|
|
@ -31,8 +31,11 @@ class GP(GPBase):
|
|||
GPBase.__init__(self, X, likelihood, kernel, normalize_X=normalize_X)
|
||||
self._set_params(self._get_params())
|
||||
|
||||
def __setstate__(self, state):
|
||||
GPBase.__setstate__(self, state)
|
||||
def getstate(self):
|
||||
return GPBase.getstate(self)
|
||||
|
||||
def setstate(self, state):
|
||||
GPBase.setstate(self, state)
|
||||
self._set_params(self._get_params())
|
||||
|
||||
def _set_params(self, p):
|
||||
|
|
|
|||
|
|
@ -33,12 +33,12 @@ class GPBase(Model):
|
|||
# All leaf nodes should call self._set_params(self._get_params()) at
|
||||
# the end
|
||||
|
||||
def __getstate__(self):
|
||||
def getstate(self):
|
||||
"""
|
||||
Get the current state of the class,
|
||||
here just all the indices, rest can get recomputed
|
||||
"""
|
||||
return Model.__getstate__(self) + [self.X,
|
||||
return Model.getstate(self) + [self.X,
|
||||
self.num_data,
|
||||
self.input_dim,
|
||||
self.kern,
|
||||
|
|
@ -47,7 +47,7 @@ class GPBase(Model):
|
|||
self._Xoffset,
|
||||
self._Xscale]
|
||||
|
||||
def __setstate__(self, state):
|
||||
def setstate(self, state):
|
||||
self._Xscale = state.pop()
|
||||
self._Xoffset = state.pop()
|
||||
self.output_dim = state.pop()
|
||||
|
|
@ -56,7 +56,7 @@ class GPBase(Model):
|
|||
self.input_dim = state.pop()
|
||||
self.num_data = state.pop()
|
||||
self.X = state.pop()
|
||||
Model.__setstate__(self, state)
|
||||
Model.setstate(self, state)
|
||||
|
||||
def plot_f(self, samples=0, plot_limits=None, which_data='all', which_parts='all', resolution=None, full_cov=False, fignum=None, ax=None):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -6,50 +6,49 @@ from .. import likelihoods
|
|||
from ..inference import optimization
|
||||
from ..util.linalg import jitchol
|
||||
from GPy.util.misc import opt_wrapper
|
||||
from parameterised import Parameterised
|
||||
from parameterized import Parameterized
|
||||
import multiprocessing as mp
|
||||
import numpy as np
|
||||
from GPy.core.domains import POSITIVE, REAL
|
||||
from numpy.linalg.linalg import LinAlgError
|
||||
# import numdifftools as ndt
|
||||
|
||||
class Model(Parameterised):
|
||||
class Model(Parameterized):
|
||||
_fail_count = 0 # Count of failed optimization steps (see objective)
|
||||
_allowed_failures = 10 # number of allowed failures
|
||||
def __init__(self):
|
||||
Parameterised.__init__(self)
|
||||
Parameterized.__init__(self)
|
||||
self.priors = None
|
||||
self.optimization_runs = []
|
||||
self.sampling_runs = []
|
||||
self.preferred_optimizer = 'scg'
|
||||
# self._set_params(self._get_params()) has been taken out as it should only be called on leaf nodes
|
||||
def _get_params(self):
|
||||
raise NotImplementedError, "this needs to be implemented to use the Model class"
|
||||
def _set_params(self, x):
|
||||
raise NotImplementedError, "this needs to be implemented to use the Model class"
|
||||
def log_likelihood(self):
|
||||
raise NotImplementedError, "this needs to be implemented to use the Model class"
|
||||
def _log_likelihood_gradients(self):
|
||||
raise NotImplementedError, "this needs to be implemented to use the Model class"
|
||||
|
||||
def __getstate__(self):
|
||||
def getstate(self):
|
||||
"""
|
||||
Get the current state of the class,
|
||||
here just all the indices, rest can get recomputed
|
||||
Get the current state of the class.
|
||||
|
||||
Inherited from Parameterized, so add those parameters to the state
|
||||
"""
|
||||
return Parameterised.__getstate__(self) + \
|
||||
return Parameterized.getstate(self) + \
|
||||
[self.priors, self.optimization_runs,
|
||||
self.sampling_runs, self.preferred_optimizer]
|
||||
|
||||
def __setstate__(self, state):
|
||||
def setstate(self, state):
|
||||
"""
|
||||
set state from previous call to getstate
|
||||
|
||||
call Parameterized with the rest of the state
|
||||
"""
|
||||
self.preferred_optimizer = state.pop()
|
||||
self.sampling_runs = state.pop()
|
||||
self.optimization_runs = state.pop()
|
||||
self.priors = state.pop()
|
||||
Parameterised.__setstate__(self, state)
|
||||
Parameterized.setstate(self, state)
|
||||
|
||||
def set_prior(self, regexp, what):
|
||||
"""
|
||||
|
|
@ -355,7 +354,7 @@ class Model(Parameterised):
|
|||
return 0.5 * self._get_params().size * np.log(2 * np.pi) + self.log_likelihood() - hld
|
||||
|
||||
def __str__(self):
|
||||
s = Parameterised.__str__(self).split('\n')
|
||||
s = Parameterized.__str__(self).split('\n')
|
||||
# add priors to the string
|
||||
if self.priors is not None:
|
||||
strs = [str(p) if p is not None else '' for p in self.priors]
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import cPickle
|
|||
import warnings
|
||||
import transformations
|
||||
|
||||
class Parameterised(object):
|
||||
class Parameterized(object):
|
||||
def __init__(self):
|
||||
"""
|
||||
This is the base class for model and kernel. Mostly just handles tieing and constraining of parameters
|
||||
|
|
@ -20,19 +20,45 @@ class Parameterised(object):
|
|||
self.constrained_indices = []
|
||||
self.constraints = []
|
||||
|
||||
def pickle(self, filename, protocol= -1):
|
||||
f = file(filename, 'w')
|
||||
cPickle.dump(self, f, protocol)
|
||||
f.close()
|
||||
def _get_params(self):
|
||||
raise NotImplementedError, "this needs to be implemented to use the Model class"
|
||||
def _set_params(self, x):
|
||||
raise NotImplementedError, "this needs to be implemented to use the Model class"
|
||||
|
||||
def pickle(self, filename, protocol=None):
|
||||
if protocol is None:
|
||||
if self._has_get_set_state():
|
||||
protocol = 0
|
||||
else:
|
||||
protocol = -1
|
||||
with open(filename, 'w') as f:
|
||||
cPickle.dump(self, f, protocol)
|
||||
|
||||
def copy(self):
|
||||
"""Returns a (deep) copy of the current model """
|
||||
return copy.deepcopy(self)
|
||||
|
||||
def __getstate__(self):
|
||||
if self._has_get_set_state():
|
||||
return self.getstate()
|
||||
return self.__dict__
|
||||
|
||||
def __setstate__(self, state):
|
||||
if self._has_get_set_state():
|
||||
return self.setstate(state)
|
||||
self.__dict__ = state
|
||||
|
||||
def _has_get_set_state(self):
|
||||
return 'getstate' in vars(self.__class__) and 'setstate' in vars(self.__class__)
|
||||
|
||||
def getstate(self):
|
||||
"""
|
||||
Get the current state of the class,
|
||||
here just all the indices, rest can get recomputed
|
||||
|
||||
For inheriting from Parameterized:
|
||||
Allways append the state of the inherited object
|
||||
and call down to the inherited object in setstate!!
|
||||
"""
|
||||
return [self.tied_indices,
|
||||
self.fixed_indices,
|
||||
|
|
@ -40,54 +66,13 @@ class Parameterised(object):
|
|||
self.constrained_indices,
|
||||
self.constraints]
|
||||
|
||||
def __setstate__(self, state):
|
||||
def setstate(self, state):
|
||||
self.constraints = state.pop()
|
||||
self.constrained_indices = state.pop()
|
||||
self.fixed_values = state.pop()
|
||||
self.fixed_indices = state.pop()
|
||||
self.tied_indices = state.pop()
|
||||
|
||||
@property
|
||||
def params(self):
|
||||
"""
|
||||
Returns a **copy** of parameters in non transformed space
|
||||
|
||||
:see_also: :py:func:`GPy.core.Parameterised.params_transformed`
|
||||
"""
|
||||
return self._get_params()
|
||||
|
||||
@params.setter
|
||||
def params(self, params):
|
||||
self._set_params(params)
|
||||
|
||||
@property
|
||||
def params_transformed(self):
|
||||
"""
|
||||
Returns a **copy** of parameters in transformed space
|
||||
|
||||
:see_also: :py:func:`GPy.core.Parameterised.params`
|
||||
"""
|
||||
return self._get_params_transformed()
|
||||
|
||||
@params_transformed.setter
|
||||
def params_transformed(self, params):
|
||||
self._set_params_transformed(params)
|
||||
|
||||
_get_set_deprecation = """get and set methods wont be available at next minor release
|
||||
in the next releases you will get and set with following syntax:
|
||||
Assume m is a model class:
|
||||
print m['var'] # > prints all parameters matching 'var'
|
||||
m['var'] = 2. # > sets all parameters matching 'var' to 2.
|
||||
m['var'] = <array-like> # > sets parameters matching 'var' to <array-like>
|
||||
"""
|
||||
def get(self, regexp):
|
||||
warnings.warn(self._get_set_deprecation, FutureWarning, stacklevel=2)
|
||||
return self[regexp]
|
||||
|
||||
def set(self, regexp, val):
|
||||
warnings.warn(self._get_set_deprecation, FutureWarning, stacklevel=2)
|
||||
self[regexp] = val
|
||||
|
||||
def __getitem__(self, regexp, return_names=False):
|
||||
"""
|
||||
Get a model parameter by name. The name is applied as a regular
|
||||
|
|
@ -113,13 +98,16 @@ class Parameterised(object):
|
|||
if len(matches):
|
||||
val = np.array(val)
|
||||
assert (val.size == 1) or val.size == len(matches), "Shape mismatch: {}:({},)".format(val.size, len(matches))
|
||||
x = self.params
|
||||
x = self._get_params()
|
||||
x[matches] = val
|
||||
self.params = x
|
||||
self._set_params(x)
|
||||
else:
|
||||
raise AttributeError, "no parameter matches %s" % name
|
||||
|
||||
def tie_params(self, regexp):
|
||||
"""
|
||||
Tie (all!) parameters matching the regular expression `regexp`.
|
||||
"""
|
||||
matches = self.grep_param_names(regexp)
|
||||
assert matches.size > 0, "need at least something to tie together"
|
||||
if len(self.tied_indices):
|
||||
|
|
@ -50,22 +50,22 @@ class SparseGP(GPBase):
|
|||
if self.has_uncertain_inputs:
|
||||
self.X_variance /= np.square(self._Xscale)
|
||||
|
||||
def __getstate__(self):
|
||||
def getstate(self):
|
||||
"""
|
||||
Get the current state of the class,
|
||||
here just all the indices, rest can get recomputed
|
||||
"""
|
||||
return GPBase.__getstate__(self) + [self.Z,
|
||||
return GPBase.getstate(self) + [self.Z,
|
||||
self.num_inducing,
|
||||
self.has_uncertain_inputs,
|
||||
self.X_variance]
|
||||
|
||||
def __setstate__(self, state):
|
||||
def setstate(self, state):
|
||||
self.X_variance = state.pop()
|
||||
self.has_uncertain_inputs = state.pop()
|
||||
self.num_inducing = state.pop()
|
||||
self.Z = state.pop()
|
||||
GPBase.__setstate__(self, state)
|
||||
GPBase.setstate(self, state)
|
||||
|
||||
def _compute_kernel_matrices(self):
|
||||
# kernel computations, using BGPLVM notation
|
||||
|
|
|
|||
|
|
@ -91,6 +91,14 @@ class SVIGP(GPBase):
|
|||
self._param_steplength_trace = []
|
||||
self._vb_steplength_trace = []
|
||||
|
||||
def getstate(self):
|
||||
return GPBase.getstate(self)
|
||||
|
||||
|
||||
def setstate(self, state):
|
||||
return GPBase.setstate(self, state)
|
||||
|
||||
|
||||
def _compute_kernel_matrices(self):
|
||||
# kernel computations, using BGPLVM notation
|
||||
self.Kmm = self.kern.K(self.Z)
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
import numpy as np
|
||||
import pylab as pb
|
||||
from ..core.parameterised import Parameterised
|
||||
from ..core.parameterized import Parameterized
|
||||
from parts.kernpart import Kernpart
|
||||
import itertools
|
||||
from parts.prod import Prod as prod
|
||||
|
||||
class kern(Parameterised):
|
||||
class kern(Parameterized):
|
||||
def __init__(self, input_dim, parts=[], input_slices=None):
|
||||
"""
|
||||
This is the main kernel class for GPy. It handles multiple (additive) kernel functions, and keeps track of variaous things like which parameters live where.
|
||||
|
|
@ -41,14 +41,14 @@ class kern(Parameterised):
|
|||
|
||||
self.compute_param_slices()
|
||||
|
||||
Parameterised.__init__(self)
|
||||
Parameterized.__init__(self)
|
||||
|
||||
def __getstate__(self):
|
||||
def getstate(self):
|
||||
"""
|
||||
Get the current state of the class,
|
||||
here just all the indices, rest can get recomputed
|
||||
"""
|
||||
return Parameterised.__getstate__(self) + [self.parts,
|
||||
return Parameterized.getstate(self) + [self.parts,
|
||||
self.Nparts,
|
||||
self.num_params,
|
||||
self.input_dim,
|
||||
|
|
@ -56,14 +56,14 @@ class kern(Parameterised):
|
|||
self.param_slices
|
||||
]
|
||||
|
||||
def __setstate__(self, state):
|
||||
def setstate(self, state):
|
||||
self.param_slices = state.pop()
|
||||
self.input_slices = state.pop()
|
||||
self.input_dim = state.pop()
|
||||
self.num_params = state.pop()
|
||||
self.Nparts = state.pop()
|
||||
self.parts = state.pop()
|
||||
Parameterised.__setstate__(self, state)
|
||||
Parameterized.setstate(self, state)
|
||||
|
||||
|
||||
def plot_ARD(self, fignum=None, ax=None, title=None):
|
||||
|
|
|
|||
|
|
@ -48,16 +48,16 @@ class BayesianGPLVM(SparseGP, GPLVM):
|
|||
SparseGP.__init__(self, X, likelihood, kernel, Z=Z, X_variance=X_variance, **kwargs)
|
||||
self.ensure_default_constraints()
|
||||
|
||||
def __getstate__(self):
|
||||
def getstate(self):
|
||||
"""
|
||||
Get the current state of the class,
|
||||
here just all the indices, rest can get recomputed
|
||||
"""
|
||||
return SparseGP.__getstate__(self) + [self.init]
|
||||
return SparseGP.getstate(self) + [self.init]
|
||||
|
||||
def __setstate__(self, state):
|
||||
def setstate(self, state):
|
||||
self.init = state.pop()
|
||||
SparseGP.__setstate__(self, state)
|
||||
SparseGP.setstate(self, state)
|
||||
|
||||
def _get_param_names(self):
|
||||
X_names = sum([['X_%i_%i' % (n, q) for q in range(self.input_dim)] for n in range(self.num_data)], [])
|
||||
|
|
|
|||
|
|
@ -25,11 +25,20 @@ class GPRegression(GP):
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self,X,Y,kernel=None,normalize_X=False,normalize_Y=False):
|
||||
def __init__(self, X, Y, kernel=None, normalize_X=False, normalize_Y=False):
|
||||
if kernel is None:
|
||||
kernel = kern.rbf(X.shape[1])
|
||||
|
||||
likelihood = likelihoods.Gaussian(Y,normalize=normalize_Y)
|
||||
likelihood = likelihoods.Gaussian(Y, normalize=normalize_Y)
|
||||
|
||||
GP.__init__(self, X, likelihood, kernel, normalize_X=normalize_X)
|
||||
self.ensure_default_constraints()
|
||||
|
||||
def getstate(self):
|
||||
return GP.getstate(self)
|
||||
|
||||
|
||||
def setstate(self, state):
|
||||
return GP.setstate(self, state)
|
||||
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -84,8 +84,8 @@ class MRD(Model):
|
|||
Model.__init__(self)
|
||||
self.ensure_default_constraints()
|
||||
|
||||
def __getstate__(self):
|
||||
return Model.__getstate__(self) + [self.names,
|
||||
def getstate(self):
|
||||
return Model.getstate(self) + [self.names,
|
||||
self.bgplvms,
|
||||
self.gref,
|
||||
self.nparams,
|
||||
|
|
@ -95,7 +95,7 @@ class MRD(Model):
|
|||
self.NQ,
|
||||
self.MQ]
|
||||
|
||||
def __setstate__(self, state):
|
||||
def setstate(self, state):
|
||||
self.MQ = state.pop()
|
||||
self.NQ = state.pop()
|
||||
self.num_data = state.pop()
|
||||
|
|
@ -105,7 +105,7 @@ class MRD(Model):
|
|||
self.gref = state.pop()
|
||||
self.bgplvms = state.pop()
|
||||
self.names = state.pop()
|
||||
Model.__setstate__(self, state)
|
||||
Model.setstate(self, state)
|
||||
|
||||
@property
|
||||
def X(self):
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class SparseGPClassification(SparseGP):
|
|||
|
||||
def __init__(self, X, Y=None, likelihood=None, kernel=None, normalize_X=False, normalize_Y=False, Z=None, num_inducing=10):
|
||||
if kernel is None:
|
||||
kernel = kern.rbf(X.shape[1]) + kern.white(X.shape[1],1e-3)
|
||||
kernel = kern.rbf(X.shape[1]) + kern.white(X.shape[1], 1e-3)
|
||||
|
||||
if likelihood is None:
|
||||
distribution = likelihoods.likelihood_functions.Binomial()
|
||||
|
|
@ -41,7 +41,16 @@ class SparseGPClassification(SparseGP):
|
|||
i = np.random.permutation(X.shape[0])[:num_inducing]
|
||||
Z = X[i].copy()
|
||||
else:
|
||||
assert Z.shape[1]==X.shape[1]
|
||||
assert Z.shape[1] == X.shape[1]
|
||||
|
||||
SparseGP.__init__(self, X, likelihood, kernel, Z=Z, normalize_X=normalize_X)
|
||||
self.ensure_default_constraints()
|
||||
|
||||
def getstate(self):
|
||||
return SparseGP.getstate(self)
|
||||
|
||||
|
||||
def setstate(self, state):
|
||||
return SparseGP.setstate(self, state)
|
||||
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -43,3 +43,13 @@ class SparseGPRegression(SparseGP):
|
|||
|
||||
SparseGP.__init__(self, X, likelihood, kernel, Z=Z, normalize_X=normalize_X, X_variance=X_variance)
|
||||
self.ensure_default_constraints()
|
||||
pass
|
||||
|
||||
def getstate(self):
|
||||
return SparseGP.getstate(self)
|
||||
|
||||
|
||||
def setstate(self, state):
|
||||
return SparseGP.setstate(self, state)
|
||||
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -28,6 +28,14 @@ class SparseGPLVM(SparseGPRegression, GPLVM):
|
|||
SparseGPRegression.__init__(self, X, Y, kernel=kernel, num_inducing=num_inducing)
|
||||
self.ensure_default_constraints()
|
||||
|
||||
def getstate(self):
|
||||
return SparseGPRegression.getstate(self)
|
||||
|
||||
|
||||
def setstate(self, state):
|
||||
return SparseGPRegression.setstate(self, state)
|
||||
|
||||
|
||||
def _get_param_names(self):
|
||||
return (sum([['X_%i_%i' % (n, q) for q in range(self.input_dim)] for n in range(self.num_data)], [])
|
||||
+ SparseGPRegression._get_param_names(self))
|
||||
|
|
|
|||
|
|
@ -42,3 +42,11 @@ class SVIGPRegression(SVIGP):
|
|||
|
||||
SVIGP.__init__(self, X, likelihood, kernel, Z, q_u=q_u, batchsize=batchsize)
|
||||
self.load_batch()
|
||||
|
||||
def getstate(self):
|
||||
return GPBase.getstate(self)
|
||||
|
||||
|
||||
def setstate(self, state):
|
||||
return GPBase.setstate(self, state)
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,14 @@ class WarpedGP(GP):
|
|||
GP.__init__(self, X, likelihood, kernel, normalize_X=normalize_X)
|
||||
self._set_params(self._get_params())
|
||||
|
||||
def getstate(self):
|
||||
return GP.getstate(self)
|
||||
|
||||
|
||||
def setstate(self, state):
|
||||
return GP.setstate(self, state)
|
||||
|
||||
|
||||
def _scale_data(self, Y):
|
||||
self._Ymax = Y.max()
|
||||
self._Ymin = Y.min()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,38 @@ core Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`domains` Module
|
||||
---------------------
|
||||
|
||||
.. automodule:: GPy.core.domains
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`fitc` Module
|
||||
------------------
|
||||
|
||||
.. automodule:: GPy.core.fitc
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`gp` Module
|
||||
----------------
|
||||
|
||||
.. automodule:: GPy.core.gp
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`gp_base` Module
|
||||
---------------------
|
||||
|
||||
.. automodule:: GPy.core.gp_base
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`model` Module
|
||||
-------------------
|
||||
|
||||
|
|
@ -17,10 +49,10 @@ core Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`parameterised` Module
|
||||
:mod:`parameterized` Module
|
||||
---------------------------
|
||||
|
||||
.. automodule:: GPy.core.parameterised
|
||||
.. automodule:: GPy.core.parameterized
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
|
@ -33,3 +65,27 @@ core Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`sparse_gp` Module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.core.sparse_gp
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`svigp` Module
|
||||
-------------------
|
||||
|
||||
.. automodule:: GPy.core.svigp
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`transformations` Module
|
||||
-----------------------------
|
||||
|
||||
.. automodule:: GPy.core.transformations
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
|
|
|||
|
|
@ -25,14 +25,6 @@ examples Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`non_gaussian` Module
|
||||
--------------------------
|
||||
|
||||
.. automodule:: GPy.examples.non_gaussian
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`regression` Module
|
||||
------------------------
|
||||
|
||||
|
|
@ -41,6 +33,14 @@ examples Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`stochastic` Module
|
||||
------------------------
|
||||
|
||||
.. automodule:: GPy.examples.stochastic
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`tutorials` Module
|
||||
-----------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
inference Package
|
||||
=================
|
||||
|
||||
:mod:`SGD` Module
|
||||
-----------------
|
||||
:mod:`conjugate_gradient_descent` Module
|
||||
----------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.SGD
|
||||
.. automodule:: GPy.inference.conjugate_gradient_descent
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`gradient_descent_update_rules` Module
|
||||
-------------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.gradient_descent_update_rules
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
|
@ -25,3 +33,19 @@ inference Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`scg` Module
|
||||
-----------------
|
||||
|
||||
.. automodule:: GPy.inference.scg
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`sgd` Module
|
||||
-----------------
|
||||
|
||||
.. automodule:: GPy.inference.sgd
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
|
|
|||
161
doc/GPy.kern.rst
161
doc/GPy.kern.rst
|
|
@ -9,38 +9,6 @@ kern Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`Brownian` Module
|
||||
----------------------
|
||||
|
||||
.. automodule:: GPy.kern.Brownian
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`Matern32` Module
|
||||
----------------------
|
||||
|
||||
.. automodule:: GPy.kern.Matern32
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`Matern52` Module
|
||||
----------------------
|
||||
|
||||
.. automodule:: GPy.kern.Matern52
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`bias` Module
|
||||
------------------
|
||||
|
||||
.. automodule:: GPy.kern.bias
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`constructors` Module
|
||||
--------------------------
|
||||
|
||||
|
|
@ -49,30 +17,6 @@ kern Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`coregionalise` Module
|
||||
---------------------------
|
||||
|
||||
.. automodule:: GPy.kern.coregionalise
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`exponential` Module
|
||||
-------------------------
|
||||
|
||||
.. automodule:: GPy.kern.exponential
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`finite_dimensional` Module
|
||||
--------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.finite_dimensional
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`kern` Module
|
||||
------------------
|
||||
|
||||
|
|
@ -81,107 +25,10 @@ kern Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`kernpart` Module
|
||||
----------------------
|
||||
Subpackages
|
||||
-----------
|
||||
|
||||
.. automodule:: GPy.kern.kernpart
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
.. toctree::
|
||||
|
||||
:mod:`linear` Module
|
||||
--------------------
|
||||
|
||||
.. automodule:: GPy.kern.linear
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`periodic_Matern32` Module
|
||||
-------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.periodic_Matern32
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`periodic_Matern52` Module
|
||||
-------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.periodic_Matern52
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`periodic_exponential` Module
|
||||
----------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.periodic_exponential
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`prod` Module
|
||||
------------------
|
||||
|
||||
.. automodule:: GPy.kern.prod
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`prod_orthogonal` Module
|
||||
-----------------------------
|
||||
|
||||
.. automodule:: GPy.kern.prod_orthogonal
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`rational_quadratic` Module
|
||||
--------------------------------
|
||||
|
||||
.. automodule:: GPy.kern.rational_quadratic
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`rbf` Module
|
||||
-----------------
|
||||
|
||||
.. automodule:: GPy.kern.rbf
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`spline` Module
|
||||
--------------------
|
||||
|
||||
.. automodule:: GPy.kern.spline
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`symmetric` Module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.kern.symmetric
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`sympykern` Module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.kern.sympykern
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`white` Module
|
||||
-------------------
|
||||
|
||||
.. automodule:: GPy.kern.white
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
GPy.kern.parts
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ likelihoods Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`EP` Module
|
||||
:mod:`ep` Module
|
||||
----------------
|
||||
|
||||
.. automodule:: GPy.likelihoods.ep
|
||||
|
|
@ -17,7 +17,7 @@ likelihoods Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`Gaussian` Module
|
||||
:mod:`gaussian` Module
|
||||
----------------------
|
||||
|
||||
.. automodule:: GPy.likelihoods.gaussian
|
||||
|
|
@ -41,3 +41,11 @@ likelihoods Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`link_functions` Module
|
||||
----------------------------
|
||||
|
||||
.. automodule:: GPy.likelihoods.link_functions
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ models Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`Bayesian_GPLVM` Module
|
||||
:mod:`bayesian_gplvm` Module
|
||||
----------------------------
|
||||
|
||||
.. automodule:: GPy.models.bayesian_gplvm
|
||||
|
|
@ -17,18 +17,18 @@ models Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`gp` Module
|
||||
----------------
|
||||
:mod:`fitc_classification` Module
|
||||
---------------------------------
|
||||
|
||||
.. automodule:: GPy.models.gp
|
||||
.. automodule:: GPy.models.fitc_classification
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`gplvm` Module
|
||||
-------------------
|
||||
:mod:`gp_classification` Module
|
||||
-------------------------------
|
||||
|
||||
.. automodule:: GPy.models.gplvm
|
||||
.. automodule:: GPy.models.gp_classification
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
|
@ -41,18 +41,26 @@ models Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`sparse_gp` Module
|
||||
-----------------------
|
||||
:mod:`gplvm` Module
|
||||
-------------------
|
||||
|
||||
.. automodule:: GPy.models.sparse_gp
|
||||
.. automodule:: GPy.models.gplvm
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`SparseGPLVM` Module
|
||||
--------------------------
|
||||
:mod:`mrd` Module
|
||||
-----------------
|
||||
|
||||
.. automodule:: GPy.models.sparse_gplvm
|
||||
.. automodule:: GPy.models.mrd
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`sparse_gp_classification` Module
|
||||
--------------------------------------
|
||||
|
||||
.. automodule:: GPy.models.sparse_gp_classification
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
|
@ -65,13 +73,21 @@ models Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
.. :mod:`uncollapsed_sparse_GP` Module
|
||||
.. -----------------------------------
|
||||
:mod:`sparse_gplvm` Module
|
||||
--------------------------
|
||||
|
||||
.. .. automodule:: GPy.models.uncollapsed_sparse_GP
|
||||
.. :members:
|
||||
.. :undoc-members:
|
||||
.. :show-inheritance:
|
||||
.. automodule:: GPy.models.sparse_gplvm
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`svigp_regression` Module
|
||||
------------------------------
|
||||
|
||||
.. automodule:: GPy.models.svigp_regression
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`warped_gp` Module
|
||||
-----------------------
|
||||
|
|
|
|||
|
|
@ -1,6 +1,14 @@
|
|||
testing Package
|
||||
===============
|
||||
|
||||
:mod:`testing` Package
|
||||
----------------------
|
||||
|
||||
.. automodule:: GPy.testing
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`bgplvm_tests` Module
|
||||
--------------------------
|
||||
|
||||
|
|
@ -9,6 +17,22 @@ testing Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`cgd_tests` Module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.testing.cgd_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`checkgrad` Module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.testing.checkgrad
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`examples_tests` Module
|
||||
----------------------------
|
||||
|
||||
|
|
@ -33,6 +57,14 @@ testing Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`mrd_tests` Module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.testing.mrd_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`prior_tests` Module
|
||||
-------------------------
|
||||
|
||||
|
|
@ -41,6 +73,22 @@ testing Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`psi_stat_expactation_tests` Module
|
||||
----------------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.psi_stat_expactation_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`psi_stat_gradient_tests` Module
|
||||
-------------------------------------
|
||||
|
||||
.. automodule:: GPy.testing.psi_stat_gradient_tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`sparse_gplvm_tests` Module
|
||||
--------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,14 @@ util Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`classification` Module
|
||||
----------------------------
|
||||
|
||||
.. automodule:: GPy.util.classification
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`datasets` Module
|
||||
----------------------
|
||||
|
||||
|
|
@ -25,6 +33,14 @@ util Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`decorators` Module
|
||||
------------------------
|
||||
|
||||
.. automodule:: GPy.util.decorators
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`linalg` Module
|
||||
--------------------
|
||||
|
||||
|
|
@ -41,6 +57,22 @@ util Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`mocap` Module
|
||||
-------------------
|
||||
|
||||
.. automodule:: GPy.util.mocap
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`pca` Module
|
||||
-----------------
|
||||
|
||||
.. automodule:: GPy.util.pca
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`plot` Module
|
||||
------------------
|
||||
|
||||
|
|
@ -49,6 +81,14 @@ util Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`plot_latent` Module
|
||||
-------------------------
|
||||
|
||||
.. automodule:: GPy.util.plot_latent
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`squashers` Module
|
||||
-----------------------
|
||||
|
||||
|
|
@ -57,6 +97,22 @@ util Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`univariate_Gaussian` Module
|
||||
---------------------------------
|
||||
|
||||
.. automodule:: GPy.util.univariate_Gaussian
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`visualize` Module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.util.visualize
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`warping_functions` Module
|
||||
-------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -103,8 +103,10 @@ class Mock(object):
|
|||
#import mock
|
||||
|
||||
print "Mocking"
|
||||
MOCK_MODULES = ['pylab', 'sympy', 'sympy.utilities', 'sympy.utilities.codegen', 'sympy.core.cache', 'sympy.core', 'sympy.parsing', 'sympy.parsing.sympy_parser', 'matplotlib']
|
||||
#'matplotlib', 'matplotlib.color', 'matplotlib.pyplot', 'pylab' ]
|
||||
MOCK_MODULES = ['sympy',
|
||||
'sympy.utilities', 'sympy.utilities.codegen', 'sympy.core.cache',
|
||||
'sympy.core', 'sympy.parsing', 'sympy.parsing.sympy_parser',
|
||||
]
|
||||
for mod_name in MOCK_MODULES:
|
||||
sys.modules[mod_name] = Mock()
|
||||
|
||||
|
|
@ -288,7 +290,7 @@ latex_elements = {
|
|||
#'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#'preamble': '',
|
||||
'preamble': '\\usepackage{MnSymbol}',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ For a quick start, you can have a look at one of the tutorials:
|
|||
* `Interacting with models <tuto_interacting_with_models.html>`_
|
||||
* `A kernel overview <tuto_kernel_overview.html>`_
|
||||
* `Writing new kernels <tuto_creating_new_kernels.html>`_
|
||||
* `Writing new models <tuto_creating_new_models.html>`_
|
||||
|
||||
You may also be interested by some examples in the GPy/examples folder.
|
||||
|
||||
|
|
|
|||
64
doc/tuto_creating_new_models.rst
Normal file
64
doc/tuto_creating_new_models.rst
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
.. _creating_new_models:
|
||||
|
||||
*******************
|
||||
Creating new Models
|
||||
*******************
|
||||
|
||||
In GPy all models inherit from the base class :py:class:`~GPy.core.parameterized.Parameterized`. :py:class:`~GPy.core.parameterized.Parameterized` is a class which allows for parameterization of objects. All it holds is functionality for tying, bounding and fixing of parameters. It also provides the functionality of searching and manipulating parameters by regular expression syntax. See :py:class:`~GPy.core.parameterized.Parameterized` for more information.
|
||||
|
||||
The :py:class:`~GPy.core.model.Model` class provides parameter introspection, objective function and optimization.
|
||||
|
||||
In order to fully use all functionality of :py:class:`~GPy.core.model.Model` some methods need to be implemented / overridden. In order to explain the functionality of those methods we will use a wrapper to the numpy ``rosen`` function, which holds input parameters :math:`\mathbf{X}`. Where :math:`\mathbf{X}\in\mathbb{R}^{N\times 1}`.
|
||||
|
||||
Obligatory methods
|
||||
==================
|
||||
|
||||
:py:meth:`~GPy.core.model.Model.__init__` :
|
||||
Initialize the model with the given parameters. In our example we have to store shape information of :math:`\mathbf X` and the parameters themselves::
|
||||
|
||||
self.X = X
|
||||
self.num_inputs = self.X.shape[0]
|
||||
assert self.X.ndim == 1, only vector inputs allowed
|
||||
|
||||
:py:meth:`~GPy.core.model.Model._get_params` :
|
||||
Return parameters of the model as a flattened numpy array-like. So, in our example we have to return the input parameters::
|
||||
|
||||
return self.X.flatten()
|
||||
|
||||
:py:meth:`~GPy.core.model.Model._set_params` :
|
||||
Set parameters, which have been fetched through :py:meth:`~GPy.core.model.Model._get_params`. In other words, "invert" the functionality of :py:meth:`~GPy.core.model.Model._get_params`::
|
||||
|
||||
self.X = params[:self.num_inputs*self.input_dim].reshape(self.num_inputs)
|
||||
|
||||
:py:meth:`~GPy.core.model.Model.log_likelihood` :
|
||||
Returns the log-likelihood of the new model. For our example this is just the call to ``rosen``::
|
||||
|
||||
return scipy.optimize.rosen(self.X)
|
||||
|
||||
:py:meth:`~GPy.core.model.Model._log_likelihood_gradients` :
|
||||
Returns the gradients with respect to all parameters::
|
||||
|
||||
return scipy.optimize.rosen_der(self.X)
|
||||
|
||||
|
||||
Optional methods
|
||||
================
|
||||
|
||||
If you want some special functionality please provide the following methods:
|
||||
|
||||
Using the pickle functionality
|
||||
------------------------------
|
||||
|
||||
To be able to use the pickle functionality ``m.pickle(<path>)`` the methods ``getstate(self)`` and ``setstate(self, state)`` have to be provided. The convention for a ``state`` in ``GPy`` is a list of all parameters, which are needed to restore the model. All classes provided in ``GPy`` follow this convention, thus you can just append to the state of the inherited class and call the inherited class' ``setstate`` with the appropriate state.
|
||||
|
||||
:py:meth:`~GPy.core.model.Model.getstate` :
|
||||
This method returns a state of the model, following the memento pattern. As we are inheriting from :py:class:`~GPy.core.model.Model`, we have to return the state of Model as well. In out example we have `X` and `num_inputs` as state::
|
||||
|
||||
return Model.getstate(self) + [self.X, self.num_inputs]
|
||||
|
||||
:py:meth:`~GPy.core.model.Model.setstate` :
|
||||
This method restores this model with the given ``state``::
|
||||
|
||||
self.num_inputs = state.pop()
|
||||
self.X = state.pop()
|
||||
return Model.setstate(self, state)
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
.. _interacting_with_models:
|
||||
|
||||
*************************************
|
||||
Interacting with models
|
||||
*************************************
|
||||
|
|
@ -210,6 +212,6 @@ white_variance and noise_variance are tied together.::
|
|||
|
||||
Further Reading
|
||||
===============
|
||||
All of the mechansiams for dealing with parameters are baked right into GPy.core.model, from which all of the classes in GPy.models inherrit. To learn how to construct your own model, you might want to read ??link?? creating_new_models.
|
||||
All of the mechansiams for dealing with parameters are baked right into GPy.core.model, from which all of the classes in GPy.models inherrit. To learn how to construct your own model, you might want to read :ref:`creating_new_models`.
|
||||
|
||||
By deafult, GPy uses the tnc optimizer (from scipy.optimize.tnc). To use other optimisers, and to control the setting of those optimisers, as well as other funky features like automated restarts and diagnostics, you can read the optimization tutorial ??link??.
|
||||
By deafult, GPy uses the scg optimizer. To use other optimisers, and to control the setting of those optimisers, as well as other funky features like automated restarts and diagnostics, you can read the optimization tutorial ??link??.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue