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

plot._distributions does not acoomodate named models #54

Closed Patrick5455 closed 2 years ago

Patrick5455 commented 4 years ago

I could not plot distributions for a model that I specified its name...

# the covid19_inference/plot.py needs to be refactored to accommodate this

# Error log below

"""

  KeyError                                  Traceback (most recent call last)

  <ipython-input-309-983232f0c631> in <module>()
  ----> 1 plot_distributions(model=this_model,model_trace=model1, color='b')

  2 frames

  <ipython-input-308-056ce75e6fe4> in plot_distributions(model_trace, model, color)
      33 
      34     for idx, var in enumerate(left_column):
  ---> 35         cov19.plot._distribution(model, model_trace, var, ax=axes[idx, 0], color=color)
      36 
      37     for idx, var in enumerate(mid_column):

  /usr/local/lib/python3.6/dist-packages/covid19_inference/plot.py in _distribution(model, trace, key, ax, color, draw_prior)
      767     if "lambda" in key or "mu" == key:
      768         ax.set_xlim(0, 0.5)
  --> 769         ax.axvline(np.median(trace["mu"]), ls=":", color="black")
      770     elif "I_begin" == key:
      771         ax.set_xlim(0)

  /usr/local/lib/python3.6/dist-packages/pymc3/backends/base.py in __getitem__(self, idx)
      317         if var in self.stat_names:
      318             return self.get_sampler_stats(var, burn=burn, thin=thin)
  --> 319         raise KeyError("Unknown variable %s" % var)
      320 
      321     _attrs = set(['_straces', 'varnames', 'chains', 'stat_names',

  KeyError: 'Unknown variable mu'

  """
semohr commented 4 years ago

As far as I understand you are trying to plot a model with other distribution names. My prediction without seeing your model: You do not use mu as a name but you do have *lambda* in a distribution name somewhere.

Sadly a lot of plotting behavior is hardcoded depending on the distribution name. There is no way to fix that without completely overhauling our model and plotting pipeline. For your problem it may help to remove line 767-769 in the plotting sub module but I would need to see the full model code to be sure.

Patrick5455 commented 4 years ago

Thanks for the help semohr. I ignored naming the model. All other things work fine.

semohr commented 2 years ago

This should be fixed with the new plotting routines #63