Skip to content

Commit

Permalink
make smooth data public api
Browse files Browse the repository at this point in the history
  • Loading branch information
OriolAbril committed Dec 22, 2023
1 parent 96aebb9 commit 12d86f4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion arviz/plots/bpvplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def plot_bpv(
Notes
-----
Discrete data is smoothed before computing either p-values or u-values using the
function :func:`smooth_data`
function :func:`~arviz.smooth_data`
Examples
--------
Expand Down
1 change: 1 addition & 0 deletions arviz/stats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"autocorr",
"autocov",
"make_ufunc",
"smooth_data",
"wrap_xarray_ufunc",
"reloo",
"_calculate_ics",
Expand Down
13 changes: 11 additions & 2 deletions arviz/stats/stats_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .density_utils import histogram as _histogram


__all__ = ["autocorr", "autocov", "ELPDData", "make_ufunc", "wrap_xarray_ufunc"]
__all__ = ["autocorr", "autocov", "ELPDData", "make_ufunc", "smooth_data", "wrap_xarray_ufunc"]


def autocov(ary, axis=-1):
Expand Down Expand Up @@ -564,7 +564,9 @@ def _circular_standard_deviation(samples, high=2 * np.pi, low=0, skipna=False, a


def smooth_data(obs_vals, pp_vals):
"""Smooth data, helper function for discrete data in plot_pbv, loo_pit and plot_loo_pit.
"""Smooth data using a cubic spline.
Helper function for discrete data in plot_pbv, loo_pit and plot_loo_pit.
Parameters
----------
Expand All @@ -573,6 +575,13 @@ def smooth_data(obs_vals, pp_vals):
pp_vals : (S, N) array-like
Posterior predictive samples. ``N`` is the number of observations,
and ``S`` is the number of samples (generally n_chains*n_draws).
Returns
-------
obs_vals : (N) ndarray
Smoothed observed data
pp_vals : (S, N) ndarray
Smoothed posterior predictive samples
"""
x = np.linspace(0, 1, len(obs_vals))
csi = CubicSpline(x, obs_vals)
Expand Down
1 change: 1 addition & 0 deletions doc/source/api/stats_utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Stats utils
autocov
autocorr
make_ufunc
smooth_data
wrap_xarray_ufunc

0 comments on commit 12d86f4

Please sign in to comment.