Remove the dependency on matplotlib

This commit is contained in:
Zhenwen Dai 2014-09-12 11:51:51 +01:00
parent d7eee6aa00
commit 049b58c729
22 changed files with 80 additions and 48 deletions

View file

@ -5,9 +5,13 @@
""" """
Gaussian Processes classification Gaussian Processes classification
""" """
import pylab as pb
import GPy import GPy
try:
import pylab as pb
except:
pass
default_seed = 10000 default_seed = 10000
def oil(num_inducing=50, max_iters=100, kernel=None, optimize=True, plot=True): def oil(num_inducing=50, max_iters=100, kernel=None, optimize=True, plot=True):

View file

@ -1,5 +1,8 @@
import numpy as np import numpy as np
import pylab as pb try:
import pylab as pb
except:
pass
import GPy import GPy
pb.ion() pb.ion()
pb.close('all') pb.close('all')

View file

@ -1,7 +1,10 @@
import GPy import GPy
import numpy as np import numpy as np
import matplotlib.pyplot as plt
from GPy.util import datasets from GPy.util import datasets
try:
import matplotlib.pyplot as plt
except:
pass
def student_t_approx(optimize=True, plot=True): def student_t_approx(optimize=True, plot=True):
""" """

View file

@ -4,7 +4,10 @@
""" """
Gaussian Processes regression examples Gaussian Processes regression examples
""" """
import pylab as pb try:
import pylab as pb
except:
pass
import numpy as np import numpy as np
import GPy import GPy

View file

@ -1,7 +1,10 @@
# Copyright (c) 2012, GPy authors (see AUTHORS.txt). # Copyright (c) 2012, GPy authors (see AUTHORS.txt).
# Licensed under the BSD 3-clause license (see LICENSE.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 numpy as np
import GPy import GPy

View file

@ -6,8 +6,11 @@
Code of Tutorials Code of Tutorials
""" """
import pylab as pb try:
pb.ion() import pylab as pb
pb.ion()
except:
pass
import numpy as np import numpy as np
import GPy import GPy

View file

@ -20,8 +20,6 @@ class RBF(Stationary):
_support_GPU = True _support_GPU = True
def __init__(self, input_dim, variance=1., lengthscale=None, ARD=False, active_dims=None, name='rbf', useGPU=False): 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) 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() self.psicomp = PSICOMP_RBF()
if self.useGPU: if self.useGPU:
self.psicomp = PSICOMP_RBF_GPU() self.psicomp = PSICOMP_RBF_GPU()

View file

@ -3,14 +3,10 @@
import numpy as np import numpy as np
from scipy import weave
from kern import Kern from kern import Kern
from ...util.linalg import tdot
from ...util.misc import param_to_array
from ...core.parameterization import Param from ...core.parameterization import Param
from ...core.parameterization.transformations import Logexp from ...core.parameterization.transformations import Logexp
from ...util.caching import Cache_this from ...util.caching import Cache_this
from ...core.parameterization import variational
from ...util.config import * from ...util.config import *
class TruncLinear(Kern): class TruncLinear(Kern):

View file

@ -3,8 +3,6 @@
import numpy as np import numpy as np
import pylab as pb
import sys, pdb
from ..core import GP from ..core import GP
from ..models import GPLVM from ..models import GPLVM
from ..mappings import * from ..mappings import *

View file

