Example #1
0
def get_immunity_mult(region_model):
    """Returns the immunity multiplier, a measure of the immunity in a region.

    The greater the immunity multiplier, the greater the effect of immunity.
    The more populous a region, the greater the effect of immunity (since outbreaks
        are usually localized)
    Later on, use this multiplier by multiplying the transmission rate by:
        effective_r = R_t * (1-perc_population_infected_thus_far)**immunity_mult
    """

    population = region_model.region_params['population']
    if region_model.country_str == 'US':
        if region_model.subregion_str:
            immunity_mult = IMMUNITY_MULTIPLIER_US_SUBREGION
        else:
            immunity_mult = IMMUNITY_MULTIPLIER
    elif region_model.subregion_str:
        immunity_mult = IMMUNITY_MULTIPLIER
    elif population < 20000000:
        immunity_mult = inv_sigmoid(10000000, 0.0000003,
                                    IMMUNITY_MULTIPLIER - 1, 1)(population)
    else:
        immunity_mult = inv_sigmoid(20000000, 0.00000003,
                                    IMMUNITY_MULTIPLIER - 1.25,
                                    1.25)(population)

    if region_model.country_str not in EARLY_IMPACTED_COUNTRIES:
        # these countries may not have comprehensive early testing, hence we
        # correct for that by increasing the immunity mult
        immunity_mult *= 1.1

    return immunity_mult
Example #2
0
    def get_immunity_mult(self):
        """Returns the immunity multiplier, a measure of the immunity in a region.

        The greater the immunity multiplier, the greater the effect of immunity.
        The more populous a region, the greater the effect of immunity (since outbreaks
            are usually localized)
        Later on, use this multiplier by multiplying the transmission rate by:
            effective_r = R_t * (1-perc_population_infected_thus_far)**immunity_mult
        """

        assert 0 <= IMMUNITY_MULTIPLIER <= 2, IMMUNITY_MULTIPLIER
        assert 0 <= IMMUNITY_MULTIPLIER_US_SUBREGION <= 2, IMMUNITY_MULTIPLIER_US_SUBREGION

        population = self.region_params['population']
        if self.country_str == 'US':
            if self.subregion_str:
                immunity_mult = IMMUNITY_MULTIPLIER_US_SUBREGION
            else:
                immunity_mult = IMMUNITY_MULTIPLIER
        elif self.subregion_str:
            immunity_mult = IMMUNITY_MULTIPLIER
        elif population < 20000000:
            immunity_mult = utils.inv_sigmoid(10000000, 0.0000003,
                                              IMMUNITY_MULTIPLIER - 1,
                                              1)(population)
        else:
            immunity_mult = utils.inv_sigmoid(20000000, 0.00000003,
                                              IMMUNITY_MULTIPLIER - 1.25,
                                              1.25)(population)

        if self.country_str not in EARLY_IMPACTED_COUNTRIES + [
                'Brazil', 'Mexico'
        ]:
            # These countries may not have comprehensive early testing, so the true prevalence
            #   may be higher, hence we correct for that by increasing the immunity mult
            # We also do not include Brazil/Mexico due to the already-high immunity_mult
            immunity_mult *= 1.1

        return immunity_mult
def get_transition_sigmoid(inflection_day, rate_of_inflection, init_r_0, lockdown_r_0):
    """Returns a sigmoid function based on the specified parameters.

    A sigmoid helps smooth the transition between init_r_0 and lockdown_r_0,
        with the midpoint being inflection_day.
    rate_of_inflection is typically a value between 0-1, with 1 being a very steep
        transition. We typically use 0.2-0.5 in our projections.
    """
    assert 0 < rate_of_inflection <= 1, rate_of_inflection
    assert 0 < init_r_0 <= 10, init_r_0
    assert 0 <= lockdown_r_0 <= 10, lockdown_r_0
    shift = inflection_day
    a = rate_of_inflection
    b = init_r_0 - lockdown_r_0
    c = lockdown_r_0
    return utils.inv_sigmoid(shift, a, b, c)
def get_transition_sigmoid(inflection_idx, inflection_rate, low_value, high_value,
        check_values=True):
    """Returns a sigmoid function based on the specified parameters.

    A sigmoid helps smooth the transition between low_value and high_value,
        with the midpoint being inflection_idx.
    inflection_rate is typically a value between 0-1, with 1 being a very steep
        transition. We typically use 0.2-0.5 in our projections.
    """
    if check_values:
        assert 0 < inflection_rate <= 1, inflection_rate
        assert 0 < low_value <= 10, low_value
        assert 0 <= high_value <= 10, high_value
    shift = inflection_idx
    a = inflection_rate
    b = low_value - high_value
    c = high_value
    return utils.inv_sigmoid(shift, a, b, c)