From 71bc90bf98a69504046eeef8e79aea0d3f305e56 Mon Sep 17 00:00:00 2001 From: mzwiessele Date: Wed, 30 Sep 2015 14:43:04 +0100 Subject: [PATCH] [newest patch updates, cleaned interfaces and mean_function addidtions] --- GPy/__init__.py | 20 +++++++++++++------- GPy/core/parameterization/parameter_core.py | 2 +- GPy/core/sparse_gp.py | 4 +--- GPy/mappings/linear.py | 2 +- GPy/models/gp_classification.py | 4 ++-- GPy/plotting/matplot_dep/models_plots.py | 14 ++++++++++---- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/GPy/__init__.py b/GPy/__init__.py index 2b5c233f..170f7e10 100644 --- a/GPy/__init__.py +++ b/GPy/__init__.py @@ -34,18 +34,24 @@ except: def tests(verbose=10): Tester(testing).test(verbose=verbose) -def load(file_path): +def load(file_or_path): """ Load a previously pickled model, using `m.pickle('path/to/file.pickle)' :param file_name: path/to/file.pickle """ - import cPickle as pickle try: - with open(file_path, 'rb') as f: - m = pickle.load(f) + import cPickle as pickle + if isinstance(file_or_path, basestring): + with open(file_or_path, 'rb') as f: + m = pickle.load(f) + else: + m = pickle.load(file_or_path) except: - import pickle as pickle - with open(file_path, 'rb') as f: - m = pickle.load(f) + import pickle + if isinstance(file_or_path, basestring): + with open(file_or_path, 'rb') as f: + m = pickle.load(f) + else: + m = pickle.load(file_or_path) return m diff --git a/GPy/core/parameterization/parameter_core.py b/GPy/core/parameterization/parameter_core.py index 48c05a8d..308bf20d 100644 --- a/GPy/core/parameterization/parameter_core.py +++ b/GPy/core/parameterization/parameter_core.py @@ -227,8 +227,8 @@ class Nameable(Gradcheckable): Make an object nameable inside the hierarchy. """ def __init__(self, name, *a, **kw): - super(Nameable, self).__init__(*a, **kw) self._name = name or self.__class__.__name__ + super(Nameable, self).__init__(*a, **kw) @property def name(self): diff --git a/GPy/core/sparse_gp.py b/GPy/core/sparse_gp.py index 667072e4..9f570591 100644 --- a/GPy/core/sparse_gp.py +++ b/GPy/core/sparse_gp.py @@ -43,12 +43,10 @@ class SparseGP(GP): def __init__(self, X, Y, Z, kernel, likelihood, mean_function=None, X_variance=None, inference_method=None, name='sparse gp', Y_metadata=None, normalizer=False): - self.missing_data = np.isnan(Y).any() - #pick a sensible inference method if inference_method is None: if isinstance(likelihood, likelihoods.Gaussian): - inference_method = var_dtc.VarDTC(limit=1 if not self.missing_data else Y.shape[1]) + inference_method = var_dtc.VarDTC(limit=1) else: #inference_method = ?? raise NotImplementedError("what to do what to do?") diff --git a/GPy/mappings/linear.py b/GPy/mappings/linear.py index ee464694..c105dd81 100644 --- a/GPy/mappings/linear.py +++ b/GPy/mappings/linear.py @@ -25,7 +25,7 @@ class Linear(Mapping): """ def __init__(self, input_dim, output_dim, name='linmap'): - Mapping.__init__(self, input_dim=input_dim, output_dim=output_dim, name=name) + super(Linear, self).__init__(input_dim=input_dim, output_dim=output_dim, name=name) self.A = Param('A', np.random.randn(self.input_dim, self.output_dim)) self.link_parameter(self.A) diff --git a/GPy/models/gp_classification.py b/GPy/models/gp_classification.py index bbf4f316..2c4f7be4 100644 --- a/GPy/models/gp_classification.py +++ b/GPy/models/gp_classification.py @@ -20,10 +20,10 @@ class GPClassification(GP): """ - def __init__(self, X, Y, kernel=None,Y_metadata=None): + def __init__(self, X, Y, kernel=None,Y_metadata=None, mean_function=None): if kernel is None: kernel = kern.RBF(X.shape[1]) likelihood = likelihoods.Bernoulli() - GP.__init__(self, X=X, Y=Y, kernel=kernel, likelihood=likelihood, inference_method=EP(), name='gp_classification') + GP.__init__(self, X=X, Y=Y, kernel=kernel, likelihood=likelihood, inference_method=EP(), mean_function=mean_function, name='gp_classification') diff --git a/GPy/plotting/matplot_dep/models_plots.py b/GPy/plotting/matplot_dep/models_plots.py index 0e5d5895..208267c0 100644 --- a/GPy/plotting/matplot_dep/models_plots.py +++ b/GPy/plotting/matplot_dep/models_plots.py @@ -230,10 +230,16 @@ def plot_fit(model, plot_limits=None, which_data_rows='all', ecolor='k', fmt=None, elinewidth=.5, alpha=.5) #set the limits of the plot to some sensible values - ymin, ymax = min(np.append(Y[which_data_rows, which_data_ycols].flatten(), lower)), max(np.append(Y[which_data_rows, which_data_ycols].flatten(), upper)) - ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin) - ax.set_xlim(xmin, xmax) - ax.set_ylim(ymin, ymax) + try: + ymin, ymax = min(np.append(Y[which_data_rows, which_data_ycols].flatten(), lower)), max(np.append(Y[which_data_rows, which_data_ycols].flatten(), upper)) + if ymin != ymax: + ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin) + ax.set_xlim(xmin, xmax) + ax.set_ylim(ymin, ymax) + except: + # do nothing + # No training data on model + pass #add inducing inputs (if a sparse model is used) if hasattr(model,"Z"):