mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-04-29 14:56:24 +02:00
changes to FITC
This commit is contained in:
parent
3aca6e4683
commit
00230d7b02
2 changed files with 23 additions and 15 deletions
|
|
@ -57,7 +57,6 @@ class FITC(sparse_GP):
|
||||||
self.Diag0 = self.psi0 - np.diag(self.Qnn)
|
self.Diag0 = self.psi0 - np.diag(self.Qnn)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.beta_star = self.likelihood.precision/(1. + self.likelihood.precision*self.Diag0[:,None]) #Includes Diag0 in the precision
|
self.beta_star = self.likelihood.precision/(1. + self.likelihood.precision*self.Diag0[:,None]) #Includes Diag0 in the precision
|
||||||
self.V_star = self.beta_star * self.likelihood.Y
|
self.V_star = self.beta_star * self.likelihood.Y
|
||||||
|
|
||||||
|
|
@ -72,12 +71,10 @@ class FITC(sparse_GP):
|
||||||
self.A = tdot(tmp)
|
self.A = tdot(tmp)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# factor B
|
# factor B
|
||||||
self.B = np.eye(self.M) + self.A
|
self.B = np.eye(self.M) + self.A
|
||||||
self.LB = jitchol(self.B)
|
self.LB = jitchol(self.B)
|
||||||
|
self.LBi,info = linalg.lapack.flapack.dtrtrs(self.LB,np.eye(self.M),lower=1)
|
||||||
|
|
||||||
self.psi1V = np.dot(self.psi1, self.V_star)
|
self.psi1V = np.dot(self.psi1, self.V_star)
|
||||||
|
|
||||||
|
|
@ -93,10 +90,8 @@ class FITC(sparse_GP):
|
||||||
dlogB_dpsi0 = -.5*self.kern.dKdiag_dtheta(self.beta_star,X=self.X)
|
dlogB_dpsi0 = -.5*self.kern.dKdiag_dtheta(self.beta_star,X=self.X)
|
||||||
dlogB_dpsi1 = self.kern.dK_dtheta(b_psi1_Ki,self.X,self.Z)
|
dlogB_dpsi1 = self.kern.dK_dtheta(b_psi1_Ki,self.X,self.Z)
|
||||||
dlogB_dKmm = -.5*self.kern.dK_dtheta(Ki_pbp_Ki,X=self.Z)
|
dlogB_dKmm = -.5*self.kern.dK_dtheta(Ki_pbp_Ki,X=self.Z)
|
||||||
|
|
||||||
self.dlogB_dtheta = dlogB_dpsi0 + dlogB_dpsi1 + dlogB_dKmm
|
self.dlogB_dtheta = dlogB_dpsi0 + dlogB_dpsi1 + dlogB_dKmm
|
||||||
|
|
||||||
|
|
||||||
# dyby_dtheta
|
# dyby_dtheta
|
||||||
Kmmi = np.dot(self.Lmi.T,self.Lmi)
|
Kmmi = np.dot(self.Lmi.T,self.Lmi)
|
||||||
VVT = np.outer(self.V_star,self.V_star)
|
VVT = np.outer(self.V_star,self.V_star)
|
||||||
|
|
@ -116,11 +111,22 @@ class FITC(sparse_GP):
|
||||||
tmp = np.dot(psin_K.T,psin_K)
|
tmp = np.dot(psin_K.T,psin_K)
|
||||||
dyby_dKmm = .5*V_n**2 * tmp
|
dyby_dKmm = .5*V_n**2 * tmp
|
||||||
dyby_dtheta += self.kern.dK_dtheta(dyby_dKmm,self.Z)
|
dyby_dtheta += self.kern.dK_dtheta(dyby_dKmm,self.Z)
|
||||||
|
|
||||||
|
|
||||||
#self.dyby_dtheta = dyby_dpsi0 #+ dyby_dpsi1 + dyby_dKmm
|
|
||||||
self.dyby_dtheta = dyby_dtheta
|
self.dyby_dtheta = dyby_dtheta
|
||||||
|
|
||||||
|
# dlogB_dtheta
|
||||||
|
#C_B
|
||||||
|
dlogKi_dKmm = -.5 * Kmmi
|
||||||
|
dlogB_dtheta = self.kern.dK_dtheta(dlogKi_dKmm,self.Z)
|
||||||
|
#C_A
|
||||||
|
#C_AA
|
||||||
|
LBiLmi = np.dot(self.LBi,self.Lmi)
|
||||||
|
partial = .5*np.dot(LBiLmi.T,LBiLmi)
|
||||||
|
dlogB_dtheta += self.kern.dK_dtheta(partial,self.Z)
|
||||||
|
#C_AB
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# the partial derivative vector for the likelihood
|
# the partial derivative vector for the likelihood
|
||||||
|
|
@ -131,7 +137,7 @@ class FITC(sparse_GP):
|
||||||
raise NotImplementedError, "heteroscedatic derivates not implemented"
|
raise NotImplementedError, "heteroscedatic derivates not implemented"
|
||||||
else:
|
else:
|
||||||
# likelihood is not heterscedatic
|
# likelihood is not heterscedatic
|
||||||
self.partial_for_likelihood = 0
|
self.partial_for_likelihood = 0 #FIXME
|
||||||
#self.partial_for_likelihood = -0.5 * self.N * self.D * self.likelihood.precision + 0.5 * self.likelihood.trYYT * self.likelihood.precision ** 2
|
#self.partial_for_likelihood = -0.5 * self.N * self.D * self.likelihood.precision + 0.5 * self.likelihood.trYYT * self.likelihood.precision ** 2
|
||||||
#self.partial_for_likelihood += 0.5 * self.D * (self.psi0.sum() * self.likelihood.precision ** 2 - np.trace(self.A) * self.likelihood.precision)
|
#self.partial_for_likelihood += 0.5 * self.D * (self.psi0.sum() * self.likelihood.precision ** 2 - np.trace(self.A) * self.likelihood.precision)
|
||||||
#self.partial_for_likelihood += self.likelihood.precision * (0.5 * np.sum(self.A * self.DBi_plus_BiPBi) - np.sum(np.square(self._LBi_Lmi_psi1V)))
|
#self.partial_for_likelihood += self.likelihood.precision * (0.5 * np.sum(self.A * self.DBi_plus_BiPBi) - np.sum(np.square(self._LBi_Lmi_psi1V)))
|
||||||
|
|
@ -186,8 +192,8 @@ class FITC(sparse_GP):
|
||||||
"""
|
"""
|
||||||
def log_likelihood(self):
|
def log_likelihood(self):
|
||||||
""" Compute the (lower bound on the) log marginal likelihood """
|
""" Compute the (lower bound on the) log marginal likelihood """
|
||||||
#A = -0.5 * self.N * self.D * np.log(2.*np.pi) + 0.5 * np.sum(np.log(self.beta_star))
|
#A = -0.5 * self.N * self.D * np.log(2.*np.pi) + 0.5 * np.sum(np.log(self.beta_star)) - 0.5 * np.sum(self.V_star * self.likelihood.Y)
|
||||||
A = - 0.5 * np.sum(self.V_star * self.likelihood.Y)
|
C = -self.D * (np.sum(np.log(np.diag(self.LB))))
|
||||||
"""
|
"""
|
||||||
A = -0.5 * self.N * self.D * np.log(2.*np.pi) + 0.5 * np.sum(np.log(self.beta_star)) - 0.5 * np.sum(self.V_star * self.likelihood.Y)
|
A = -0.5 * self.N * self.D * np.log(2.*np.pi) + 0.5 * np.sum(np.log(self.beta_star)) - 0.5 * np.sum(self.V_star * self.likelihood.Y)
|
||||||
#B = -0.5 * self.D * (np.sum(self.likelihood.precision.flatten() * self.psi0) - np.trace(self.A))
|
#B = -0.5 * self.D * (np.sum(self.likelihood.precision.flatten() * self.psi0) - np.trace(self.A))
|
||||||
|
|
@ -195,7 +201,7 @@ class FITC(sparse_GP):
|
||||||
D = 0.5 * np.sum(np.square(self._LBi_Lmi_psi1V))
|
D = 0.5 * np.sum(np.square(self._LBi_Lmi_psi1V))
|
||||||
return A + C + D # +B
|
return A + C + D # +B
|
||||||
"""
|
"""
|
||||||
return A
|
return C
|
||||||
|
|
||||||
|
|
||||||
def _log_likelihood_gradients(self):
|
def _log_likelihood_gradients(self):
|
||||||
|
|
@ -203,8 +209,9 @@ class FITC(sparse_GP):
|
||||||
return np.hstack((self.dL_dZ().flatten(), self.dL_dtheta(), self.likelihood._gradients(partial=self.partial_for_likelihood)))
|
return np.hstack((self.dL_dZ().flatten(), self.dL_dtheta(), self.likelihood._gradients(partial=self.partial_for_likelihood)))
|
||||||
|
|
||||||
def dL_dtheta(self):
|
def dL_dtheta(self):
|
||||||
#dL_dtheta = self.dlogB_dtheta
|
dL_dtheta = self.dlogB_dtheta
|
||||||
dL_dtheta = self.dyby_dtheta
|
#dL_dtheta = self.dyby_dtheta
|
||||||
|
dL_dtheta = self.dlogB_dtheta + self.dyby_dtheta
|
||||||
"""
|
"""
|
||||||
dL_dtheta = self.kern.dK_dtheta(self.dL_dKmm, self.Z)
|
dL_dtheta = self.kern.dK_dtheta(self.dL_dKmm, self.Z)
|
||||||
if self.has_uncertain_inputs:
|
if self.has_uncertain_inputs:
|
||||||
|
|
|
||||||
|
|
@ -12,3 +12,4 @@ from sparse_GPLVM import sparse_GPLVM
|
||||||
from Bayesian_GPLVM import Bayesian_GPLVM
|
from Bayesian_GPLVM import Bayesian_GPLVM
|
||||||
from mrd import MRD
|
from mrd import MRD
|
||||||
from generalized_FITC import generalized_FITC
|
from generalized_FITC import generalized_FITC
|
||||||
|
from FITC import FITC
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue