Skip to content

Commit 82fcc04

Browse files
DOC: Document KDE kwargs for #318 and cleanup unrelated histogram changes
1 parent 4f42b88 commit 82fcc04

4 files changed

Lines changed: 71 additions & 5 deletions

File tree

src/arviz_stats/accessors.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,23 @@ def mcse(self, sample_dims=None, method="mean", prob=None, **kwargs):
116116
return self._apply("mcse", sample_dims=sample_dims, method=method, prob=prob, **kwargs)
117117

118118
def kde(self, dim=None, **kwargs):
119-
"""Compute the KDE for all variables in the dataset."""
119+
"""Compute the KDE for all variables in the dataset.
120+
121+
Parameters
122+
----------
123+
dim : str or sequence of str, optional
124+
Dimension(s) over which to compute the KDE.
125+
**kwargs : dict, optional
126+
Additional keyword arguments passed to the underlying KDE
127+
implementations. Supported arguments include `bw`, `adaptive`,
128+
`circular`, and `grid_len`. See the array-level `kde` methods
129+
for full details on these parameters.
130+
131+
Returns
132+
-------
133+
xarray.Dataset
134+
A dataset containing the KDE grids and pdf values for each variable.
135+
"""
120136
return self._apply("kde", dim=dim, **kwargs)
121137

122138
def qds(self, dim=None, **kwargs):

src/arviz_stats/base/array.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,21 +560,29 @@ def histogram(self, ary, bins=None, range=None, weights=None, axis=-1, density=T
560560
return histogram_ufunc(ary, bins, range, shape_from_1st=True)
561561

562562
def kde(self, ary, axis=-1, circular=False, grid_len=512, **kwargs):
563-
"""Compute of kde on array-like inputs.
563+
"""Compute KDE on array-like inputs.
564564
565565
Parameters
566566
----------
567567
ary : array-like
568568
axis : int, sequence of int or None, default -1
569569
circular : bool, default False
570570
grid_len : int, default 512
571-
**kwargs
571+
**kwargs : dict, optional
572+
Additional keyword arguments passed to the KDE implementation.
573+
Supported arguments include:
574+
575+
* bw : str or float, optional
576+
The bandwidth of the kernel. Options include "scott" (default),
577+
"silverman", "isj", and "experimental", or a positive float.
578+
* adaptive : bool, optional
579+
Whether to use an adaptive KDE. Defaults to False.
572580
573581
Returns
574582
-------
575583
grid, pdf, bw : array-like
576584
`grid` and `pdf` will have the same shape: the same as `ary` minus the dimensions
577-
in `axis` plus an extra dimension of lenght `grid_len`. Same for `bw`
585+
in `axis` plus an extra dimension of length `grid_len`. Same for `bw`
578586
except it will not have the extra dimension.
579587
"""
580588
ary, axes = process_ary_axes(ary, axis)

src/arviz_stats/base/dataarray.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,29 @@ def histogram(self, da, dim=None, bins=None, range=None, weights=None, density=T
228228
return out
229229

230230
def kde(self, da, dim=None, circular=False, grid_len=512, **kwargs):
231-
"""Compute kde on DataArray input."""
231+
"""Compute KDE on DataArray input.
232+
233+
Parameters
234+
----------
235+
da : xarray.DataArray
236+
Input data.
237+
dim : str or sequence of str, optional
238+
Dimension(s) over which to compute the KDE.
239+
circular : bool, default False
240+
Whether the data is circular (e.g., angles).
241+
grid_len : int, default 512
242+
Number of points on the KDE grid.
243+
**kwargs : dict, optional
244+
Additional keyword arguments passed to the array-level KDE
245+
implementation. See the underlying array `kde` method for a
246+
complete list of supported arguments (like `bw` and `adaptive`).
247+
248+
Returns
249+
-------
250+
out : xarray.DataArray
251+
An xarray DataArray containing the grid and pdf values along the
252+
`plot_axis` dimension, with the bandwidth `bw` stored as a coordinate.
253+
"""
232254
dims = validate_dims(dim)
233255
grid, pdf, bw = apply_ufunc(
234256
self.array_class.kde,

src/arviz_stats/numba/array.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ def kde_gufunc(a, grid_in, circular, bw, adaptive, grid, pdf, bw_out):
128128
def kde(self, ary, axis=-1, circular=False, grid_len=512, **kwargs):
129129
"""Compute the guvectorized kde.
130130
131+
Parameters
132+
----------
133+
ary : array-like
134+
Input array.
135+
axis : int, sequence of int or None, default -1
136+
Axis or axes along which the KDE is computed.
137+
circular : bool, default False
138+
Whether the data is circular (e.g., angles).
139+
grid_len : int, default 512
140+
Number of points on the KDE grid.
141+
**kwargs : dict, optional
142+
Additional keyword arguments passed to the KDE implementation.
143+
Supported arguments include:
144+
145+
* bw : str or float, optional
146+
The bandwidth of the kernel. Options include "scott" (default),
147+
"silverman", "isj", and "experimental", or a positive float.
148+
* adaptive : bool, optional
149+
Whether to use an adaptive KDE. Defaults to False.
150+
131151
Notes
132152
-----
133153
There currenly is no jit compiling of the kde computation steps other than the

0 commit comments

Comments
 (0)