From 345e5b3e7c324c59bf4148aeeb56fe746574270d Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Fri, 14 Feb 2014 15:05:38 +0000 Subject: [PATCH] some updates for params changes and likelihood fixes --- GPy/core/parameterization/array_core.py | 22 ++++++++++++++++--- GPy/core/parameterization/param.py | 2 +- .../latent_function_inference/laplace.py | 2 ++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/GPy/core/parameterization/array_core.py b/GPy/core/parameterization/array_core.py index 78b9e8f2..9f2c7ae6 100644 --- a/GPy/core/parameterization/array_core.py +++ b/GPy/core/parameterization/array_core.py @@ -37,10 +37,26 @@ class ObservableArray(np.ndarray, Observable): if obj is None: return self._observers_ = getattr(obj, '_observers_', None) + def _s_not_empty(self, s): + # this checks whether there is something picked by this slice. + return True + # TODO: disarmed, for performance increase, + if not isinstance(s, (list,tuple,np.ndarray)): + return True + if isinstance(s, (list,tuple)): + return len(s)!=0 + if isinstance(s, np.ndarray): + if s.dtype is bool: + return np.all(s) + else: + return s.size != 0 + def __setitem__(self, s, val, update=True): - super(ObservableArray, self).__setitem__(s, val) - if update: - self._notify_observers() + if self._s_not_empty(s): + super(ObservableArray, self).__setitem__(s, val) + if update: + self._notify_observers() + def __getslice__(self, start, stop): return self.__getitem__(slice(start, stop)) def __setslice__(self, start, stop, val): diff --git a/GPy/core/parameterization/param.py b/GPy/core/parameterization/param.py index 46fa3377..37e710a8 100644 --- a/GPy/core/parameterization/param.py +++ b/GPy/core/parameterization/param.py @@ -146,7 +146,7 @@ class Param(ObservableArray, Constrainable, Gradcheckable, Indexable, Parameteri def __setitem__(self, s, val, update=True): super(Param, self).__setitem__(s, val, update=update) #self._notify_tied_parameters() - if update: + if update and self._s_not_empty(s): self._notify_parameters_changed() #=========================================================================== diff --git a/GPy/inference/latent_function_inference/laplace.py b/GPy/inference/latent_function_inference/laplace.py index 1c524d71..906a7867 100644 --- a/GPy/inference/latent_function_inference/laplace.py +++ b/GPy/inference/latent_function_inference/laplace.py @@ -216,6 +216,8 @@ class Laplace(object): """ if not log_concave: #print "Under 1e-10: {}".format(np.sum(W < 1e-6)) + # W[W<1e-6] = 1e-6 + # NOTE: when setting a parameter inside parameters_changed it will allways come to closed update circles!!! W.__setitem__(W < 1e-6, 1e-6, update=False) # FIXME-HACK: This is a hack since GPy can't handle negative variances which can occur # If the likelihood is non-log-concave. We wan't to say that there is a negative variance # To cause the posterior to become less certain than the prior and likelihood,