def make_poisson_pmf(lam, high, step=1): pmf = Pmf() for k in range(0, high + 1, step): p = eval_poisson_pmf(lam, k) pmf.set(k, p) pmf.normalize() return pmf
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 make_gaussian_pmf(mu, sigma, num_sigmas, n=101): pmf = Pmf() low = mu - num_sigmas * sigma high = mu + num_sigmas * sigma for x in np.linspace(low, high, n): p = scipy.stats.norm.pdf(x, mu, sigma) pmf.set(x, p) pmf.normalize() return pmf
def make_uniform_pmf(low, high): pmf = Pmf() for x in make_range(low, high): pmf.set(x, 1) pmf.normalize() return pmf
def make_pmf_from_list(values, name=''): pmf = Pmf(name=name) for value in values: pmf.incr(value) pmf.normalize() return pmf