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

Add plot_rank #143

Closed

Conversation

suhaani-agarwal
Copy link

@suhaani-agarwal suhaani-agarwal commented Feb 21, 2025

The plot_rank function has been migrated and refactored to align with the modularized structure of ArviZ-Plots. This function is a key diagnostic tool for MCMC convergence, helping visualize how well chains mix by plotting the ranks of posterior draws.

Key Improvements & Refactoring Details

🔹 Data Handling:

  • The function extracts variables from the posterior dataset, handling 2D (chain, draw) and 3D (chain, draw, extra dims like "school") cases.
  • A helper function ensures data is always reshaped correctly to (chain, draw), ensuring robust handling of various input shapes.

🔹 Plot Structure:

  • Before creating subplots, the function precomputes the number of plots needed, optimizing layout management.
  • Unused subplots are automatically hidden, improving figure aesthetics.

🔹 Visualization Options:
Supports two plotting styles:

  1. Bars: Uses histograms to show frequency-based rank distribution.
  2. Vlines: Uses vertical markers to highlight rank positioning.

🔹 Modularization & Maintainability:

  • Color selection logic is extracted, allowing easy customization.
  • The plotting logic is split into dedicated helper functions (plot_variable, compute_ranks, etc.), making future modifications easier.

🔹 Error Handling & Flexibility:

  • Improved handling for missing var_names and incorrect input shapes.
  • Extra dimension handling (like "school") is more intuitive and explicit.

I've started working on refactoring the missing features from ArviZ-Plots and ensuring plot_rank fully aligns with the expected functionality.

I'd love guidance on what can be improved, any missing edge cases, and potential optimizations to further refine the implementation.

Looking forward to your feedback!


📚 Documentation preview 📚: https://arviz-plots--143.org.readthedocs.build/en/143/

@suhaani-agarwal suhaani-agarwal changed the title Migrate plot_rank to ArviZ-Plots Add plot_rank Feb 21, 2025
@aloctavodia
Copy link
Contributor

Hi @suhaani-agarwal thanks for the contribution. Unfortunately, this PR can not be merged, as this is not how plots are implemented in arviz-plots. If you want to contribute to the project I recommend that you read the documentation, and then get familiar with the base code. You can check other plots to see how to implement a plot_rank. Before opening a PR I recommend you open an issue stating that you are planning to work on a given feature or comment in an already-opened issue. For instance, I will have recommended not implementing vlines, or bars and instead focus on ecdf_rank plots.

@suhaani-agarwal
Copy link
Author

Hi @aloctavodia
I appreciate the guidance and will take some time to go through the documentation and base code more thoroughly.

I’d love to contribute to the project. Could you suggest any open issues that would be good for me to work on?

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.

2 participants