Esempio n. 1
0
 def test_analysis(self, jhu_data, population_data):
     scenario = Scenario(jhu_data, population_data, country="Italy")
     with pytest.raises(KeyError):
         scenario.simulate(name="Main", show_figure=False)
     with pytest.raises(ValueError):
         scenario.estimate(model=SIRF)
     # S-R trend analysis
     scenario.trend(show_figure=False)
     warnings.filterwarnings("ignore", category=UserWarning)
     scenario.trend(show_figure=True)
     # Parameter estimation of SIR-F model
     with pytest.raises(ValueError):
         scenario.param_history(targets=["Rt"], show_figure=False)
     with pytest.raises(ValueError):
         scenario.estimate(model=SIRF, tau=1440)
     scenario.estimate(model=SIRF)
     # History of estimation
     scenario.estimate_history(phase="1st")
     with pytest.raises(KeyError):
         scenario.estimate_history(phase="0th")
     # Accuracy of estimation
     scenario.estimate_accuracy(phase="1st")
     with pytest.raises(KeyError):
         scenario.estimate_accuracy(phase="0th")
     # Prediction
     scenario.add(name="Main", days=100)
     scenario.simulate(name="Main", show_figure=False)
     scenario.simulate(name="Main", show_figure=True)
     scenario.param_history(targets=["Rt"], show_figure=False)
     scenario.param_history(targets=["Rt"], divide_by_first=False)
     scenario.param_history(targets=["Rt"], show_box_plot=False)
     with pytest.raises(KeyError):
         scenario.param_history(targets=["Rt", "Value"])
     with pytest.raises(KeyError):
         scenario.param_history(targets=["Rt"], box_plot=False)
     # New scenario
     sigma_new = scenario.get("sigma", phase="last") * 2
     with pytest.raises(KeyError):
         scenario.get("value")
     warnings.filterwarnings("ignore", category=DeprecationWarning)
     scenario.add_phase(name="New medicines", days=100, sigma=sigma_new)
     # Summarize scenarios
     summary_df = scenario.summary()
     assert isinstance(summary_df, pd.DataFrame)
     desc_df = scenario.describe()
     assert isinstance(desc_df, pd.DataFrame)
     # Estimation errors
     with pytest.raises(TypeError):
         scenario.estimate(SIRF, phases="1st")
     with pytest.raises(KeyError):
         scenario.estimate(SIRF, phases=["100th"])
Esempio n. 2
0
 def test_estimate(self, jhu_data, population_data, country):
     warnings.simplefilter("ignore", category=UserWarning)
     # Setting
     snl = Scenario(jhu_data, population_data, country)
     snl.first_date = "01Apr2020"
     snl.last_date = "01Aug2020"
     with pytest.raises(ValueError):
         snl.estimate(SIR)
     snl.trend(show_figure=False)
     with pytest.raises(AttributeError):
         snl.estimate_history(phase="last")
     # Parameter estimation
     with pytest.raises(KeyError):
         snl.estimate(SIR, phases=["30th"])
     with pytest.raises(ValueError):
         snl.estimate(model=SIR, tau=1440)
     snl.estimate(SIR, timeout=1, timeout_iteration=1)
     # Estimation history
     snl.estimate_history(phase="last")
     # Estimation accuracy
     snl.estimate_accuracy(phase="last")
     # Get a value
     snl.get(Term.RT)
     with pytest.raises(KeyError):
         snl.get("feeling")
