This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Description
Bug description
Calling multiple times .fit(X, y) whenever self.noise exists causes self.kernel to add new WhiteKernel noise.
Steps to reproduce
from skopt.learning.gaussian_process import gpr, kernels #gpr is the package with the bug
import numpy as np
np.random.seed(0) # for reproduction
gp = gpr.GaussianProcessRegressor(kernel=kernels.RBF(), alpha=1e-7, noise=0.01)
train_inputs = np.array([0, 0.1, 0.2]).reshape(-1, 1)
train_targets = np.array([1, 1.5, 0.6])
for i in range(10):
gp.fit(train_inputs, train_targets)
test_inputs = np.arange(0, 0.25, 0.05).reshape(-1, 1)
gp.predict(test_inputs)
print(str(gp.get_params()['kernel__k1']).count("WhiteKernel")) # number of WhiteKernels in self.kernel increases with each .fit
train_inputs = np.vstack([train_inputs, np.random.rand()])
train_targets = np.append(train_targets, np.random.rand())
Proposed solution
Lines 182-184, 189-194 from skopt.learning.gaussian_process.gpr should be on the init function, right after line 161
if isinstance(self.noise, str) and self.noise != "gaussian":
raise ValueError("expected noise to be 'gaussian', got %s"
% self.noise)
if self.noise == "gaussian":
kernel = kernel + WhiteKernel()
elif self.noise:
kernel = kernel + WhiteKernel(
noise_level=self.noise, noise_level_bounds="fixed"
)