def make_mixture(meta_pmf, name='mix'): mix = Pmf(name=name) for pmf, p1 in meta_pmf.iter_items(): for x, p2 in pmf.iter_items(): mix.incr(x, p1 * p2) mix.normalize() return mix
def conditional(self, i, j, val, name=''): pmf = Pmf(name=name) for vs, prob in self.iter_items(): if vs[j] != val: continue pmf.incr(vs[i], prob) pmf.normalize() return pmf
def coef_variation(suite): pmf = Pmf() for (mu, sigma), p in suite.iter_items(): pmf.incr(sigma/mu, p) return pmf
def marginal(self, i, name=''): pmf = Pmf(name=name) for vs, prob in self.iter_items(): pmf.incr(vs[i], prob) return pmf
def make_pmf_from_list(values, name=''): pmf = Pmf(name=name) for value in values: pmf.incr(value) pmf.normalize() return pmf
def reverse_scale(self, pmf): reverse = Pmf() for value, prob in pmf.iter_items(): raw = self.reverse(value) reverse.incr(raw, prob) return reverse