mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-05 14:55:15 +02:00
changes to rbf and white to allow new parameter gradient structure
This commit is contained in:
parent
ad5a967b39
commit
7b5e8a9ffc
6 changed files with 43 additions and 46 deletions
|
|
@ -24,7 +24,7 @@ class ExactGaussianInference(object):
|
|||
"""
|
||||
find a matrix L which satisfies LL^T = YY^T.
|
||||
|
||||
Note that L may have fewer columns than Y, else L=Y.
|
||||
Note that L may have fewer columns than Y, else L=Y.
|
||||
"""
|
||||
N, D = Y.shape
|
||||
if (N>D):
|
||||
|
|
@ -33,22 +33,26 @@ class ExactGaussianInference(object):
|
|||
#if Y in self.cache, return self.Cache[Y], else store Y in cache and return L.
|
||||
raise NotImplementedError, 'TODO' #TODO
|
||||
|
||||
def inference(self, K, likelihood, Y, Y_metadata=None):
|
||||
def inference(self, kern, X, likelihood, Y, Y_metadata=None):
|
||||
"""
|
||||
Returns a Posterior class containing essential quantities of the posterior
|
||||
"""
|
||||
YYT_factor = self.get_YYTfactor(Y)
|
||||
|
||||
K = kern.K(X)
|
||||
|
||||
Wi, LW, LWi, W_logdet = pdinv(K + likelihood.covariance_matrix(Y, Y_metadata))
|
||||
|
||||
alpha, _ = dpotrs(LW, YYT_factor, lower=1)
|
||||
|
||||
dL_dK = 0.5 * (tdot(alpha) - Y.shape[1] * Wi)
|
||||
|
||||
log_marginal = 0.5*(-Y.size * log_2_pi - Y.shape[1] * W_logdet - np.sum(alpha * YYT_factor))
|
||||
|
||||
dL_dtheta_lik = likelihood._gradients(np.diag(dL_dK))
|
||||
dL_dK = 0.5 * (tdot(alpha) - Y.shape[1] * Wi)
|
||||
|
||||
return Posterior(log_marginal, dL_dK, dL_dtheta_lik, LW, alpha, K)
|
||||
kern.update_gradients_full(dL_dK)
|
||||
|
||||
likelihood.update_gradients(np.diag(dL_dK))
|
||||
|
||||
return Posterior(log_marginal, dL_dK, LW, alpha, K)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ from ..util.linalg import mdot, jitchol, pddet, dpotrs
|
|||
from functools import partial as partial_func
|
||||
import warnings
|
||||
|
||||
class Laplace(likelihood):
|
||||
class LaplaceInference(object):
|
||||
"""Laplace approximation to a posterior"""
|
||||
|
||||
def __init__(self, data, noise_model, extra_data=None):
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class Posterior(object):
|
|||
schemes and the model classes.
|
||||
|
||||
"""
|
||||
def __init__(self, log_marginal, dL_dK, dL_dtheta_lik, woodbury_chol=None, woodbury_vector=None, K=None, mean=None, cov=None, K_chol=None):
|
||||
def __init__(self, log_marginal, dL_dK, woodbury_chol=None, woodbury_vector=None, K=None, mean=None, cov=None, K_chol=None):
|
||||
"""
|
||||
log_marginal: log p(Y|X)
|
||||
dL_dK: d/dK log p(Y|X)
|
||||
|
|
@ -56,7 +56,7 @@ class Posterior(object):
|
|||
if ((woodbury_chol is not None) and (woodbury_vector is not None) and (K is not None)) or ((mean is not None) and (cov is not None) and (K is not None)):
|
||||
pass # we have sufficient to compute the posterior
|
||||
else:
|
||||
raise ValueError, "insufficient onformation to compute the posterior"
|
||||
raise ValueError, "insufficient information to compute the posterior"
|
||||
|
||||
#option 1:
|
||||
self._woodbury_chol = woodbury_chol
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue