// calculate left right flanking factors
fl = np.kron(qi_Pi, qj_Pj)
fr = np.kron(Pi_inv_pi, Pj_inv_pj)
// calculate D based on the method
Dij = np.kron(wi, wj)
if self.p is not None:
Q = np.diagflat(Dij)
D = np.eye(Q.shape[0])
S = self._mu[0] * Q
for k in self._mu[1:]:
D *= Q
S += k*D
else:
if self.kernel_type == "geometric":
D = np.diagflat(1/(1-self.lamda*Dij))
elif self.kernel_type == "exponential":
D = np.diagflat(np.exp(self.lamda*Dij))
return np.linalg.multi_dot((fl, D, fr))
class RandomWalkLabeled(RandomWalk):
The labeled random walk kernel class.
After Change
Id = np.identity(s)
if self.p is not None:
P = np.eye(XY.shape[0])
S = self._mu[0] * P
for k in self._mu[1:]:
P *= XY
S += k*P
else:
if self.kernel_type == "geometric":
S = inv(Id - self.lamda*XY).T
elif self.kernel_type == "exponential":
S = expm(self.lamda*XY).T
p = np.ones(shape=(1, s))return p.dot(S).dot(p.T)
elif self.method_type == "fast":
// Spectral demoposition algorithm as presented in
// [Vishwanathan et al., 2006] p.13, s.4.4, with
// complexity of O((|E|+|V|)|E||V|^2) for graphs