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

Use revised Pareto k threshold #2349

Merged
merged 5 commits into from
Jun 5, 2024
Merged

Use revised Pareto k threshold #2349

merged 5 commits into from
Jun 5, 2024

Conversation

aloctavodia
Copy link
Contributor

@aloctavodia aloctavodia commented May 27, 2024

The newest revision of the PSIS paper now recommends:

  • "good" ---------> k < min(1 - 1/log10(S), 0.7)
  • "bad" -----------> min(1 - 1/log10(S), 0.7) <= k < 1
  • "very bad" ---> k > 1

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

arviz/plots/backends/bokeh/khatplot.py Outdated Show resolved Hide resolved
arviz/plots/khatplot.py Outdated Show resolved Hide resolved
@aloctavodia
Copy link
Contributor Author

"good_k" value is computed once and stored in the ELPDData. I am open to suggestions for a better name.

Comment on lines 179 to 181
if isinstance(khats, ELPDData):
good_k = khats.good_k
khats = khats.pareto_k
Copy link
Member

Choose a reason for hiding this comment

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

        if isinstance(khats, ELPDData):
            good_k = khats.good_k
            khats = khats.pareto_k
        else:
            good_k = None
            warnings.warn()

This should be something like this instead. Right now, dataarrays are also valid input as they are array-like, but we have more info than we do for numpy arrays, so they are treated more similarly to elpddata input. I think this is a reason for some of the test failures.

Note: also rebase on main to avoid unrelated failures that have been fixed already.

"importance sampling is less likely to work well if the marginal posterior and "
"LOO posterior are very different. This is more likely to happen with a non-robust "
"model and highly influential observations."
f"Estimated shape parameter of Pareto distribution is greater than {good_k:.1f} "
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably show 2 digits at least, otherwise it might be confusing to people when checking the plot so see why 0.68 is counted as bad if the printed value is 0.7 (but the good_k value is actually 0.66). The plot generally allows for more than one digit precision lookouts, all plots in https://python.arviz.org/en/stable/api/generated/arviz.plot_khat.html for example do.

(0.5, 0.7] (ok) {{3:{0}d}} {{7:6.1f}}%
(0.7, 1] (bad) {{4:{0}d}} {{8:6.1f}}%
(1, Inf) (very bad) {{5:{0}d}} {{9:6.1f}}%
(-Inf, {{8:.1f}}] (good) {{2:{0}d}} {{5:6.1f}}%
Copy link
Member

Choose a reason for hiding this comment

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

same comment here

khats = khats.pareto_k
if not isinstance(khats, DataArray):
raise ValueError("Incorrect khat data input. Check the documentation")
Copy link
Member

Choose a reason for hiding this comment

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

The valueerror is a different if altogether, not the else branch of the one above. It is reached if the input isn't one of numpy array, dataarray or elpddata, or if the elpddata for some reason doesn't store the khat data as a dataarray

Copy link
Member

@OriolAbril OriolAbril left a comment

Choose a reason for hiding this comment

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

I think it's good now, we can merge once test pass. If you can it would be nice to add a line to the changelog too

Copy link

codecov bot commented Jun 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.97%. Comparing base (eda7f38) to head (3d11015).
Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2349      +/-   ##
==========================================
+ Coverage   86.95%   86.97%   +0.01%     
==========================================
  Files         123      123              
  Lines       12722    12733      +11     
==========================================
+ Hits        11063    11074      +11     
  Misses       1659     1659              

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

@aloctavodia aloctavodia merged commit 3a454f7 into main Jun 5, 2024
12 checks passed
@aloctavodia aloctavodia deleted the good_k branch June 5, 2024 18:01
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