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 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 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 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 __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 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_goal_time_pmf(suite): pmfs = [ make_exponential_pmf(lam, high=2, n=201) for lam, _ in suite.iter_items() ] probs = [prob for _, prob in suite.iter_items()] meta_pmf = Pmf(values=pmfs, probs=probs) mix = make_mixture(meta_pmf, name=suite.name) return mix
def make_cv_cdf(self, name=''): mean = np.array([self.d.value[i][0] for i in range(len(self.d))]) std = np.array([self.d.value[i][1] for i in range(len(self.d))]) cv = std / mean pmf = Pmf(values=cv, probs=self.d.prob, name=self.name if self.name else name) pmf.sort_by_value() return pmf.make_cdf()
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
def make_pmf(self, steps=101, name=''): name = name if name else self.name if self.alpha < 1 or self.beta < 1: cdf = self.make_cdf() pmf = cdf.make_pmf(name) return pmf xs = [i / (steps - 1.0) for i in range(steps)] probs = [self.eval_pdf(x) for x in xs] pmf = Pmf(values=xs, probs=probs, name=name) return pmf
def __init__(self): self.scale = read_scale() scores = read_ranks() self.pmf_score = Pmf(values=scores.score, probs=scores.number) self.raw = self.reverse_scale(self.pmf_score) self.max_score = max(self.raw.values()) self.prior = divide_values(self.raw, self.max_score) self.difficulties = make_difficulties(center=-0.05, width=1.8, n=self.max_score)
def reverse_scale(self, pmf): reverse = Pmf() for value, prob in pmf.iter_items(): raw = self.reverse(value) reverse.incr(raw, prob) return reverse
def coef_variation(suite): pmf = Pmf() for (mu, sigma), p in suite.iter_items(): pmf.incr(sigma/mu, p) 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 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 make_location_pmf(alpha, beta, locations, name=''): probs = [1.0 / strafing_speed(alpha, beta, x) for x in locations] pmf = Pmf(values=locations, probs=probs, name=name) return pmf
def dist_of_r(self, name=""): values = [detector.r for detector, _ in self.iter_items()] pmf = Pmf(values=values, probs=self.probs(), name=name) return pmf
def binary_pmf(p): pmf = Pmf() pmf.set(1, p) pmf.set(0, 1 - p) return pmf
def pmf_correct(efficacy, difficulties): pmf0 = Pmf([0]) ps = [prob_correct(efficacy, diff) for diff in difficulties] pmfs = [binary_pmf(p) for p in ps] dist = sum(pmfs, pmf0) return dist
def make_pmf(self, xs, name=''): probs = self.density(xs) pmf = Pmf(values=xs, probs=probs, name=name) return pmf
def make_exponential_pmf(lam, high, n=200): xs = np.linspace(0, high, n) probs = [eval_exponential_pdf(lam, x) for x in xs] pmf = Pmf(values=xs, probs=probs) return pmf