pythonscikit-learnkernelgaussian-process

How to calculate the WhiteKernel from sklearn using numpy?


I have to reconstruct a kernel unsing numpy:

kernel=ConstantKernel() * RBF() + WhiteKernel()

This is what i got for the ConstantKernel and the RBF (it works):

def predict(self, x) -> np.ndarray:

    x_train = self.x_train / self.length_scale
    x_test = x / self.length_scale

    sqdist = \
        np.sum(x_train ** 2, axis=1).reshape(-1, 1) \
        + np.sum(x_test ** 2, axis=1) \
        - 2 * np.dot(x_train, x_test.T)

    k_star = np.exp(-0.5 * sqdist) * self.constant_value

    return np.dot(k_star.T, self.alpha)

now i am wondering how to reconstruct the WhiteKernel. Some ideas? Thank you!


Solution

  • Okay, i got it. You just dont have to do it. The prediction without the white kernel is totally fine. It just helps for training.