Skip to content

Commit

Permalink
FIX inconsistent hyperparameter and bounds issue in GP kernels (sciki…
Browse files Browse the repository at this point in the history
  • Loading branch information
marenwestermann committed Jul 18, 2020
1 parent b5e2a00 commit 0550793
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/gaussian_process/plot_gpr_co2.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def load_mauna_loa_atmospheric_co2():
k3 = 0.5**2 * RationalQuadratic(length_scale=1.0, alpha=1.0)
k4 = 0.1**2 * RBF(length_scale=0.1) \
+ WhiteKernel(noise_level=0.1**2,
noise_level_bounds=(1e-3, np.inf)) # noise terms
noise_level_bounds=(1e-5, np.inf)) # noise terms
kernel = k1 + k2 + k3 + k4

gp = GaussianProcessRegressor(kernel=kernel, alpha=0,
Expand Down
2 changes: 2 additions & 0 deletions sklearn/gaussian_process/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ def _check_bounds_params(self):
np.atleast_2d(self.theta).T)
idx = 0
for hyp in self.hyperparameters:
if hyp.fixed:
continue
for dim in range(hyp.n_elements):
if list_close[idx, 0]:
warnings.warn("The optimal value found for "
Expand Down
13 changes: 12 additions & 1 deletion sklearn/gaussian_process/tests/test_gpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels \
import RBF, ConstantKernel as C, WhiteKernel
from sklearn.gaussian_process.kernels import DotProduct
from sklearn.gaussian_process.kernels import DotProduct, ExpSineSquared
from sklearn.gaussian_process.tests._mini_sequence_kernel import MiniSeqKernel
from sklearn.exceptions import ConvergenceWarning

Expand Down Expand Up @@ -525,3 +525,14 @@ def test_warning_bounds():
"specified lower bound 10.0. "
"Decreasing the bound and calling "
"fit again may find a better value.")


def test_bound_check_fixed_hyperparameter():
# Regression test for issue #17943
# Check that having a hyperparameter with fixed bounds doesn't cause an
# error
k1 = 50.0**2 * RBF(length_scale=50.0) # long term smooth rising trend
k2 = ExpSineSquared(length_scale=1.0, periodicity=1.0,
periodicity_bounds="fixed") # seasonal component
kernel = k1 + k2
GaussianProcessRegressor(kernel=kernel).fit(X, y)

0 comments on commit 0550793

Please sign in to comment.