From e0d3633ec36d930ef06cea20c7ff72db96441434 Mon Sep 17 00:00:00 2001 From: James Hensman Date: Thu, 16 Oct 2014 17:00:17 +0100 Subject: [PATCH] handles import of pods correctly --- GPy/examples/classification.py | 22 ++++++++++++++++------ GPy/examples/regression.py | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/GPy/examples/classification.py b/GPy/examples/classification.py index deb44ffc..cf71be24 100644 --- a/GPy/examples/classification.py +++ b/GPy/examples/classification.py @@ -6,12 +6,6 @@ Gaussian Processes classification """ import GPy -import pods - -try: - from matplotlib import pyplot as plt -except: - pass default_seed = 10000 @@ -20,6 +14,8 @@ def oil(num_inducing=50, max_iters=100, kernel=None, optimize=True, plot=True): Run a Gaussian process classification on the three phase oil data. The demonstration calls the basic GP classification model and uses EP to approximate the likelihood. """ + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.oil() X = data['X'] Xtest = data['Xtest'] @@ -55,6 +51,8 @@ def toy_linear_1d_classification(seed=default_seed, optimize=True, plot=True): """ + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.toy_linear_1d_classification(seed=seed) Y = data['Y'][:, 0:1] Y[Y.flatten() == -1] = 0 @@ -72,6 +70,7 @@ def toy_linear_1d_classification(seed=default_seed, optimize=True, plot=True): # Plot if plot: + from matplotlib import pyplot as plt fig, axes = plt.subplots(2, 1) m.plot_f(ax=axes[0]) m.plot(ax=axes[1]) @@ -88,6 +87,8 @@ def toy_linear_1d_classification_laplace(seed=default_seed, optimize=True, plot= """ + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.toy_linear_1d_classification(seed=seed) Y = data['Y'][:, 0:1] Y[Y.flatten() == -1] = 0 @@ -108,6 +109,7 @@ def toy_linear_1d_classification_laplace(seed=default_seed, optimize=True, plot= # Plot if plot: + from matplotlib import pyplot as plt fig, axes = plt.subplots(2, 1) m.plot_f(ax=axes[0]) m.plot(ax=axes[1]) @@ -124,6 +126,8 @@ def sparse_toy_linear_1d_classification(num_inducing=10, seed=default_seed, opti """ + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.toy_linear_1d_classification(seed=seed) Y = data['Y'][:, 0:1] Y[Y.flatten() == -1] = 0 @@ -138,6 +142,7 @@ def sparse_toy_linear_1d_classification(num_inducing=10, seed=default_seed, opti # Plot if plot: + from matplotlib import pyplot as plt fig, axes = plt.subplots(2, 1) m.plot_f(ax=axes[0]) m.plot(ax=axes[1]) @@ -154,6 +159,8 @@ def toy_heaviside(seed=default_seed, optimize=True, plot=True): """ + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.toy_linear_1d_classification(seed=seed) Y = data['Y'][:, 0:1] Y[Y.flatten() == -1] = 0 @@ -172,6 +179,7 @@ def toy_heaviside(seed=default_seed, optimize=True, plot=True): # Plot if plot: + from matplotlib import pyplot as plt fig, axes = plt.subplots(2, 1) m.plot_f(ax=axes[0]) m.plot(ax=axes[1]) @@ -191,6 +199,8 @@ def crescent_data(model_type='Full', num_inducing=10, seed=default_seed, kernel= :param kernel: kernel to use in the model :type kernel: a GPy kernel """ + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.crescent_data(seed=seed) Y = data['Y'] Y[Y.flatten()==-1] = 0 diff --git a/GPy/examples/regression.py b/GPy/examples/regression.py index e398e959..6851f83c 100644 --- a/GPy/examples/regression.py +++ b/GPy/examples/regression.py @@ -10,10 +10,11 @@ except: pass import numpy as np import GPy -import pods def olympic_marathon_men(optimize=True, plot=True): """Run a standard Gaussian process regression on the Olympic marathon data.""" + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.olympic_marathon_men() # create simple GP Model @@ -83,6 +84,8 @@ def epomeo_gpx(max_iters=200, optimize=True, plot=True): from the Mount Epomeo runs. Requires gpxpy to be installed on your system to load in the data. """ + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.epomeo_gpx() num_data_list = [] for Xpart in data['X']: @@ -126,6 +129,8 @@ def multiple_optima(gene_number=937, resolution=80, model_restarts=10, seed=1000 length_scales = np.linspace(0.1, 60., resolution) log_SNRs = np.linspace(-3., 4., resolution) + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.della_gatta_TRP63_gene_expression(data_set='della_gatta',gene_number=gene_number) # data['Y'] = data['Y'][0::2, :] # data['X'] = data['X'][0::2, :] @@ -206,6 +211,8 @@ def _contour_data(data, length_scales, log_SNRs, kernel_call=GPy.kern.RBF): def olympic_100m_men(optimize=True, plot=True): """Run a standard Gaussian process regression on the Rogers and Girolami olympics data.""" + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.olympic_100m_men() # create simple GP Model @@ -223,6 +230,8 @@ def olympic_100m_men(optimize=True, plot=True): def toy_rbf_1d(optimize=True, plot=True): """Run a simple demonstration of a standard Gaussian process fitting it to data sampled from an RBF covariance.""" + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.toy_rbf_1d() # create simple GP Model @@ -237,6 +246,8 @@ def toy_rbf_1d(optimize=True, plot=True): def toy_rbf_1d_50(optimize=True, plot=True): """Run a simple demonstration of a standard Gaussian process fitting it to data sampled from an RBF covariance.""" + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.toy_rbf_1d_50() # create simple GP Model @@ -352,6 +363,8 @@ def toy_ARD_sparse(max_iters=1000, kernel_type='linear', num_samples=300, D=4, o def robot_wireless(max_iters=100, kernel=None, optimize=True, plot=True): """Predict the location of a robot given wirelss signal strength readings.""" + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.robot_wireless() # create simple GP Model @@ -376,6 +389,8 @@ def robot_wireless(max_iters=100, kernel=None, optimize=True, plot=True): def silhouette(max_iters=100, optimize=True, plot=True): """Predict the pose of a figure given a silhouette. This is a task from Agarwal and Triggs 2004 ICML paper.""" + try:import pods + except ImportError:print 'pods unavailable, see https://github.com/sods/ods for example datasets' data = pods.datasets.silhouette() # create simple GP Model