diff --git a/GPy/core/model.py b/GPy/core/model.py index 7a080817..1dfaeeb7 100644 --- a/GPy/core/model.py +++ b/GPy/core/model.py @@ -31,8 +31,8 @@ class Model(Parameterized): def getstate(self): """ Get the current state of the class. - Inherited from Parameterized, so add those parameters to the state + :return: list of states from the model. """ @@ -46,7 +46,7 @@ class Model(Parameterized): call Parameterized with the rest of the state :param state: the state of the model. - :type state: list as returned from getstate. + :type state: list as returned from getstate. """ self.preferred_optimizer = state.pop() self.sampling_runs = state.pop() @@ -397,17 +397,20 @@ class Model(Parameterized): return np.nan return 0.5 * self._get_params().size * np.log(2 * np.pi) + self.log_likelihood() - hld - def __str__(self, names=None): - if names is None: - names = self._get_print_names() - s = Parameterized.__str__(self, names=names).split('\n') + def __str__(self): + s = Parameterized.__str__(self).split('\n') + #def __str__(self, names=None): + # if names is None: + # names = self._get_print_names() + #s = Parameterized.__str__(self, names=names).split('\n') # add priors to the string if self.priors is not None: strs = [str(p) if p is not None else '' for p in self.priors] else: - strs = [''] * len(self._get_param_names()) - name_indices = self.grep_param_names("|".join(names)) - strs = np.array(strs)[name_indices] + strs = [''] * len(self._get_params()) + # strs = [''] * len(self._get_param_names()) + # name_indices = self.grep_param_names("|".join(names)) + # strs = np.array(strs)[name_indices] width = np.array(max([len(p) for p in strs] + [5])) + 4 log_like = self.log_likelihood() diff --git a/GPy/core/parameterized.py b/GPy/core/parameterized.py index cad4d2a9..015f35f5 100644 --- a/GPy/core/parameterized.py +++ b/GPy/core/parameterized.py @@ -27,9 +27,9 @@ class Parameterized(object): def _get_param_names(self): raise NotImplementedError, "this needs to be implemented to use the Parameterized class" - def _get_print_names(self): - """ Override for which names to print out, when using print m """ - return self._get_param_names() + #def _get_print_names(self): + # """ Override for which names to print out, when using print m """ + # return self._get_param_names() def pickle(self, filename, protocol=None): if protocol is None: @@ -63,10 +63,10 @@ class Parameterized(object): """ Get the current state of the class, here just all the indices, rest can get recomputed - For inheriting from Parameterized: - Allways append the state of the inherited object - and call down to the inherited object in setstate!! + + Allways append the state of the inherited object + and call down to the inherited object in setstate!! """ return [self.tied_indices, self.fixed_indices, @@ -336,26 +336,30 @@ class Parameterized(object): n = [nn for i, nn in enumerate(n) if not i in remove] return n - @property - def all(self): - return self.__str__(self._get_param_names()) + #@property + #def all(self): + # return self.__str__(self._get_param_names()) - def __str__(self, names=None, nw=30): + #def __str__(self, names=None, nw=30): + def __str__(self, nw=30): """ Return a string describing the parameter names and their ties and constraints """ - if names is None: - names = self._get_print_names() - name_indices = self.grep_param_names("|".join(names)) + names = self._get_param_names() + #if names is None: + # names = self._get_print_names() + #name_indices = self.grep_param_names("|".join(names)) N = len(names) if not N: return "This object has no free parameters." header = ['Name', 'Value', 'Constraints', 'Ties'] - values = self._get_params()[name_indices] # map(str,self._get_params()) + values = self._get_params() # map(str,self._get_params()) + #values = self._get_params()[name_indices] # map(str,self._get_params()) # sort out the constraints - constraints = [''] * len(self._get_param_names()) + constraints = [''] * len(names) + #constraints = [''] * len(self._get_param_names()) for i, t in zip(self.constrained_indices, self.constraints): for ii in i: constraints[ii] = t.__str__() diff --git a/GPy/core/sparse_gp.py b/GPy/core/sparse_gp.py index 48a7d523..0e4e54d7 100644 --- a/GPy/core/sparse_gp.py +++ b/GPy/core/sparse_gp.py @@ -208,8 +208,8 @@ class SparseGP(GPBase): return sum([['iip_%i_%i' % (i, j) for j in range(self.Z.shape[1])] for i in range(self.Z.shape[0])], [])\ + self.kern._get_param_names_transformed() + self.likelihood._get_param_names() - def _get_print_names(self): - return self.kern._get_param_names_transformed() + self.likelihood._get_param_names() + #def _get_print_names(self): + # return self.kern._get_param_names_transformed() + self.likelihood._get_param_names() def update_likelihood_approximation(self): """ diff --git a/GPy/models/bayesian_gplvm.py b/GPy/models/bayesian_gplvm.py index ae74e5f2..e514ad19 100644 --- a/GPy/models/bayesian_gplvm.py +++ b/GPy/models/bayesian_gplvm.py @@ -66,8 +66,8 @@ class BayesianGPLVM(SparseGP, GPLVM): S_names = sum([['X_variance_%i_%i' % (n, q) for q in range(self.input_dim)] for n in range(self.num_data)], []) return (X_names + S_names + SparseGP._get_param_names(self)) - def _get_print_names(self): - return SparseGP._get_print_names(self) + #def _get_print_names(self): + # return SparseGP._get_print_names(self) def _get_params(self): """ diff --git a/GPy/models/mrd.py b/GPy/models/mrd.py index 4c7fa167..99e50a19 100644 --- a/GPy/models/mrd.py +++ b/GPy/models/mrd.py @@ -25,11 +25,11 @@ class MRD(Model): :param input_dim: latent dimensionality :type input_dim: int :param initx: initialisation method for the latent space : - + * 'concat' - PCA on concatenation of all datasets * 'single' - Concatenation of PCA on datasets, respectively * 'random' - Random draw from a normal - + :type initx: ['concat'|'single'|'random'] :param initz: initialisation method for inducing inputs :type initz: 'permute'|'random' @@ -163,28 +163,31 @@ class MRD(Model): self._init_X(initx, self.likelihood_list) self._init_Z(initz, self.X) - def _get_latent_param_names(self): + #def _get_latent_param_names(self): + def _get_param_names(self): n1 = self.gref._get_param_names() n1var = n1[:self.NQ * 2 + self.MQ] - return n1var - - - def _get_kernel_names(self): + # return n1var + # + #def _get_kernel_names(self): map_names = lambda ns, name: map(lambda x: "{1}_{0}".format(*x), itertools.izip(ns, itertools.repeat(name))) - kernel_names = (map_names(SparseGP._get_param_names(g)[self.MQ:], n) for g, n in zip(self.bgplvms, self.names)) - return kernel_names + return list(itertools.chain(n1var, *(map_names(\ + SparseGP._get_param_names(g)[self.MQ:], n) \ + for g, n in zip(self.bgplvms, self.names)))) + # kernel_names = (map_names(SparseGP._get_param_names(g)[self.MQ:], n) for g, n in zip(self.bgplvms, self.names)) + # return kernel_names - def _get_param_names(self): + #def _get_param_names(self): # X_names = sum([['X_%i_%i' % (n, q) for q in range(self.input_dim)] for n in range(self.num_data)], []) # S_names = sum([['X_variance_%i_%i' % (n, q) for q in range(self.input_dim)] for n in range(self.num_data)], []) - n1var = self._get_latent_param_names() - kernel_names = self._get_kernel_names() - return list(itertools.chain(n1var, *kernel_names)) + # n1var = self._get_latent_param_names() + # kernel_names = self._get_kernel_names() + # return list(itertools.chain(n1var, *kernel_names)) - def _get_print_names(self): - return list(itertools.chain(*self._get_kernel_names())) + #def _get_print_names(self): + # return list(itertools.chain(*self._get_kernel_names())) def _get_params(self): """