diff --git a/GPy/examples/classification.py b/GPy/examples/classification.py index ae9d8eb8..2dc5ad53 100644 --- a/GPy/examples/classification.py +++ b/GPy/examples/classification.py @@ -5,9 +5,13 @@ """ Gaussian Processes classification """ -import pylab as pb import GPy +try: + import pylab as pb +except: + pass + default_seed = 10000 def oil(num_inducing=50, max_iters=100, kernel=None, optimize=True, plot=True): diff --git a/GPy/examples/coreg_example.py b/GPy/examples/coreg_example.py index 66ba143d..6ec635eb 100644 --- a/GPy/examples/coreg_example.py +++ b/GPy/examples/coreg_example.py @@ -1,5 +1,8 @@ import numpy as np -import pylab as pb +try: + import pylab as pb +except: + pass import GPy pb.ion() pb.close('all') diff --git a/GPy/examples/non_gaussian.py b/GPy/examples/non_gaussian.py index c0fcd693..1e2be93b 100644 --- a/GPy/examples/non_gaussian.py +++ b/GPy/examples/non_gaussian.py @@ -1,7 +1,10 @@ import GPy import numpy as np -import matplotlib.pyplot as plt from GPy.util import datasets +try: + import matplotlib.pyplot as plt +except: + pass def student_t_approx(optimize=True, plot=True): """ diff --git a/GPy/examples/regression.py b/GPy/examples/regression.py index c4465061..83bb0453 100644 --- a/GPy/examples/regression.py +++ b/GPy/examples/regression.py @@ -4,7 +4,10 @@ """ Gaussian Processes regression examples """ -import pylab as pb +try: + import pylab as pb +except: + pass import numpy as np import GPy diff --git a/GPy/examples/stochastic.py b/GPy/examples/stochastic.py index c302ec7d..cc365cae 100644 --- a/GPy/examples/stochastic.py +++ b/GPy/examples/stochastic.py @@ -1,7 +1,10 @@ # Copyright (c) 2012, GPy authors (see AUTHORS.txt). # Licensed under the BSD 3-clause license (see LICENSE.txt) -import pylab as pb +try: + import pylab as pb +except: + pass import numpy as np import GPy diff --git a/GPy/examples/tutorials.py b/GPy/examples/tutorials.py index 7825992d..aa82d9f9 100644 --- a/GPy/examples/tutorials.py +++ b/GPy/examples/tutorials.py @@ -6,8 +6,11 @@ Code of Tutorials """ -import pylab as pb -pb.ion() +try: + import pylab as pb + pb.ion() +except: + pass import numpy as np import GPy diff --git a/GPy/kern/_src/rbf.py b/GPy/kern/_src/rbf.py index 3711738a..62539e6d 100644 --- a/GPy/kern/_src/rbf.py +++ b/GPy/kern/_src/rbf.py @@ -20,8 +20,6 @@ class RBF(Stationary): _support_GPU = True def __init__(self, input_dim, variance=1., lengthscale=None, ARD=False, active_dims=None, name='rbf', useGPU=False): super(RBF, self).__init__(input_dim, variance, lengthscale, ARD, active_dims, name, useGPU=useGPU) - self.weave_options = {} - self.group_spike_prob = False self.psicomp = PSICOMP_RBF() if self.useGPU: self.psicomp = PSICOMP_RBF_GPU() diff --git a/GPy/kern/_src/trunclinear.py b/GPy/kern/_src/trunclinear.py index 76ed31f7..4ebd51b6 100644 --- a/GPy/kern/_src/trunclinear.py +++ b/GPy/kern/_src/trunclinear.py @@ -3,14 +3,10 @@ import numpy as np -from scipy import weave from kern import Kern -from ...util.linalg import tdot -from ...util.misc import param_to_array from ...core.parameterization import Param from ...core.parameterization.transformations import Logexp from ...util.caching import Cache_this -from ...core.parameterization import variational from ...util.config import * class TruncLinear(Kern): diff --git a/GPy/models/bcgplvm.py b/GPy/models/bcgplvm.py index f21a01f4..c54ffdf6 100644 --- a/GPy/models/bcgplvm.py +++ b/GPy/models/bcgplvm.py @@ -3,8 +3,6 @@ import numpy as np -import pylab as pb -import sys, pdb from ..core import GP from ..models import GPLVM from ..mappings import * diff --git a/GPy/models/gplvm.py b/GPy/models/gplvm.py index 79128270..4e45ac4a 100644 --- a/GPy/models/gplvm.py +++ b/GPy/models/gplvm.py @@ -3,7 +3,6 @@ import numpy as np -import pylab as pb from .. import kern from ..core import GP, Param from ..likelihoods import Gaussian @@ -55,7 +54,7 @@ class GPLVM(GP): #J = np.zeros((X.shape[0],X.shape[1],self.output_dim)) J = self.jacobian(X) for i in range(X.shape[0]): - target[i]=np.sqrt(pb.det(np.dot(J[i,:,:],np.transpose(J[i,:,:])))) + target[i]=np.sqrt(np.linalg.det(np.dot(J[i,:,:],np.transpose(J[i,:,:])))) return target def plot(self): @@ -63,6 +62,7 @@ class GPLVM(GP): pb.scatter(self.likelihood.Y[:, 0], self.likelihood.Y[:, 1], 40, self.X[:, 0].copy(), linewidth=0, cmap=pb.cm.jet) # @UndefinedVariable Xnew = np.linspace(self.X.min(), self.X.max(), 200)[:, None] mu, _ = self.predict(Xnew) + import pylab as pb pb.plot(mu[:, 0], mu[:, 1], 'k', linewidth=1.5) def plot_latent(self, labels=None, which_indices=None, diff --git a/GPy/models/sparse_gplvm.py b/GPy/models/sparse_gplvm.py index 4642e158..251103f4 100644 --- a/GPy/models/sparse_gplvm.py +++ b/GPy/models/sparse_gplvm.py @@ -3,13 +3,8 @@ import numpy as np -import pylab as pb -import sys, pdb +import sys from GPy.models.sparse_gp_regression import SparseGPRegression -from GPy.models.gplvm import GPLVM -# from .. import kern -# from ..core import model -# from ..util.linalg import pdinv, PCA class SparseGPLVM(SparseGPRegression): """ diff --git a/GPy/plotting/__init__.py b/GPy/plotting/__init__.py index 7a39ca9a..d3a96914 100644 --- a/GPy/plotting/__init__.py +++ b/GPy/plotting/__init__.py @@ -1,4 +1,7 @@ # Copyright (c) 2014, GPy authors (see AUTHORS.txt). # Licensed under the BSD 3-clause license (see LICENSE.txt) -import matplot_dep +try: + import matplot_dep +except (ImportError, NameError): + print 'Fail to load GPy.plotting.matplot_dep.' \ No newline at end of file diff --git a/GPy/plotting/matplot_dep/base_plots.py b/GPy/plotting/matplot_dep/base_plots.py index db9ab8e4..b4142342 100644 --- a/GPy/plotting/matplot_dep/base_plots.py +++ b/GPy/plotting/matplot_dep/base_plots.py @@ -2,8 +2,11 @@ # Licensed under the BSD 3-clause license (see LICENSE.txt) -import Tango -import pylab as pb +try: + import Tango + import pylab as pb +except: + pass import numpy as np def ax_default(fignum, ax): diff --git a/GPy/plotting/matplot_dep/dim_reduction_plots.py b/GPy/plotting/matplot_dep/dim_reduction_plots.py index 1d5fdd61..20e8e962 100644 --- a/GPy/plotting/matplot_dep/dim_reduction_plots.py +++ b/GPy/plotting/matplot_dep/dim_reduction_plots.py @@ -1,12 +1,16 @@ -import pylab as pb + import numpy as np from latent_space_visualizations.controllers.imshow_controller import ImshowController,ImAnnotateController from ...util.misc import param_to_array from ...core.parameterization.variational import VariationalPosterior from .base_plots import x_frame2D import itertools -import Tango -from matplotlib.cm import get_cmap +try: + import Tango + from matplotlib.cm import get_cmap + import pylab as pb +except: + pass def most_significant_input_dimensions(model, which_indices): """ diff --git a/GPy/plotting/matplot_dep/inference_plots.py b/GPy/plotting/matplot_dep/inference_plots.py index 6a3a8a93..c802932c 100644 --- a/GPy/plotting/matplot_dep/inference_plots.py +++ b/GPy/plotting/matplot_dep/inference_plots.py @@ -1,8 +1,10 @@ # Copyright (c) 2012, GPy authors (see AUTHORS.txt). # Licensed under the BSD 3-clause license (see LICENSE.txt) -import pylab as pb -import sys +try: + import pylab as pb +except: + pass #import numpy as np #import Tango #from base_plots import gpplot, x_frame1D, x_frame2D diff --git a/GPy/plotting/matplot_dep/mapping_plots.py b/GPy/plotting/matplot_dep/mapping_plots.py index 3e3ea793..6156687d 100644 --- a/GPy/plotting/matplot_dep/mapping_plots.py +++ b/GPy/plotting/matplot_dep/mapping_plots.py @@ -1,9 +1,12 @@ # Copyright (c) 2012, GPy authors (see AUTHORS.txt). # Licensed under the BSD 3-clause license (see LICENSE.txt) -import pylab as pb import numpy as np -import Tango +try: + import Tango + import pylab as pb +except: + pass from base_plots import x_frame1D, x_frame2D diff --git a/GPy/plotting/matplot_dep/maps.py b/GPy/plotting/matplot_dep/maps.py index e941ab2d..dbedaa98 100644 --- a/GPy/plotting/matplot_dep/maps.py +++ b/GPy/plotting/matplot_dep/maps.py @@ -1,13 +1,14 @@ import numpy as np -import pylab as pb -import matplotlib.patches as patches -from matplotlib.patches import Polygon -from matplotlib.collections import PatchCollection -#from matplotlib import cm +try: + import pylab as pb + from matplotlib.patches import Polygon + from matplotlib.collections import PatchCollection + #from matplotlib import cm + pb.ion() +except: + pass import re -pb.ion() - def plot(shape_records,facecolor='w',edgecolor='k',linewidths=.5, ax=None,xlims=None,ylims=None): """ Plot the geometry of a shapefile diff --git a/GPy/plotting/matplot_dep/models_plots.py b/GPy/plotting/matplot_dep/models_plots.py index 46a79ad8..509c9485 100644 --- a/GPy/plotting/matplot_dep/models_plots.py +++ b/GPy/plotting/matplot_dep/models_plots.py @@ -1,9 +1,12 @@ # Copyright (c) 2012, GPy authors (see AUTHORS.txt). # Licensed under the BSD 3-clause license (see LICENSE.txt) -import pylab as pb +try: + import Tango + import pylab as pb +except: + pass import numpy as np -import Tango from base_plots import gpplot, x_frame1D, x_frame2D from ...util.misc import param_to_array from ...models.gp_coregionalized_regression import GPCoregionalizedRegression diff --git a/GPy/plotting/matplot_dep/priors_plots.py b/GPy/plotting/matplot_dep/priors_plots.py index af999740..8f02a03b 100644 --- a/GPy/plotting/matplot_dep/priors_plots.py +++ b/GPy/plotting/matplot_dep/priors_plots.py @@ -3,7 +3,10 @@ import numpy as np -import pylab as pb +try: + import pylab as pb +except: + pass def univariate_plot(prior): diff --git a/GPy/plotting/matplot_dep/ssgplvm.py b/GPy/plotting/matplot_dep/ssgplvm.py index 4106e251..ef45a759 100644 --- a/GPy/plotting/matplot_dep/ssgplvm.py +++ b/GPy/plotting/matplot_dep/ssgplvm.py @@ -6,7 +6,6 @@ import pylab from ...models import SSGPLVM from img_plots import plot_2D_images -from ...util.misc import param_to_array class SSGPLVM_plot(object): def __init__(self,model, imgsize): diff --git a/GPy/util/datasets.py b/GPy/util/datasets.py index 17b26f31..93a5dceb 100644 --- a/GPy/util/datasets.py +++ b/GPy/util/datasets.py @@ -2,7 +2,6 @@ import csv import os import copy import numpy as np -import pylab as pb import GPy import scipy.io import cPickle as pickle @@ -346,6 +345,7 @@ def football_data(season='1314', data_set='football_data'): data_resources[data_set_season]['files'] = [files] if not data_available(data_set_season): download_data(data_set_season) + import pylab as pb for file in reversed(files): filename = os.path.join(data_path, data_set_season, file) # rewrite files removing blank rows. diff --git a/GPy/util/pca.py b/GPy/util/pca.py index 967d0e1b..046f47d7 100644 --- a/GPy/util/pca.py +++ b/GPy/util/pca.py @@ -5,8 +5,11 @@ Created on 10 Sep 2012 @copyright: Max Zwiessele 2012 ''' import numpy -import pylab -import matplotlib +try: + import pylab + import matplotlib +except: + pass from numpy.linalg.linalg import LinAlgError class pca(object): @@ -88,13 +91,15 @@ class pca(object): def plot_2d(self, X, labels=None, s=20, marker='o', dimensions=(0, 1), ax=None, colors=None, - fignum=None, cmap=matplotlib.cm.jet, # @UndefinedVariable + fignum=None, cmap=None, # @UndefinedVariable ** kwargs): """ Plot dimensions `dimensions` with given labels against each other in PC space. Labels can be any sequence of labels of dimensions X.shape[0]. Labels can be drawn with a subsequent call to legend() """ + if cmap is None: + cmap = matplotlib.cm.jet if ax is None: fig = pylab.figure(fignum) ax = fig.add_subplot(111)