This documentation is for astroML version 0.2

This page

Links

astroML Mailing List

GitHub Issue Tracker

Videos

Scipy 2012 (15 minute talk)

Scipy 2013 (20 minute talk)

Citing

If you use the software, please consider citing astroML.

11.2.1.3. astroML.density_estimation.knuth_bin_width

astroML.density_estimation.knuth_bin_width(data, return_bins=False)

Return the optimal histogram bin width using Knuth’s rule [R15]

Parameters :

data : array-like, ndim=1

observed (one-dimensional) data

return_bins : bool (optional)

if True, then return the bin edges

Returns :

dx : float

optimal bin width. Bins are measured starting at the first data point.

bins : ndarray

bin edges: returned if return_bins is True

Notes

The optimal number of bins is the value M which maximizes the function

F(M|x,I) = n\log(M) + \log\Gamma(\frac{M}{2})
- M\log\Gamma(\frac{1}{2})
- \log\Gamma(\frac{2n+M}{2})
+ \sum_{k=1}^M \log\Gamma(n_k + \frac{1}{2})

where \Gamma is the Gamma function, n is the number of data points, n_k is the number of measurements in bin k.

References

[R15](1, 2) Knuth, K.H. “Optimal Data-Based Binning for Histograms”. arXiv:0605197, 2006