Add eCDF plot to SBC plots#1853
Conversation
|
Thanks a lot for you PR @MolinAlexei ! We will have will have a look at it soon. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1853 +/- ##
==========================================
+ Coverage 87.94% 87.96% +0.02%
==========================================
Files 140 140
Lines 12845 13192 +347
==========================================
+ Hits 11297 11605 +308
- Misses 1548 1587 +39
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Code reviewFound 2 issues:
Lines 2039 to 2056 in 9f1a6f1
Lines 2028 to 2087 in 9f1a6f1 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
janfb
left a comment
There was a problem hiding this comment.
looks good, thanks @MolinAlexei!
Please check the automated PR comment above, plus a couple of suggestions inline below, e.g., I suggest to add a ylim as the current default view is a bit too close.
| plot_types = ["hist", "cdf", "ecdf"] | ||
| assert plot_type in plot_types, ( | ||
| "plot type {plot_type} not implemented, use one in {plot_types}." | ||
| ) |
There was a problem hiding this comment.
ecdf as third option is a bit misleading, I suggest calling it cdf-diff.
Also, can you please change the assert into an if-else that raises a ValueError if the plot_type is wrong?
| colors: Optional[List[str]] = None, | ||
| fig: Optional[Figure] = None, | ||
| ax: Optional[Axes] = None, | ||
| figsize: Optional[tuple] = None, |
There was a problem hiding this comment.
add ylim kwarg here (see comment below), set the default: ylim: Optional[tuple[float, float]] = (-0.1, 0.1)
There was a problem hiding this comment.
please add the ylim arg here explicitly, that's the user facing level. in the docstring say that it applies to the cdf-diff only
There was a problem hiding this comment.
here is where we set the default. the downstream functions then require the ylim and have no defaut.
…e cdf-diff plot, and corrected a mistake in the docstring for the plotting function
|
Hi, I implemented all requested changes in a new commit, let me know if that works for you |
janfb
left a comment
There was a problem hiding this comment.
thanks for the updates @MolinAlexei !
I had another look and realized it would be better to set the default at the user-facing function and remove the default in the low-lever private functions. Can you please accept my suggestions and implement the comments? Thanks 🙏
| if ylim is not None: | ||
| plt.ylim(ylim) | ||
| else: | ||
| plt.ylim(-0.125, 0.125) | ||
|
|
||
| plt.xlim(0, 1) |
There was a problem hiding this comment.
| if ylim is not None: | |
| plt.ylim(ylim) | |
| else: | |
| plt.ylim(-0.125, 0.125) | |
| plt.xlim(0, 1) | |
| plt.ylim(*ylim) | |
| plt.xlim(0, 1) |
| obtained from different methods. | ||
| num_bins: number of bins used for binning the ranks, default is | ||
| num_sbc_runs / 20. | ||
| plot_type: type of SBC plot, histograms ("hist") or empirical cdfs ("cdf"). |
There was a problem hiding this comment.
please adapt the docstring here as well. please check for other locations that might need updating.
| num_ticks: int = 3, | ||
| ylim: Optional[tuple[float, float]] = None, | ||
| ) -> None: | ||
| """Plot ranks as a delta of the empirical CDFs to the expected CDF |
There was a problem hiding this comment.
| """Plot ranks as a delta of the empirical CDFs to the expected CDF | |
| """Plot ranks as a difference of the empirical to the expected CDF |
| plt.xlabel("posterior rank" if xlabel is None else xlabel) | ||
|
|
||
|
|
||
| def _plot_ranks_as_ecdf( |
There was a problem hiding this comment.
I suggest to rename this helper funcation to _plot_ranks_as_cdf_diff
| num_cols: int = 4, | ||
| params_in_subplots: bool = False, | ||
| show_ylabel: bool = False, | ||
| ylim: Optional[Tuple[float, float]] = (-0.125, 0.125), |
There was a problem hiding this comment.
we should actually make this required here and have the default at the top, user facing level:
| ylim: Optional[Tuple[float, float]] = (-0.125, 0.125), | |
| ylim: Tuple[float, float], |
| alpha: float = 0.8, | ||
| show_ylabel: bool = True, | ||
| num_ticks: int = 3, | ||
| ylim: Optional[tuple[float, float]] = None, |
There was a problem hiding this comment.
we should actually make this required here and have the default at the top, user facing level:
| ylim: Optional[tuple[float, float]] = None, | |
| ylim: Tuple[float, float], |
There was a problem hiding this comment.
then we don't need the if-else anymore, see below.
| params_in_subplots: whether to show each parameter in a separate subplot, or | ||
| all in one. | ||
| show_ylabel: whether to show ylabels and ticks. | ||
| ylim: limits on the y-axis |
There was a problem hiding this comment.
add, that this applies to the cdf-diff case only
| colors: Optional[List[str]] = None, | ||
| fig: Optional[Figure] = None, | ||
| ax: Optional[Axes] = None, | ||
| figsize: Optional[tuple] = None, |
There was a problem hiding this comment.
please add the ylim arg here explicitly, that's the user facing level. in the docstring say that it applies to the cdf-diff only
| colors: Optional[List[str]] = None, | ||
| fig: Optional[Figure] = None, | ||
| ax: Optional[Axes] = None, | ||
| figsize: Optional[tuple] = None, |
There was a problem hiding this comment.
here is where we set the default. the downstream functions then require the ylim and have no defaut.


I added an option to do eCDF plotting in the sbc_plot function.
This was apparently already done in pull request #1739, but has not been merged with the main branch since.
I used the same formatting as the existing functions used in
sbc_plots. The way I compute the ellipse may be wrong, as I just transform the shaded area from the CDF to an eCDF.