/usr/local/lib64/python3.6/site-packages/numpy/lib/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/numpy/lib/__pycache__/histograms.cpython-36.pyc (32023B)
3
EgŜ @ s4 d Z ddlZddlZddlZddlZddlZddlmZ dddgZ ej
ejddZeZ
d d
Zdd Zd
d Zdd Zdd Zdd Zdd Zdd Zdd ZeeeeeeeedZdd Zdd Zd d! Zd"d# Zd$d% Zd0d&d'Zeed1d)dZd2d*d+Zeed3d,dZ d4d-d.Z!ee!d5d/dZ"dS )6z
Histogram-related functions
N) overrides histogramhistogramddhistogram_bin_edgesnumpy)modulec C s t | j | j S )a Peak-to-peak value of x.
This implementation avoids the problem of signed integer arrays having a
peak-to-peak value that cannot be represented with the array's data type.
This function returns an unsigned value for signed integer arrays.
)_unsigned_subtractmaxmin)x r @/usr/local/lib64/python3.6/site-packages/numpy/lib/histograms.py_ptp s r c C s ~t | tj| j S )a~
Square root histogram bin estimator.
Bin width is inversely proportional to the data size. Used by many
programs for its simplicity.
Parameters
----------
x : array_like
Input data that is to be histogrammed, trimmed to range. May not
be empty.
Returns
-------
h : An estimate of the optimal bin width for the given data.
)r npsqrtsize)r ranger r r
_hist_bin_sqrt s r c C s ~t | tj| jd S )a
Sturges histogram bin estimator.
A very simplistic estimator based on the assumption of normality of
the data. This estimator has poor performance for non-normal data,
which becomes especially obvious for large data sets. The estimate
depends only on size of the data.
Parameters
----------
x : array_like
Input data that is to be histogrammed, trimmed to range. May not
be empty.
Returns
-------
h : An estimate of the optimal bin width for the given data.
g ?)r r log2r )r r r r r
_hist_bin_sturges5 s r c C s ~t | d| jd S )aI
Rice histogram bin estimator.
Another simple estimator with no normality assumption. It has better
performance for large data than Sturges, but tends to overestimate
the number of bins. The number of bins is proportional to the cube
root of data size (asymptotically optimal). The estimate depends
only on size of the data.
Parameters
----------
x : array_like
Input data that is to be histogrammed, trimmed to range. May not
be empty.
Returns
-------
h : An estimate of the optimal bin width for the given data.
g @g ? gUUUUUU?)r r )r r r r r
_hist_bin_riceL s r c C s$ ~dt jd | j d t j| S )a
Scott histogram bin estimator.
The binwidth is proportional to the standard deviation of the data
and inversely proportional to the cube root of data size
(asymptotically optimal).
Parameters
----------
x : array_like
Input data that is to be histogrammed, trimmed to range. May not
be empty.
Returns
-------
h : An estimate of the optimal bin width for the given data.
g 8@g ?g ?g @gUUUUUU?)r pir std)r r r r r
_hist_bin_scottd s r c s~ j t dksdkr"dS fdd}tdttj }ttd|d |d}||krvtj dt
dd | S )
a6
Histogram bin estimator based on minimizing the estimated integrated squared error (ISE).
The number of bins is chosen by minimizing the estimated ISE against the unknown true distribution.
The ISE is estimated using cross-validation and can be regarded as a generalization of Scott's rule.
https://en.wikipedia.org/wiki/Histogram#Scott.27s_normal_reference_rule
This paper by Stone appears to be the origination of this rule.
http://digitalassets.lib.berkeley.edu/sdtr/ucb/text/34.pdf
Parameters
----------
x : array_like
Input data that is to be histogrammed, trimmed to range. May not
be empty.
range : (float, float)
The lower and upper range of the bins.
Returns
-------
h : An estimate of the optimal bin width for the given data.
r c s: | }t j| dd }d d |j| | S )N)binsr r r )r r dot)nbinshhZp_k)nptp_xr r r r
jhat s z_hist_bin_stone.
.jhatd )keyz/The number of bins estimated may be suboptimal.r )
stacklevel)r r r intr r r
_rangewarningswarnRuntimeWarning)r r r# Znbins_upper_boundr r )r! r" r r r
_hist_bin_stonez s
r, c C s ~| j dkrtjd| j d | j d | j d }tj| }|dkr| tj| }tj||| tj|d| tj|}t| dtj| j tjdtj || S dS )a
Doane's histogram bin estimator.
Improved version of Sturges' formula which works better for
non-normal data. See
stats.stackexchange.com/questions/55134/doanes-formula-for-histogram-binning
Parameters
----------
x : array_like
Input data that is to be histogrammed, trimmed to range. May not
be empty.
Returns
-------
h : An estimate of the optimal bin width for the given data.
r g @g ?r g )
r r r r ZmeanZtrue_dividepowerr r absolute)r r Zsg1sigmatempZg1r r r
_hist_bin_doane s
(
r1 c C s* ~t jt j| ddg }d| | jd S )a=
The Freedman-Diaconis histogram bin estimator.
The Freedman-Diaconis rule uses interquartile range (IQR) to
estimate binwidth. It is considered a variation of the Scott rule
with more robustness as the IQR is less affected by outliers than
the standard deviation. However, the IQR depends on fewer points
than the standard deviation, so it is less accurate, especially for
long tailed distributions.
If the IQR is 0, this function returns 0 for the bin width.
Binwidth is inversely proportional to the cube root of data size
(asymptotically optimal).
Parameters
----------
x : array_like
Input data that is to be histogrammed, trimmed to range. May not
be empty.
Returns
-------
h : An estimate of the optimal bin width for the given data.
K g @g ?g @g gUUUUUUտ)r subtractZ
percentiler )r r Ziqrr r r
_hist_bin_fd s r5 c C s, t | |}t| |}~|r$t||S |S dS )a
Histogram bin estimator that uses the minimum width of the
Freedman-Diaconis and Sturges estimators if the FD bin width is non-zero.
If the bin width from the FD estimator is 0, the Sturges estimator is used.
The FD estimator is usually the most robust method, but its width
estimate tends to be too large for small `x` and bad for data with limited
variance. The Sturges estimator is quite good for small (<1000) datasets
and is the default in the R language. This method gives good off-the-shelf
behaviour.
.. versionchanged:: 1.15.0
If there is limited variance the IQR can be 0, which results in the
FD bin width being 0 too. This is not a valid bin width, so
``np.histogram_bin_edges`` chooses 1 bin instead, which may not be optimal.
If the IQR is 0, it's unlikely any variance-based estimators will be of
use, so we revert to the Sturges estimator, which only uses the size of the
dataset in its calculation.
Parameters
----------
x : array_like
Input data that is to be histogrammed, trimmed to range. May not
be empty.
Returns
-------
h : An estimate of the optimal bin width for the given data.
See Also
--------
_hist_bin_fd, _hist_bin_sturges
N)r5 r r
)r r Zfd_bwZ
sturges_bwr r r
_hist_bin_auto s "
r6 )ZstoneautoZdoanefdZriceZscottr Zsturgesc C s| t j| } | jt jkr>tjdj| jt jtdd | j t j} |dk rlt j|}|j
| j
krdtd|j }| j } | |fS )z: Check a and weights have matching shapes, and ravel both z1Converting input from {} to {} for compatibility.r )r&