Ejemplo n.º 1
0
    def sample_normalized_community(self) -> float:
        """
        Sample an approximation of the entire current community prediction,
        on the normalized scale. The main reason that it's just an approximation
        is that we don't know exactly where probability mass outside of the question
        range should be, so we place it arbitrarily.

        :return: One sample on the normalized scale
        """

        # FIXME: Samples below/above range are pretty arbitrary
        sample_below_range = -dist.halfnormal(0.1)
        sample_above_range = 1 + dist.halfnormal(0.1)
        sample_in_range = ppl.sample(self.community_dist_in_range()) / float(
            len(self.prediction_histogram)
        )
        p_below = self.latest_community_percentiles["low"]
        p_above = 1 - self.latest_community_percentiles["high"]
        p_in_range = 1 - p_below - p_above
        return float(
            dist.random_choice(
                [sample_below_range, sample_in_range, sample_above_range],
                ps=[p_below, p_in_range, p_above],
            )
        )
Ejemplo n.º 2
0
    def sample_normalized_community(self) -> float:
        """
        Sample an approximation of the entire current community prediction, on the normalized scale.
        The main reason that it's just an approximation is that we don't know
        exactly where probability mass outside of the question range should be, so we place it arbitrarily
        (see comment for more)

        :return: One sample on the normalized scale
        """

        # 0.02 is chosen pretty arbitrarily based on what I think will work best
        # from playing around with the Metaculus API previously.
        # Feel free to tweak if something else seems better.
        # Ideally this wouldn't be a fixed number and would depend on
        # how spread out we actually expect the probability mass to be
        outside_range_scale = 0.02

        sample_below_range = -abs(np.random.logistic(
            0, outside_range_scale))  # type: ignore
        sample_above_range = abs(np.random.logistic(
            1, outside_range_scale))  # type: ignore
        sample_in_range = ppl.sample(self.community_dist_in_range()) / float(
            len(self.prediction_histogram))

        p_below = self.latest_community_percentiles["low"]
        p_above = 1 - self.latest_community_percentiles["high"]
        p_in_range = 1 - p_below - p_above

        return float(
            ppl.random_choice(
                [sample_below_range, sample_in_range, sample_above_range],
                ps=[p_below, p_in_range, p_above],
            ))
Ejemplo n.º 3
0
def random_choice(options, ps=None):
    if ps is None:
        ps = np.full(len(options), 1 / len(options))
    else:
        ps = np.array(ps)

    idx = sample(dist.Categorical(ps))
    return options[idx]
Ejemplo n.º 4
0
def beta_from_hits(hits, total, **kwargs):
    return sample(BetaFromHits(hits, total), **kwargs)
Ejemplo n.º 5
0
def lognormal_from_interval(low, high, **kwargs):
    return sample(LogNormalFromInterval(low, high), **kwargs)
Ejemplo n.º 6
0
def halfnormal_from_interval(high, **kwargs):
    return sample(HalfNormalFromInterval(high), **kwargs)
Ejemplo n.º 7
0
def beta(a=1, b=1, **kwargs):
    return sample(dist.Beta(a, b), **kwargs)
Ejemplo n.º 8
0
def categorical(ps, **kwargs):
    return sample(Categorical(ps), **kwargs)
Ejemplo n.º 9
0
def uniform(low=0, high=1, **kwargs):
    return sample(dist.Uniform(low, high), **kwargs)
Ejemplo n.º 10
0
def halfnormal(stdev=1, **kwargs):
    return sample(dist.HalfNormal(stdev), **kwargs)
Ejemplo n.º 11
0
def lognormal(loc=0, scale=1, **kwargs):
    return sample(dist.LogNormal(loc, scale), **kwargs)
Ejemplo n.º 12
0
def normal(mean=0, stdev=1, **kwargs):
    return sample(dist.Normal(mean, stdev), **kwargs)
Ejemplo n.º 13
0
def bernoulli(p=0.5, **kwargs):
    return sample(dist.Bernoulli(probs=float(p)), **kwargs)