@ -3,7 +3,6 @@
import numpy as np import numpy as np
import pylab as pb
from .. import kern from .. import kern
from ..core import GP, Param from ..core import GP, Param
from ..likelihoods import Gaussian from ..likelihoods import Gaussian
@ -55,7 +54,7 @@ class GPLVM(GP):
#J = np.zeros((X.shape[0],X.shape[1],self.output_dim)) #J = np.zeros((X.shape[0],X.shape[1],self.output_dim))
J = self.jacobian(X) J = self.jacobian(X)
for i in range(X.shape[0]): 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 return target
def plot(self): 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 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] Xnew = np.linspace(self.X.min(), self.X.max(), 200)[:, None]
mu, _ = self.predict(Xnew) mu, _ = self.predict(Xnew)
import pylab as pb
pb.plot(mu[:, 0], mu[:, 1], 'k', linewidth=1.5) pb.plot(mu[:, 0], mu[:, 1], 'k', linewidth=1.5)
def plot_latent(self, labels=None, which_indices=None, def plot_latent(self, labels=None, which_indices=None,

View file

@ -3,13 +3,8 @@
import numpy as np import numpy as np
import pylab as pb import sys
import sys, pdb
from GPy.models.sparse_gp_regression import SparseGPRegression 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): class SparseGPLVM(SparseGPRegression):
""" """

View file

@ -1,4 +1,7 @@
# Copyright (c) 2014, GPy authors (see AUTHORS.txt). # Copyright (c) 2014, GPy authors (see AUTHORS.txt).
# Licensed under the BSD 3-clause license (see LICENSE.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.'

View file

@ -2,8 +2,11 @@
# Licensed under the BSD 3-clause license (see LICENSE.txt) # Licensed under the BSD 3-clause license (see LICENSE.txt)
import Tango try:
import pylab as pb import Tango
import pylab as pb
except:
pass
import numpy as np import numpy as np
def ax_default(fignum, ax): def ax_default(fignum, ax):

View file

@ -1,12 +1,16 @@
import pylab as pb
import numpy as np import numpy as np
from latent_space_visualizations.controllers.imshow_controller import ImshowController,ImAnnotateController from latent_space_visualizations.controllers.imshow_controller import ImshowController,ImAnnotateController
from ...util.misc import param_to_array from ...util.misc import param_to_array
from ...core.parameterization.variational import VariationalPosterior from ...core.parameterization.variational import VariationalPosterior
from .base_plots import x_frame2D from .base_plots import x_frame2D
import itertools import itertools
import Tango try:
from matplotlib.cm import get_cmap import Tango
from matplotlib.cm import get_cmap
import pylab as pb
except:
pass
def most_significant_input_dimensions(model, which_indices): def most_significant_input_dimensions(model, which_indices):
""" """

View file

@ -1,8 +1,10 @@
# Copyright (c) 2012, GPy authors (see AUTHORS.txt). # Copyright (c) 2012, GPy authors (see AUTHORS.txt).
# Licensed under the BSD 3-clause license (see LICENSE.txt) # Licensed under the BSD 3-clause license (see LICENSE.txt)
import pylab as pb try:
import sys import pylab as pb
except:
pass
#import numpy as np #import numpy as np
#import Tango #import Tango
#from base_plots import gpplot, x_frame1D, x_frame2D #from base_plots import gpplot, x_frame1D, x_frame2D

View file

@ -1,9 +1,12 @@
# Copyright (c) 2012, GPy authors (see AUTHORS.txt). # Copyright (c) 2012, GPy authors (see AUTHORS.txt).
# Licensed under the BSD 3-clause license (see LICENSE.txt) # Licensed under the BSD 3-clause license (see LICENSE.txt)
import pylab as pb
import numpy as np import numpy as np
import Tango try:
import Tango
import pylab as pb
except:
pass
from base_plots import x_frame1D, x_frame2D from base_plots import x_frame1D, x_frame2D

View file

@ -1,13 +1,14 @@
import numpy as np import numpy as np
import pylab as pb try:
import matplotlib.patches as patches import pylab as pb
from matplotlib.patches import Polygon from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection from matplotlib.collections import PatchCollection
#from matplotlib import cm #from matplotlib import cm
pb.ion()
except:
pass
import re import re
pb.ion()
def plot(shape_records,facecolor='w',edgecolor='k',linewidths=.5, ax=None,xlims=None,ylims=None): def plot(shape_records,facecolor='w',edgecolor='k',linewidths=.5, ax=None,xlims=None,ylims=None):
""" """
Plot the geometry of a shapefile Plot the geometry of a shapefile

View file

@ -1,9 +1,12 @@
# Copyright (c) 2012, GPy authors (see AUTHORS.txt). # Copyright (c) 2012, GPy authors (see AUTHORS.txt).
# Licensed under the BSD 3-clause license (see LICENSE.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 numpy as np
import Tango
from base_plots import gpplot, x_frame1D, x_frame2D from base_plots import gpplot, x_frame1D, x_frame2D
from ...util.misc import param_to_array from ...util.misc import param_to_array
from ...models.gp_coregionalized_regression import GPCoregionalizedRegression from ...models.gp_coregionalized_regression import GPCoregionalizedRegression

View file

@ -3,7 +3,10 @@
import numpy as np import numpy as np
import pylab as pb try:
import pylab as pb
except:
pass
def univariate_plot(prior): def univariate_plot(prior):

View file

@ -6,7 +6,6 @@ import pylab
from ...models import SSGPLVM from ...models import SSGPLVM
from img_plots import plot_2D_images from img_plots import plot_2D_images
from ...util.misc import param_to_array
class SSGPLVM_plot(object): class SSGPLVM_plot(object):
def __init__(self,model, imgsize): def __init__(self,model, imgsize):

View file

@ -2,7 +2,6 @@ import csv
import os import os
import copy import copy
import numpy as np import numpy as np
import pylab as pb
import GPy import GPy
import scipy.io import scipy.io
import cPickle as pickle import cPickle as pickle
@ -346,6 +345,7 @@ def football_data(season='1314', data_set='football_data'):
data_resources[data_set_season]['files'] = [files] data_resources[data_set_season]['files'] = [files]
if not data_available(data_set_season): if not data_available(data_set_season):
download_data(data_set_season) download_data(data_set_season)
import pylab as pb
for file in reversed(files): for file in reversed(files):
filename = os.path.join(data_path, data_set_season, file) filename = os.path.join(data_path, data_set_season, file)
# rewrite files removing blank rows. # rewrite files removing blank rows.

View file

@ -5,8 +5,11 @@ Created on 10 Sep 2012
@copyright: Max Zwiessele 2012 @copyright: Max Zwiessele 2012
''' '''
import numpy import numpy
import pylab try:
import matplotlib import pylab
import matplotlib
except:
pass
from numpy.linalg.linalg import LinAlgError from numpy.linalg.linalg import LinAlgError
class pca(object): class pca(object):
@ -88,13 +91,15 @@ class pca(object):
def plot_2d(self, X, labels=None, s=20, marker='o', def plot_2d(self, X, labels=None, s=20, marker='o',
dimensions=(0, 1), ax=None, colors=None, dimensions=(0, 1), ax=None, colors=None,
fignum=None, cmap=matplotlib.cm.jet, # @UndefinedVariable fignum=None, cmap=None, # @UndefinedVariable
** kwargs): ** kwargs):
""" """
Plot dimensions `dimensions` with given labels against each other in Plot dimensions `dimensions` with given labels against each other in
PC space. Labels can be any sequence of labels of dimensions X.shape[0]. PC space. Labels can be any sequence of labels of dimensions X.shape[0].
Labels can be drawn with a subsequent call to legend() Labels can be drawn with a subsequent call to legend()
""" """
if cmap is None:
cmap = matplotlib.cm.jet
if ax is None: if ax is None:
fig = pylab.figure(fignum) fig = pylab.figure(fignum)
ax = fig.add_subplot(111) ax = fig.add_subplot(111)