10000 MISC Using np.finfo(float).eps instead of 1e-10 in Matern kernel · scikit-learn/scikit-learn@0b035a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b035a8

Browse files
author
Jan Hendrik Metzen
committed
MISC Using np.finfo(float).eps instead of 1e-10 in Matern kernel
Furthmore, fixed typo and increased readability of test_matern_kernel.
1 parent 5a73544 commit 0b035a8

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

examples/svm/plot_svm_matern_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
is compared on a (discontinuous) step-function:
1111
* The Matern kernel for coef0==1.5, learning a once differentiable function
1212
* The Matern kernel for coef0==2.5, learning a twice differentiable function
13-
* The Matern kernel for coef0==3.5, learning a three-rimes differentiable
13+
* The Matern kernel for coef0==3.5, learning a three-times differentiable
1414
function
1515
* The absolute-exponential kernel which corresponds to a Matern kernel
1616
with coef0==0.5

sklearn/metrics/pairwise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ def matern_kernel(X, Y=None, gamma=None, coef0=1.5):
792792
K *= np.sqrt(5) * gamma
793793
K = (1 + K + K ** 2 / 3.0) * np.exp(-K)
794794
else: # general case; expensive to evaluate
795-
K[K == 0.0] += 1e-10 # strict zeros would result in nan
795+
K[K == 0.0] += np.finfo(float).eps # strict zeros would result in nan
796796
tmp = (np.sqrt(2 * coef0) * gamma * K)
797797
K[:] = (2 ** (1 - coef0)) / scipy.special.gamma(coef0)
798798
K *= tmp ** coef0

sklearn/metrics/tests/test_pairwise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def test_matern_kernel():
421421
X = rng.random_sample((5, 4))
422422
K = matern_kernel(X, X)
423423
# the diagonal elements of a matern kernel are 1
424-
assert_array_almost_equal(K.flat[::6], np.ones(5))
424+
assert_array_almost_equal(np.diag(K), np.ones(5))
425425
# matern kernel for coef0==inf is equal to rbf kernel
426426
K_rbf = rbf_kernel(X, X)
427427
K = matern_kernel(X, X, coef0=np.inf)

0 commit comments

Comments
 (0)
0