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