Exemplo n.º 1
0
    def prepare_logistic(self, normalized_dist: dist.Logistic) -> dist.Logistic:
        """
        Transform a single logistic distribution by clipping the
        parameters and adding scale information as needed for submission to
        Metaculus. The loc and scale have to be within a certain range
        for the Metaculus API to accept the prediction.

        :param dist: a (normalized) logistic distribution
        :return: a transformed logistic distribution
        """
        if hasattr(normalized_dist, "base_dist"):
            normalized_dist = normalized_dist.base_dist  # type: ignore

        if normalized_dist.s <= 0:
            raise ValueError("logistic_params.scale must be greater than 0")

        clipped_loc = min(normalized_dist.loc, max_loc)
        clipped_scale = float(onp.clip(normalized_dist.s, min_scale, max_scale))  # type: ignore

        if self.low_open:
            low = float(onp.clip(normalized_dist.cdf(0), min_open_low, max_open_low,))
        else:
            low = 0

        if self.high_open:
            high = float(
                onp.clip(normalized_dist.cdf(1), min_open_high + low, max_open_high,)
            )
        else:
            high = 1

        return dist.Logistic(
            clipped_loc, clipped_scale, Scale(0, 1), {"low": low, "high": high}
        )
Exemplo n.º 2
0
def logistic_mixture_norm_test():
    xscale = Scale(-50, 50)
    return LogisticMixture(
        components=[Logistic(-40, 1, xscale),
                    Logistic(50, 10, xscale)],
        probs=[0.5, 0.5],
    )
Exemplo n.º 3
0
def normalized_logistic_mixture():
    return LogisticMixture(
        components=[
            Logistic(loc=0.15, s=0.037034005, scale=Scale(0, 1)),
            Logistic(loc=0.85, s=0.032395907, scale=Scale(0, 1)),
        ],
        probs=[0.6, 0.4],
    )
Exemplo n.º 4
0
def logistic_mixture():
    return LogisticMixture(
        components=[
            Logistic(loc=10000, scale=1000),
            Logistic(loc=100000, scale=10000)
        ],
        probs=[0.8, 0.2],
    )
Exemplo n.º 5
0
def logistic_mixture_p_overlapping():
    xscale = three_sd_scale(4000000.035555004, 200000.02)
    return LogisticMixture(
        components=[
            Logistic(4000000.035555004, 200000.02, xscale),
            Logistic(4000000.0329152746, 200000.0, xscale),
        ],
        probs=[0.5, 0.5],
    )
Exemplo n.º 6
0
def logistic_mixture_p_uneven():
    xscale = Scale(-10, 20)
    return LogisticMixture(
        components=[
            Logistic(loc=10, s=3, scale=xscale),
            Logistic(loc=5, s=5, scale=xscale),
        ],
        probs=[1.8629593e-29, 1.0],
    )
Exemplo n.º 7
0
def logistic_mixture10():
    xscale = Scale(-20, 40)
    return LogisticMixture(
        components=[
            Logistic(loc=15, s=2.3658268, scale=xscale),
            Logistic(loc=5, s=2.3658268, scale=xscale),
        ],
        probs=[0.5, 0.5],
    )
Exemplo n.º 8
0
def logistic_mixture():
    xscale = Scale(0, 150000)
    return LogisticMixture(
        components=[
            Logistic(loc=10000, s=1000, scale=xscale),
            Logistic(loc=100000, s=10000, scale=xscale),
        ],
        probs=[0.8, 0.2],
    )
Exemplo n.º 9
0
def logistic_mixture15():
    xscale = Scale(-10, 40)
    return LogisticMixture(
        components=[
            Logistic(loc=10, s=3.658268, scale=xscale),
            Logistic(loc=20, s=3.658268, scale=xscale),
        ],
        probs=[0.5, 0.5],
    )
Exemplo n.º 10
0
def smooth_logistic_mixture():
    xscale = Scale(1, 1000000.0)
    return LogisticMixture(
        components=[
            Logistic(loc=400000, s=100000, scale=xscale),
            Logistic(loc=700000, s=50000, scale=xscale),
        ],
        probs=[0.8, 0.2],
    )
Exemplo n.º 11
0
def truncated_logistic_mixture():
    xscale = Scale(5000, 120000)
    return LogisticMixture(
        components=[
            Truncate(
                Logistic(loc=10000, s=1000, scale=xscale), floor=5000, ceiling=500000
            ),
            Truncate(
                Logistic(loc=100000, s=10000, scale=xscale), floor=5000, ceiling=500000
            ),
        ],
        probs=[0.8, 0.2],
    )
Exemplo n.º 12
0
def test_percentiles_from_mixture():
    xscale = Scale(-1, 4)
    mixture = LogisticMixture(
        components=[
            Logistic(loc=1, s=0.1, scale=xscale),
            Logistic(loc=2, s=0.1, scale=xscale),
        ],
        probs=[0.5, 0.5],
    )
    conditions = mixture.percentiles(percentiles=[0.1, 0.5, 0.9])
    for condition in conditions:
        if condition.max == 0.5:
            assert condition.p == pytest.approx(1.5, rel=0.01)
    return conditions
Exemplo n.º 13
0
    def get_true_scale_logistic(self, normalized_dist: Logistic) -> Logistic:
        """
        Convert a normalized logistic distribution to a logistic on
        the true scale of the question.

        :param normalized_dist: normalized logistic distribution
        :return: logistic distribution on the true scale of the question
        """

        return normalized_dist.denormalize(self.scale)
Exemplo n.º 14
0
    def get_true_scale_logistic(self, normalized_dist: Logistic) -> Logistic:
        """
        Convert a normalized logistic distribution to a logistic on
        the true scale of the question.

        :param normalized_dist: normalized logistic distribution
        :return: logistic distribution on the true scale of the question
        """
        scale_loc = (normalized_dist.loc * self.question_range_width +
                     self.question_range["min"])

        true_scale = normalized_dist.scale * self.question_range_width
        return Logistic(scale_loc, true_scale)
Exemplo n.º 15
0
def easyLogistic(loc, scale):
    return Logistic(loc, scale, three_sd_scale(loc, scale))