How to specify nu=infinity for Matern kernel in Sklearn?

Viewed 373

I'm trying to create a Matern kernel in Sklearn with the parameter nu set to infinity.

from sklearn.gaussian_process.kernels import Matern
import numpy as np
kernel = Matern(nu=float('inf'))
a = np.random.randn(5)[:,np.newaxis]
b = a
kernel(a,b)

When I run this code, I get an error message:

"RuntimeWarning: invalid value encountered in multiply
K *= tmp ** self.nu"

How else then may I specify the parameter nu as infinity in a Matern kernel? Thanks

1 Answers

Although the documentation seems to suggest that inf is a valid value for nu the code doesn't seem to account for that value, which is why you're seeing that error. However as the nu approaches infinity Matern kernel becomes equivalent to the squared exponential function, or the RBF in sklearn, so you can just use the following

from sklearn.gaussian_process.kernels import RBF
import numpy as np
kernel = RBF()
a = np.random.randn(5)[:,np.newaxis]
b = a
kernel(a,b)
Related