mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-08 03:22:38 +02:00
Merge pull request #321 from SheffieldML/limit=3
[chaching] changing all chacher limits to 3
This commit is contained in:
commit
462e23ab2b
48 changed files with 72 additions and 72 deletions
|
|
@ -44,7 +44,7 @@ class SparseGP(GP):
|
||||||
#pick a sensible inference method
|
#pick a sensible inference method
|
||||||
if inference_method is None:
|
if inference_method is None:
|
||||||
if isinstance(likelihood, likelihoods.Gaussian):
|
if isinstance(likelihood, likelihoods.Gaussian):
|
||||||
inference_method = var_dtc.VarDTC(limit=1)
|
inference_method = var_dtc.VarDTC(limit=3)
|
||||||
else:
|
else:
|
||||||
#inference_method = ??
|
#inference_method = ??
|
||||||
raise NotImplementedError("what to do what to do?")
|
raise NotImplementedError("what to do what to do?")
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ class VarDTC(LatentFunctionInference):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
const_jitter = 1e-8
|
const_jitter = 1e-8
|
||||||
def __init__(self, limit=1):
|
def __init__(self, limit=3):
|
||||||
from paramz.caching import Cacher
|
from paramz.caching import Cacher
|
||||||
self.limit = limit
|
self.limit = limit
|
||||||
self.get_trYYT = Cacher(self._get_trYYT, limit)
|
self.get_trYYT = Cacher(self._get_trYYT, limit)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class VarDTC_minibatch(LatentFunctionInference):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
const_jitter = 1e-8
|
const_jitter = 1e-8
|
||||||
def __init__(self, batchsize=None, limit=1, mpi_comm=None):
|
def __init__(self, batchsize=None, limit=3, mpi_comm=None):
|
||||||
|
|
||||||
self.batchsize = batchsize
|
self.batchsize = batchsize
|
||||||
self.mpi_comm = mpi_comm
|
self.mpi_comm = mpi_comm
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class Add(CombinationKernel):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@Cache_this(limit=2, force_kwargs=['which_parts'])
|
@Cache_this(limit=3, force_kwargs=['which_parts'])
|
||||||
def K(self, X, X2=None, which_parts=None):
|
def K(self, X, X2=None, which_parts=None):
|
||||||
"""
|
"""
|
||||||
Add all kernels together.
|
Add all kernels together.
|
||||||
|
|
@ -51,7 +51,7 @@ class Add(CombinationKernel):
|
||||||
which_parts = [which_parts]
|
which_parts = [which_parts]
|
||||||
return reduce(np.add, (p.K(X, X2) for p in which_parts))
|
return reduce(np.add, (p.K(X, X2) for p in which_parts))
|
||||||
|
|
||||||
@Cache_this(limit=2, force_kwargs=['which_parts'])
|
@Cache_this(limit=3, force_kwargs=['which_parts'])
|
||||||
def Kdiag(self, X, which_parts=None):
|
def Kdiag(self, X, which_parts=None):
|
||||||
if which_parts is None:
|
if which_parts is None:
|
||||||
which_parts = self.parts
|
which_parts = self.parts
|
||||||
|
|
@ -98,17 +98,17 @@ class Add(CombinationKernel):
|
||||||
[target.__iadd__(p.gradients_XX_diag(dL_dKdiag, X)) for p in self.parts]
|
[target.__iadd__(p.gradients_XX_diag(dL_dKdiag, X)) for p in self.parts]
|
||||||
return target
|
return target
|
||||||
|
|
||||||
@Cache_this(limit=1, force_kwargs=['which_parts'])
|
@Cache_this(limit=3, force_kwargs=['which_parts'])
|
||||||
def psi0(self, Z, variational_posterior):
|
def psi0(self, Z, variational_posterior):
|
||||||
if not self._exact_psicomp: return Kern.psi0(self,Z,variational_posterior)
|
if not self._exact_psicomp: return Kern.psi0(self,Z,variational_posterior)
|
||||||
return reduce(np.add, (p.psi0(Z, variational_posterior) for p in self.parts))
|
return reduce(np.add, (p.psi0(Z, variational_posterior) for p in self.parts))
|
||||||
|
|
||||||
@Cache_this(limit=1, force_kwargs=['which_parts'])
|
@Cache_this(limit=3, force_kwargs=['which_parts'])
|
||||||
def psi1(self, Z, variational_posterior):
|
def psi1(self, Z, variational_posterior):
|
||||||
if not self._exact_psicomp: return Kern.psi1(self,Z,variational_posterior)
|
if not self._exact_psicomp: return Kern.psi1(self,Z,variational_posterior)
|
||||||
return reduce(np.add, (p.psi1(Z, variational_posterior) for p in self.parts))
|
return reduce(np.add, (p.psi1(Z, variational_posterior) for p in self.parts))
|
||||||
|
|
||||||
@Cache_this(limit=1, force_kwargs=['which_parts'])
|
@Cache_this(limit=3, force_kwargs=['which_parts'])
|
||||||
def psi2(self, Z, variational_posterior):
|
def psi2(self, Z, variational_posterior):
|
||||||
if not self._exact_psicomp: return Kern.psi2(self,Z,variational_posterior)
|
if not self._exact_psicomp: return Kern.psi2(self,Z,variational_posterior)
|
||||||
psi2 = reduce(np.add, (p.psi2(Z, variational_posterior) for p in self.parts))
|
psi2 = reduce(np.add, (p.psi2(Z, variational_posterior) for p in self.parts))
|
||||||
|
|
@ -144,7 +144,7 @@ class Add(CombinationKernel):
|
||||||
raise NotImplementedError("psi2 cannot be computed for this kernel")
|
raise NotImplementedError("psi2 cannot be computed for this kernel")
|
||||||
return psi2
|
return psi2
|
||||||
|
|
||||||
@Cache_this(limit=1, force_kwargs=['which_parts'])
|
@Cache_this(limit=3, force_kwargs=['which_parts'])
|
||||||
def psi2n(self, Z, variational_posterior):
|
def psi2n(self, Z, variational_posterior):
|
||||||
if not self._exact_psicomp: return Kern.psi2n(self, Z, variational_posterior)
|
if not self._exact_psicomp: return Kern.psi2n(self, Z, variational_posterior)
|
||||||
psi2 = reduce(np.add, (p.psi2n(Z, variational_posterior) for p in self.parts))
|
psi2 = reduce(np.add, (p.psi2n(Z, variational_posterior) for p in self.parts))
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ class EQ_ODE2(Kern):
|
||||||
self.W = Param('W', W)
|
self.W = Param('W', W)
|
||||||
self.link_parameters(self.lengthscale, self.C, self.B, self.W)
|
self.link_parameters(self.lengthscale, self.C, self.B, self.W)
|
||||||
|
|
||||||
@Cache_this(limit=2)
|
@Cache_this(limit=3)
|
||||||
def K(self, X, X2=None):
|
def K(self, X, X2=None):
|
||||||
#This way is not working, indexes are lost after using k._slice_X
|
#This way is not working, indexes are lost after using k._slice_X
|
||||||
#index = np.asarray(X, dtype=np.int)
|
#index = np.asarray(X, dtype=np.int)
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class Kern(Parameterized):
|
||||||
def _effective_input_dim(self):
|
def _effective_input_dim(self):
|
||||||
return np.size(self._all_dims_active)
|
return np.size(self._all_dims_active)
|
||||||
|
|
||||||
@Cache_this(limit=20)
|
@Cache_this(limit=3)
|
||||||
def _slice_X(self, X):
|
def _slice_X(self, X):
|
||||||
try:
|
try:
|
||||||
return X[:, self._all_dims_active].astype('float')
|
return X[:, self._all_dims_active].astype('float')
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class Linear(Kern):
|
||||||
self.link_parameter(self.variances)
|
self.link_parameter(self.variances)
|
||||||
self.psicomp = PSICOMP_Linear()
|
self.psicomp = PSICOMP_Linear()
|
||||||
|
|
||||||
@Cache_this(limit=2)
|
@Cache_this(limit=3)
|
||||||
def K(self, X, X2=None):
|
def K(self, X, X2=None):
|
||||||
if self.ARD:
|
if self.ARD:
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
|
|
@ -62,7 +62,7 @@ class Linear(Kern):
|
||||||
else:
|
else:
|
||||||
return self._dot_product(X, X2) * self.variances
|
return self._dot_product(X, X2) * self.variances
|
||||||
|
|
||||||
@Cache_this(limit=1, ignore_args=(0,))
|
@Cache_this(limit=3, ignore_args=(0,))
|
||||||
def _dot_product(self, X, X2=None):
|
def _dot_product(self, X, X2=None):
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
return tdot(X)
|
return tdot(X)
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class MLP(Kern):
|
||||||
self.link_parameters(self.variance, self.weight_variance, self.bias_variance)
|
self.link_parameters(self.variance, self.weight_variance, self.bias_variance)
|
||||||
|
|
||||||
|
|
||||||
@Cache_this(limit=20, ignore_args=())
|
@Cache_this(limit=3, ignore_args=())
|
||||||
def K(self, X, X2=None):
|
def K(self, X, X2=None):
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
X_denom = np.sqrt(self._comp_prod(X)+1.)
|
X_denom = np.sqrt(self._comp_prod(X)+1.)
|
||||||
|
|
@ -57,7 +57,7 @@ class MLP(Kern):
|
||||||
XTX = self._comp_prod(X,X2)/X_denom[:,None]/X2_denom[None,:]
|
XTX = self._comp_prod(X,X2)/X_denom[:,None]/X2_denom[None,:]
|
||||||
return self.variance*four_over_tau*np.arcsin(XTX)
|
return self.variance*four_over_tau*np.arcsin(XTX)
|
||||||
|
|
||||||
@Cache_this(limit=20, ignore_args=())
|
@Cache_this(limit=3, ignore_args=())
|
||||||
def Kdiag(self, X):
|
def Kdiag(self, X):
|
||||||
"""Compute the diagonal of the covariance matrix for X."""
|
"""Compute the diagonal of the covariance matrix for X."""
|
||||||
X_prod = self._comp_prod(X)
|
X_prod = self._comp_prod(X)
|
||||||
|
|
@ -88,14 +88,14 @@ class MLP(Kern):
|
||||||
"""Gradient of diagonal of covariance with respect to X"""
|
"""Gradient of diagonal of covariance with respect to X"""
|
||||||
return self._comp_grads_diag(dL_dKdiag, X)[3]
|
return self._comp_grads_diag(dL_dKdiag, X)[3]
|
||||||
|
|
||||||
@Cache_this(limit=50, ignore_args=())
|
@Cache_this(limit=3, ignore_args=())
|
||||||
def _comp_prod(self, X, X2=None):
|
def _comp_prod(self, X, X2=None):
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
return (np.square(X)*self.weight_variance).sum(axis=1)+self.bias_variance
|
return (np.square(X)*self.weight_variance).sum(axis=1)+self.bias_variance
|
||||||
else:
|
else:
|
||||||
return (X*self.weight_variance).dot(X2.T)+self.bias_variance
|
return (X*self.weight_variance).dot(X2.T)+self.bias_variance
|
||||||
|
|
||||||
@Cache_this(limit=20, ignore_args=(1,))
|
@Cache_this(limit=3, ignore_args=(1,))
|
||||||
def _comp_grads(self, dL_dK, X, X2=None):
|
def _comp_grads(self, dL_dK, X, X2=None):
|
||||||
var,w,b = self.variance, self.weight_variance, self.bias_variance
|
var,w,b = self.variance, self.weight_variance, self.bias_variance
|
||||||
K = self.K(X, X2)
|
K = self.K(X, X2)
|
||||||
|
|
@ -130,7 +130,7 @@ class MLP(Kern):
|
||||||
dX2 = common.T.dot(X)*w-((common*XTX).sum(axis=0)/(X2_prod+1.))[:,None]*X2*w
|
dX2 = common.T.dot(X)*w-((common*XTX).sum(axis=0)/(X2_prod+1.))[:,None]*X2*w
|
||||||
return dvar, dw, db, dX, dX2
|
return dvar, dw, db, dX, dX2
|
||||||
|
|
||||||
@Cache_this(limit=20, ignore_args=(1,))
|
@Cache_this(limit=3, ignore_args=(1,))
|
||||||
def _comp_grads_diag(self, dL_dKdiag, X):
|
def _comp_grads_diag(self, dL_dKdiag, X):
|
||||||
var,w,b = self.variance, self.weight_variance, self.bias_variance
|
var,w,b = self.variance, self.weight_variance, self.bias_variance
|
||||||
K = self.Kdiag(X)
|
K = self.Kdiag(X)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class Poly(Kern):
|
||||||
_, _, B = self._AB(X, X2)
|
_, _, B = self._AB(X, X2)
|
||||||
return B * self.variance
|
return B * self.variance
|
||||||
|
|
||||||
@Cache_this(limit=2)
|
@Cache_this(limit=3)
|
||||||
def _AB(self, X, X2=None):
|
def _AB(self, X, X2=None):
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
dot_prod = np.dot(X, X.T)
|
dot_prod = np.dot(X, X.T)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class Prod(CombinationKernel):
|
||||||
kernels.insert(i, part)
|
kernels.insert(i, part)
|
||||||
super(Prod, self).__init__(kernels, name)
|
super(Prod, self).__init__(kernels, name)
|
||||||
|
|
||||||
@Cache_this(limit=2, force_kwargs=['which_parts'])
|
@Cache_this(limit=3, force_kwargs=['which_parts'])
|
||||||
def K(self, X, X2=None, which_parts=None):
|
def K(self, X, X2=None, which_parts=None):
|
||||||
if which_parts is None:
|
if which_parts is None:
|
||||||
which_parts = self.parts
|
which_parts = self.parts
|
||||||
|
|
@ -48,7 +48,7 @@ class Prod(CombinationKernel):
|
||||||
which_parts = [which_parts]
|
which_parts = [which_parts]
|
||||||
return reduce(np.multiply, (p.K(X, X2) for p in which_parts))
|
return reduce(np.multiply, (p.K(X, X2) for p in which_parts))
|
||||||
|
|
||||||
@Cache_this(limit=2, force_kwargs=['which_parts'])
|
@Cache_this(limit=3, force_kwargs=['which_parts'])
|
||||||
def Kdiag(self, X, which_parts=None):
|
def Kdiag(self, X, which_parts=None):
|
||||||
if which_parts is None:
|
if which_parts is None:
|
||||||
which_parts = self.parts
|
which_parts = self.parts
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ from .gaussherm import PSICOMP_GH
|
||||||
from . import rbf_psi_comp, linear_psi_comp, ssrbf_psi_comp, sslinear_psi_comp
|
from . import rbf_psi_comp, linear_psi_comp, ssrbf_psi_comp, sslinear_psi_comp
|
||||||
|
|
||||||
class PSICOMP_RBF(PSICOMP):
|
class PSICOMP_RBF(PSICOMP):
|
||||||
@Cache_this(limit=10, ignore_args=(0,))
|
@Cache_this(limit=3, ignore_args=(0,))
|
||||||
def psicomputations(self, kern, Z, variational_posterior, return_psi2_n=False):
|
def psicomputations(self, kern, Z, variational_posterior, return_psi2_n=False):
|
||||||
variance, lengthscale = kern.variance, kern.lengthscale
|
variance, lengthscale = kern.variance, kern.lengthscale
|
||||||
if isinstance(variational_posterior, variational.NormalPosterior):
|
if isinstance(variational_posterior, variational.NormalPosterior):
|
||||||
|
|
@ -31,7 +31,7 @@ class PSICOMP_RBF(PSICOMP):
|
||||||
else:
|
else:
|
||||||
raise ValueError("unknown distriubtion received for psi-statistics")
|
raise ValueError("unknown distriubtion received for psi-statistics")
|
||||||
|
|
||||||
@Cache_this(limit=10, ignore_args=(0,2,3,4))
|
@Cache_this(limit=3, ignore_args=(0,2,3,4))
|
||||||
def psiDerivativecomputations(self, kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, variational_posterior):
|
def psiDerivativecomputations(self, kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, variational_posterior):
|
||||||
variance, lengthscale = kern.variance, kern.lengthscale
|
variance, lengthscale = kern.variance, kern.lengthscale
|
||||||
if isinstance(variational_posterior, variational.NormalPosterior):
|
if isinstance(variational_posterior, variational.NormalPosterior):
|
||||||
|
|
@ -43,7 +43,7 @@ class PSICOMP_RBF(PSICOMP):
|
||||||
|
|
||||||
class PSICOMP_Linear(PSICOMP):
|
class PSICOMP_Linear(PSICOMP):
|
||||||
|
|
||||||
@Cache_this(limit=10, ignore_args=(0,))
|
@Cache_this(limit=3, ignore_args=(0,))
|
||||||
def psicomputations(self, kern, Z, variational_posterior, return_psi2_n=False):
|
def psicomputations(self, kern, Z, variational_posterior, return_psi2_n=False):
|
||||||
variances = kern.variances
|
variances = kern.variances
|
||||||
if isinstance(variational_posterior, variational.NormalPosterior):
|
if isinstance(variational_posterior, variational.NormalPosterior):
|
||||||
|
|
@ -53,7 +53,7 @@ class PSICOMP_Linear(PSICOMP):
|
||||||
else:
|
else:
|
||||||
raise ValueError("unknown distriubtion received for psi-statistics")
|
raise ValueError("unknown distriubtion received for psi-statistics")
|
||||||
|
|
||||||
@Cache_this(limit=10, ignore_args=(0,2,3,4))
|
@Cache_this(limit=3, ignore_args=(0,2,3,4))
|
||||||
def psiDerivativecomputations(self, kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, variational_posterior):
|
def psiDerivativecomputations(self, kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, variational_posterior):
|
||||||
variances = kern.variances
|
variances = kern.variances
|
||||||
if isinstance(variational_posterior, variational.NormalPosterior):
|
if isinstance(variational_posterior, variational.NormalPosterior):
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class PSICOMP_GH(PSICOMP):
|
||||||
def _setup_observers(self):
|
def _setup_observers(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@Cache_this(limit=10, ignore_args=(0,))
|
@Cache_this(limit=3, ignore_args=(0,))
|
||||||
def comp_K(self, Z, qX):
|
def comp_K(self, Z, qX):
|
||||||
if self.Xs is None or self.Xs.shape != qX.mean.shape:
|
if self.Xs is None or self.Xs.shape != qX.mean.shape:
|
||||||
from paramz import ObsAr
|
from paramz import ObsAr
|
||||||
|
|
@ -38,7 +38,7 @@ class PSICOMP_GH(PSICOMP):
|
||||||
self.Xs[i] = self.locs[i]*S_sq+mu
|
self.Xs[i] = self.locs[i]*S_sq+mu
|
||||||
return self.Xs
|
return self.Xs
|
||||||
|
|
||||||
@Cache_this(limit=10, ignore_args=(0,))
|
@Cache_this(limit=3, ignore_args=(0,))
|
||||||
def psicomputations(self, kern, Z, qX, return_psi2_n=False):
|
def psicomputations(self, kern, Z, qX, return_psi2_n=False):
|
||||||
mu, S = qX.mean.values, qX.variance.values
|
mu, S = qX.mean.values, qX.variance.values
|
||||||
N,M,Q = mu.shape[0],Z.shape[0],mu.shape[1]
|
N,M,Q = mu.shape[0],Z.shape[0],mu.shape[1]
|
||||||
|
|
@ -62,7 +62,7 @@ class PSICOMP_GH(PSICOMP):
|
||||||
psi2 += self.weights[i]* tdot(Kfu.T)
|
psi2 += self.weights[i]* tdot(Kfu.T)
|
||||||
return psi0, psi1, psi2
|
return psi0, psi1, psi2
|
||||||
|
|
||||||
@Cache_this(limit=10, ignore_args=(0, 2,3,4))
|
@Cache_this(limit=3, ignore_args=(0, 2,3,4))
|
||||||
def psiDerivativecomputations(self, kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, qX):
|
def psiDerivativecomputations(self, kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, qX):
|
||||||
mu, S = qX.mean.values, qX.variance.values
|
mu, S = qX.mean.values, qX.variance.values
|
||||||
if self.cache_K: Xs = self.comp_K(Z, qX)
|
if self.cache_K: Xs = self.comp_K(Z, qX)
|
||||||
|
|
|
||||||
|
|
@ -132,5 +132,5 @@ def _psi2compDer(dL_dpsi2, variance, lengthscale, Z, mu, S):
|
||||||
|
|
||||||
return _dL_dvar, _dL_dl, _dL_dZ, _dL_dmu, _dL_dS
|
return _dL_dvar, _dL_dl, _dL_dZ, _dL_dmu, _dL_dS
|
||||||
|
|
||||||
_psi1computations = Cacher(__psi1computations, limit=5)
|
_psi1computations = Cacher(__psi1computations, limit=3)
|
||||||
_psi2computations = Cacher(__psi2computations, limit=5)
|
_psi2computations = Cacher(__psi2computations, limit=3)
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ class PSICOMP_RBF_GPU(PSICOMP_RBF):
|
||||||
except:
|
except:
|
||||||
return self.fall_back.psicomputations(kern, Z, variational_posterior, return_psi2_n)
|
return self.fall_back.psicomputations(kern, Z, variational_posterior, return_psi2_n)
|
||||||
|
|
||||||
@Cache_this(limit=10, ignore_args=(0,))
|
@Cache_this(limit=3, ignore_args=(0,))
|
||||||
def _psicomputations(self, kern, Z, variational_posterior, return_psi2_n=False):
|
def _psicomputations(self, kern, Z, variational_posterior, return_psi2_n=False):
|
||||||
"""
|
"""
|
||||||
Z - MxQ
|
Z - MxQ
|
||||||
|
|
@ -371,7 +371,7 @@ class PSICOMP_RBF_GPU(PSICOMP_RBF):
|
||||||
except:
|
except:
|
||||||
return self.fall_back.psiDerivativecomputations(kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, variational_posterior)
|
return self.fall_back.psiDerivativecomputations(kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, variational_posterior)
|
||||||
|
|
||||||
@Cache_this(limit=10, ignore_args=(0,2,3,4))
|
@Cache_this(limit=3, ignore_args=(0,2,3,4))
|
||||||
def _psiDerivativecomputations(self, kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, variational_posterior):
|
def _psiDerivativecomputations(self, kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, variational_posterior):
|
||||||
# resolve the requirement of dL_dpsi2 to be symmetric
|
# resolve the requirement of dL_dpsi2 to be symmetric
|
||||||
if len(dL_dpsi2.shape)==2: dL_dpsi2 = (dL_dpsi2+dL_dpsi2.T)/2
|
if len(dL_dpsi2.shape)==2: dL_dpsi2 = (dL_dpsi2+dL_dpsi2.T)/2
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ try:
|
||||||
return psi0,psi1,psi2,psi2n
|
return psi0,psi1,psi2,psi2n
|
||||||
|
|
||||||
from GPy.util.caching import Cacher
|
from GPy.util.caching import Cacher
|
||||||
psicomputations = Cacher(_psicomputations, limit=1)
|
psicomputations = Cacher(_psicomputations, limit=3)
|
||||||
|
|
||||||
def psiDerivativecomputations(dL_dpsi0, dL_dpsi1, dL_dpsi2, variance, lengthscale, Z, variational_posterior):
|
def psiDerivativecomputations(dL_dpsi0, dL_dpsi1, dL_dpsi2, variance, lengthscale, Z, variational_posterior):
|
||||||
ARD = (len(lengthscale)!=1)
|
ARD = (len(lengthscale)!=1)
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ class PSICOMP_SSRBF_GPU(PSICOMP_RBF):
|
||||||
def get_dimensions(self, Z, variational_posterior):
|
def get_dimensions(self, Z, variational_posterior):
|
||||||
return variational_posterior.mean.shape[0], Z.shape[0], Z.shape[1]
|
return variational_posterior.mean.shape[0], Z.shape[0], Z.shape[1]
|
||||||
|
|
||||||
@Cache_this(limit=1, ignore_args=(0,))
|
@Cache_this(limit=3, ignore_args=(0,))
|
||||||
def psicomputations(self, kern, Z, variational_posterior, return_psi2_n=False):
|
def psicomputations(self, kern, Z, variational_posterior, return_psi2_n=False):
|
||||||
"""
|
"""
|
||||||
Z - MxQ
|
Z - MxQ
|
||||||
|
|
@ -409,7 +409,7 @@ class PSICOMP_SSRBF_GPU(PSICOMP_RBF):
|
||||||
else:
|
else:
|
||||||
return psi0, psi1_gpu.get(), psi2_gpu.get()
|
return psi0, psi1_gpu.get(), psi2_gpu.get()
|
||||||
|
|
||||||
@Cache_this(limit=1, ignore_args=(0,2,3,4))
|
@Cache_this(limit=3, ignore_args=(0,2,3,4))
|
||||||
def psiDerivativecomputations(self, kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, variational_posterior):
|
def psiDerivativecomputations(self, kern, dL_dpsi0, dL_dpsi1, dL_dpsi2, Z, variational_posterior):
|
||||||
variance, lengthscale = kern.variance, kern.lengthscale
|
variance, lengthscale = kern.variance, kern.lengthscale
|
||||||
from ....util.linalg_gpu import sum_axis
|
from ....util.linalg_gpu import sum_axis
|
||||||
|
|
|
||||||
|
|
@ -81,11 +81,11 @@ class Stationary(Kern):
|
||||||
def dK_dr(self, r):
|
def dK_dr(self, r):
|
||||||
raise NotImplementedError("implement derivative of the covariance function wrt r to use this class")
|
raise NotImplementedError("implement derivative of the covariance function wrt r to use this class")
|
||||||
|
|
||||||
@Cache_this(limit=20, ignore_args=())
|
@Cache_this(limit=3, ignore_args=())
|
||||||
def dK2_drdr(self, r):
|
def dK2_drdr(self, r):
|
||||||
raise NotImplementedError("implement second derivative of covariance wrt r to use this method")
|
raise NotImplementedError("implement second derivative of covariance wrt r to use this method")
|
||||||
|
|
||||||
@Cache_this(limit=5, ignore_args=())
|
@Cache_this(limit=3, ignore_args=())
|
||||||
def K(self, X, X2=None):
|
def K(self, X, X2=None):
|
||||||
"""
|
"""
|
||||||
Kernel function applied on inputs X and X2.
|
Kernel function applied on inputs X and X2.
|
||||||
|
|
|
||||||
|
|
@ -54,12 +54,12 @@ class TruncLinear(Kern):
|
||||||
self.add_parameter(self.variances)
|
self.add_parameter(self.variances)
|
||||||
self.add_parameter(self.delta)
|
self.add_parameter(self.delta)
|
||||||
|
|
||||||
@Cache_this(limit=2)
|
@Cache_this(limit=3)
|
||||||
def K(self, X, X2=None):
|
def K(self, X, X2=None):
|
||||||
XX = self.variances*self._product(X, X2)
|
XX = self.variances*self._product(X, X2)
|
||||||
return XX.sum(axis=-1)
|
return XX.sum(axis=-1)
|
||||||
|
|
||||||
@Cache_this(limit=2)
|
@Cache_this(limit=3)
|
||||||
def _product(self, X, X2=None):
|
def _product(self, X, X2=None):
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
X2 = X
|
X2 = X
|
||||||
|
|
@ -149,12 +149,12 @@ class TruncLinear_inf(Kern):
|
||||||
self.add_parameter(self.variances)
|
self.add_parameter(self.variances)
|
||||||
|
|
||||||
|
|
||||||
# @Cache_this(limit=2)
|
# @Cache_this(limit=3)
|
||||||
def K(self, X, X2=None):
|
def K(self, X, X2=None):
|
||||||
tmp = self._product(X, X2)
|
tmp = self._product(X, X2)
|
||||||
return (self.variances*tmp).sum(axis=-1)
|
return (self.variances*tmp).sum(axis=-1)
|
||||||
|
|
||||||
# @Cache_this(limit=2)
|
# @Cache_this(limit=3)
|
||||||
def _product(self, X, X2=None):
|
def _product(self, X, X2=None):
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
X2 = X
|
X2 = X
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class BayesianGPLVM(SparseGP_MPI):
|
||||||
else:
|
else:
|
||||||
from ..inference.latent_function_inference.var_dtc import VarDTC
|
from ..inference.latent_function_inference.var_dtc import VarDTC
|
||||||
self.logger.debug("creating inference_method var_dtc")
|
self.logger.debug("creating inference_method var_dtc")
|
||||||
inference_method = VarDTC(limit=1 if not missing_data else Y.shape[1])
|
inference_method = VarDTC(limit=3 if not missing_data else Y.shape[1])
|
||||||
if isinstance(inference_method,VarDTC_minibatch):
|
if isinstance(inference_method,VarDTC_minibatch):
|
||||||
inference_method.mpi_comm = mpi_comm
|
inference_method.mpi_comm = mpi_comm
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class BayesianGPLVMMiniBatch(SparseGPMiniBatch):
|
||||||
if inference_method is None:
|
if inference_method is None:
|
||||||
from ..inference.latent_function_inference.var_dtc import VarDTC
|
from ..inference.latent_function_inference.var_dtc import VarDTC
|
||||||
self.logger.debug("creating inference_method var_dtc")
|
self.logger.debug("creating inference_method var_dtc")
|
||||||
inference_method = VarDTC(limit=1 if not missing_data else Y.shape[1])
|
inference_method = VarDTC(limit=3 if not missing_data else Y.shape[1])
|
||||||
|
|
||||||
super(BayesianGPLVMMiniBatch,self).__init__(X, Y, Z, kernel, likelihood=likelihood,
|
super(BayesianGPLVMMiniBatch,self).__init__(X, Y, Z, kernel, likelihood=likelihood,
|
||||||
name=name, inference_method=inference_method,
|
name=name, inference_method=inference_method,
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class SparseGPMiniBatch(SparseGP):
|
||||||
# pick a sensible inference method
|
# pick a sensible inference method
|
||||||
if inference_method is None:
|
if inference_method is None:
|
||||||
if isinstance(likelihood, likelihoods.Gaussian):
|
if isinstance(likelihood, likelihoods.Gaussian):
|
||||||
inference_method = var_dtc.VarDTC(limit=1 if not missing_data else Y.shape[1])
|
inference_method = var_dtc.VarDTC(limit=3 if not missing_data else Y.shape[1])
|
||||||
else:
|
else:
|
||||||
#inference_method = ??
|
#inference_method = ??
|
||||||
raise NotImplementedError("what to do what to do?")
|
raise NotImplementedError("what to do what to do?")
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ def jitchol(A, maxtries=5):
|
||||||
try: raise
|
try: raise
|
||||||
except:
|
except:
|
||||||
logging.warning('\n'.join(['Added jitter of {:.10e}'.format(jitter),
|
logging.warning('\n'.join(['Added jitter of {:.10e}'.format(jitter),
|
||||||
' in '+traceback.format_list(traceback.extract_stack(limit=2)[-2:-1])[0][2:]]))
|
' in '+traceback.format_list(traceback.extract_stack(limit=3)[-2:-1])[0][2:]]))
|
||||||
return L
|
return L
|
||||||
|
|
||||||
# def dtrtri(L, lower=1):
|
# def dtrtri(L, lower=1):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue