Example #1
0
def time_evolution_optimistic_scenario_example():
    """
    Example in which the sensitivities s^S and s^C are high for who uses the app, and the app is used by 60% of the
    population.
    """

    # gs = [asymptomatic, symptomatic]

    n_iterations = 8

    p_gs, beta0_gs = make_scenario_parameters_for_asymptomatic_symptomatic_model(
    )

    scenario = Scenario(
        p_gs=p_gs,
        beta0_gs=beta0_gs,
        t_0=0,
        ssapp=[0, 0.8],
        ssnoapp=[0, 0.2],
        scapp=0.8,
        scnoapp=0.2,
        xi=0.9,
        papp=lambda t: 0.6,
        p_DeltaATapp=DeltaMeasure(position=2),
        p_DeltaATnoapp=DeltaMeasure(position=4),
    )

    step_data_list = compute_time_evolution(
        scenario=scenario,
        real_range=RealRange(0, tau_max, integration_step),
        n_iterations=n_iterations,
        verbose=True,
    )

    plot_time_evolution(step_data_list=step_data_list)
Example #2
0
def dependency_on_share_of_symptomatics_homogeneous_model_example():
    """
    Example of several computations of the limit Eff_∞ in homogeneous scenarios (i.e. with no app usage)
    in which the fraction p_sym of symptomatic individuals and their contribution to R^0 vary.
    """

    p_sym_list = [0.3, 0.4, 0.5, 0.6, 0.7]
    x_axis_list = []
    Effinfty_values_list = []

    for p_sym in p_sym_list:

        contribution_of_symptomatics_to_R0 = 1 - math.exp(
            -4.993 * p_sym
        )  # Random choice, gives 0.95 when p_sym = 0.6
        R0_sym = contribution_of_symptomatics_to_R0 / p_sym * R0
        R0_asy = (1 - contribution_of_symptomatics_to_R0) / (1 - p_sym) * R0

        # gs = [asymptomatic, symptomatic]
        p_gs, beta0_gs = make_scenario_parameters_for_asymptomatic_symptomatic_model(
            p_sym=p_sym,
            contribution_of_symptomatics_to_R0=contribution_of_symptomatics_to_R0,
        )
        n_iterations = 6

        scenario = make_homogeneous_scenario(
            p_gs=p_gs,
            beta0_gs=beta0_gs,
            t_0=0,
            ss=[0, 0.5],
            sc=0.7,
            xi=0.9,
            p_DeltaAT=DeltaMeasure(position=2),
        )

        step_data_list = compute_time_evolution(
            scenario=scenario,
            real_range=RealRange(0, tau_max, integration_step),
            n_iterations=n_iterations,
            verbose=False,
        )

        Rinfty = step_data_list[-1].R
        Effinfty = effectiveness_from_R(Rinfty)

        x_axis_list.append(
            f"p_sym = {p_sym},\nκ={round(contribution_of_symptomatics_to_R0, 2)},\nR^0_sym={round(R0_sym, 2)},\nR^0_asy={round(R0_asy, 2)}"
        )
        Effinfty_values_list.append(Effinfty)

    plt.xticks(p_sym_list, x_axis_list, rotation=0)
    plt.xlim(0, p_sym_list[-1])
    plt.ylim(0, 0.8)
    plt.ylabel("Eff_∞")
    plt.grid(True)
    plt.plot(p_sym_list, Effinfty_values_list, color="black",),

    plt.show()
