Open briling opened 2 weeks ago
@YAY-C @liam-o-marsh
Kernel names such as 'myL'
, 'myLfast'
, 'myG'
are probably not very good, how would you guys replace them? (I would still keep the old ones as well for backward compatibility)
I'm not even sure what the code of 'myL' does, sorry.
what's the second argument in np.exp(K,K)
for? (edit: nevermind the second K
is for out
)
follow-up: I tried to rewrite the custom laplacian kernel. Is there a place where it wouldn't behave like the old version?
def my_laplacian_kernel_old(X, Y, gamma):
""" Compute Laplacian kernel between X and Y
.. todo::
Write the docstring
"""
def cdist(X, Y):
K = np.zeros((len(X),len(Y)))
for i,x in enumerate(X):
x = np.array([x] * len(Y))
d = np.abs(x-Y)
while len(d.shape)>1:
d = np.sum(d, axis=1) # several axis available for np > 1.7.0 (TODO shall we move this)
K[i,:] = d
return K
K = -gamma * cdist(X, Y)
np.exp(K, K)
return K
def my_laplacian_kernel(X, Y, gamma):
""" Compute Laplacian kernel between X and Y
.. todo::
Write the docstring
"""
assert X.shape[1:] == Y.shape[1:]
innerdims = X.ndim-1
transposer = tuple(range(1,X.ndim)) + (0,)
K = np.tensordot(X, Y.transpose(*transposer), innerdims)
K *= -gamma
np.exp(K, out=K)
return K