From 50029ca4a7a47c5220c879c6c888a3fdba5b5dc2 Mon Sep 17 00:00:00 2001 From: James Hensman Date: Thu, 6 Dec 2012 11:46:34 -0800 Subject: [PATCH] implemented default constraints via m.ensure_default_constraints() --- GPy/core/model.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/GPy/core/model.py b/GPy/core/model.py index 3d64441e..6ae292d0 100644 --- a/GPy/core/model.py +++ b/GPy/core/model.py @@ -162,6 +162,20 @@ class model(parameterised): else: self.expand_param(initial_parameters) + def ensure_default_constraints(self,warn=False): + """ + Ensure that any variables which should clearly be positive have been constrained somehow. + """ + positive_strings = ['variance','lengthscale', 'precision'] + for s in positive_strings: + for i in self.grep_param_names(s): + if not (i in self.all_constrained_indices()): + name = self.get_param_names()[i] + self.constrain_positive(name) + if warn: + print "Warning! constraining %s postive"%name + + def optimize(self, optimizer=None, start=None, **kwargs): """ Optimize the model using self.log_likelihood and self.log_likelihood_gradient, as well as self.priors.