Example #3
0
def time_evolution_with_varying_parameters():
    """
    Run the algorithm several times, each with a different choice of the parameters s^S, s^C, xi, and p^app.
    """

    tau_max = 30
    integration_step = 0.1

    n_iterations = 8

    # gs = [asymptomatic, symptomatic]
    p_gs, beta0_gs = make_scenario_parameters_for_asymptomatic_symptomatic_model(
    )

    ssnoapp = 0.2
    scnoapp = 0.2
    DeltaATapp = 2
    DeltaATnoapp = 4

    # Varying parameters
    ssapp_list = [0.2, 0.5, 0.8]
    scapp_list = [0.5, 0.8]
    xi_list = [0.7, 0.9]
    papp_list = [0.2, 0.5, 0.7, 0.9]

    for ssapp in ssapp_list:
        for scapp in scapp_list:
            for xi in xi_list:
                for papp in papp_list:
                    scenario = Scenario(
                        p_gs=p_gs,
                        beta0_gs=beta0_gs,
                        t_0=0,
                        ssapp=[0, ssapp],
                        ssnoapp=[0, ssnoapp],
                        scapp=scapp,
                        scnoapp=scnoapp,
                        xi=xi,
                        papp=lambda tau: papp,
                        p_DeltaATapp=DeltaMeasure(position=DeltaATapp),
                        p_DeltaATnoapp=DeltaMeasure(position=DeltaATnoapp),
                    )

                    step_data_list = compute_time_evolution(
                        scenario=scenario,
                        real_range=RealRange(0, tau_max, integration_step),
                        n_iterations=n_iterations,
                        verbose=False,
                    )

                    Rinfty = step_data_list[-1].R
                    Effinfty = effectiveness_from_R(Rinfty)

                    print(
                        f" {ssapp} & {scapp} & {xi} & {papp} & {round2(Rinfty)} & {round2(Effinfty)} \\\ "
                    )
    def test_R_suppression(self):
        _, beta0_gs = make_scenario_parameters_for_asymptomatic_symptomatic_model()
        beta0_ti_gs = [lambda tau: beta0_gs[0](0, tau), lambda tau: beta0_gs[1](0, tau)]
        xi = 0.8  # Any value in [0,1] will do
        tau_max = 30

        FTapp_ti_gs = [
            lambda tau: 0,
            lambda tau: 1 if tau >= 10 else 0,
        ]
        FTnoapp_ti_gs = [
            lambda tau: 0,
            lambda tau: 1 if tau >= 20 else 0,
        ]

        (
            betaapp_ti_gs,
            betanoapp_ti_gs,
            Rapp_ti_gs,
            Rnoapp_ti_gs,
        ) = compute_beta_and_R_components_from_FT(
            FTapp_ti_gs=FTapp_ti_gs,
            FTnoapp_ti_gs=FTnoapp_ti_gs,
            beta0_ti_gs=beta0_ti_gs,
            xi=xi,
            tau_max=tau_max,
        )

        R0_gs = [integrate(f=beta0_ti_gs[g], a=0, b=tau_max) for g in [0, 1]]

        # No suppression for asymptomatic:
        assert all(
            beta0_ti_gs[0](tau) == betaapp_ti_gs[0](tau) == betanoapp_ti_gs[0](tau)
            for tau in (0, 3, 6, 9, 12, 15)
        )
        assert Rapp_ti_gs[0] == Rnoapp_ti_gs[0] == R0_gs[0]
        # For symptomatic with app, suppression for tau >= 10
        assert all(beta0_ti_gs[1](tau) == betaapp_ti_gs[1](tau) for tau in (0, 3, 6, 9))
        assert all(
            betaapp_ti_gs[1](tau) == (1 - xi) * beta0_ti_gs[1](tau)
            for tau in (10, 13, 16, 19)
        )
        assert (1 - xi) * R0_gs[1] <= Rapp_ti_gs[1] <= R0_gs[1]
        # For symptomatic without app, suppression for tau >= 20
        assert all(
            beta0_ti_gs[1](tau) == betanoapp_ti_gs[1](tau)
            for tau in (0, 3, 6, 9, 12, 15, 18)
        )
        assert all(
            betanoapp_ti_gs[1](tau) == (1 - xi) * beta0_ti_gs[1](tau)
            for tau in (20, 25)
        )
        assert (1 - xi) * R0_gs[1] <= Rnoapp_ti_gs[1] <= R0_gs[1]
Example #5
0
def dependency_on_app_adoption_example():
    """
    Example of several computations of the limit Eff_∞ with app usage, where the fraction p^app of app adopters varies.
    """
    n_iterations = 8

    # gs = [asymptomatic, symptomatic]
    p_gs, beta0_gs = make_scenario_parameters_for_asymptomatic_symptomatic_model()

    papp_list = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
    Effinfty_values_list = []

    for papp in papp_list:
        scenario = Scenario(
            p_gs=p_gs,
            beta0_gs=beta0_gs,
            t_0=0,
            ssapp=[0, 0.5],
            ssnoapp=[0, 0.2],
            scapp=0.7,
            scnoapp=0.2,
            xi=0.9,
            papp=lambda t: papp,
            p_DeltaATapp=DeltaMeasure(position=2),
            p_DeltaATnoapp=DeltaMeasure(position=4),
        )

        step_data_list = compute_time_evolution(
            scenario=scenario,
            real_range=RealRange(0, tau_max, integration_step),
            n_iterations=n_iterations,
            verbose=False,
        )

        Rinfty = step_data_list[-1].R
        Effinfty = effectiveness_from_R(Rinfty)
        Effinfty_values_list.append(Effinfty)

    fig = plt.figure(figsize=(10, 15))

    Rinfty_plot = fig.add_subplot(111)
    Rinfty_plot.set_xlabel("p^app")
    Rinfty_plot.set_ylabel("Eff_∞")
    Rinfty_plot.grid(True)
    Rinfty_plot.set_xlim(0, 1)
    Rinfty_plot.set_ylim(0, 1)
    Rinfty_plot.plot(papp_list, Effinfty_values_list, color="black",),

    plt.show()
