From 661d3c37373ec77f86e063cb61bea8a3424691c6 Mon Sep 17 00:00:00 2001 From: Jonas Seiler Date: Thu, 22 May 2014 13:23:23 +0200 Subject: [PATCH] fix sign error in gp + unit test #3180 --- sklearn/gaussian_process/gaussian_process.py | 3 +-- .../tests/test_gaussian_process.py | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/sklearn/gaussian_process/gaussian_process.py b/sklearn/gaussian_process/gaussian_process.py index 2c630ef20e747..a50ad5724e34a 100644 --- a/sklearn/gaussian_process/gaussian_process.py +++ b/sklearn/gaussian_process/gaussian_process.py @@ -730,9 +730,8 @@ def minus_reduced_likelihood_function(log10t): raise ve optimal_theta = 10. ** log10_optimal_theta - optimal_minus_rlf_value, optimal_par = \ + optimal_rlf_value, optimal_par = \ self.reduced_likelihood_function(theta=optimal_theta) - optimal_rlf_value = - optimal_minus_rlf_value # Compare the new optimizer to the best previous one if k > 0: diff --git a/sklearn/gaussian_process/tests/test_gaussian_process.py b/sklearn/gaussian_process/tests/test_gaussian_process.py index 61d617690edb9..3e6fb9c787cd4 100644 --- a/sklearn/gaussian_process/tests/test_gaussian_process.py +++ b/sklearn/gaussian_process/tests/test_gaussian_process.py @@ -135,3 +135,27 @@ def test_no_normalize(): gp = GaussianProcess(normalize=False).fit(X, y) y_pred = gp.predict(X) assert_true(np.allclose(y_pred, y)) + + +def test_1d_tough_noisy(regr=regression.constant, corr=correlation.squared_exponential, + random_start=10, beta0=None): + """ + MLE estimation of a one-dimensional Gaussian Process model. + Check random start optimization with noisy / duplicate inputs. + + Test the interpolating property. + """ + + X = np.atleast_2d([1., 3., 5., 6., 7., 8., 9., 10., 12., 13., 14., 17.]).T + x = np.atleast_2d(np.linspace(0, 20, 100)).T + + y = f(X).ravel() + np.random.normal(0, 0.1, len(X)) + + gp = GaussianProcess(regr=regr, corr=corr, beta0=beta0, + theta0=1e-2, thetaL=1e-4, thetaU=1., + random_start=random_start, verbose=False, nugget=0.002).fit(X, y) + + y_pred, MSE = gp.predict(x, eval_MSE=True) + y = f(x).ravel() + + assert_true((np.abs(y_pred - y) <= (1.96 * MSE) ).all()) #check that true value is within 95% conf. int. \ No newline at end of file