From c9d28ca8072aacb65221c48d6ab21704681db325 Mon Sep 17 00:00:00 2001 From: "Oriol (ProDesk)" Date: Fri, 20 Dec 2024 19:51:19 +0100 Subject: [PATCH] homogenize mpl and bokeh versions --- arviz/plots/backends/bokeh/bpvplot.py | 7 ++++--- arviz/plots/bpvplot.py | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/arviz/plots/backends/bokeh/bpvplot.py b/arviz/plots/backends/bokeh/bpvplot.py index 83fa52d00f..75f6692ae6 100644 --- a/arviz/plots/backends/bokeh/bpvplot.py +++ b/arviz/plots/backends/bokeh/bpvplot.py @@ -41,6 +41,7 @@ def plot_bpv( plot_ref_kwargs, backend_kwargs, show, + smoothing, ): """Bokeh bpv plot.""" if backend_kwargs is None: @@ -90,6 +91,9 @@ def plot_bpv( obs_vals = obs_vals.flatten() pp_vals = pp_vals.reshape(total_pp_samples, -1) + if (obs_vals.dtype.kind == "i" or pp_vals.dtype.kind == "i") and smoothing == True: + obs_vals, pp_vals = smooth_data(obs_vals, pp_vals) + if kind == "p_value": tstat_pit = np.mean(pp_vals <= obs_vals, axis=-1) x_s, tstat_pit_dens = kde(tstat_pit) @@ -115,9 +119,6 @@ def plot_bpv( ) elif kind == "u_value": - if obs_vals.dtype.kind == "i" or pp_vals.dtype.kind == "i": - obs_vals, pp_vals = smooth_data(obs_vals, pp_vals) - tstat_pit = np.mean(pp_vals <= obs_vals, axis=0) x_s, tstat_pit_dens = kde(tstat_pit) ax_i.line(x_s, tstat_pit_dens, color=color) diff --git a/arviz/plots/bpvplot.py b/arviz/plots/bpvplot.py index 32ea789bd3..fc09f6830f 100644 --- a/arviz/plots/bpvplot.py +++ b/arviz/plots/bpvplot.py @@ -16,6 +16,7 @@ def plot_bpv( bpv=True, plot_mean=True, reference="analytical", + smoothing=None, mse=False, n_ref=100, hdi_prob=0.94, @@ -36,7 +37,6 @@ def plot_bpv( backend_kwargs=None, group="posterior", show=None, - smoothing=True, ): r"""Plot Bayesian p-value for observed data and Posterior/Prior predictive. @@ -73,6 +73,9 @@ def plot_bpv( reference : {"analytical", "samples", None}, default "analytical" How to compute the distributions used as reference for ``kind=u_values`` or ``kind=p_values``. Use `None` to not plot any reference. + smoothing : bool, optional + If True and the data has integer dtype, smooth the data before computing the p-values, + u-values or tstat. By default, True when `kind` is "u_value" and False otherwise. mse : bool, default False Show scaled mean square error between uniform distribution and marginal p_value distribution. @@ -149,8 +152,6 @@ def plot_bpv( the same comparison happens, but with the values in `prior_predictive` group. show : bool, optional Call backend show function. - smoothing : bool, default True - If True, smooth the data before computing the p-values or u-values. Returns ------- @@ -209,6 +210,9 @@ def plot_bpv( elif not 1 >= hdi_prob > 0: raise ValueError("The value of hdi_prob should be in the interval (0, 1]") + if smoothing is None: + smoothing = kind.lower() == "u_value" + if data_pairs is None: data_pairs = {}