From 42acfd02364095f29e85a62d039f91bbe66a1100 Mon Sep 17 00:00:00 2001 From: jajupmochi Date: Thu, 2 Dec 2021 16:52:41 +0100 Subject: [PATCH] [Fix] Fix laplacian_kernel and cosine_kernel between pairs of numpy vectors. --- gklearn/utils/kernels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gklearn/utils/kernels.py b/gklearn/utils/kernels.py index c35cc2f..182668b 100644 --- a/gklearn/utils/kernels.py +++ b/gklearn/utils/kernels.py @@ -127,7 +127,7 @@ def linearkernel(x, y): def cosine_kernel(x, y): - return np.dot(x, y) / (np.abs(x) * np.abs(y)) + return np.dot(x, y) / (np.linalg.norm(x) * np.linalg.norm(y)) def sigmoid_kernel(x, y, gamma=None, coef0=1): @@ -146,7 +146,7 @@ def laplacian_kernel(x, y, gamma=None): if gamma is None: gamma = 1.0 / len(x) - k = -gamma * np.abs(np.subtract(x, y)) + k = -gamma * np.linalg.norm(np.subtract(x, y)) k = np.exp(k) return k