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

This commit is contained in:
Zhenwen Dai 2014-09-04 14:18:35 +01:00
commit df1be1a5f6
7 changed files with 30 additions and 15 deletions

View file

@ -287,7 +287,7 @@ class Model(Parameterized):
# just check the global ratio
dx = np.zeros(x.shape)
dx[transformed_index] = step * (np.sign(np.random.uniform(-1, 1, transformed_index.size)) if transformed_index.size != 2 else 1.)
# evaulate around the point x
f1 = self._objective(x + dx)
f2 = self._objective(x - dx)

View file

@ -13,7 +13,7 @@ Observable Pattern for patameterization
"""
from transformations import Logexp, NegativeLogexp, Logistic, __fixed__, FIXED, UNFIXED
from transformations import Transformation,Logexp, NegativeLogexp, Logistic, __fixed__, FIXED, UNFIXED
import numpy as np
import re
import logging
@ -573,7 +573,8 @@ class Indexable(Nameable, Observable):
Constrain the parameter to the given
:py:class:`GPy.core.transformations.Transformation`.
"""
self.param_array[...] = transform.initialize(self.param_array)
if isinstance(transform, Transformation):
self.param_array[...] = transform.initialize(self.param_array)
reconstrained = self.unconstrain()
added = self._add_to_index_operations(self.constraints, reconstrained, transform, warning)
self.notify_observers(self, None if trigger_parent else -np.inf)
@ -649,7 +650,7 @@ class Indexable(Nameable, Observable):
"""
Helper preventing copy code.
This adds the given what (transformation, prior etc) to parameter index operations which.
revonstrained are reconstrained indices.
reconstrained are reconstrained indices.
warn when reconstraining parameters if warning is True.
TODO: find out which parameters have changed specifically
"""

View file

@ -7,7 +7,7 @@ Created on 6 Nov 2013
import numpy as np
from parameterized import Parameterized
from param import Param
from transformations import Logexp, Logistic
from transformations import Logexp, Logistic,__fixed__
class VariationalPrior(Parameterized):
def __init__(self, name='latent space', **kw):
@ -35,12 +35,15 @@ class NormalPrior(VariationalPrior):
class SpikeAndSlabPrior(VariationalPrior):
def __init__(self, pi=None, learnPi=False, variance = 1.0, name='SpikeAndSlabPrior', **kw):
super(VariationalPrior, self).__init__(name=name, **kw)
self.pi = Param('pi', pi, Logistic(1e-10,1.-1e-10))
super(SpikeAndSlabPrior, self).__init__(name=name, **kw)
self.variance = Param('variance',variance)
self.learnPi = learnPi
if learnPi:
self.add_parameters(self.pi)
self.pi = Param('Pi', pi, Logistic(1e-10,1.-1e-10))
else:
self.pi = Param('Pi', pi, __fixed__)
self.add_parameter(self.pi)
def KL_divergence(self, variational_posterior):
mu = variational_posterior.mean

View file

@ -46,7 +46,7 @@ class SparseGP_MPI(SparseGP):
self.add_parameter(self.X, index=0)
if variational_prior is not None:
self.add_parameter(variational_prior)
self.X.fix()
# self.X.fix()
self.mpi_comm = mpi_comm
# Manage the data (Y) division
@ -67,6 +67,9 @@ class SparseGP_MPI(SparseGP):
del dc['N_range']
del dc['N_list']
del dc['Y_local']
if 'normalizer' not in dc:
dc['normalizer'] = None
dc['Y_normalized'] = dc['Y']
return dc
#=====================================================

View file

@ -170,12 +170,14 @@ class VarDTC_minibatch(LatentFunctionInference):
Kmm = kern.K(Z).copy()
diag.add(Kmm, self.const_jitter)
checkFullRank(Kmm)
r1 = checkFullRank(Kmm,name='Kmm')
Lm = jitchol(Kmm)
LmInvPsi2LmInvT = backsub_both_sides(Lm,psi2_full,transpose='right')
Lambda = np.eye(Kmm.shape[0])+LmInvPsi2LmInvT
checkFullRank(Lambda)
r2 = checkFullRank(Lambda,name='Lambda')
if (not r1) or (not r2):
raise
LL = jitchol(Lambda)
LL = np.dot(Lm,LL)
b,_ = dtrtrs(LL, psi1Y_full.T)
@ -339,7 +341,13 @@ def update_gradients(model, mpi_comm=None):
Y = model.Y_local
X = model.X[model.N_range[0]:model.N_range[1]]
model._log_marginal_likelihood, dL_dKmm, model.posterior = model.inference_method.inference_likelihood(model.kern, X, model.Z, model.likelihood, Y)
try:
model._log_marginal_likelihood, dL_dKmm, model.posterior = model.inference_method.inference_likelihood(model.kern, X, model.Z, model.likelihood, Y)
except Exception:
if model.mpi_comm is None or model.mpi_comm.rank==0:
import time
model.pickle('model_'+str(int(time.time()))+'.pickle')
raise
het_noise = model.likelihood.variance.size > 1

View file

@ -70,8 +70,8 @@ class SSGPLVM(SparseGP_MPI):
X = SpikeAndSlabPosterior(X, X_variance, gamma)
super(SSGPLVM,self).__init__(X, Y, Z, kernel, likelihood, variational_prior=self.variational_prior, inference_method=inference_method, name=name, mpi_comm=mpi_comm, normalizer=normalizer, **kwargs)
self.X.unfix()
self.X.variance.constrain_positive()
# self.X.unfix()
# self.X.variance.constrain_positive()
if self.group_spike:
[self.X.gamma[:,i].tie('tieGamma'+str(i)) for i in xrange(self.X.gamma.shape[1])] # Tie columns together

View file

@ -26,7 +26,7 @@ def checkFullRank(m, tol=1e-10, name=None, force_check=False):
print 'The size of '+name+'is too big to check (>=10000)!'
return True
s = np.linalg.eigvals(m)
s = np.real(np.linalg.eigvals(m))
if s.min()/s.max()<tol:
print name+' is close to singlar!'