Example #6
0
def dependency_on_testing_timeliness_homogeneous_model_example():
    """
    Example of several computations of the limit Eff_∞ in homogeneous scenarios (i.e. with no app usage)
    in which the time interval Δ^{A → T} varies from 0 to 10 days.
    """
    n_iterations = 8

    # gs = [asymptomatic, symptomatic]
    p_gs, beta0_gs = make_scenario_parameters_for_asymptomatic_symptomatic_model()

    DeltaAT_values_list = list(range(0, 10))
    Effinfty_values_list = []

    for DeltaAT in DeltaAT_values_list:

        scenario = make_homogeneous_scenario(
            p_gs=p_gs,
            beta0_gs=beta0_gs,
            t_0=0,
            ss=[0, 0.5],
            sc=0.7,
            xi=0.9,
            p_DeltaAT=DeltaMeasure(position=DeltaAT),
        )

        step_data_list = compute_time_evolution(
            scenario=scenario,
            real_range=RealRange(0, tau_max, integration_step),
            n_iterations=n_iterations,
            verbose=False,
        )

        Rinfty = step_data_list[-1].R
        Effinfty = effectiveness_from_R(Rinfty)
        Effinfty_values_list.append(Effinfty)

    fig = plt.figure(figsize=(10, 15))

    Rinfty_plot = fig.add_subplot(111)
    Rinfty_plot.set_xlabel("Δ^{A → T} (days)")
    Rinfty_plot.set_ylabel("Eff_∞")
    Rinfty_plot.grid(True)
    Rinfty_plot.set_xlim(0, DeltaAT_values_list[-1])
    Rinfty_plot.set_ylim(0, 0.6)
    Rinfty_plot.plot(DeltaAT_values_list, Effinfty_values_list, color="black",),

    plt.show()
Example #7
0
def time_evolution_gradual_app_adoption_example():
    """
    Example in which the share of people using the app linearly increases, until reaching 60% in 30 days.
    """

    # gs = [asymptomatic, symptomatic]

    n_iterations = 16

    p_gs, beta0_gs = make_scenario_parameters_for_asymptomatic_symptomatic_model(
    )

    def papp(t: float) -> float:
        papp_infty = 0.6
        t_saturation = 30
        if 0 <= t < t_saturation:
            return papp_infty * t / t_saturation
        elif t >= t_saturation:
            return papp_infty

    scenario = Scenario(
        p_gs=p_gs,
        beta0_gs=beta0_gs,
        t_0=0,
        ssapp=[0, 0.8],
        ssnoapp=[0, 0.2],
        scapp=0.8,
        scnoapp=0.2,
        xi=0.9,
        papp=papp,
        p_DeltaATapp=DeltaMeasure(position=2),
        p_DeltaATnoapp=DeltaMeasure(position=4),
    )

    step_data_list = compute_time_evolution(
        scenario=scenario,
        real_range=RealRange(0, tau_max, integration_step),
        n_iterations=n_iterations,
        verbose=True,
    )

    plot_time_evolution(step_data_list=step_data_list)
Example #8
0
def time_evolution_homogeneous_model_optimistic_scenario_example():
    """
    Example in which there is no app usage, and the sensitivities s^S and s^C are quite high
    """

    # gs = [asymptomatic, symptomatic]

    n_iterations = 8

    p_gs, beta0_gs = make_scenario_parameters_for_asymptomatic_symptomatic_model(
    )

    ss = [0, 0.5]
    sc = 0.7
    xi = 0.9
    DeltaAT = 2

    scenario = Scenario(
        p_gs=p_gs,
        beta0_gs=beta0_gs,
        t_0=0,
        ssapp=[0, 0],
        ssnoapp=ss,
        scapp=0,
        scnoapp=sc,
        xi=xi,
        papp=lambda tau: 0,
        p_DeltaATapp=DeltaMeasure(position=0),
        p_DeltaATnoapp=DeltaMeasure(position=DeltaAT),
    )

    step_data_list = compute_time_evolution(
        scenario=scenario,
        real_range=RealRange(0, tau_max, integration_step),
        n_iterations=n_iterations,
        verbose=True,
    )

    plot_time_evolution(step_data_list=step_data_list, plot_components=False)
    def test_only_symptoms_control(self):

        tau_max = 30
        integration_step = 0.1

        # gs = [asymptomatic, symptomatic]:
        p_gs, beta0_gs = make_scenario_parameters_for_asymptomatic_symptomatic_model(
        )

        scenario = Scenario(
            p_gs=p_gs,
            beta0_gs=beta0_gs,
            t_0=0,
            ssapp=[0, 0.7],
            ssnoapp=[0, 0.5],
            scapp=0,
            scnoapp=0,
            xi=1,
            papp=lambda tau: 0,
            p_DeltaATapp=DeltaMeasure(position=1),
            p_DeltaATnoapp=DeltaMeasure(position=2),
        )

        step_data_list = compute_time_evolution(
            scenario=scenario,
            real_range=RealRange(0, tau_max, integration_step),
            n_iterations=4,
            verbose=False,
        )

        precision = 3
        first_step_data = step_data_list[0]
        last_step_data = step_data_list[-1]
        assert check_equality_with_precision(x=first_step_data.R,
                                             y=last_step_data.R,
                                             decimal=precision)
