コード例 #1
0
def build_all_wi_scenario_dicts_from_outputs(output_filename):
    opti_outputs_df = read_opti_outputs(output_filename)

    all_wi_sc_params = {}
    for country in OPTI_REGIONS:
        all_wi_sc_params[country] = {}
        for sc_idx, settings in WI_SCENARIO_MAPPING.items():
            decision_vars = read_decision_vars(
                opti_outputs_df,
                country,
                "by_age",
                settings["duration"],
                settings["objective"],
            )
            if decision_vars is not None:
                all_wi_sc_params[country][
                    sc_idx] = build_optimised_scenario_dictionary(
                        country,
                        sc_idx,
                        decision_vars,
                        WI_SCENARIO_MAPPING,
                        for_waning_immunity=True,
                        final_mixing=settings["final_mixing"],
                    )
    return all_wi_sc_params
コード例 #2
0
def main():
    opti_output_filename = "opti_outputs.csv"
    opti_outputs_df = read_opti_outputs(opti_output_filename)
    target_objective = {
        "deaths": 20,
        "yoll": 1000,
    }

    for direction in ["up", "down"]:
        for country in OPTI_REGIONS:
            for mode in MODES:
                for duration in DURATIONS:
                    for objective in OBJECTIVES:
                        print()
                        print()
                        print(country + " " + objective + " " + mode + " " +
                              str(duration) + " " + direction)
                        run_sensitivity_perturbations(
                            opti_outputs_df,
                            country,
                            duration,
                            mode,
                            objective,
                            target_objective_per_million=target_objective[
                                objective],
                            tol=0.02,
                            direction=direction,
                        )
コード例 #3
0
def main():
    # Reset pyplot style
    mpl.rcParams.update(mpl.rcParamsDefault)
    mpl.pyplot.style.use("ggplot")
    opti_output_filename = "opti_outputs.csv"
    opti_outputs_df = read_opti_outputs(opti_output_filename)

    for mode in MODES:
        print(mode)
        optimised_matrices = {}
        original_matrices = {}
        for country in OPTI_REGIONS:
            print(country)
            original_matrices[country] = get_optimised_mixing_matrix(
                country, [1] * 16, MODES[0], DURATIONS[0])
            optimised_matrices[country] = {}
            for duration in DURATIONS:
                print(duration)
                optimised_matrices[country][duration] = {}
                for objective in OBJECTIVES:
                    print(objective)
                    decision_vars = read_decision_vars(opti_outputs_df,
                                                       country, mode, duration,
                                                       objective)
                    optimised_matrices[country][duration][
                        objective] = get_optimised_mixing_matrix(
                            country, decision_vars, mode, duration)

        plot_multicountry_matrices(original_matrices, optimised_matrices, mode)
コード例 #4
0
def run_sensitivity_minimum_mixing(
        opti_output_filename="dummy_vars_for_test.csv"):
    opti_outputs_df = read_opti_outputs(opti_output_filename)
    results = {}

    mode = MODES[0]
    objective = OBJECTIVES[1]

    for country in OPTI_REGIONS:
        results[country] = {}
        root_model = run_root_model(country)
        for duration in DURATIONS:
            results[country][duration] = {}
            decision_vars = read_decision_vars(opti_outputs_df, country, mode,
                                               duration, objective)
            if decision_vars is None:
                continue
            for min_mixing in [0.10, 0.20, 0.30, 0.40, 0.50]:
                modified_vars = copy.deepcopy(decision_vars)
                modified_vars = [max([v, min_mixing]) for v in modified_vars]
                print(
                    f"evaluate objective for {country} | {duration} | {objective}: min_mixing={min_mixing}"
                )
                h, d, yoll = objective_function(modified_vars, root_model,
                                                mode, country, duration)
                res_dict = {
                    "h": bool(h),
                    "d": float(d),
                    "yoll": float(yoll),
                }
                results[country][duration][min_mixing] = res_dict
    file_path = os.path.join(
        BASE_PATH,
        "apps",
        "covid_19",
        "mixing_optimisation",
        "sensitivity_analyses",
        "min_mixing_results.yml",
    )
    with open(file_path, "w") as f:
        yaml.dump(results, f)
    return results
コード例 #5
0
def main():
    # Reset pyplot style
    mpl.rcParams.update(mpl.rcParamsDefault)
    mpl.pyplot.style.use("ggplot")
    opti_output_filename = "opti_outputs.csv"
    opti_outputs_df = read_opti_outputs(opti_output_filename)
    all_results = {}
    for country in OPTI_REGIONS:
        all_results[country] = {}
        for mode in MODES:
            all_results[country][mode] = {}
            for duration in DURATIONS:
                all_results[country][mode][duration] = {}
                for objective in OBJECTIVES:

                    all_results[country][mode][duration][objective] = read_decision_vars(
                        opti_outputs_df, country, mode, duration, objective
                    )

    for mode in MODES:
        plot_multicountry_optimal_plan(all_results, mode)