mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-27 14:25:16 +02:00
Merge branch 'devel' of github.com:SheffieldML/GPy into devel
This commit is contained in:
commit
3a97e253bf
10 changed files with 73 additions and 39 deletions
|
|
@ -18,8 +18,6 @@ import numpy as np
|
|||
import re
|
||||
import logging
|
||||
|
||||
__updated__ = '2014-11-03'
|
||||
|
||||
class HierarchyError(Exception):
|
||||
"""
|
||||
Gets thrown when something is wrong with the parameter hierarchy.
|
||||
|
|
@ -896,6 +894,7 @@ class OptimizationHandlable(Indexable):
|
|||
def _connect_parameters(self):
|
||||
pass
|
||||
|
||||
_name_digit = re.compile("(?P<name>.*)_(?P<digit>\d+)$")
|
||||
class Parameterizable(OptimizationHandlable):
|
||||
"""
|
||||
A parameterisable class.
|
||||
|
|
@ -1022,29 +1021,38 @@ class Parameterizable(OptimizationHandlable):
|
|||
self.__dict__[pname] = param
|
||||
return
|
||||
|
||||
def warn_and_retry():
|
||||
print """
|
||||
WARNING: added a parameter with formatted name {},
|
||||
which is already assigned to {}.
|
||||
Trying to change the parameter name to
|
||||
|
||||
{}.{}
|
||||
""".format(pname, self.hierarchy_name(), self.hierarchy_name(), param.name + "_")
|
||||
param.name += "_"
|
||||
def warn_and_retry(param, match=None):
|
||||
#===================================================================
|
||||
# print """
|
||||
# WARNING: added a parameter with formatted name {},
|
||||
# which is already assigned to {}.
|
||||
# Trying to change the parameter name to
|
||||
#
|
||||
# {}.{}
|
||||
# """.format(pname, self.hierarchy_name(), self.hierarchy_name(), param.name + "_")
|
||||
#===================================================================
|
||||
if match is None:
|
||||
param.name += "_1"
|
||||
else:
|
||||
param.name = match.group('name') + "_" + str(int(match.group('digit'))+1)
|
||||
self._add_parameter_name(param, ignore_added_names)
|
||||
# and makes sure to not delete programmatically added parameters
|
||||
if pname in self.__dict__:
|
||||
if not (param is self.__dict__[pname]):
|
||||
if pname in self._added_names_:
|
||||
del self.__dict__[pname]
|
||||
self._add_parameter_name(param)
|
||||
else:
|
||||
warn_and_retry()
|
||||
elif pname not in dir(self):
|
||||
for other in self.parameters[::-1]:
|
||||
if other is not param and other.name.startswith(param.name):
|
||||
warn_and_retry(param, _name_digit.match(other.name))
|
||||
return
|
||||
if pname not in dir(self):
|
||||
self.__dict__[pname] = param
|
||||
self._added_names_.add(pname)
|
||||
else:
|
||||
warn_and_retry()
|
||||
elif pname in self.__dict__:
|
||||
if pname in self._added_names_:
|
||||
other = self.__dict__[pname]
|
||||
if not (param is other):
|
||||
del self.__dict__[pname]
|
||||
self._added_names_.remove(pname)
|
||||
warn_and_retry(other)
|
||||
warn_and_retry(param, _name_digit.match(other.name))
|
||||
return
|
||||
|
||||
def _remove_parameter_name(self, param=None, pname=None):
|
||||
assert param is None or pname is None, "can only delete either param by name, or the name of a param"
|
||||
|
|
|
|||
|
|
@ -76,12 +76,14 @@ class VarDTC(LatentFunctionInference):
|
|||
# VVT_factor is a matrix such that tdot(VVT_factor) = VVT...this is for efficiency!
|
||||
#self.YYTfactor = self.get_YYTfactor(Y)
|
||||
#VVT_factor = self.get_VVTfactor(self.YYTfactor, beta)
|
||||
het_noise = beta.size > 1
|
||||
if beta.ndim == 1:
|
||||
beta = beta[:, None]
|
||||
VVT_factor = beta*Y
|
||||
#VVT_factor = beta*Y
|
||||
trYYT = self.get_trYYT(Y)
|
||||
|
||||
# do the inference:
|
||||
het_noise = beta.size > 1
|
||||
num_inducing = Z.shape[0]
|
||||
num_data = Y.shape[0]
|
||||
# kernel computations, using BGPLVM notation
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class MixedNoise(Likelihood):
|
|||
variance = np.zeros(ind.size)
|
||||
for lik, j in zip(self.likelihoods_list, range(len(self.likelihoods_list))):
|
||||
variance[ind==j] = lik.variance
|
||||
return variance[:,None]
|
||||
return variance
|
||||
|
||||
def betaY(self,Y,Y_metadata):
|
||||
#TODO not here.
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class GPCoregionalizedRegression(GP):
|
|||
:param kernel_name: name of the kernel
|
||||
:type kernel_name: string
|
||||
"""
|
||||
def __init__(self, X_list, Y_list, kernel=None, likelihoods_list=None, name='GPCR',W_rank=1,kernel_name='X'):
|
||||
def __init__(self, X_list, Y_list, kernel=None, likelihoods_list=None, name='GPCR',W_rank=1,kernel_name='coreg'):
|
||||
|
||||
#Input and Output
|
||||
X,Y,self.output_index = util.multioutput.build_XY(X_list,Y_list)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class GPLVM(GP):
|
|||
|
||||
|
||||
"""
|
||||
def __init__(self, Y, input_dim, init='PCA', X=None, kernel=None, normalize_Y=False, name="gplvm"):
|
||||
def __init__(self, Y, input_dim, init='PCA', X=None, kernel=None, name="gplvm"):
|
||||
|
||||
"""
|
||||
:param Y: observed data
|
||||
|
|
@ -68,7 +68,7 @@ class GPLVM(GP):
|
|||
def plot_latent(self, labels=None, which_indices=None,
|
||||
resolution=50, ax=None, marker='o', s=40,
|
||||
fignum=None, legend=True,
|
||||
plot_limits=None,
|
||||
plot_limits=None,
|
||||
aspect='auto', updates=False, **kwargs):
|
||||
import sys
|
||||
assert "matplotlib" in sys.modules, "matplotlib package has not been imported."
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class SparseGPCoregionalizedRegression(SparseGP):
|
|||
:type kernel_name: string
|
||||
"""
|
||||
|
||||
def __init__(self, X_list, Y_list, Z_list=[], kernel=None, likelihoods_list=None, num_inducing=10, X_variance=None, name='SGPCR',W_rank=1,kernel_name='X'):
|
||||
def __init__(self, X_list, Y_list, Z_list=[], kernel=None, likelihoods_list=None, num_inducing=10, X_variance=None, name='SGPCR',W_rank=1,kernel_name='coreg'):
|
||||
|
||||
#Input and Output
|
||||
X,Y,self.output_index = util.multioutput.build_XY(X_list,Y_list)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class Kern_check_model(GPy.core.Model):
|
|||
"""
|
||||
def __init__(self, kernel=None, dL_dK=None, X=None, X2=None):
|
||||
GPy.core.Model.__init__(self, 'kernel_test_model')
|
||||
np.random.seed()
|
||||
if kernel==None:
|
||||
kernel = GPy.kern.RBF(1)
|
||||
if X is None:
|
||||
|
|
|
|||
|
|
@ -377,17 +377,14 @@ class GradientTests(np.testing.TestCase):
|
|||
m = GPy.models.GPLVM(Y, input_dim, init='PCA', kernel=k)
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_GP_EP_probit(self):
|
||||
N = 20
|
||||
X = np.hstack([np.random.normal(5, 2, N / 2), np.random.normal(10, 2, N / 2)])[:, None]
|
||||
Y = np.hstack([np.ones(N / 2), np.zeros(N / 2)])[:, None]
|
||||
kernel = GPy.kern.RBF(1)
|
||||
m = GPy.models.GPClassification(X, Y, kernel=kernel)
|
||||
m.update_likelihood_approximation()
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_sparse_EP_DTC_probit(self):
|
||||
N = 20
|
||||
X = np.hstack([np.random.normal(5, 2, N / 2), np.random.normal(10, 2, N / 2)])[:, None]
|
||||
|
|
@ -399,7 +396,6 @@ class GradientTests(np.testing.TestCase):
|
|||
# likelihood = GPy.likelihoods.EP(Y, distribution)
|
||||
# m = GPy.core.SparseGP(X, likelihood, kernel, Z)
|
||||
# m.ensure_default_constraints()
|
||||
m.update_likelihood_approximation()
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
@unittest.expectedFailure
|
||||
|
|
@ -412,7 +408,8 @@ class GradientTests(np.testing.TestCase):
|
|||
m.update_likelihood_approximation()
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
def multioutput_regression_1D(self):
|
||||
@unittest.expectedFailure
|
||||
def test_multioutput_regression_1D(self):
|
||||
X1 = np.random.rand(50, 1) * 8
|
||||
X2 = np.random.rand(30, 1) * 5
|
||||
X = np.vstack((X1, X2))
|
||||
|
|
@ -422,10 +419,12 @@ class GradientTests(np.testing.TestCase):
|
|||
|
||||
k1 = GPy.kern.RBF(1)
|
||||
m = GPy.models.GPMultioutputRegression(X_list=[X1, X2], Y_list=[Y1, Y2], kernel_list=[k1])
|
||||
import ipdb;ipdb.set_trace()
|
||||
m.constrain_fixed('.*rbf_var', 1.)
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
def multioutput_sparse_regression_1D(self):
|
||||
@unittest.expectedFailure
|
||||
def test_multioutput_sparse_regression_1D(self):
|
||||
X1 = np.random.rand(500, 1) * 8
|
||||
X2 = np.random.rand(300, 1) * 5
|
||||
X = np.vstack((X1, X2))
|
||||
|
|
@ -447,6 +446,21 @@ class GradientTests(np.testing.TestCase):
|
|||
m = GPy.models.GPHeteroscedasticRegression(X, Y, kern)
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
def test_sparse_gp_heteroscedastic_regression(self):
|
||||
num_obs = 25
|
||||
X = np.random.randint(0, 140, num_obs)
|
||||
X = X[:, None]
|
||||
Y = 25. + np.sin(X / 20.) * 2. + np.random.rand(num_obs)[:, None]
|
||||
kern = GPy.kern.Bias(1) + GPy.kern.RBF(1)
|
||||
Y_metadata = {'output_index':np.arange(num_obs)[:,None]}
|
||||
noise_terms = np.unique(Y_metadata['output_index'].flatten())
|
||||
likelihoods_list = [GPy.likelihoods.Gaussian(name="Gaussian_noise_%s" %j) for j in noise_terms]
|
||||
likelihood = GPy.likelihoods.MixedNoise(likelihoods_list=likelihoods_list)
|
||||
m = GPy.core.SparseGP(X, Y, X[np.random.choice(num_obs, 10)],
|
||||
kern, likelihood,
|
||||
GPy.inference.latent_function_inference.VarDTC(),
|
||||
Y_metadata=Y_metadata)
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
def test_gp_kronecker_gaussian(self):
|
||||
N1, N2 = 30, 20
|
||||
|
|
|
|||
|
|
@ -16,5 +16,4 @@ import diag
|
|||
import initialization
|
||||
import multioutput
|
||||
import linalg_gpu
|
||||
import mpi
|
||||
|
||||
|
|
|
|||
20
setup.py
20
setup.py
|
|
@ -5,9 +5,8 @@ import os
|
|||
from setuptools import setup
|
||||
|
||||
# Version number
|
||||
version = '0.4.6'
|
||||
version = '0.6.0'
|
||||
|
||||
from pkg_resources import Requirement
|
||||
def read(fname):
|
||||
return open(os.path.join(os.path.dirname(__file__), fname)).read()
|
||||
|
||||
|
|
@ -19,14 +18,25 @@ setup(name = 'GPy',
|
|||
license = "BSD 3-clause",
|
||||
keywords = "machine-learning gaussian-processes kernels",
|
||||
url = "http://sheffieldml.github.com/GPy/",
|
||||
packages = ["GPy.models", "GPy.inference.optimization", "GPy.inference", "GPy.inference.latent_function_inference", "GPy.likelihoods", "GPy.mappings", "GPy.examples", "GPy.core.parameterization", "GPy.core", "GPy.testing", "GPy", "GPy.util", "GPy.kern", "GPy.kern._src.psi_comp", "GPy.kern._src", "GPy.plotting.matplot_dep.latent_space_visualizations.controllers", "GPy.plotting.matplot_dep.latent_space_visualizations", "GPy.plotting.matplot_dep", "GPy.plotting"],
|
||||
packages = ["GPy.models",
|
||||
"GPy.inference.optimization",
|
||||
"GPy.inference",
|
||||
"GPy.inference.latent_function_inference",
|
||||
"GPy.likelihoods", "GPy.mappings",
|
||||
"GPy.examples", "GPy.core.parameterization",
|
||||
"GPy.core", "GPy.testing",
|
||||
"GPy", "GPy.util", "GPy.kern",
|
||||
"GPy.kern._src.psi_comp", "GPy.kern._src",
|
||||
"GPy.plotting.matplot_dep.latent_space_visualizations.controllers",
|
||||
"GPy.plotting.matplot_dep.latent_space_visualizations",
|
||||
"GPy.plotting.matplot_dep", "GPy.plotting"],
|
||||
package_dir={'GPy': 'GPy'},
|
||||
package_data = {'GPy': ['defaults.cfg', 'installation.cfg', 'util/data_resources.json', 'util/football_teams.json']},
|
||||
py_modules = ['GPy.__init__'],
|
||||
long_description=read('README.md'),
|
||||
install_requires=['numpy>=1.6', 'scipy>=0.9'],
|
||||
install_requires=['numpy>=1.8', 'scipy>=0.14'],
|
||||
extras_require = {
|
||||
'docs':['matplotlib>=1.1','Sphinx','ipython'],
|
||||
'docs':['matplotlib>=1.4','Sphinx','ipython'],
|
||||
},
|
||||
classifiers=[
|
||||
"License :: OSI Approved :: BSD License"],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue