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
Beispiel #2
0
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
Beispiel #3
0
 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)
Beispiel #4
0
 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()
Beispiel #5
0
 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_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
Beispiel #7
0
    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
Beispiel #8
0
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
Beispiel #9
0
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
Beispiel #10
0
    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)
Beispiel #11
0
 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
Beispiel #12
0
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()
Beispiel #13
0
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
Beispiel #14
0
 def marginal(self, i, name=''):
     pmf = Pmf(name=name)
     for vs, prob in self.iter_items():
         pmf.incr(vs[i], prob)
     return pmf
Beispiel #15
0
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
Beispiel #16
0
 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
Beispiel #17
0
 def make_pmf(self, xs, name=''):
     probs = self.density(xs)
     pmf = Pmf(values=xs, probs=probs, name=name)
     return pmf
Beispiel #18
0
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
Beispiel #19
0
def make_pmf_from_list(values, name=''):
    pmf = Pmf(name=name)
    for value in values:
        pmf.incr(value)
    pmf.normalize()
    return pmf
Beispiel #20
0
def make_uniform_pmf(low, high):
    pmf = Pmf()
    for x in make_range(low, high):
        pmf.set(x, 1)
    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
Beispiel #22
0
def binary_pmf(p):
    pmf = Pmf()
    pmf.set(1, p)
    pmf.set(0, 1 - p)
    return pmf
Beispiel #23
0
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
Beispiel #24
0
 def reverse_scale(self, pmf):
     reverse = Pmf()
     for value, prob in pmf.iter_items():
         raw = self.reverse(value)
         reverse.incr(raw, prob)
     return reverse