def __str__(self): """ This defaultly puts a \0 at the end so that we can sort -z if we want (e.g. if we print out a posterior first) """ return '\n' + '\n'.join([ "%-15s: %s" % (qq(w), str(v)) for w, v in sorted(self.value.items()) ]) + '\0'
class MyHypothesis(GaussianLikelihood, LOTHypothesis): def __init__(self, **kwargs): LOTHypothesis.__init__(self, grammar=grammar, **kwargs) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Main # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if __name__ == "__main__": from LOTlib3 import break_ctrlc from LOTlib3.Miscellaneous import qq from LOTlib3.TopN import TopN from LOTlib3.Samplers.MetropolisHastings import MetropolisHastingsSampler h0 = MyHypothesis() data = make_data() top = TopN(N=10) thin = 100 for i, h in enumerate(break_ctrlc(MetropolisHastingsSampler(h0, data))): top << h if i % thin == 0: print("#", i, h.posterior_score, h.prior, h.likelihood, qq(h)) for h in top: print(h.posterior_score, h.prior, h.likelihood, qq(h))
def __str__(self): return '\n'.join([ "%-15s: %s" % (qq(w), lambdastring(v.value)) for w, v in sorted(self.value.items()) ]) + '\0'
def __repr__(self): return qq(str(self.utterance)) + ' in ' + str( self.context) + " from " + str(self.possible_utterances)