File: //usr/local/lib/python3.10/dist-packages/numpy/lib/__pycache__/histograms.cpython-310.pyc
o
���g�� � @ s8 d Z ddlZddlZddlZddlZddlZddlmZ g d�Z ej
ejdd�ZeZ
dd� Zd d
� Zdd� Zd
d� Zdd� Zdd� Zdd� Zdd� Zdd� Zeeeeeeeed�Zdd� Zdd� Zdd� Zd d!� Zd"d#� Zd1d$d%�Zee�d2d'd(��Z d3d)d*�Zee�d4d+d,��Z d3d-d.�Z!ee!�d4d/d0��Z"dS )5z
Histogram-related functions
� N)� overrides)� histogram�histogramdd�histogram_bin_edges�numpy)�modulec C s t | �� | �� �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_subtract�max�min)�x� r �?/usr/local/lib/python3.10/dist-packages/numpy/lib/histograms.py�_ptp s r c C s ~t | �t�| 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 �np�sqrt�size�r �ranger r r
�_hist_bin_sqrt s r c C s ~t | �t�| j�d 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.
� �?)r r �log2r 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.
� @�UUUUUU�?)r r r r r r
�_hist_bin_riceL s r c C s$ ~dt jd | j d t �| � 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@� �?r )r �pir �stdr r r r
�_hist_bin_scottd s "r c s~ �j � t���� dks�dkrdS � ���fdd�}tdtt�� ���}ttd|d �|d�}||kr;tj 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�| �d�d � }d� d |�|� | S )N)�binsr r � r )r r �dot)�nbins�hh�p_k��n�ptp_xr r r r
�jhat� s z_hist_bin_stone.<locals>.jhat�d )�keyz/The number of bins estimated may be suboptimal.� ��
stacklevel)r r r �intr r r
�_range�warnings�warn�RuntimeWarning)r r r) �nbins_upper_boundr# r r&