Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

201 add visualizations using arviz to tutorials #211

Merged
merged 17 commits into from
Jun 26, 2024

Conversation

sbidari
Copy link
Collaborator

@sbidari sbidari commented Jun 24, 2024

Added arviz plots to two tutorials

  • basic Rt model (Getting started)
  • hospital admissions model

@sbidari sbidari requested a review from damonbayer June 24, 2024 22:18
@sbidari sbidari linked an issue Jun 24, 2024 that may be closed by this pull request
Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.47%. Comparing base (99cdf42) to head (101553c).

Current head 101553c differs from pull request most recent head 7bf74c7

Please upload reports for the commit 7bf74c7 to get more accurate results.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #211   +/-   ##
=======================================
  Coverage   92.47%   92.47%           
=======================================
  Files          40       40           
  Lines         877      877           
=======================================
  Hits          811      811           
  Misses         66       66           
Flag Coverage Δ
unittests 92.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dylanhmorris
Copy link
Collaborator

Thanks, @sbidari!

One quick fix to start. The website build in CI is failing:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[8], line 1
----> 1 import arviz as az
      2 idata = az.from_numpyro(model1.mcmc)
      3 az.plot_trace(idata.posterior["Rt"],compact=True);

ModuleNotFoundError: No module named 'arviz'

Adding arviz as a dependency to docs/pyproject.toml should resolve this. Can do that at the command line from the top level project directory with:

poetry add -C docs arviz

[tool.poetry.dependencies]
python = "^3.12"
sphinx = "^7.2.6"
jax = "^0.4.25"
jaxlib = "^0.4.25"
numpyro = "^0.15.0"
sphinxcontrib-mermaid = "^0.9.2"
polars = "^0.20.16"
matplotlib = "^3.8.3"
sphinx-autodoc-typehints = "^2.1.0"
sphinx-book-theme = "^1.1.2"

@dylanhmorris
Copy link
Collaborator

dylanhmorris commented Jun 24, 2024

My mistake; I should've looked more closely at the source yaml for website / render-docs. The rendering of the tutorials uses the dependencies in model/pyproject.toml not those in docs/pyproject.toml. I think we should add arviz as a dev dependency for model in the first instance:

poetry add -C model --group dev arviz

Can remove it from the docs dependencies for now

poetry remove -C docs arviz

@sbidari
Copy link
Collaborator Author

sbidari commented Jun 24, 2024

poetry add -C model --group dev arviz

This command is not changing any dependencies in the model

Capture

@dylanhmorris
Copy link
Collaborator

what's the output of git diff model/pyproject.toml?

@sbidari
Copy link
Collaborator Author

sbidari commented Jun 25, 2024

My bad, the command did work as expected.

Copy link
Collaborator

@damonbayer damonbayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Can we try to make something with plot_hdi? Or at a minimum swap the x and y axes in these plots so they are more readable as a time series?

My aspiration for these types of plots is to look like the lineribbon plots from ggdist.

model/docs/getting_started.qmd Outdated Show resolved Hide resolved
model/docs/getting_started.qmd Outdated Show resolved Hide resolved
Co-authored-by: Dylan H. Morris <[email protected]>
@sbidari
Copy link
Collaborator Author

sbidari commented Jun 25, 2024

Can we try to make something with plot_hdi? Or at a minimum swap the x and y axes in these plots so they are more readable as a time series?

Yep! Working on it

@sbidari
Copy link
Collaborator Author

sbidari commented Jun 25, 2024

I created hdi plots that are more readable to replace the forest plots. Let me know what you think and if there are any other type of plots you'd like to be added @damonbayer

@sbidari sbidari requested a review from damonbayer June 25, 2024 21:31
Copy link
Collaborator

@damonbayer damonbayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hdi plots look great! Nice!

Two requests:

  1. I don't think it makes sense to plot all of the Rt traces on top of each other because you cannot tell them apart or tell if any of them are problematic. Consider just plotting a single variable.
  2. Please also revisit the axis labels and titles of figures. Make sure each figure has axis labels and use words like "posterior distribution" and "credible interval" to accurately indicate what is shown in the figures.

@sbidari sbidari requested a review from damonbayer June 26, 2024 13:38
@gvegayon
Copy link
Member

gvegayon commented Jun 26, 2024

This is looking great, @sbidari! Quarto and rst format are picky. I noticed sometimes figures wouldn't render or be added to the website if some conditions were unmet:

image

You have to:

  1. Explicitly plot the figure using plot.show().
  2. Have the code-chunk label with no empty spaces and starting with the fig prefix.
  3. Have a caption.

In your case, the code chunk labelled fig2-trace-Rt should be renamed to something like fig-trace-Rt2 (point 2). I believe that should fix it. For more details, see this PR.

cc @damonbayer @dylanhmorris @AFg6K7h4fhy2

@sbidari
Copy link
Collaborator Author

sbidari commented Jun 26, 2024

Thanks for catching this @gvegayon

Copy link
Collaborator

@damonbayer damonbayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking very close. A few minor changes.

sbidari and others added 2 commits June 26, 2024 14:01
Co-authored-by: Damon Bayer <[email protected]>
Copy link
Member

@gvegayon gvegayon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The website now renders properly.

model/docs/example_with_datasets.qmd Show resolved Hide resolved
@sbidari
Copy link
Collaborator Author

sbidari commented Jun 26, 2024

ready for review @damonbayer

@damonbayer damonbayer self-requested a review June 26, 2024 19:40
Copy link
Collaborator

@damonbayer damonbayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@damonbayer damonbayer merged commit 84f7809 into main Jun 26, 2024
4 checks passed
@damonbayer damonbayer deleted the 201-add-visualizations-using-arviz-to-tutorials branch June 26, 2024 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add visualizations using Arviz to tutorials
4 participants