Example #10
0
def dependency_on_efficiencies_example():
    """
    Example of several computations of the limit Eff_∞ with app usage, where the parameters s^{s,app} and s^{c,app}
    vary.
    """
    n_iterations = 8

    # gs = [asymptomatic, symptomatic]
    p_gs, beta0_gs = make_scenario_parameters_for_asymptomatic_symptomatic_model()

    ssapp_list = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]
    scapp_list = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]

    Effinfty_values_list = []

    for scapp in scapp_list:
        Effinfty_values_list_for_scapp = []
        for ssapp in ssapp_list:

            scenario = Scenario(
                p_gs=p_gs,
                beta0_gs=beta0_gs,
                t_0=0,
                ssapp=[0, ssapp],
                ssnoapp=[0, 0.2],
                scapp=scapp,
                scnoapp=0.2,
                xi=0.9,
                papp=lambda t: 0.6,
                p_DeltaATapp=DeltaMeasure(position=2),
                p_DeltaATnoapp=DeltaMeasure(position=4),
            )

            step_data_list = compute_time_evolution(
                scenario=scenario,
                real_range=RealRange(0, tau_max, integration_step),
                n_iterations=n_iterations,
                verbose=False,
            )

            Rinfty = step_data_list[-1].R
            Effinfty = effectiveness_from_R(Rinfty)

            print(
                f"s^{{s,app}} = {ssapp}, s^{{c,app}} = {scapp}, Eff_∞ = {round(Effinfty, 2)}"
            )

            Effinfty_values_list_for_scapp.append(Effinfty)

        Effinfty_values_list.append(Effinfty_values_list_for_scapp)

    ssapp_values_array, scapp_values_array = np.meshgrid(ssapp_list, scapp_list)

    fig = plt.figure(figsize=(10, 15))
    ax = fig.gca(projection="3d")

    ax.plot_surface(
        ssapp_values_array, scapp_values_array, np.array(Effinfty_values_list),
    )

    ax.set_xlabel("s^{s,app}")
    ax.set_ylabel("s^{c,app}")
    ax.set_zlabel("Eff_∞")

    plt.show()
Example #11
0
def dependency_on_infectiousness_width_homogeneous_model_example():
    """
    Example of several computations of the limit Eff_∞ in homogeneous scenarios (i.e. with no app usage)
    in which the default distribution ρ^0 of the generation time is rescaled by different factors.
    """

    infectiousness_rescale_factors = [0.6, 0.8, 1, 1.2, 1.4, 1.6, 1.8]

    expected_default_generation_times_list = []
    Effinfty_values_list = []

    for f in infectiousness_rescale_factors:

        def rescaled_rho0(tau):
            return (1 / f) * rho0(tau / f)

        assert round(integrate(rescaled_rho0, 0, tau_max), 5) == 1

        EtauC0 = integrate(
            lambda tau: tau * rescaled_rho0(tau), 0, tau_max
        )  # Expected default generation time
        expected_default_generation_times_list.append(EtauC0)

        # gs = [asymptomatic, symptomatic]
        p_gs, beta0_gs = make_scenario_parameters_for_asymptomatic_symptomatic_model(
            rho0=rescaled_rho0
        )
        n_iterations = 6

        scenario = make_homogeneous_scenario(
            p_gs=p_gs,
            beta0_gs=beta0_gs,
            t_0=0,
            ss=[0, 0.5],
            sc=0.7,
            xi=0.9,
            p_DeltaAT=DeltaMeasure(position=2),
        )

        step_data_list = compute_time_evolution(
            scenario=scenario,
            real_range=RealRange(0, tau_max, integration_step),
            n_iterations=n_iterations,
            verbose=False,
        )

        Rinfty = step_data_list[-1].R
        Effinfty = effectiveness_from_R(Rinfty)

        Effinfty_values_list.append(Effinfty)

    plt.ylim(0, 0.8)
    plt.grid(True)
    plt.plot(
        expected_default_generation_times_list, Effinfty_values_list, color="black",
    ),
    plt.xlabel("E(τ^{0,C})")
    plt.ylabel("Eff_∞")
    plt.title(
        "Effectiveness under rescaling of the default generation time distribution"
    )

    plt.show()