lisphilar / covid19-sir

CovsirPhy: Python library for COVID-19 analysis with phase-dependent SIR-derived ODE models.
https://lisphilar.github.io/covid19-sir/
Apache License 2.0
109 stars 44 forks source link

[Fix] Days argument in forecast - doesn't correspond to the number of prediction days #715

Closed Inglezos closed 3 years ago

Inglezos commented 3 years ago

Summary

For example if I use ita_scenario.fit_predict(oxcgrt_data=oxcgrt_data, name="Forecast", days=[1]) and then ita_sim_df = ita_scenario.simulate(variables=["Confirmed", "Infected", "Fatal", "Recovered"], color_dict={"Confirmed": "blue", "Infected": "orange", "Fatal": "red", "Recovered": "green"}, name="Forecast"), I see that in the plot but mostly in the ita_sim_df, the future days are up to 14Apr21, not only up to one day into the future (that would be 11 or 12 Apr21) as I would expect by using days. Is this considered normal? Because I feel that a value of around 2-3 days are added beforehand to the output days.

Codes

import covsirphy as cs

data_loader = cs.DataLoader(directory="kaggle/input")
jhu_data = data_loader.jhu()
population_data = data_loader.population()
oxcgrt_data = data_loader.oxcgrt()

country = "Italy"
ita_scenario = cs.Scenario(jhu_data, population_data, country)
ita_scenario.register(extras=[oxcgrt_data])
ita_delay = ita_scenario.estimate_delay(use_difference=False)
ita_scenario.records(variables=["Confirmed", "Infected", "Fatal", "Recovered"], color_dict={"Confirmed": "blue", "Infected": "orange", "Fatal": "red", "Recovered": "green"})

_ = ita_scenario.trend()
ita_scenario.estimate(cs.SIRF)
ita_scenario.add(name="Main", days=30)

ita_scenario.fit_predict(oxcgrt_data=oxcgrt_data, name="Forecast", days=[1]).summary(name="Forecast")
ita_sim_df = ita_scenario.simulate(variables=["Confirmed", "Infected", "Fatal", "Recovered"],
                                   color_dict={"Confirmed": "blue", "Infected": "orange", "Fatal": "red", "Recovered": "green"},
                                   name="Forecast")

Environment

lisphilar commented 3 years ago

Yes, this could be fixed.

Counts of days starts from 0 at this time and confusing. So, days=[1] means that the end date of the future phase is 13Apr when today is 11Apr with the latest version.

Scenario.simulate() simulates to the next date (14Apr) of the end date (13Apr). This behavior is from PhaseUnit.simulate(). PhaseUnit.simulate() needs this begavior internally because values on 14Apr will be used as initial values when the next phase (14Apr - ) is available. However, yes, this is a confusing behavior for users of Scenario.simulate(). The last date (14Apr) should be removed from Scenario.simulate() output.

lisphilar commented 3 years ago

The last date of simulation was changed from the next date (14Apr in the above example) to the exact end date (13Apr) at version 2.19.1-zeta-fu2 with #718.

Next, I will fix the count of days in prediction.

lisphilar commented 3 years ago

I think this was fixed with #756 (version 2.19.1-theta).

Inglezos commented 3 years ago

I think so too, we can close it.