mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-12 05:22:38 +02:00
psi statistics for the linear kernel
This commit is contained in:
parent
71e461a780
commit
7d8e2183a2
3 changed files with 24 additions and 24 deletions
|
|
@ -325,11 +325,11 @@ class kern(parameterised):
|
|||
|
||||
# MASSIVE TODO: do something smart for white
|
||||
# "crossterms"
|
||||
psi1_matrices = [np.zeros((mu.shape[0], Z.shape[0])) for p in self.parts]
|
||||
[p.psi1(Z[s2],mu[s1],S[s1],psi1_target[s1,s2]) for p,s1,s2,psi1_target in zip(self.parts,slices1,slices2, psi1_matrices)]
|
||||
for a,b in itertools.combinations(psi1_matrices, 2):
|
||||
tmp = np.multiply(a,b)
|
||||
target += tmp[:,None,:] + tmp[:, :,None]
|
||||
# psi1_matrices = [np.zeros((mu.shape[0], Z.shape[0])) for p in self.parts]
|
||||
# [p.psi1(Z[s2],mu[s1],S[s1],psi1_target[s1,s2]) for p,s1,s2,psi1_target in zip(self.parts,slices1,slices2, psi1_matrices)]
|
||||
# for a,b in itertools.combinations(psi1_matrices, 2):
|
||||
# tmp = np.multiply(a,b)
|
||||
# target += tmp[:,None,:] + tmp[:, :,None]
|
||||
|
||||
return target
|
||||
|
||||
|
|
@ -340,21 +340,21 @@ class kern(parameterised):
|
|||
[p.dpsi2_dtheta(partial[s1,s2,s2],Z[s2,i_s],mu[s1,i_s],S[s1,i_s],target[ps]) for p,i_s,s1,s2,ps in zip(self.parts,self.input_slices,slices1,slices2,self.param_slices)]
|
||||
|
||||
|
||||
# "crossterms"
|
||||
# 1. get all the psi1 statistics
|
||||
psi1_matrices = [np.zeros((mu.shape[0], Z.shape[0])) for p in self.parts]
|
||||
[p.psi1(Z[s2],mu[s1],S[s1],psi1_target[s1,s2]) for p,s1,s2,psi1_target in zip(self.parts,slices1,slices2, psi1_matrices)]
|
||||
partial1 = np.zeros_like(partial1)
|
||||
# # "crossterms"
|
||||
# # 1. get all the psi1 statistics
|
||||
# psi1_matrices = [np.zeros((mu.shape[0], Z.shape[0])) for p in self.parts]
|
||||
# [p.psi1(Z[s2],mu[s1],S[s1],psi1_target[s1,s2]) for p,s1,s2,psi1_target in zip(self.parts,slices1,slices2, psi1_matrices)]
|
||||
# partial1 = np.zeros_like(partial1)
|
||||
|
||||
# 2. get all the dpsi1/dtheta gradients
|
||||
psi1_gradients = [np.zeros(self.Nparam) for p in self.parts]
|
||||
[p.dpsi1_dtheta(partial1[s2,s1],Z[s2,i_s],mu[s1,i_s],S[s1,i_s],psi1g_target[ps]) for p,ps,s1,s2,i_s,psi1g_target in zip(self.parts, self.param_slices,slices1,slices2,self.input_slices,psi1_gradients)]
|
||||
# # 2. get all the dpsi1/dtheta gradients
|
||||
# psi1_gradients = [np.zeros(self.Nparam) for p in self.parts]
|
||||
# [p.dpsi1_dtheta(partial1[s2,s1],Z[s2,i_s],mu[s1,i_s],S[s1,i_s],psi1g_target[ps]) for p,ps,s1,s2,i_s,psi1g_target in zip(self.parts, self.param_slices,slices1,slices2,self.input_slices,psi1_gradients)]
|
||||
|
||||
# 3. multiply them somehow
|
||||
for a,b in itertools.combinations(range(len(psi1_matrices)), 2):
|
||||
gne = (psi1_gradients[a][None]*psi1_matrices[b].sum(0)[:,None]).sum(0)
|
||||
# # 3. multiply them somehow
|
||||
# for a,b in itertools.combinations(range(len(psi1_matrices)), 2):
|
||||
# gne = (psi1_gradients[a][None]*psi1_matrices[b].sum(0)[:,None]).sum(0)
|
||||
|
||||
target += (gne[None] + gne[:, None]).sum(0)
|
||||
# target += (gne[None] + gne[:, None]).sum(0)
|
||||
return target
|
||||
|
||||
def dpsi2_dZ(self,partial,Z,mu,S,slices1=None,slices2=None):
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class linear(kernpart):
|
|||
if variances is not None:
|
||||
if isinstance(variances, float):
|
||||
variances = np.array([variances])
|
||||
|
||||
|
||||
assert variances.shape == (1,)
|
||||
else:
|
||||
variances = np.ones(1)
|
||||
|
|
@ -91,11 +91,11 @@ class linear(kernpart):
|
|||
|
||||
def dpsi0_dtheta(self,partial,Z,mu,S,target):
|
||||
expected = np.square(mu) + S
|
||||
target += (partial[:, None] * (-2.*np.sum(expected,0))).sum()
|
||||
target += (partial[:, None] * (np.sum(expected,0))).sum()
|
||||
|
||||
def dpsi0_dmuS(self,partial, Z,mu,S,target_mu,target_S):
|
||||
target_mu += partial[:, None] * (2*mu*self.variances)
|
||||
target_S += partial[:, None] * self.variances
|
||||
target_mu += partial[:, None] * (2.0*mu*self.variances) * mu.shape[0]
|
||||
target_S += partial[:, None] * self.variances * mu.shape[0]
|
||||
|
||||
def dpsi0_dZ(self,Z,mu,S,target):
|
||||
pass
|
||||
|
|
@ -110,7 +110,7 @@ class linear(kernpart):
|
|||
|
||||
def dpsi1_dmuS(self,partial,Z,mu,S,target_mu,target_S):
|
||||
"""Do nothing for S, it does not affect psi1"""
|
||||
target_mu += (partial.T[:,:, None]*(Z/self.variances)).sum(1)
|
||||
target_mu += (partial.T[:,:, None]*(Z*self.variances)).sum(1)
|
||||
|
||||
def dpsi1_dZ(self,partial,Z,mu,S,target):
|
||||
self.dK_dX(partial.T,Z,mu,target)
|
||||
|
|
@ -131,7 +131,6 @@ class linear(kernpart):
|
|||
|
||||
def dpsi2_dmuS(self,partial,Z,mu,S,target_mu,target_S):
|
||||
"""Think N,M,M,Q """
|
||||
mu2_S = np.sum(np.square(mu)+S,0)# Q,
|
||||
ZZ = Z[:,None,:]*Z[None,:,:] # M,M,Q
|
||||
tmp = ZZ*np.square(self.variances) # M,M,Q
|
||||
target_mu += (partial[:,:,:,None]*tmp*2.*mu[:,None,None,:]).sum(1).sum(1)
|
||||
|
|
@ -139,7 +138,7 @@ class linear(kernpart):
|
|||
|
||||
def dpsi2_dZ(self,partial,Z,mu,S,target):
|
||||
mu2_S = np.sum(np.square(mu)+S,0)# Q,
|
||||
target += (partial[:,:,:,None]* (Z * mu2_S * np.square(self.variances))).sum(0).sum(0)
|
||||
target += (partial[:,:,:,None]* (Z * mu2_S * np.square(self.variances))).sum(0).sum(1)
|
||||
|
||||
#---------------------------------------#
|
||||
# Precomputations #
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue