mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-08 15:05:15 +02:00
print_all function removed, print m works as before.
This commit is contained in:
parent
4bb2ea9606
commit
1931e447f4
5 changed files with 53 additions and 43 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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__()
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue