def __enter__(self): SampleStream.__enter__(self) if self.file is not None: self.file_ = open(self.file, self.mode) else: self.file_ = stdout
def __exit__(self, t, value, traceback): f = open(self.path, 'w') pickle.dump(self.samples, f) f.close() SampleStream.__exit__(self, t, value, traceback)
def __init__(self, generator=None, plot_every=1000, window=False, block=False, file='trace.pdf'): self.__dict__.update(locals()) self.posteriors = [] self.priors = [] self.likelihoods = [] SampleStream.__init__(self, generator)
def __init__(self, N=1000, key='posterior_score', sorted=True): """ :param N: How many samples to store. :param key: The key we sort by :param sorted: When we output, do we output sorted? (slightly slower) :return: """ self.__dict__.update(locals()) SampleStream.__init__(self) self.top = TopN(N=N, key=key)
def __exit__(self, t, value, traceback): ## Here, only on exit do I give my data (the tops) to my outputs for v in self.top.get_all(sorted=sorted): # Cannot just call self.process_and_push since self.process always returns None if v is not None: for a in self.outputs: a.process_and_push(v) return SampleStream.__exit__(self, t, value, traceback)
def __exit__(self, t, value, traceback): ## Here, only on exit do I give my data (the tops) to my outputs for v in self.top.get_all(sorted=sorted): # Cannot just call self.process_and_push since self.process always returns None if v is not None: for a in self.outputs: a.process_and_push(v) return SampleStream.__exit__(self, t,value,traceback)
def __exit__(self, t, value, traceback): if self.file is not None: self.file_.close() SampleStream.__exit__(self, t, value, traceback)
def __init__(self, path='samples.pkl'): SampleStream.__init__(self, generator=None) self.path = path self.samples = []
def __init__(self, n=10): SampleStream.__init__(self) self.n = n self.cnt = 0
def __init__(self, *outputs): SampleStream.__init__(self) ##UUGH because of the weird associativity, >> will return the last in the chain. ## But really my child should be the root of whatever chain I got. self.outputs = [o.root() for o in outputs]
def __init__(self): SampleStream.__init__(self) self.seen = set()
def __exit__(self, t, value, traceback): print self return SampleStream.__exit__(self, t, value, traceback)
def __init__(self, file=None, prefix='', mode='w'): self.__dict__.update(locals()) SampleStream.__init__(self, generator=None)
def __init__(self, generator=None): self.last = None SampleStream.__init__(self, generator=generator)
def __exit__(self, t, value, traceback): self.plot() return SampleStream.__exit__(self, t, value, traceback)
def __init__(self, key='posterior_score'): SampleStream.__init__(self) self.key = key self.Z = -Infinity
def __init__(self, key="posterior_score"): SampleStream.__init__(self) self.key = key self.Z = -Infinity