def pmf_of_wait_time(pmf_zb): pmf_meta = Pmf() for gap, prob in pmf_zb.iter_items(): uniform = make_uniform_pmf(0, gap) pmf_meta.set(uniform, prob) pmf_y = make_mixture(pmf_meta) return pmf_y
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_goal_pmf(suite): meta_pmf = Pmf() for lam, prob in suite.iter_items(): pmf = make_poisson_pmf(lam, 10) meta_pmf.set(pmf, prob) mix = make_mixture(meta_pmf, name=suite.name) return mix
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_raw_score_dist(self, efficacies): pmfs = Pmf() for efficacy, prob in efficacies.iter_items(): print("make_raw_score_dist(): processing {} {}".format( efficacy, prob)) scores = pmf_correct(efficacy, self.difficulties) pmfs.set(scores, prob) mix = make_mixture(pmfs) return mix
class WaitMixtureEstimator(object): def __init__(self, wtc, are, num_passengers=15): self.meta_pmf = Pmf() for lam, prob in are.post_lam.iter_items(): if prob <= 0: continue ete = ElapsedTimeEstimator(wtc, lam, num_passengers) self.meta_pmf.set(ete.pmf_y, prob) self.mixture = make_mixture(self.meta_pmf) def plot(self, time_limit=600): plt.figure(figsize=(8, 6)) mix_cdf = self.mixture.make_cdf() mix_cdf.d = mix_cdf.d.loc[mix_cdf.d.value <= time_limit, ] plt.plot(mix_cdf.d.value, mix_cdf.d.prob, color='r') for pmf in self.meta_pmf.values(): cdf = pmf.make_cdf() cdf.d = cdf.d.loc[cdf.d.value <= time_limit, ] plt.plot(cdf.d.value, cdf.d.prob, color='b') plt.show()
def make_uniform_pmf(low, high): pmf = Pmf() for x in make_range(low, high): pmf.set(x, 1) pmf.normalize() return pmf
def binary_pmf(p): pmf = Pmf() pmf.set(1, p) pmf.set(0, 1 - p) return pmf