def setstate(self, state): """ set state from previous call to getstate call Parameterized with the rest of the state :param state: the state of the model. :type state: list as returned from getstate. """ self.preferred_optimizer = state.pop() self.sampling_runs = state.pop() self.optimization_runs = state.pop() self.priors = state.pop() Parameterized.setstate(self, state)
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_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() log_prior = self.log_prior() obj_funct = '\nLog-likelihood: {0:.3e}'.format(log_like) if len(''.join(strs)) != 0: obj_funct += ', Log prior: {0:.3e}, LL+prior = {0:.3e}'.format( log_prior, log_like + log_prior) obj_funct += '\n\n' s[0] = obj_funct + s[0] s[0] += "|{h:^{col}}".format(h='prior', col=width) s[1] += '-' * (width + 1) for p in range(2, len(strs) + 2): s[p] += '|{prior:^{width}}'.format(prior=strs[p - 2], width=width) return '\n'.join(s)
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_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() log_prior = self.log_prior() obj_funct = '\nLog-likelihood: {0:.3e}'.format(log_like) if len(''.join(strs)) != 0: obj_funct += ', Log prior: {0:.3e}, LL+prior = {0:.3e}'.format(log_prior, log_like + log_prior) obj_funct += '\n\n' s[0] = obj_funct + s[0] s[0] += "|{h:^{col}}".format(h='prior', col=width) s[1] += '-' * (width + 1) for p in range(2, len(strs) + 2): s[p] += '|{prior:^{width}}'.format(prior=strs[p - 2], width=width) return '\n'.join(s)
def __set__(self, obj, val): """ Call Parameter's __set__, but warn if the file cannot be found. """ try: self._resolve(val) except IOError, e: Parameterized(name="%s.%s"%(obj.name,self._attrib_name)).warning('%s'%(e.args[0]))
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. """ return Parameterized.getstate(self) + \ [self.priors, self.optimization_runs, self.sampling_runs, self.preferred_optimizer]
def __init__(self): Parameterized.__init__(self) self.priors = None self.optimization_runs = [] self.sampling_runs = [] self.preferred_optimizer = 'scg'