예제 #1
0
def test_create_abcsmc(data_api):
    inf.ABCSMC(
        data_api.read_table("human/abcsmc-parameters", "abcsmc-parameters"),
        data_api.read_table("human/historical-deaths", "historical-deaths"),
        data_api.read_table("human/compartment-transition", "compartment-transition"),
        data_api.read_table("human/population", "population"),
        data_api.read_table("human/commutes", "commutes"),
        data_api.read_table("human/mixing-matrix", "mixing-matrix"),
        data_api.read_table("human/infection-probability", "infection-probability"),
        data_api.read_table("human/initial-infections", "initial-infections"),
        data_api.read_table("human/infectious-compartments", "infectious-compartments"),
        data_api.read_table("human/trials", "trials"),
        data_api.read_table("human/start-end-date", "start-end-date"),
        data_api.read_table("human/movement-multipliers", "movement-multipliers"),
        data_api.read_table("human/stochastic-mode", "stochastic-mode"),
        data_api.read_table("human/random-seed", "random-seed"),
    )
예제 #2
0
def test_create_abcsmc_too_many_infection_probas(data_api):
    with pytest.raises(AssertionError):
        inf.ABCSMC(
            data_api.read_table("human/abcsmc-parameters", "abcsmc-parameters"),
            data_api.read_table("human/historical-deaths", "historical-deaths"),
            data_api.read_table("human/compartment-transition", "compartment-transition"),
            data_api.read_table("human/population", "population"),
            data_api.read_table("human/commutes", "commutes"),
            data_api.read_table("human/mixing-matrix", "mixing-matrix"),
            pd.DataFrame([{"Date": "2020-01-01", "Value": 0.5}, {"Date": "2020-01-02", "Value": 0.5}]),
            data_api.read_table("human/initial-infections", "initial-infections"),
            data_api.read_table("human/infectious-compartments", "infectious-compartments"),
            data_api.read_table("human/trials", "trials"),
            data_api.read_table("human/start-end-date", "start-end-date"),
            data_api.read_table("human/movement-multipliers", "movement-multipliers"),
            data_api.read_table("human/stochastic-mode", "stochastic-mode"),
            data_api.read_table("human/random-seed", "random-seed"),
        )
예제 #3
0
def test_create_abcsmc_invalid_abc_smc_params(data_api, param_index):
    parameters = data_api.read_table("human/abcsmc-parameters", "abcsmc-parameters")
    parameters.at[param_index, "Value"] = 0

    with pytest.raises(AssertionError):
        inf.ABCSMC(
            parameters,
            data_api.read_table("human/historical-deaths", "historical-deaths"),
            data_api.read_table("human/compartment-transition", "compartment-transition"),
            data_api.read_table("human/population", "population"),
            data_api.read_table("human/commutes", "commutes"),
            data_api.read_table("human/mixing-matrix", "mixing-matrix"),
            data_api.read_table("human/infection-probability", "infection-probability"),
            data_api.read_table("human/initial-infections", "initial-infections"),
            data_api.read_table("human/infectious-compartments", "infectious-compartments"),
            data_api.read_table("human/trials", "trials"),
            data_api.read_table("human/start-end-date", "start-end-date"),
            data_api.read_table("human/movement-multipliers", "movement-multipliers"),
            data_api.read_table("human/stochastic-mode", "stochastic-mode"),
            data_api.read_table("human/random-seed", "random-seed"),
        )
예제 #4
0
def test_ABCSMC_run_model_with_issues(mock_warn_logger, data_api):
    abcsmc = inf.ABCSMC(
        data_api.read_table("human/abcsmc-parameters", "abcsmc-parameters"),
        data_api.read_table("human/historical-deaths", "historical-deaths"),
        data_api.read_table("human/compartment-transition", "compartment-transition"),
        data_api.read_table("human/population", "population").iloc[:10],
        data_api.read_table("human/commutes", "commutes"),
        data_api.read_table("human/mixing-matrix", "mixing-matrix"),
        pd.DataFrame([{"Date": "2020-01-01", "Value": 0.5}]),
        data_api.read_table("human/initial-infections", "initial-infections"),
        data_api.read_table("human/infectious-compartments", "infectious-compartments"),
        data_api.read_table("human/trials", "trials"),
        data_api.read_table("human/start-end-date", "start-end-date"),
        data_api.read_table("human/movement-multipliers", "movement-multipliers"),
        data_api.read_table("human/stochastic-mode", "stochastic-mode"),
        data_api.read_table("human/random-seed", "random-seed"),
    )

    particle = inf.Particle.generate_from_priors(abcsmc)
    abcsmc.run_model(particle)

    mock_warn_logger.assert_has_calls([call("We had %s issues when running the model:", 36)])
def abcsmc(data_api):  # pylint: disable=redefined-outer-name
    yield inference.ABCSMC(
        data_api.read_table("human/abcsmc-parameters", "abcsmc-parameters"),
        data_api.read_table("human/historical-deaths", "historical-deaths"),
        data_api.read_table("human/compartment-transition",
                            "compartment-transition"),
        data_api.read_table("human/population", "population"),
        data_api.read_table("human/commutes", "commutes"),
        data_api.read_table("human/mixing-matrix", "mixing-matrix"),
        pd.DataFrame([{
            "Date": "2020-01-01",
            "Value": 0.5
        }]),
        data_api.read_table("human/initial-infections", "initial-infections"),
        data_api.read_table("human/infectious-compartments",
                            "infectious-compartments"),
        data_api.read_table("human/trials", "trials"),
        data_api.read_table("human/start-end-date", "start-end-date"),
        data_api.read_table("human/movement-multipliers",
                            "movement-multipliers"),
        data_api.read_table("human/stochastic-mode", "stochastic-mode"),
        data_api.read_table("human/random-seed", "random-seed"),
    )