mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-30 14:35:15 +02:00
Merge branch 'devel' of github.com:SheffieldML/GPy into ties
This commit is contained in:
commit
df1be1a5f6
7 changed files with 30 additions and 15 deletions
|
|
@ -287,7 +287,7 @@ class Model(Parameterized):
|
||||||
# just check the global ratio
|
# just check the global ratio
|
||||||
dx = np.zeros(x.shape)
|
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.)
|
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
|
# evaulate around the point x
|
||||||
f1 = self._objective(x + dx)
|
f1 = self._objective(x + dx)
|
||||||
f2 = self._objective(x - dx)
|
f2 = self._objective(x - dx)
|
||||||
|
|
|
||||||
|
|
@ -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 numpy as np
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -573,7 +573,8 @@ class Indexable(Nameable, Observable):
|
||||||
Constrain the parameter to the given
|
Constrain the parameter to the given
|
||||||
:py:class:`GPy.core.transformations.Transformation`.
|
: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()
|
reconstrained = self.unconstrain()
|
||||||
added = self._add_to_index_operations(self.constraints, reconstrained, transform, warning)
|
added = self._add_to_index_operations(self.constraints, reconstrained, transform, warning)
|
||||||
self.notify_observers(self, None if trigger_parent else -np.inf)
|
self.notify_observers(self, None if trigger_parent else -np.inf)
|
||||||
|
|
@ -649,7 +650,7 @@ class Indexable(Nameable, Observable):
|
||||||
"""
|
"""
|
||||||
Helper preventing copy code.
|
Helper preventing copy code.
|
||||||
This adds the given what (transformation, prior etc) to parameter index operations which.
|
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.
|
warn when reconstraining parameters if warning is True.
|
||||||
TODO: find out which parameters have changed specifically
|
TODO: find out which parameters have changed specifically
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ Created on 6 Nov 2013
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from parameterized import Parameterized
|
from parameterized import Parameterized
|
||||||
from param import Param
|
from param import Param
|
||||||
from transformations import Logexp, Logistic
|
from transformations import Logexp, Logistic,__fixed__
|
||||||
|
|
||||||
class VariationalPrior(Parameterized):
|
class VariationalPrior(Parameterized):
|
||||||
def __init__(self, name='latent space', **kw):
|
def __init__(self, name='latent space', **kw):
|
||||||
|
|
@ -35,12 +35,15 @@ class NormalPrior(VariationalPrior):
|
||||||
|
|
||||||
class SpikeAndSlabPrior(VariationalPrior):
|
class SpikeAndSlabPrior(VariationalPrior):
|
||||||
def __init__(self, pi=None, learnPi=False, variance = 1.0, name='SpikeAndSlabPrior', **kw):
|
def __init__(self, pi=None, learnPi=False, variance = 1.0, name='SpikeAndSlabPrior', **kw):
|
||||||
super(VariationalPrior, self).__init__(name=name, **kw)
|
super(SpikeAndSlabPrior, self).__init__(name=name, **kw)
|
||||||
self.pi = Param('pi', pi, Logistic(1e-10,1.-1e-10))
|
|
||||||
self.variance = Param('variance',variance)
|
self.variance = Param('variance',variance)
|
||||||
self.learnPi = learnPi
|
self.learnPi = learnPi
|
||||||
if 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):
|
def KL_divergence(self, variational_posterior):
|
||||||
mu = variational_posterior.mean
|
mu = variational_posterior.mean
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class SparseGP_MPI(SparseGP):
|
||||||
self.add_parameter(self.X, index=0)
|
self.add_parameter(self.X, index=0)
|
||||||
if variational_prior is not None:
|
if variational_prior is not None:
|
||||||
self.add_parameter(variational_prior)
|
self.add_parameter(variational_prior)
|
||||||
self.X.fix()
|
# self.X.fix()
|
||||||
|
|
||||||
self.mpi_comm = mpi_comm
|
self.mpi_comm = mpi_comm
|
||||||
# Manage the data (Y) division
|
# Manage the data (Y) division
|
||||||
|
|
@ -67,6 +67,9 @@ class SparseGP_MPI(SparseGP):
|
||||||
del dc['N_range']
|
del dc['N_range']
|
||||||
del dc['N_list']
|
del dc['N_list']
|
||||||
del dc['Y_local']
|
del dc['Y_local']
|
||||||
|
if 'normalizer' not in dc:
|
||||||
|
dc['normalizer'] = None
|
||||||
|
dc['Y_normalized'] = dc['Y']
|
||||||
return dc
|
return dc
|
||||||
|
|
||||||
#=====================================================
|
#=====================================================
|
||||||
|
|
|
||||||
|
|
@ -170,12 +170,14 @@ class VarDTC_minibatch(LatentFunctionInference):
|
||||||
|
|
||||||
Kmm = kern.K(Z).copy()
|
Kmm = kern.K(Z).copy()
|
||||||
diag.add(Kmm, self.const_jitter)
|
diag.add(Kmm, self.const_jitter)
|
||||||
checkFullRank(Kmm)
|
r1 = checkFullRank(Kmm,name='Kmm')
|
||||||
Lm = jitchol(Kmm)
|
Lm = jitchol(Kmm)
|
||||||
|
|
||||||
LmInvPsi2LmInvT = backsub_both_sides(Lm,psi2_full,transpose='right')
|
LmInvPsi2LmInvT = backsub_both_sides(Lm,psi2_full,transpose='right')
|
||||||
Lambda = np.eye(Kmm.shape[0])+LmInvPsi2LmInvT
|
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 = jitchol(Lambda)
|
||||||
LL = np.dot(Lm,LL)
|
LL = np.dot(Lm,LL)
|
||||||
b,_ = dtrtrs(LL, psi1Y_full.T)
|
b,_ = dtrtrs(LL, psi1Y_full.T)
|
||||||
|
|
@ -339,7 +341,13 @@ def update_gradients(model, mpi_comm=None):
|
||||||
Y = model.Y_local
|
Y = model.Y_local
|
||||||
X = model.X[model.N_range[0]:model.N_range[1]]
|
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
|
het_noise = model.likelihood.variance.size > 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,8 +70,8 @@ class SSGPLVM(SparseGP_MPI):
|
||||||
X = SpikeAndSlabPosterior(X, X_variance, gamma)
|
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)
|
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.unfix()
|
||||||
self.X.variance.constrain_positive()
|
# self.X.variance.constrain_positive()
|
||||||
|
|
||||||
if self.group_spike:
|
if self.group_spike:
|
||||||
[self.X.gamma[:,i].tie('tieGamma'+str(i)) for i in xrange(self.X.gamma.shape[1])] # Tie columns together
|
[self.X.gamma[:,i].tie('tieGamma'+str(i)) for i in xrange(self.X.gamma.shape[1])] # Tie columns together
|
||||||
|
|
|
||||||
|
|
@ -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)!'
|
print 'The size of '+name+'is too big to check (>=10000)!'
|
||||||
return True
|
return True
|
||||||
|
|
||||||
s = np.linalg.eigvals(m)
|
s = np.real(np.linalg.eigvals(m))
|
||||||
|
|
||||||
if s.min()/s.max()<tol:
|
if s.min()/s.max()<tol:
|
||||||
print name+' is close to singlar!'
|
print name+' is close to singlar!'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue