Merge branch 'devel' of github.com:SheffieldML/GPy into devel

This commit is contained in:
Zhenwen Dai 2014-11-03 16:04:59 +00:00
commit 105a6c5377
19 changed files with 138 additions and 464 deletions

View file

@ -415,7 +415,6 @@ def mrd_simulation(optimize=True, verbose=True, plot=True, plot_sim=True, **kw):
def mrd_simulation_missing_data(optimize=True, verbose=True, plot=True, plot_sim=True, **kw):
from GPy import kern
from GPy.models import MRD
from GPy.inference.latent_function_inference.var_dtc import VarDTCMissingData
D1, D2, D3, N, num_inducing, Q = 60, 20, 36, 60, 6, 5
_, _, Ylist = _simulate_matern(D1, D2, D3, N, num_inducing, plot_sim)
@ -429,12 +428,8 @@ def mrd_simulation_missing_data(optimize=True, verbose=True, plot=True, plot_sim
inanlist.append(inan)
Y[inan] = _np.nan
imlist = []
for inan in inanlist:
imlist.append(VarDTCMissingData(limit=1, inan=inan))
m = MRD(Ylist, input_dim=Q, num_inducing=num_inducing,
kernel=k, inference_method=imlist,
kernel=k, inference_method=None,
initx="random", initz='permute', **kw)
if optimize:
@ -494,7 +489,7 @@ def olivetti_faces(optimize=True, verbose=True, plot=True):
def stick_play(range=None, frame_rate=15, optimize=False, verbose=True, plot=True):
import GPy
import pods
import pods
data = pods.datasets.osu_run1()
# optimize

View file

@ -167,7 +167,7 @@ class VarDTC(LatentFunctionInference):
woodbury_vector = Cpsi1Vf # == Cpsi1V
else:
print 'foobar'
stop
import ipdb; ipdb.set_trace()
psi1V = np.dot(Y.T*beta, psi1).T
tmp, _ = dtrtrs(Lm, psi1V, lower=1, trans=0)
tmp, _ = dpotrs(LB, tmp, lower=1)

View file

@ -1,47 +0,0 @@
# Copyright (c) 2014 The GPy authors (see AUTHORS.txt)
# Licensed under the BSD 3-clause license (see LICENSE.txt)
import sympy as sym
from GPy.util.symbolic import gammaln, normcdfln, normcdf, IndMatrix, create_matrix
import numpy as np
import link_functions
from symbolic import Symbolic
from scipy import stats
class Ordinal(Symbolic):
"""
Ordinal
.. math::
p(y_{i}|\pi(f_{i})) = \left(\frac{r}{r+f_i}\right)^r \frac{\Gamma(r+y_i)}{y!\Gamma(r)}\left(\frac{f_i}{r+f_i}\right)^{y_i}
.. Note::
Y takes non zero integer values..
link function should have a positive domain, e.g. log (default).
.. See also::
symbolic.py, for the parent class
"""
def __init__(self, categories=3, gp_link=None):
if gp_link is None:
gp_link = link_functions.Identity()
dispersion = sym.Symbol('width', positive=True, real=True)
y_0 = sym.Symbol('y_0', nonnegative=True, integer=True)
f_0 = sym.Symbol('f_0', positive=True, real=True)
log_pdf = create_matrix('log_pdf', 1, categories)
log_pdf[0] = normcdfln(-f_0)
if categories>2:
w = create_matrix('w', 1, categories)
log_pdf[categories-1] = normcdfln(w.sum() + f_0)
for i in range(1, categories-1):
log_pdf[i] = sym.log(normcdf(w[0, 0:i-1].sum() + f_0) - normcdf(w[0, 0:i].sum()-f_0) )
else:
log_pdf[1] = normcdfln(f_0)
log_pdf.index_var = y_0
super(Ordinal, self).__init__(log_pdf=log_pdf, gp_link=gp_link, name='Ordinal')
# TODO: Check this.
self.log_concave = True

View file

@ -13,11 +13,11 @@ from ..inference.latent_function_inference import InferenceMethodList
from ..likelihoods import Gaussian
from ..util.initialization import initialize_latent
from ..core.sparse_gp import SparseGP, GP
from GPy.models.bayesian_gplvm import BayesianGPLVM
from GPy.core.parameterization.variational import VariationalPosterior
from GPy.core.sparse_gp_mpi import SparseGP_MPI
from GPy.models.bayesian_gplvm_minibatch import BayesianGPLVMMiniBatch
from GPy.models.sparse_gp_minibatch import SparseGPMiniBatch
class MRD(BayesianGPLVM):
class MRD(BayesianGPLVMMiniBatch):
"""
!WARNING: This is bleeding edge code and still in development.
Functionality may change fundamentally during development!
@ -92,7 +92,8 @@ class MRD(BayesianGPLVM):
else:
fracs = [X.var(0)]*len(Ylist)
self.Z = Param('inducing inputs', self._init_Z(initz, X))
Z = self._init_Z(initz, X)
self.Z = Param('inducing inputs', Z)
self.num_inducing = self.Z.shape[0] # ensure M==N if M>N
# sort out the kernels
@ -104,6 +105,7 @@ class MRD(BayesianGPLVM):
kernels = []
for i in range(len(Ylist)):
k = kernel.copy()
print k is kernel, k.observers, k.constraints
kernels.append(k)
else:
assert len(kernel) == len(Ylist), "need one kernel per output"
@ -114,7 +116,7 @@ class MRD(BayesianGPLVM):
X_variance = np.random.uniform(0.1, 0.2, X.shape)
self.variational_prior = NormalPrior()
self.X = NormalPosterior(X, X_variance)
#self.X = NormalPosterior(X, X_variance)
if likelihoods is None:
likelihoods = [Gaussian(name='Gaussian_noise'.format(i)) for i in range(len(Ylist))]
@ -123,48 +125,33 @@ class MRD(BayesianGPLVM):
self.logger.info("adding X and Z")
super(MRD, self).__init__(Y, input_dim, X=X, X_variance=X_variance, num_inducing=num_inducing,
Z=self.Z, kernel=None, inference_method=self.inference_method, likelihood=Gaussian(),
name='bayesian gplvm', mpi_comm=None, normalizer=None,
name='manifold relevance determination', normalizer=None,
missing_data=False, stochastic=False, batchsize=1)
import GPy
self._log_marginal_likelihood = 0
print "------------"
print self.size
print self.constraints[GPy.constraints.Logexp()][-10:]
print "------------"
self.unlink_parameter(self.likelihood)
print self.size
print self.constraints[GPy.constraints.Logexp()][-10:]
print "------------"
self.unlink_parameter(self.kern)
print self.size
print self.constraints[GPy.constraints.Logexp()][-10:]
print "------------"
print
print '================='
del self.kern
del self.likelihood
self.num_data = Ylist[0].shape[0]
if isinstance(batchsize, int):
batchsize = itertools.repeat(batchsize)
print self.size
print self.constraints[GPy.constraints.Logexp()][-10:]
self.bgplvms = []
for i, n, k, l, Y, im, bs in itertools.izip(itertools.count(), Ynames, kernels, likelihoods, Ylist, self.inference_method, batchsize):
assert Y.shape[0] == self.num_data, "All datasets need to share the number of datapoints, and those have to correspond to one another"
md = np.isnan(Y).any()
spgp = SparseGP(self.X, Y, self.Z, k, l, im, n, None, normalizer, md, stochastic, bs)
spgp = SparseGPMiniBatch(self.X, Y, Z, k, l, im, n, None, normalizer, md, stochastic, bs)
spgp.unlink_parameter(spgp.Z)
del spgp.Z
del spgp.X
spgp.Z = self.Z
spgp.X = self.X
self.link_parameter(spgp, i+2)
print self.constraints[GPy.constraints.Logexp()][-10:]
self.link_parameter(self.Z, 2)
print self.size
print self.constraints[GPy.constraints.Logexp()][-10:]
print "==========="
self.bgplvms.append(spgp)
self.posterior = None
self.logger.info("init done")
@ -173,7 +160,9 @@ class MRD(BayesianGPLVM):
self._log_marginal_likelihood = 0
self.Z.gradient[:] = 0.
self.X.gradient[:] = 0.
for b, i in itertools.izip(self.parameters[3:], self.inference_method):
for b, i in itertools.izip(self.bgplvms, self.inference_method):
self._log_marginal_likelihood += b._log_marginal_likelihood
self.logger.info('working on im <{}>'.format(hex(id(i))))
self.Z.gradient[:] += b.full_values['Zgrad']
grad_dict = b.grad_dict
@ -195,6 +184,7 @@ class MRD(BayesianGPLVM):
# update for the KL divergence
self.variational_prior.update_gradients_KL(self.X)
self._log_marginal_likelihood -= self.variational_prior.KL_divergence(self.X)
pass
def log_likelihood(self):
return self._log_marginal_likelihood
@ -268,7 +258,7 @@ class MRD(BayesianGPLVM):
Prediction for data set Yindex[default=0].
This predicts the output mean and variance for the dataset given in Ylist[Yindex]
"""
b = self.parameters[Yindex+2]
b = self.bgplvms[Yindex]
self.posterior = b.posterior
self.kern = b.kern
self.likelihood = b.likelihood
@ -317,16 +307,20 @@ class MRD(BayesianGPLVM):
from ..plotting.matplot_dep import dim_reduction_plots
if "Yindex" not in predict_kwargs:
predict_kwargs['Yindex'] = 0
Yindex = predict_kwargs['Yindex']
if ax is None:
fig = plt.figure(num=fignum)
ax = fig.add_subplot(111)
else:
fig = ax.figure
self.kern = self.bgplvms[Yindex].kern
self.likelihood = self.bgplvms[Yindex].likelihood
plot = dim_reduction_plots.plot_latent(self, labels, which_indices,
resolution, ax, marker, s,
fignum, plot_inducing, legend,
plot_limits, aspect, updates, predict_kwargs, imshow_kwargs)
ax.set_title(self.bgplvms[predict_kwargs['Yindex']].name)
ax.set_title(self.bgplvms[Yindex].name)
try:
fig.tight_layout()
except:
@ -336,8 +330,10 @@ class MRD(BayesianGPLVM):
def __getstate__(self):
state = super(MRD, self).__getstate__()
del state['kern']
del state['likelihood']
if state.has_key('kern'):
del state['kern']
if state.has_key('likelihood'):
del state['likelihood']
return state
def __setstate__(self, state):

View file

@ -447,6 +447,7 @@ class GradientTests(np.testing.TestCase):
m = GPy.models.GPHeteroscedasticRegression(X, Y, kern)
self.assertTrue(m.checkgrad())
def test_gp_kronecker_gaussian(self):
N1, N2 = 30, 20
X1 = np.random.randn(N1, 1)

View file

@ -130,7 +130,6 @@ class Test(unittest.TestCase):
self.assertEqual(self._first, self._trigger, 'priority should be second')
self.assertEqual(self._second, self._trigger_priority, 'priority should be second')
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()

View file

@ -221,6 +221,31 @@ class ParameterizedTest(unittest.TestCase):
np.testing.assert_equal(t.x.constraints[Logistic(0,1)], c[Logistic(0,1)])
np.testing.assert_equal(t.x.constraints['fixed'], c['fixed'])
def test_parameter_modify_in_init(self):
class TestLikelihood(Parameterized):
def __init__(self, param1 = 2., param2 = 3.):
super(TestLikelihood, self).__init__("TestLike")
self.p1 = Param('param1', param1)
self.p2 = Param('param2', param2)
self.link_parameter(self.p1)
self.link_parameter(self.p2)
self.p1.fix()
self.p1.unfix()
self.p2.constrain_negative()
self.p1.fix()
self.p2.constrain_positive()
self.p2.fix()
self.p2.constrain_positive()
m = TestLikelihood()
print m
val = m.p1.values.copy()
self.assert_(m.p1.is_fixed)
self.assert_(m.constraints[GPy.constraints.Logexp()].tolist(), [1])
m.randomize()
self.assertEqual(m.p1, val)
def test_printing(self):
print self.test1

View file

@ -141,6 +141,7 @@ class Test(ListDictTestCase):
pcopy.optimize('bfgs')
par.optimize('bfgs')
np.testing.assert_allclose(pcopy.param_array, par.param_array, atol=1e-6)
par.randomize()
with tempfile.TemporaryFile('w+b') as f:
par.pickle(f)
f.seek(0)

View file

@ -4,11 +4,10 @@ The module of tools for parallelization (MPI)
try:
from mpi4py import MPI
def get_id_within_node(comm=MPI.COMM_WORLD):
rank = comm.rank
nodename = MPI.Get_processor_name()
nodelist = comm.allgather(nodename)
return len([i for i in nodelist[:rank] if i==nodename])
except:
pass
def get_id_within_node(comm=MPI.COMM_WORLD):
rank = comm.rank
nodename = MPI.Get_processor_name()
nodelist = comm.allgather(nodename)
return len([i for i in nodelist[:rank] if i==nodename])

View file

@ -3,11 +3,11 @@ GPy
A Gaussian processes framework in Python.
* [GPy homepage](http://sheffieldml.github.io/GPy/)
* [User mailing list](https://lists.shef.ac.uk/sympa/subscribe/gpy-users)
* [Online documentation](https://gpy.readthedocs.org/en/latest/)
* [Unit tests (Travis-CI)](https://travis-ci.org/SheffieldML/GPy)
Continuous integration status: ![CI status](https://travis-ci.org/SheffieldML/GPy.png)
Citation
@ -20,6 +20,10 @@ Citation
year = {2012--2014}
}
Pronounciation
==============
We like to pronounce it 'Gee-pie'.
Getting started
===============
Installing with pip

View file

@ -44,6 +44,14 @@ GPy.inference.latent_function_inference.fitc module
: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
------------------------------------------------------

View file

@ -0,0 +1,30 @@
GPy.inference.mcmc package
==========================
Submodules
----------
GPy.inference.mcmc.hmc module
-----------------------------
.. automodule:: GPy.inference.mcmc.hmc
:members:
:undoc-members:
:show-inheritance:
GPy.inference.mcmc.samplers module
----------------------------------
.. automodule:: GPy.inference.mcmc.samplers
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: GPy.inference.mcmc
:members:
:undoc-members:
:show-inheritance:

View file

@ -1,246 +0,0 @@
GPy.kern.parts package
======================
Submodules
----------
GPy.kern.parts.Brownian module
------------------------------
.. automodule:: GPy.kern.parts.Brownian
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.Matern32 module
------------------------------
.. automodule:: GPy.kern.parts.Matern32
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.Matern52 module
------------------------------
.. automodule:: GPy.kern.parts.Matern52
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.bias module
--------------------------
.. automodule:: GPy.kern.parts.bias
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.coregionalize module
-----------------------------------
.. automodule:: GPy.kern.parts.coregionalize
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.exponential module
---------------------------------
.. automodule:: GPy.kern.parts.exponential
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.finite_dimensional module
----------------------------------------
.. automodule:: GPy.kern.parts.finite_dimensional
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.fixed module
---------------------------
.. automodule:: GPy.kern.parts.fixed
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.gibbs module
---------------------------
.. automodule:: GPy.kern.parts.gibbs
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.hetero module
----------------------------
.. automodule:: GPy.kern.parts.hetero
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.hierarchical module
----------------------------------
.. automodule:: GPy.kern.parts.hierarchical
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.independent_outputs module
-----------------------------------------
.. automodule:: GPy.kern.parts.independent_outputs
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.kernpart module
------------------------------
.. automodule:: GPy.kern.parts.kernpart
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.linear module
----------------------------
.. automodule:: GPy.kern.parts.linear
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.mlp module
-------------------------
.. automodule:: GPy.kern.parts.mlp
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.periodic_Matern32 module
---------------------------------------
.. automodule:: GPy.kern.parts.periodic_Matern32
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.periodic_Matern52 module
---------------------------------------
.. automodule:: GPy.kern.parts.periodic_Matern52
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.periodic_exponential module
------------------------------------------
.. automodule:: GPy.kern.parts.periodic_exponential
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.poly module
--------------------------
.. automodule:: GPy.kern.parts.poly
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.prod module
--------------------------
.. automodule:: GPy.kern.parts.prod
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.prod_orthogonal module
-------------------------------------
.. automodule:: GPy.kern.parts.prod_orthogonal
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.rational_quadratic module
----------------------------------------
.. automodule:: GPy.kern.parts.rational_quadratic
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.rbf module
-------------------------
.. automodule:: GPy.kern.parts.rbf
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.rbf_inv module
-----------------------------
.. automodule:: GPy.kern.parts.rbf_inv
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.rbfcos module
----------------------------
.. automodule:: GPy.kern.parts.rbfcos
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.spline module
----------------------------
.. automodule:: GPy.kern.parts.spline
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.symmetric module
-------------------------------
.. automodule:: GPy.kern.parts.symmetric
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.sympykern module
-------------------------------
.. automodule:: GPy.kern.parts.sympykern
:members:
:undoc-members:
:show-inheritance:
GPy.kern.parts.white module
---------------------------
.. automodule:: GPy.kern.parts.white
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: GPy.kern.parts
:members:
:undoc-members:
:show-inheritance:

View file

@ -1,70 +0,0 @@
GPy.likelihoods.noise_models package
====================================
Submodules
----------
GPy.likelihoods.noise_models.binomial_noise module
--------------------------------------------------
.. automodule:: GPy.likelihoods.noise_models.binomial_noise
:members:
:undoc-members:
:show-inheritance:
GPy.likelihoods.noise_models.exponential_noise module
-----------------------------------------------------
.. automodule:: GPy.likelihoods.noise_models.exponential_noise
:members:
:undoc-members:
:show-inheritance:
GPy.likelihoods.noise_models.gamma_noise module
-----------------------------------------------
.. automodule:: GPy.likelihoods.noise_models.gamma_noise
:members:
:undoc-members:
:show-inheritance:
GPy.likelihoods.noise_models.gaussian_noise module
--------------------------------------------------
.. automodule:: GPy.likelihoods.noise_models.gaussian_noise
:members:
:undoc-members:
:show-inheritance:
GPy.likelihoods.noise_models.gp_transformations module
------------------------------------------------------
.. automodule:: GPy.likelihoods.noise_models.gp_transformations
:members:
:undoc-members:
:show-inheritance:
GPy.likelihoods.noise_models.noise_distributions module
-------------------------------------------------------
.. automodule:: GPy.likelihoods.noise_models.noise_distributions
:members:
:undoc-members:
:show-inheritance:
GPy.likelihoods.noise_models.poisson_noise module
-------------------------------------------------
.. automodule:: GPy.likelihoods.noise_models.poisson_noise
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: GPy.likelihoods.noise_models
:members:
:undoc-members:
:show-inheritance:

View file

@ -12,6 +12,14 @@ GPy.models.bayesian_gplvm module
:undoc-members:
:show-inheritance:
GPy.models.bayesian_gplvm_minibatch module
------------------------------------------
.. automodule:: GPy.models.bayesian_gplvm_minibatch
:members:
:undoc-members:
:show-inheritance:
GPy.models.bcgplvm module
-------------------------
@ -116,6 +124,14 @@ GPy.models.sparse_gp_coregionalized_regression module
:undoc-members:
:show-inheritance:
GPy.models.sparse_gp_minibatch module
-------------------------------------
.. automodule:: GPy.models.sparse_gp_minibatch
:members:
:undoc-members:
:show-inheritance:
GPy.models.sparse_gp_multioutput_regression module
--------------------------------------------------

View file

@ -28,6 +28,14 @@ GPy.testing.index_operations_tests module
:undoc-members:
:show-inheritance:
GPy.testing.inference_tests module
----------------------------------
.. automodule:: GPy.testing.inference_tests
:members:
:undoc-members:
:show-inheritance:
GPy.testing.kernel_tests module
-------------------------------

View file

@ -1,30 +0,0 @@
GPy.util.latent_space_visualizations.controllers package
========================================================
Submodules
----------
GPy.util.latent_space_visualizations.controllers.axis_event_controller module
-----------------------------------------------------------------------------
.. automodule:: GPy.util.latent_space_visualizations.controllers.axis_event_controller
:members:
:undoc-members:
:show-inheritance:
GPy.util.latent_space_visualizations.controllers.imshow_controller module
-------------------------------------------------------------------------
.. automodule:: GPy.util.latent_space_visualizations.controllers.imshow_controller
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: GPy.util.latent_space_visualizations.controllers
:members:
:undoc-members:
:show-inheritance:

View file

@ -1,17 +0,0 @@
GPy.util.latent_space_visualizations package
============================================
Subpackages
-----------
.. toctree::
GPy.util.latent_space_visualizations.controllers
Module contents
---------------
.. automodule:: GPy.util.latent_space_visualizations
:members:
:undoc-members:
:show-inheritance:

View file

@ -11,6 +11,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
autodoc_default_flags = ['members', 'show-inheritance', 'private-members', 'special-members']
autodoc_member_order = "source"
import sys
import os
@ -114,7 +117,7 @@ for mod_name in MOCK_MODULES:
# ----------------------- READTHEDOCS ------------------
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = True
#on_rtd = True
if on_rtd:
sys.path.append(os.path.abspath('../GPy'))
@ -126,7 +129,8 @@ if on_rtd:
proc = subprocess.Popen("ls ../", stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
print "program output:", out
proc = subprocess.Popen("sphinx-apidoc -f -o . ../GPy", stdout=subprocess.PIPE, shell=True)
#proc = subprocess.Popen("sphinx-apidoc -f -o . ../GPy", stdout=subprocess.PIPE, shell=True)
proc = subprocess.Popen("make html", stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
print "program output:", out
#proc = subprocess.Popen("whereis numpy", stdout=subprocess.PIPE, shell=True)
@ -397,5 +401,3 @@ epub_copyright = u'2013, Author'
# Allow duplicate toc entries.
#epub_tocdup = True
autodoc_member_order = "source"