Esempio n. 3
0
 def test_simulate(self, jhu_data, population_data, country):
     warnings.simplefilter("ignore", category=UserWarning)
     warnings.simplefilter("ignore", category=DeprecationWarning)
     # Setting
     snl = Scenario(jhu_data, population_data, country)
     snl.first_date = "01Apr2020"
     snl.last_date = "01May2020"
     with pytest.raises(ValueError):
         snl.simulate()
     with pytest.raises(ValueError):
         snl.track()
     snl.trend(show_figure=False)
     # Parameter estimation
     with pytest.raises(ValueError):
         # Deprecated
         snl.param_history(["rho"])
     all_phases = snl.summary().index.tolist()
     snl.disable(all_phases[:-2])
     with pytest.raises(NameError):
         snl.simulate()
     snl.estimate(SIRF, timeout=5, timeout_iteration=5)
     # Simulation
     snl.simulate(variables=[Term.C, Term.CI, Term.F, Term.R])
     snl.simulate(phases=all_phases[-2:])
     # Parameter history (Deprecated)
     snl.param_history([Term.RT], divide_by_first=False)
     snl.param_history(["rho"])
     snl.param_history(["rho"], show_figure=False)
     snl.param_history(["rho"], show_box_plot=False)
     with pytest.raises(KeyError):
         snl.param_history(["feeling"])
     # Comparison of scenarios
     snl.describe()
     snl.track()
     snl.history(target="Rt")
     snl.history(target="sigma")
     snl.history(target="rho", show_figure=False)
     snl.history(target="Infected", phases=all_phases[-2:])
     with pytest.raises(KeyError):
         snl.history(target="temperature")
     # Change rate of parameters
     snl.history_rate(name="Main")
     snl.history_rate(
         name="Main", params=["theta", "kappa"], show_figure=False)
     with pytest.raises(TypeError):
         snl.history_rate(params="", name="Main")
     # Add new scenario
     snl.add(end_date="01Sep2020", name="New")
     snl.describe()
Esempio n. 4
0
 def test_fit_predict(self, jhu_data, population_data, oxcgrt_data, country):
     snl = Scenario(jhu_data, population_data, country)
     snl.trend(show_figure=False)
     with pytest.raises(UnExecutedError):
         snl.fit(oxcgrt_data)
     snl.estimate(SIRF, timeout=1, timeout_iteration=1)
     # Fitting
     with pytest.raises(UnExecutedError):
         snl.predict()
     info_dict = snl.fit(oxcgrt_data)
     assert isinstance(info_dict, dict)
     # Prediction
     snl.predict()
     assert Term.FUTURE in snl.summary()[Term.TENSE].unique()
     # Fitting & predict
     snl.fit_predict(oxcgrt_data)
     assert Term.FUTURE in snl.summary()[Term.TENSE].unique()
Esempio n. 5
0
 def test_score(self, jhu_data, population_data, country):
     snl = Scenario(jhu_data, population_data, country, tau=360)
     snl.trend(show_figure=False)
     snl.estimate(SIRF, timeout=1, timeout_iteration=1)
     assert isinstance(snl.score(metrics="RMSLE"), float)
     # Selected phases
     df = snl.summary()
     all_phases = df.index.tolist()
     sel_score = snl.score(phases=all_phases[-2:])
     # Selected past days (when the begging date is a start date)
     beginning_date = df.loc[df.index[-2], Term.START]
     past_days = Term.steps(beginning_date, snl.last_date, tau=1440)
     assert snl.score(past_days=past_days) == sel_score
     # Selected past days
     snl.score(past_days=60)
     with pytest.raises(ValueError):
         snl.score(phases=["1st"], past_days=60)
Esempio n. 6
0
 def test_score(self, jhu_data, population_data, country):
     snl = Scenario(jhu_data, population_data, country, tau=360)
     snl.trend(show_figure=False)
     snl.estimate(SIRF, timeout=10)
     metrics_list = ["MAE", "MSE", "MSLE", "RMSE", "RMSLE"]
     for metrics in metrics_list:
         score = snl.score(metrics=metrics)
         assert isinstance(score, float)
     # Selected phases
     df = snl.summary()
     all_phases = df.index.tolist()
     sel_score = snl.score(phases=all_phases[-2:])
     # Selected past days (when the begging date is a start date)
     beginning_date = df.loc[df.index[-2], Term.START]
     past_days = Term.steps(beginning_date, snl.last_date, tau=1440)
     assert snl.score(past_days=past_days) == sel_score
     # Selected past days
     snl.score(past_days=60)
Esempio n. 7
0
 def test_analysis(self, jhu_data, population_data):
     scenario = Scenario(jhu_data, population_data, country="Italy")
     # S-R trend analysis
     scenario.trend(show_figure=False)
     # Parameter estimation of SIR-F model
     scenario.estimate(model=SIRF)
     # Prediction
     scenario.add_phase(name="Main", days=100)
     scenario.simulate(name="Main", show_figure=False)
     scenario.param_history(targets=["Rt"], name="Main", show_figure=False)
     # New scenario
     sigma_new = scenario.get("sigma", phase="last") * 2
     scenario.add_phase(name="New medicines", days=100, sigma=sigma_new)
     # Summarize scenarios
     summary_df = scenario.summary()
     assert isinstance(summary_df, pd.DataFrame)
     desc_df = scenario.describe()
     assert isinstance(desc_df, pd.DataFrame)
