From 2ecd13b08d93448167fc66e5cd3cfff58916083d Mon Sep 17 00:00:00 2001 From: beckdaniel Date: Mon, 7 Mar 2016 10:46:42 +0000 Subject: [PATCH] moved cubic sine from tests to examples --- GPy/examples/regression.py | 26 ++++++++++++++++++++++++++ GPy/testing/model_tests.py | 29 +---------------------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/GPy/examples/regression.py b/GPy/examples/regression.py index 11734564..b6bc07a0 100644 --- a/GPy/examples/regression.py +++ b/GPy/examples/regression.py @@ -550,3 +550,29 @@ def parametric_mean_function(max_iters=100, optimize=True, plot=True): return m +def warped_gp_cubic_sine(max_iters=100): + """ + A test replicating the sine regression problem from + Snelson's paper. + """ + X = (2 * np.pi) * np.random.random(151) - np.pi + Y = np.sin(X) + np.random.normal(0,0.2,151) + Y = np.array([np.power(abs(y),float(1)/3) * (1,-1)[y<0] for y in Y]) + + warp_k = GPy.kern.RBF(1) + warp_f = GPy.util.warping_functions.TanhFunction(n_terms=2) + warp_m = GPy.models.WarpedGP(X[:, None], Y[:, None], kernel=warp_k, warping_function=warp_f) + + m = GPy.models.GPRegression(X[:, None], Y[:, None]) + m.optimize_restarts(parallel=False, robust=True, num_restarts=5, max_iters=max_iters) + warp_m.optimize_restarts(parallel=False, robust=True, num_restarts=5, max_iters=max_iters) + print(warp_m) + print(warp_m['.*warp.*']) + warp_m.predict_in_warped_space = False + warp_m.plot(title="Warped GP - Latent space") + warp_m.predict_in_warped_space = True + warp_m.plot(title="Warped GP - Warped space") + m.plot(title="Standard GP") + #warp_f.plot(X.min()-10, X.max()+10) + warp_m.plot_warping() + pb.show() diff --git a/GPy/testing/model_tests.py b/GPy/testing/model_tests.py index 351aa210..5ec64e15 100644 --- a/GPy/testing/model_tests.py +++ b/GPy/testing/model_tests.py @@ -311,6 +311,7 @@ class MiscTests(unittest.TestCase): """ A WarpedGP with the log warping function should be equal to a standard GP with log labels. + Note that we predict the median here. """ k = GPy.kern.RBF(1) Y = np.abs(self.Y) @@ -327,34 +328,6 @@ class MiscTests(unittest.TestCase): np.testing.assert_almost_equal(np.exp(preds), warp_preds, decimal=4) - @unittest.skip('Comment this to plot the modified sine function') - def test_warped_gp_sine(self): - """ - A test replicating the sine regression problem from - Snelson's paper. - """ - X = (2 * np.pi) * np.random.random(151) - np.pi - Y = np.sin(X) + np.random.normal(0,0.2,151) - Y = np.array([np.power(abs(y),float(1)/3) * (1,-1)[y<0] for y in Y]) - - import matplotlib.pyplot as plt - warp_k = GPy.kern.RBF(1) - warp_f = GPy.util.warping_functions.TanhFunction(n_terms=2) - warp_m = GPy.models.WarpedGP(X[:, None], Y[:, None], kernel=warp_k, warping_function=warp_f) - - m = GPy.models.GPRegression(X[:, None], Y[:, None]) - m.optimize_restarts(parallel=False, robust=True, num_restarts=5) - warp_m.optimize_restarts(parallel=False, robust=True, num_restarts=5) - print(warp_m) - print(warp_m['.*warp.*']) - warp_m.predict_in_warped_space = False - warp_m.plot() - warp_m.predict_in_warped_space = True - warp_m.plot() - m.plot() - warp_f.plot(X.min()-10, X.max()+10) - plt.show() - class GradientTests(np.testing.TestCase): def setUp(self):