mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-21 14:05:14 +02:00
[parallel vardtc] minor adjustments to work with current implementation of
psi stats
This commit is contained in:
parent
c62dd85418
commit
1e006f63b5
1 changed files with 84 additions and 67 deletions
|
|
@ -112,12 +112,12 @@ class VarDTC_minibatch(LatentFunctionInference):
|
||||||
if het_noise:
|
if het_noise:
|
||||||
psi2_full += beta_slice*psi2
|
psi2_full += beta_slice*psi2
|
||||||
else:
|
else:
|
||||||
psi2_full += psi2
|
psi2_full += psi2.sum(0)
|
||||||
else:
|
else:
|
||||||
if het_noise:
|
if het_noise:
|
||||||
psi2_full += beta_slice*np.outer(psi1,psi1)
|
psi2_full += beta_slice*np.outer(psi1,psi1)
|
||||||
else:
|
else:
|
||||||
psi2_full += np.outer(psi1,psi1)
|
psi2_full += np.einsum('nm,jk->mk',psi1,psi1)
|
||||||
|
|
||||||
if not het_noise:
|
if not het_noise:
|
||||||
psi0_full *= beta
|
psi0_full *= beta
|
||||||
|
|
@ -128,7 +128,7 @@ class VarDTC_minibatch(LatentFunctionInference):
|
||||||
#======================================================================
|
#======================================================================
|
||||||
# Compute Common Components
|
# Compute Common Components
|
||||||
#======================================================================
|
#======================================================================
|
||||||
|
self.psi1Y = psi1Y_full
|
||||||
Kmm = kern.K(Z).copy()
|
Kmm = kern.K(Z).copy()
|
||||||
diag.add(Kmm, self.const_jitter)
|
diag.add(Kmm, self.const_jitter)
|
||||||
Lm = jitchol(Kmm)
|
Lm = jitchol(Kmm)
|
||||||
|
|
@ -159,7 +159,10 @@ class VarDTC_minibatch(LatentFunctionInference):
|
||||||
logL_R = -np.log(beta).sum()
|
logL_R = -np.log(beta).sum()
|
||||||
else:
|
else:
|
||||||
logL_R = -num_data*np.log(beta)
|
logL_R = -num_data*np.log(beta)
|
||||||
logL = -(output_dim*(num_data*log_2_pi+logL_R+psi0_full-np.trace(LmInvPsi2LmInvT))+YRY_full-bbt)/2.-output_dim*(-np.log(np.diag(Lm)).sum()+np.log(np.diag(LL)).sum())
|
logL = (
|
||||||
|
-(output_dim*(num_data*log_2_pi+logL_R+psi0_full-np.trace(LmInvPsi2LmInvT))+YRY_full-bbt)/2.
|
||||||
|
-output_dim*(-np.log(np.diag(Lm)).sum()+np.log(np.diag(LL)).sum())
|
||||||
|
)
|
||||||
|
|
||||||
#======================================================================
|
#======================================================================
|
||||||
# Compute dL_dKmm
|
# Compute dL_dKmm
|
||||||
|
|
@ -256,14 +259,14 @@ class VarDTC_minibatch(LatentFunctionInference):
|
||||||
|
|
||||||
if het_noise:
|
if het_noise:
|
||||||
if uncertain_inputs:
|
if uncertain_inputs:
|
||||||
psiR = np.einsum('mo,nmo->n',dL_dpsi2R,psi2)
|
psiR = np.einsum('mo,nmo->',dL_dpsi2R,psi2)
|
||||||
else:
|
else:
|
||||||
psiR = np.einsum('nm,no,mo->n',psi1,psi1,dL_dpsi2R)
|
psiR = np.einsum('nm,no,mo->',psi1,psi1,dL_dpsi2R)
|
||||||
|
|
||||||
dL_dthetaL = ((np.square(betaY)).sum(axis=-1) + np.square(beta)*(output_dim*psi0)-output_dim*beta)/2. - np.square(beta)*psiR- (betaY*np.dot(betapsi1,v)).sum(axis=-1)
|
dL_dthetaL = ((np.square(betaY)).sum(axis=-1) + np.square(beta)*(output_dim*psi0)-output_dim*beta)/2. - np.square(beta)*psiR- (betaY*np.dot(betapsi1,v)).sum(axis=-1)
|
||||||
else:
|
else:
|
||||||
if uncertain_inputs:
|
if uncertain_inputs:
|
||||||
psiR = np.einsum('mo,mo->',dL_dpsi2R,psi2)
|
psiR = np.einsum('mo,nmo->',dL_dpsi2R,psi2)
|
||||||
else:
|
else:
|
||||||
psiR = np.einsum('nm,no,mo->',psi1,psi1,dL_dpsi2R)
|
psiR = np.einsum('nm,no,mo->',psi1,psi1,dL_dpsi2R)
|
||||||
|
|
||||||
|
|
@ -305,30 +308,44 @@ def update_gradients(model):
|
||||||
if isinstance(model.X, VariationalPosterior):
|
if isinstance(model.X, VariationalPosterior):
|
||||||
X_slice = model.X[n_range[0]:n_range[1]]
|
X_slice = model.X[n_range[0]:n_range[1]]
|
||||||
|
|
||||||
|
dL_dpsi1 = grad_dict['dL_dpsi1']#[None, :]
|
||||||
|
dL_dpsi2 = grad_dict['dL_dpsi2'][None, :, :]
|
||||||
#gradients w.r.t. kernel
|
#gradients w.r.t. kernel
|
||||||
model.kern.update_gradients_expectations(variational_posterior=X_slice, Z=model.Z, dL_dpsi0=grad_dict['dL_dpsi0'], dL_dpsi1=grad_dict['dL_dpsi1'], dL_dpsi2=grad_dict['dL_dpsi2'])
|
model.kern.update_gradients_expectations(variational_posterior=X_slice,Z=model.Z,dL_dpsi0=grad_dict['dL_dpsi0'],dL_dpsi1=dL_dpsi1,dL_dpsi2=dL_dpsi2)
|
||||||
kern_grad += model.kern.gradient
|
kern_grad += model.kern.gradient
|
||||||
|
|
||||||
#gradients w.r.t. Z
|
#gradients w.r.t. Z
|
||||||
model.Z.gradient += model.kern.gradients_Z_expectations(
|
model.Z.gradient += model.kern.gradients_Z_expectations(
|
||||||
dL_dpsi0=grad_dict['dL_dpsi0'], dL_dpsi1=grad_dict['dL_dpsi1'], dL_dpsi2=grad_dict['dL_dpsi2'], Z=model.Z, variational_posterior=X_slice)
|
dL_dpsi0=grad_dict['dL_dpsi0'],
|
||||||
|
dL_dpsi1=dL_dpsi1,
|
||||||
|
dL_dpsi2=dL_dpsi2,
|
||||||
|
Z=model.Z, variational_posterior=X_slice)
|
||||||
|
|
||||||
#gradients w.r.t. posterior parameters of X
|
#gradients w.r.t. posterior parameters of X
|
||||||
X_grad = model.kern.gradients_qX_expectations(variational_posterior=X_slice, Z=model.Z, dL_dpsi0=grad_dict['dL_dpsi0'], dL_dpsi1=grad_dict['dL_dpsi1'], dL_dpsi2=grad_dict['dL_dpsi2'])
|
X_grad = model.kern.gradients_qX_expectations(
|
||||||
model.set_X_gradients(X_slice, X_grad)
|
variational_posterior=X_slice,
|
||||||
|
Z=model.Z,
|
||||||
|
dL_dpsi0=grad_dict['dL_dpsi0'],
|
||||||
|
dL_dpsi1=dL_dpsi1,
|
||||||
|
dL_dpsi2=dL_dpsi2)
|
||||||
|
|
||||||
|
model.X.mean[n_range[0]:n_range[1]].gradient = X_grad[0]
|
||||||
|
model.X.variance[n_range[0]:n_range[1]].gradient = X_grad[1]
|
||||||
|
|
||||||
if het_noise:
|
if het_noise:
|
||||||
dL_dthetaL[n_range[0]:n_range[1]] = grad_dict['dL_dthetaL']
|
dL_dthetaL[n_range[0]:n_range[1]] = grad_dict['dL_dthetaL']
|
||||||
else:
|
else:
|
||||||
dL_dthetaL += grad_dict['dL_dthetaL']
|
dL_dthetaL += grad_dict['dL_dthetaL']
|
||||||
|
#import ipdb;ipdb.set_trace()
|
||||||
# Set the gradients w.r.t. kernel
|
model.grad_dict = grad_dict
|
||||||
model.kern.gradient = kern_grad
|
if isinstance(model.X, VariationalPosterior):
|
||||||
|
|
||||||
# Update Log-likelihood
|
# Update Log-likelihood
|
||||||
model._log_marginal_likelihood -= model.variational_prior.KL_divergence(model.X)
|
model._log_marginal_likelihood -= model.variational_prior.KL_divergence(model.X)
|
||||||
# update for the KL divergence
|
# update for the KL divergence
|
||||||
model.variational_prior.update_gradients_KL(model.X)
|
model.variational_prior.update_gradients_KL(model.X)
|
||||||
|
|
||||||
|
# Set the gradients w.r.t. kernel
|
||||||
|
model.kern.gradient = kern_grad
|
||||||
|
|
||||||
# dL_dthetaL
|
# dL_dthetaL
|
||||||
model.likelihood.update_gradients(dL_dthetaL)
|
model.likelihood.update_gradients(dL_dthetaL)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue