Priesemann-Group / covid19_inference

Bayesian python toolbox for inference and forecast of the spread of the Coronavirus
GNU General Public License v3.0
73 stars 70 forks source link

Plotting: AssertionError: var should be in trace.varnames #57

Closed wmf1991yeah closed 3 years ago

wmf1991yeah commented 3 years ago

I meet a problem when I run "example_what_if.ipynb" using my own data. When I run fig, axes = cov19.plot.timeseries_overview(), An error displays: "AssertionError: var should be in trace.varnames". The error is as follow: image How to address the problem? Ask for help.

semohr commented 3 years ago

I dont know how your model looks but you do have to use our variable names if you want to use these high level plotting functions. As far as I remember the pymc3 name for the new cases has to be "new_cases" otherwise the timeseries_overview plotting will not work.

You could also change "new_cases" to your variable name here or here in the what if script.

I hope this helps you to understand your problem.

wmf1991yeah commented 3 years ago

I use your SIR model and I don't change all default variable names.

semohr commented 3 years ago

Hmm this is quite strange than, I'm going to test it.

wmf1991yeah commented 3 years ago

Oh! I know, I cancel the weekend modulation because I don't need the weekend modulation. When I add the line of code. It can run correctly. image However, We really don't need the weekend modulation for Chinese CDC. How to cancel the weekend modulation at the same time, assure the correct variable name "new_cases"?

semohr commented 3 years ago

I see :+1:

You can just change the name in this line from "delayed_cases" to "new_cases" and it should work.

        new_cases = cov19.model.delay_cases(
            cases=new_cases,
            name_cases="delayed_cases",
            pr_mean_of_median=pr_delay,
            pr_median_of_width=0.3,
        )

Or add it manually to the trace with:

pm.Deterministic("new_cases",new_cases)
wmf1991yeah commented 3 years ago

I see. Thank you very much!