Esempio n. 8
0
 def test_score_error(self, jhu_data, population_data, country):
     snl = Scenario(jhu_data, population_data, country)
     with pytest.raises(ValueError):
         snl.score()
     snl.trend(show_figure=False)
     with pytest.raises(NameError):
         snl.score()
     all_phases = snl.summary().index.tolist()
     snl.disable(phases=all_phases[:-2])
     snl.estimate(SIRF, timeout=10)
     with pytest.raises(TypeError):
         snl.score(phases="0th")
     with pytest.raises(KeyError):
         snl.score(phases=["100th"])
     with pytest.raises(TypeError):
         snl.score(variables="Infected")
     with pytest.raises(KeyError):
         snl.score(variables=["Susceptible"])
     with pytest.raises(ValueError):
         snl.score(metrics="Subjective evaluation")
     with pytest.raises(ValueError):
         snl.score(phases=["0th"], past_days=100)
Esempio n. 9
0
 def test_simulate(self, jhu_data, population_data, country):
     warnings.simplefilter("ignore", category=UserWarning)
     warnings.simplefilter("ignore", category=DeprecationWarning)
     # Setting
     snl = Scenario(jhu_data, population_data, country)
     snl.first_date = "01Apr2020"
     snl.last_date = "01Aug2020"
     snl.trend(show_figure=False)
     # Parameter estimation
     with pytest.raises(ValueError):
         # Deprecated
         snl.param_history(["rho"])
     snl.estimate(SIR)
     # Simulation
     snl.simulate()
     # Parameter history (Deprecated)
     snl.param_history([Term.RT], divide_by_first=False)
     snl.param_history(["rho"])
     snl.param_history(["rho"], show_figure=False)
     snl.param_history(["rho"], show_box_plot=False)
     with pytest.raises(KeyError):
         snl.param_history(["feeling"])
     # Comparison of scenarios
     snl.describe()
     snl.history(target="Rt")
     snl.history(target="sigma")
     snl.history(target="Infected")
     with pytest.raises(KeyError):
         snl.history(target="temperature")
     # Change rate of parameters
     snl.history_rate(name="Main")
     with pytest.raises(TypeError):
         snl.history_rate(params="", name="Main")
     # Add new scenario
     snl.add(end_date="01Sep2020", name="New")
     snl.describe()
Esempio n. 10
0
 def test_estimate_tau(self, jhu_data, population_data, country):
     # Setting
     snl = Scenario(jhu_data, population_data, country)
     snl.trend(show_figure=False)
     with pytest.raises(ValueError):
         snl.estimate(SIR, tau=1440)
Esempio n. 11
0
 def test_estimate(self, jhu_data, population_data, country):
     warnings.simplefilter("ignore", category=UserWarning)
     # Setting
     snl = Scenario(jhu_data, population_data, country)
     snl.first_date = "01Apr2020"
     snl.last_date = "01Aug2020"
     with pytest.raises(ValueError):
         snl.estimate(SIR)
     snl.trend(include_init_phase=True, show_figure=False)
     snl.disable(phases=["0th"])
     with pytest.raises(AttributeError):
         snl.estimate_history(phase="1th")
     # Parameter estimation
     with pytest.raises(KeyError):
         snl.estimate(SIR, phases=["30th"])
     with pytest.raises(ValueError):
         snl.estimate(model=SIR, tau=1440)
     snl.enable(phases=["0th"])
     with pytest.raises(TypeError):
         snl.estimate(model=SIR, phases="1st")
     with pytest.raises(ValueError):
         snl.estimate(model=SIR, phases=["0th"])
     snl.clear(include_past=True)
     snl.trend(show_figure=False)
     snl.estimate(SIR)
     # Estimation history
     snl.estimate_history(phase="1st")
     # Estimation accuracy
     snl.estimate_accuracy(phase="1st")
     # Get a value
     snl.get(Term.RT)
     with pytest.raises(KeyError):
         snl.get("feeling")