a
    BCCf                    @   s  d dl Z d dlmZ d dlmZmZ d dlZd dlZd dl	m
Z
 d dlmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm  mZ d d	lmZmZ d
dlmZ d
dlm Z!m"Z# d
dl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ d
dl,m-Z-m.Z.m/Z/ d
dl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 d
dl8m9Z9 d dl:m;  m<Z< d dl=m>Z> d dl?m@Z@ d dlAm;Z; dd ZBdd ZCdddZDG dd de'ZEeEddddZFG dd  d e'ZGeGd ddd!d"ZHG d#d$ d$e'ZIeIdd%d&ZJeKd'ejL ZMeNeMZOd(d) ZPd*d+ ZQd,d- ZRd.d/ ZSd0d1 ZTd2d3 ZUd4d5 ZVd6d7 ZWG d8d9 d9e'ZXeXd:d;ZYG d<d= d=e'ZZeZdd>d&Z[G d?d@ d@e'Z\e\ejL dA ejLdA dBdZ]G dCdD dDe'Z^e^dddEdZ_G dFdG dGe`ZaG dHdI dIe@ZbdJdK ZcdLdM ZdG dNdO dOe'ZeeedddPdZfG dQdR dRe'ZgegddSd&ZhG dTdU dUe'ZieidddVdZjG dWdX dXe'ZkekddYd&ZlG dZd[ d[e'Zmemdd\d&ZnG d]d^ d^ekZoeodd_d&ZpG d`da dae'Zqeqdbd;ZrG dcdd dde'Zsesdded&ZtG dfdg dge'Zueuddhd&ZvG didj dje'ZwewejL ejLdkdZxG dldm dme'Zyeydnd;ZzG dodp dpe'Z{e{dqd;Z|G drds dse'Z}e}ddtd&Z~G dudv dve'Zedwd;Zdxdy ZG dzd{ d{e'Zedd|d&ZG d}d~ d~e'Zeddd&ZG dd de'Zeddd&ZG dd de'Zeddd&ZG dd de'Zeddd&ZG dd de'Zeddd&ZG dd de'Zeddd&ZG dd de'Zedd;ZG dd de'ZedddZG dd de'Zedd;ZG dd de'Zeddd&ZG dd de'Zeddd&ZG dd de'Zedd;Zdd ZG dd de'Zeddd&ZG dd deZeddd&ZG dd de'Zeddd&ZG dd de'Zeddd&ZG dd de'Zedd;ZG dd de'Zeddd&Zdd ZG dd de'Zedd;ZG dd de'Zedd;ZG dd de'Zeddd&ZG dd de'Zeddd&ZG ddń de'Zeddd&ZG ddȄ de'Zedd;ZG dd˄ de'ZeddddZG dd΄ de'Zeddd&ZG ddф de'Zeddd&ZG ddԄ de'Zeddd&ZG ddׄ de'Zedd;ZG ddڄ de'Zed dd&ZG dd݄ de'Zedd;ZG dd de'ZeddddZG dd de'Zedd;ZG dd de'Zedd;ZG dd de'Zedd;Zdd ZG dd de'Zeddd&ZG dd de'ZedddZG dd de'Zedd;ZG dd de'Zedd;ZG dd de'Zeddd&Zdd ZG dd de'Zedd d&ZG dd de'Zeddd&ZG dd de'Zeddd&ZG dd de'Zedd	d&ZG d
d de'Zedd;ZG dd de'Zeddd&ZG dd de'Zedd;ZG dd de'Zeddd&Zdd ZG dd de'Zeddd&ZG dd de'Zeddd&ZG dd de'Zed d;ZG d!d" d"e'Zed#d;ZG d$d% d%e'Zedd&d&ZG d'd( d(e'Zedd)d&ZG d*d+ d+e'Zed,d;ZG d-d. d.e'Zeddd/dZG d0d1 d1e'Zedd2d&ZG d3d4 d4e'Zed5d;ZG d6d7 d7e'Zed8dd9dZG d:d; d;e'Zedd<d&Z G d=d> d>e'Zed?d;Zed@d;ZG dAdB dBe'ZeddCd&ZG dDdE dEe'ZeddFd&ZG dGdH dHe'Zed8ddIdZ	G dJdK dKe'Z
e
dLd;ZG dMdN dNe'ZedOd;ZG dPdQ dQe'ZedddRdZedddSdZejr,dTe_G dUdV dVe'ZedddWdZG dXdY dYe'ZeddZd&Zd[d\ Zd]d^ Zd_d` ZG dadb dbe'Zedcd
ddZG dedf dfe'Zeddgd&ZG dhdi die'Zedjd;ZG dkdl dleaZG dmdn dne'Z e dddodZ!G dpdq dqe'Z"e"drd;Z#e"ejL ejLdsdZ$G dtdu dueZ%e%ddvd&Z&G dwdx dxe'Z'e'dd'ejL dydZ(G dzd{ d{e'Z)e)d|d;Z*G d}d~ d~e'Z+e+d dd&Z,G dd de'Z-e-dddZ.dd Z/G dd de'Z0e0dddddZ1G dd de'Z2G dd de'Z3e3dd ej4dZ5G dd de'Z6e6ddd&Z7e8e9 : ; Z<e%e<e'\Z=Z>e=e> dg Z?dS (      N)Iterable)wrapscached_property
Polynomial)extend_notes_in_docstringreplace_notes_in_docstringinherit_docstring_from)LowLevelCallable)optimize)	integrate)_lazyselect
_lazywhere   )_stats)tukeylambda_variancetukeylambda_kurtosis)get_distribution_names	_kurtosisrv_continuous_skew_get_fixed_fit_value_check_shape
_ShapeInfo)kolmognkolmognpkolmogni)_XMIN_LOGXMIN_EULER_ZETA3_SQRT_PI_SQRT_2_OVER_PI_LOG_SQRT_2_OVER_PI)CensoredData)root_scalar)FitErrorc                 C   sD   |  dd |  dd |  dd |  dd | r@td|  dS )a  
    Remove the optimizer-related keyword arguments 'loc', 'scale' and
    'optimizer' from `kwds`.  Then check that `kwds` is empty, and
    raise `TypeError("Unknown arguments: %s." % kwds)` if it is not.

    This function is used in the fit method of distributions that override
    the default method and do not use the default optimization code.

    `kwds` is modified in-place.
    locNscale	optimizermethodzUnknown arguments: %s.)pop	TypeError)kwds r.   Z/var/www/html/django/DPS/env/lib/python3.9/site-packages/scipy/stats/_continuous_distns.py_remove_optimizer_parameters'   s    r0   c                    s   t   fdd}|S )Nc                    sz   | dd }t|t}|dks2|rT| dkrTtt| | j|g|R i |S |r^|j} | |g|R i |S d S )Nr*   mlemmr   )	getlower
isinstancer$   num_censoredsupertypefit_uncensored)selfdataargsr-   r*   censoredfunr.   r/   wrapper>   s    
"z _call_super_mom.<locals>.wrapper)r   )r@   rA   r.   r?   r/   _call_super_mom:   s    rB   c                    sV   |p
|d }|| } fdd}|||sR|d9 }|| }d}t |r t|q |S )Nr   c                    s   t  | t  |kS Nnpsignlbrackrbrackr?   r.   r/   interval_contains_rootV   s    z1_get_left_bracket.<locals>.interval_contains_root   zVThe solver could not find a bracket containing a root to an MLE first order condition.)rE   isinfFitSolverError)r@   rI   rH   diffrJ   msgr.   r?   r/   _get_left_bracketO   s    


rP   c                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )	ksone_gena  Kolmogorov-Smirnov one-sided test statistic distribution.

    This is the distribution of the one-sided Kolmogorov-Smirnov (KS)
    statistics :math:`D_n^+` and :math:`D_n^-`
    for a finite sample size ``n >= 1`` (the shape parameter).

    %(before_notes)s

    See Also
    --------
    kstwobign, kstwo, kstest

    Notes
    -----
    :math:`D_n^+` and :math:`D_n^-` are given by

    .. math::

        D_n^+ &= \text{sup}_x (F_n(x) - F(x)),\\
        D_n^- &= \text{sup}_x (F(x) - F_n(x)),\\

    where :math:`F` is a continuous CDF and :math:`F_n` is an empirical CDF.
    `ksone` describes the distribution under the null hypothesis of the KS test
    that the empirical CDF corresponds to :math:`n` i.i.d. random variates
    with CDF :math:`F`.

    %(after_notes)s

    References
    ----------
    .. [1] Birnbaum, Z. W. and Tingey, F.H. "One-sided confidence contours
       for probability distribution functions", The Annals of Mathematical
       Statistics, 22(4), pp 592-596 (1951).

    %(example)s

    c                 C   s   |dk|t |k@ S Nr   rE   roundr;   nr.   r.   r/   	_argcheck   s    zksone_gen._argcheckc                 C   s   t dddtjfdgS NrV   Tr   TFr   rE   infr;   r.   r.   r/   _shape_info   s    zksone_gen._shape_infoc                 C   s   t || S rC   )scuZ	_smirnovpr;   xrV   r.   r.   r/   _pdf   s    zksone_gen._pdfc                 C   s   t ||S rC   )r^   Z	_smirnovcr_   r.   r.   r/   _cdf   s    zksone_gen._cdfc                 C   s   t ||S rC   )scZsmirnovr_   r.   r.   r/   _sf   s    zksone_gen._sfc                 C   s   t ||S rC   )r^   Z
_smirnovcir;   qrV   r.   r.   r/   _ppf   s    zksone_gen._ppfc                 C   s   t ||S rC   )rc   Zsmirnovire   r.   r.   r/   _isf   s    zksone_gen._isfN)__name__
__module____qualname____doc__rW   r]   ra   rb   rd   rg   rh   r.   r.   r.   r/   rQ   f   s   %rQ                 ?ksone)abnamec                   @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )	kstwo_gena  Kolmogorov-Smirnov two-sided test statistic distribution.

    This is the distribution of the two-sided Kolmogorov-Smirnov (KS)
    statistic :math:`D_n` for a finite sample size ``n >= 1``
    (the shape parameter).

    %(before_notes)s

    See Also
    --------
    kstwobign, ksone, kstest

    Notes
    -----
    :math:`D_n` is given by

    .. math::

        D_n = \text{sup}_x |F_n(x) - F(x)|

    where :math:`F` is a (continuous) CDF and :math:`F_n` is an empirical CDF.
    `kstwo` describes the distribution under the null hypothesis of the KS test
    that the empirical CDF corresponds to :math:`n` i.i.d. random variates
    with CDF :math:`F`.

    %(after_notes)s

    References
    ----------
    .. [1] Simard, R., L'Ecuyer, P. "Computing the Two-Sided
       Kolmogorov-Smirnov Distribution",  Journal of Statistical Software,
       Vol 39, 11, 1-18 (2011).

    %(example)s

    c                 C   s   |dk|t |k@ S rR   rS   rU   r.   r.   r/   rW      s    zkstwo_gen._argcheckc                 C   s   t dddtjfdgS rX   rZ   r\   r.   r.   r/   r]      s    zkstwo_gen._shape_infoc                 C   s    dt |ts|nt| dfS N      ?rn   )r5   r   rE   Z
asanyarrayrU   r.   r.   r/   _get_support   s    zkstwo_gen._get_supportc                 C   s
   t ||S rC   )r   r_   r.   r.   r/   ra      s    zkstwo_gen._pdfc                 C   s
   t ||S rC   r   r_   r.   r.   r/   rb      s    zkstwo_gen._cdfc                 C   s   t ||ddS NFcdfrw   r_   r.   r.   r/   rd      s    zkstwo_gen._sfc                 C   s   t ||ddS )NTry   r   re   r.   r.   r/   rg      s    zkstwo_gen._ppfc                 C   s   t ||ddS rx   r{   re   r.   r.   r/   rh      s    zkstwo_gen._isfN)ri   rj   rk   rl   rW   r]   rv   ra   rb   rd   rg   rh   r.   r.   r.   r/   rs      s   $rs   kstwo)momtyperp   rq   rr   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )kstwobign_gena  Limiting distribution of scaled Kolmogorov-Smirnov two-sided test statistic.

    This is the asymptotic distribution of the two-sided Kolmogorov-Smirnov
    statistic :math:`\sqrt{n} D_n` that measures the maximum absolute
    distance of the theoretical (continuous) CDF from the empirical CDF.
    (see `kstest`).

    %(before_notes)s

    See Also
    --------
    ksone, kstwo, kstest

    Notes
    -----
    :math:`\sqrt{n} D_n` is given by

    .. math::

        D_n = \text{sup}_x |F_n(x) - F(x)|

    where :math:`F` is a continuous CDF and :math:`F_n` is an empirical CDF.
    `kstwobign`  describes the asymptotic distribution (i.e. the limit of
    :math:`\sqrt{n} D_n`) under the null hypothesis of the KS test that the
    empirical CDF corresponds to i.i.d. random variates with CDF :math:`F`.

    %(after_notes)s

    References
    ----------
    .. [1] Feller, W. "On the Kolmogorov-Smirnov Limit Theorems for Empirical
       Distributions",  Ann. Math. Statist. Vol 19, 177-189 (1948).

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]     s    zkstwobign_gen._shape_infoc                 C   s   t | S rC   )r^   Z_kolmogpr;   r`   r.   r.   r/   ra     s    zkstwobign_gen._pdfc                 C   s
   t |S rC   )r^   Z_kolmogcr   r.   r.   r/   rb     s    zkstwobign_gen._cdfc                 C   s
   t |S rC   )rc   Z
kolmogorovr   r.   r.   r/   rd     s    zkstwobign_gen._sfc                 C   s
   t |S rC   )r^   Z	_kolmogcir;   rf   r.   r.   r/   rg     s    zkstwobign_gen._ppfc                 C   s
   t |S rC   )rc   Zkolmogir   r.   r.   r/   rh     s    zkstwobign_gen._isfN)
ri   rj   rk   rl   r]   ra   rb   rd   rg   rh   r.   r.   r.   r/   r~      s   $r~   	kstwobign)rp   rr   rK   c                 C   s   t | d  d t S NrK          @)rE   exp_norm_pdf_Cr`   r.   r.   r/   	_norm_pdf,  s    r   c                 C   s   | d  d t  S r   )_norm_pdf_logCr   r.   r.   r/   _norm_logpdf0  s    r   c                 C   s
   t | S rC   )rc   Zndtrr   r.   r.   r/   	_norm_cdf4  s    r   c                 C   s
   t | S rC   )rc   Zlog_ndtrr   r.   r.   r/   _norm_logcdf8  s    r   c                 C   s
   t | S rC   )rc   Zndtrirf   r.   r.   r/   	_norm_ppf<  s    r   c                 C   s
   t |  S rC   r   r   r.   r.   r/   _norm_sf@  s    r   c                 C   s
   t |  S rC   r   r   r.   r.   r/   _norm_logsfD  s    r   c                 C   s
   t |  S rC   r   r   r.   r.   r/   	_norm_isfH  s    r   c                   @   s   e Zd ZdZdd Zd!ddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zeeedddd Zdd  ZdS )"norm_gena  A normal continuous random variable.

    The location (``loc``) keyword specifies the mean.
    The scale (``scale``) keyword specifies the standard deviation.

    %(before_notes)s

    Notes
    -----
    The probability density function for `norm` is:

    .. math::

        f(x) = \frac{\exp(-x^2/2)}{\sqrt{2\pi}}

    for a real number :math:`x`.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   c  s    znorm_gen._shape_infoNc                 C   s
   | |S rC   )standard_normalr;   sizerandom_stater.   r.   r/   _rvsf  s    znorm_gen._rvsc                 C   s   t |S rC   r   r   r.   r.   r/   ra   i  s    znorm_gen._pdfc                 C   s   t |S rC   r   r   r.   r.   r/   _logpdfm  s    znorm_gen._logpdfc                 C   s   t |S rC   r   r   r.   r.   r/   rb   p  s    znorm_gen._cdfc                 C   s   t |S rC   r   r   r.   r.   r/   _logcdfs  s    znorm_gen._logcdfc                 C   s   t |S rC   r   r   r.   r.   r/   rd   v  s    znorm_gen._sfc                 C   s   t |S rC   )r   r   r.   r.   r/   _logsfy  s    znorm_gen._logsfc                 C   s   t |S rC   r   r   r.   r.   r/   rg   |  s    znorm_gen._ppfc                 C   s   t |S rC   r   r   r.   r.   r/   rh     s    znorm_gen._isfc                 C   s   dS )N)rm   rn   rm   rm   r.   r\   r.   r.   r/   r     s    znorm_gen._statsc                 C   s   dt dt j d  S Nru   rK   r   rE   logpir\   r.   r.   r/   _entropy  s    znorm_gen._entropya}          For the normal distribution, method of moments and maximum likelihood
        estimation give identical fits, and explicit formulas for the estimates
        are available.
        This function uses these explicit formulas for the maximum likelihood
        estimation of the normal distribution parameters, so the
        `optimizer` and `method` arguments are ignored.

notesc                 K   s   | dd }| dd }t| |d ur8|d ur8tdt|}t| sXtd|d u rj| }n|}|d u rt|| d  }n|}||fS )Nflocfscale3All parameters fixed. There is nothing to optimize.$The data contains non-finite values.rK   )	r+   r0   
ValueErrorrE   asarrayisfiniteallmeansqrt)r;   r<   r-   r   r   r'   r(   r.   r.   r/   r9     s    	

znorm_gen.fitc                 C   s"   |d dkrt |d S dS dS )z
        @returns Moments of standard normal distribution for integer n >= 0

        See eq. 16 of https://arxiv.org/abs/1209.4340v2
        rK   r   r   rm   N)rc   Z
factorial2rU   r.   r.   r/   _munp  s    znorm_gen._munp)NN)ri   rj   rk   rl   r]   r   ra   r   rb   r   rd   r   rg   rh   r   r   rB   r   r   r9   r   r.   r.   r.   r/   r   L  s"   

r   norm)rr   c                   @   sF   e Zd ZdZejZdd Zdd Zdd Z	dd	 Z
d
d Zdd ZdS )	alpha_gena&  An alpha continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `alpha` ([1]_, [2]_) is:

    .. math::

        f(x, a) = \frac{1}{x^2 \Phi(a) \sqrt{2\pi}} *
                  \exp(-\frac{1}{2} (a-1/x)^2)

    where :math:`\Phi` is the normal CDF, :math:`x > 0`, and :math:`a > 0`.

    `alpha` takes ``a`` as a shape parameter.

    %(after_notes)s

    References
    ----------
    .. [1] Johnson, Kotz, and Balakrishnan, "Continuous Univariate
           Distributions, Volume 1", Second Edition, John Wiley and Sons,
           p. 173 (1994).
    .. [2] Anthony A. Salvia, "Reliability applications of the Alpha
           Distribution", IEEE Transactions on Reliability, Vol. R-34,
           No. 3, pp. 251-252 (1985).

    %(example)s

    c                 C   s   t dddtjfdgS Nrp   Fr   FFrZ   r\   r.   r.   r/   r]     s    zalpha_gen._shape_infoc                 C   s$   d|d  t | t|d|   S Nrn   rK   )r   r   r;   r`   rp   r.   r.   r/   ra     s    zalpha_gen._pdfc                 C   s,   dt | t|d|   t t| S )Nrn   )rE   r   r   r   r   r.   r.   r/   r     s    zalpha_gen._logpdfc                 C   s   t |d|  t | S Nrn   r   r   r.   r.   r/   rb     s    zalpha_gen._cdfc                 C   s   dt |t|t|   S r   )rE   r   r   r   r;   rf   rp   r.   r.   r/   rg     s    zalpha_gen._ppfc                 C   s   t jgd t jgd  S NrK   rE   r[   nanr;   rp   r.   r.   r/   r     s    zalpha_gen._statsN)ri   rj   rk   rl   r   _open_support_mask_support_maskr]   ra   r   rb   rg   r   r.   r.   r.   r/   r     s   r   alphac                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )
anglit_gena  An anglit continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `anglit` is:

    .. math::

        f(x) = \sin(2x + \pi/2) = \cos(2x)

    for :math:`-\pi/4 \le x \le \pi/4`.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   
  s    zanglit_gen._shape_infoc                 C   s   t d| S r   )rE   cosr   r.   r.   r/   ra     s    zanglit_gen._pdfc                 C   s   t |t jd  d S N   r   rE   sinr   r   r.   r.   r/   rb     s    zanglit_gen._cdfc                 C   s   t |t jd  d S r   )rE   r   r   r   r.   r.   r/   rd     s    zanglit_gen._sfc                 C   s   t t |t jd  S Nr   )rE   arcsinr   r   r   r.   r.   r/   rg     s    zanglit_gen._ppfc                 C   s>   dt jt j d d ddt jd d  t jt j d d  fS )	Nrm      ru   r   r   `      rK   rE   r   r\   r.   r.   r/   r     s    zanglit_gen._statsc                 C   s   dt d S Nr   rK   rE   r   r\   r.   r.   r/   r     s    zanglit_gen._entropyN)ri   rj   rk   rl   r]   ra   rb   rd   rg   r   r   r.   r.   r.   r/   r     s   r   r   anglitc                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )arcsine_gena  An arcsine continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `arcsine` is:

    .. math::

        f(x) = \frac{1}{\pi \sqrt{x (1-x)}}

    for :math:`0 < x < 1`.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   8  s    zarcsine_gen._shape_infoc                 C   sL   t jdd, dt j t |d|   W  d    S 1 s>0    Y  d S )Nignoredividern   r   )rE   errstater   r   r   r.   r.   r/   ra   ;  s    zarcsine_gen._pdfc                 C   s   dt j t t | S Nr   )rE   r   r   r   r   r.   r.   r/   rb   @  s    zarcsine_gen._cdfc                 C   s   t t jd | d S r   r   r   r.   r.   r/   rg   C  s    zarcsine_gen._ppfc                 C   s   d}d}d}d}||||fS )Nru   g      ?r         r.   r;   mumu2g1g2r.   r.   r/   r   F  s
    zarcsine_gen._statsc                 C   s   dS )Ngοr.   r\   r.   r.   r/   r   M  s    zarcsine_gen._entropyN
ri   rj   rk   rl   r]   ra   rb   rg   r   r   r.   r.   r.   r/   r   $  s   r   arcsinec                   @   s   e Zd ZdZdd ZdS )FitDataErrorz=Raised when input data is inconsistent with fixed parameters.c                 C   s    d|d|d|df| _ d S )Nz>Invalid values in `data`.  Maximum likelihood estimation with z requires that z < (x - loc)/scale  < z for each x in `data`.r=   )r;   Zdistrr4   upperr.   r.   r/   __init__Y  s    zFitDataError.__init__Nri   rj   rk   rl   r   r.   r.   r.   r/   r   T  s   r   c                   @   s   e Zd ZdZdd ZdS )rM   zN
    Raised when a solver fails to converge while fitting a distribution.
    c                 C   s    d}|| dd7 }|f| _d S )Nz1Solver for the MLE equations failed to converge: 
 )replacer=   )r;   mesgZemsgr.   r.   r/   r   g  s    zFitSolverError.__init__Nr   r.   r.   r.   r/   rM   a  s   rM   c                 C   s*   t | | }||| t |    }|S rC   rc   psi)rp   rq   rV   s1psiabfuncr.   r.   r/   _beta_mle_am  s    r   c                 C   sJ   | \}}t || }||| t |   ||| t |   g}|S rC   r   )thetarV   r   s2rp   rq   r   r   r.   r.   r/   _beta_mle_abv  s    r   c                       s   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Z fddZeeedd fddZdd Z  ZS )beta_gena  A beta continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `beta` is:

    .. math::

        f(x, a, b) = \frac{\Gamma(a+b) x^{a-1} (1-x)^{b-1}}
                          {\Gamma(a) \Gamma(b)}

    for :math:`0 <= x <= 1`, :math:`a > 0`, :math:`b > 0`, where
    :math:`\Gamma` is the gamma function (`scipy.special.gamma`).

    `beta` takes :math:`a` and :math:`b` as shape parameters.

    %(after_notes)s

    %(example)s

    c                 C   s0   t dddtjfd}t dddtjfd}||gS Nrp   Fr   r   rq   rZ   r;   iaibr.   r.   r/   r]     s    zbeta_gen._shape_infoNc                 C   s   | |||S rC   beta)r;   rp   rq   r   r   r.   r.   r/   r     s    zbeta_gen._rvsc                 C   s>   t jdd t|||W  d    S 1 s00    Y  d S Nr   over)rE   r   _boostZ	_beta_pdfr;   r`   rp   rq   r.   r.   r/   ra     s    zbeta_gen._pdfc                 C   s6   t |d | t |d | }|t ||8 }|S r   )rc   xlog1pyxlogybetaln)r;   r`   rp   rq   lPxr.   r.   r/   r     s    "zbeta_gen._logpdfc                 C   s   t |||S rC   )r   Z	_beta_cdfr   r.   r.   r/   rb     s    zbeta_gen._cdfc                 C   s   t |||S rC   )r   Z_beta_sfr   r.   r.   r/   rd     s    zbeta_gen._sfc                 C   s>   t jdd t|||W  d    S 1 s00    Y  d S r   )rE   r   r   Z	_beta_isfr   r.   r.   r/   rh     s    zbeta_gen._isfc                 C   s>   t jdd t|||W  d    S 1 s00    Y  d S r   )rE   r   r   Z	_beta_ppfr;   rf   rp   rq   r.   r.   r/   rg     s    zbeta_gen._ppfc                 C   s,   t ||t ||t ||t ||fS rC   )r   Z
_beta_meanZ_beta_varianceZ_beta_skewnessZ_beta_kurtosis_excessr;   rp   rq   r.   r.   r/   r     s
    



zbeta_gen._statsc                    sT   t |tr| }t| t| fdd}t|d\}}t j|||fdS )Nc                    s   | \}}d||  t || d  || d  t ||  }|d |d d| d   |d |d   d| | |d   }||| || d  || d   }|d9 }|  | gS )NrK   r         rE   r   )r`   rp   rq   skkur   r   r.   r/   r     s    8@$z beta_gen._fitstart.<locals>.func)rn   rn   r   )	r5   r$   	_uncensorr   r   r   fsolver7   	_fitstart)r;   r<   r   rp   rq   	__class__r	  r/   r    s    
zbeta_gen._fitstartz        In the special case where `method="MLE"` and
        both `floc` and `fscale` are given, a
        `ValueError` is raised if any value `x` in `data` does not satisfy
        `floc < x < floc + fscale`.

r   c                    s:  | dd }| dd }|d u s(|d u rBt j|g|R i |S |dd  |dd  t|g d}t|g d}t| |d ur|d urtdt|	 stdt
|| | }t|dkst|dkrtd	||| d
| }|d us|d ur|d ur(|}	d| }d| }n|}	|	| d|  }
tjt|
|	t|t| fdd\}}}}|dkr~t|d|d }
|d ur.|	|
 }
}	nt| }t|  }|d|  |jdd d }|| }
d| | }	tjt|
|	gt|||fdd\}}}}|dkr&t|d|\}
}	|
|	||fS )Nr   r   f0faZfix_a)f1fbZfix_br   r   r   r   r   r4   r   T)r=   full_output)r   )Zddof)r3   r7   r9   r+   r   r0   r   rE   r   r   Zravelanyr   r   r   r  r   lenr   sumrM   rc   log1pvarr   )r;   r<   r=   r-   r   r   r  r  xbarrq   rp   r   infoierr   r   r   facr  r.   r/   r9     s`    
	






zbeta_gen.fitc                 C   s   dd }dd }dd }dd }|d	kr:|d	kr:|||S |d
krd|| dkrd|||krd|||S |d
kr|| dkr|||kr|||S |||S d S )Nc                 S   sJ   t | || d t |   |d t |  | | d t | |   S r   )rc   r   r   rp   rq   r.   r.   r/   regularB  s
    z"beta_gen._entropy.<locals>.regularc                 S   s   | | }dt dt j t |  t | dt |  d  }d| d|d   |d  d|d	   }d
|  d| d   | d  | d	  }d
| d|d   |d  |d	  }||| | d  S )Nru   rK   r  r   n                         i
   x   r   )rp   rq   sum_ablog_termt1t2t3r.   r.   r/   asymptotic_ab_largeF  s    4($$z.beta_gen._entropy.<locals>.asymptotic_ab_largec                 S   s   | | }t | | d t |   }dd|  dd|   |d d  |d d  |d d  |d	 d
  |d d
  d|  dd|   |d d  |d d  |d d  |d	 d
  |d d  }|t| |  t| dt|  }|| | S )Nr   rK      r#  r$  r'  r%                 r  <   ~   )rc   gammalnr   rE   r  r   )rp   rq   r(  r*  r+  r)  r.   r.   r/   asymptotic_b_largeP  s0    :







*z-beta_gen._entropy.<locals>.asymptotic_b_largec                 S   sB   | dkrdS t | }t|}t| d|  d }|dd|   S )Nrn   i  r&  rK      )rE   log10int)vjdigitsdr.   r.   r/   threshold_large\  s    
z*beta_gen._entropy.<locals>.threshold_largeg    RAg    (RAg    .Ar.   )r;   rp   rq   r   r-  r6  r>  r.   r.   r/   r   A  s    
	
 
 
zbeta_gen._entropy)NN)ri   rj   rk   rl   r]   r   ra   r   rb   rd   rh   rg   r   r  rB   r   r   r9   r   __classcell__r.   r.   r  r/   r     s   

er   r   c                   @   sX   e Zd ZdZejZdd ZdddZdd Z	d	d
 Z
dd Zdd Zdd Zdd ZdS )betaprime_gena  A beta prime continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `betaprime` is:

    .. math::

        f(x, a, b) = \frac{x^{a-1} (1+x)^{-a-b}}{\beta(a, b)}

    for :math:`x >= 0`, :math:`a > 0`, :math:`b > 0`, where
    :math:`\beta(a, b)` is the beta function (see `scipy.special.beta`).

    `betaprime` takes ``a`` and ``b`` as shape parameters.

    The distribution is related to the `beta` distribution as follows:
    If :math:`X` follows a beta distribution with parameters :math:`a, b`,
    then :math:`Y = X/(1-X)` has a beta prime distribution with
    parameters :math:`a, b` ([1]_).

    The beta prime distribution is a reparametrized version of the
    F distribution.  The beta prime distribution with shape parameters
    ``a`` and ``b`` and ``scale = s`` is equivalent to the F distribution
    with parameters ``d1 = 2*a``, ``d2 = 2*b`` and ``scale = (a/b)*s``.
    For example,

    >>> from scipy.stats import betaprime, f
    >>> x = [1, 2, 5, 10]
    >>> a = 12
    >>> b = 5
    >>> betaprime.pdf(x, a, b, scale=2)
    array([0.00541179, 0.08331299, 0.14669185, 0.03150079])
    >>> f.pdf(x, 2*a, 2*b, scale=(a/b)*2)
    array([0.00541179, 0.08331299, 0.14669185, 0.03150079])

    %(after_notes)s

    References
    ----------
    .. [1] Beta prime distribution, Wikipedia,
           https://en.wikipedia.org/wiki/Beta_prime_distribution

    %(example)s

    c                 C   s0   t dddtjfd}t dddtjfd}||gS r   rZ   r   r.   r.   r/   r]     s    zbetaprime_gen._shape_infoNc                 C   s(   t j|||d}t j|||d}|| S Nr   r   )gammarvs)r;   rp   rq   r   r   u1u2r.   r.   r/   r     s    zbetaprime_gen._rvsc                 C   s   t | |||S rC   rE   r   r   r   r.   r.   r/   ra     s    zbetaprime_gen._pdfc                 C   s,   t |d |t || | t || S r   )rc   r   r   r   r   r.   r.   r/   r     s    zbetaprime_gen._logpdfc                 C   s"   t |dk|||gdd dd dS )Nr   c                 S   s   t dd|   ||S rR   r   rd   x_Za_b_r.   r.   r/   <lambda>      z$betaprime_gen._cdf.<locals>.<lambda>c                 S   s   t | d|   ||S rR   r   rb   rI  r.   r.   r/   rL    rM  f2r   r   r.   r.   r/   rb     s
    zbetaprime_gen._cdfc                 C   s"   t |dk|||gdd dd dS )Nr   c                 S   s   t dd|   ||S rR   rN  rI  r.   r.   r/   rL    rM  z#betaprime_gen._sf.<locals>.<lambda>c                 S   s   t | d|   ||S rR   rH  rI  r.   r.   r/   rL    rM  rO  rQ  r   r.   r.   r/   rd     s
    zbetaprime_gen._sfc                 C   s   t |||\}}}tj|||}t jdd |d|  }W d    n1 sR0    Y  |dk}dtj|| || ||  d ||< |S )Nr   r   r   gH.?)rE   broadcast_arraysstatsr   rg   r   rh   )r;   prp   rq   routir.   r.   r/   rg     s    *(zbetaprime_gen._ppfc                    s"   t | k||f fddtjdS )Nc                    s(   t j fddtdd D ddS )Nc                    s    g | ]} | d  |  qS r   r.   .0rW  r  r.   r/   
<listcomp>  rM  z9betaprime_gen._munp.<locals>.<lambda>.<locals>.<listcomp>r   r   Zaxis)rE   prodranger  rV   r  r/   rL    rM  z%betaprime_gen._munp.<locals>.<lambda>	fillvaluer   rE   r[   )r;   rV   rp   rq   r.   r_  r/   r     s
    
zbetaprime_gen._munp)NN)ri   rj   rk   rl   r   r   r   r]   r   ra   r   rb   rd   rg   r   r.   r.   r.   r/   r@  r  s   /
r@  	betaprimec                   @   sB   e Zd ZdZdd Zdd Zdd Zdd	 ZdddZdd Z	dS )bradford_genab  A Bradford continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `bradford` is:

    .. math::

        f(x, c) = \frac{c}{\log(1+c) (1+cx)}

    for :math:`0 <= x <= 1` and :math:`c > 0`.

    `bradford` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS NcFr   r   rZ   r\   r.   r.   r/   r]     s    zbradford_gen._shape_infoc                 C   s   ||| d  t | S r   rc   r  r;   r`   rf  r.   r.   r/   ra     s    zbradford_gen._pdfc                 C   s   t || t | S rC   rg  rh  r.   r.   r/   rb     s    zbradford_gen._cdfc                 C   s   t |t | | S rC   rc   expm1r  r;   rf   rf  r.   r.   r/   rg     s    zbradford_gen._ppfmvc                 C   sx  t d| }|| ||  }|d | d|  d| | |  }d }d }d|v rt dd| | d| | |d   d| | ||d  d    }|t |||d  d|   d| |d  d|    }d	|v rl|d |d  |d| d
  d  d| | | |d  |d   d| | | d| d   d|d   }|d| ||d  d|  d   }||||fS )Nrn   r   rK   sr/  	   r  r  kr      r      )rE   r   r   )r;   rf  momentsro  r   r   r   r   r.   r.   r/   r     s     $F:
B
$zbradford_gen._statsc                 C   s$   t d| }|d t ||  S Nr   r   r   )r;   rf  ro  r.   r.   r/   r     s    zbradford_gen._entropyN)rl  r   r.   r.   r.   r/   rd    s   
rd  bradfordc                   @   sh   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )burr_gena  A Burr (Type III) continuous random variable.

    %(before_notes)s

    See Also
    --------
    fisk : a special case of either `burr` or `burr12` with ``d=1``
    burr12 : Burr Type XII distribution
    mielke : Mielke Beta-Kappa / Dagum distribution

    Notes
    -----
    The probability density function for `burr` is:

    .. math::

        f(x; c, d) = c d \frac{x^{-c - 1}}
                              {{(1 + x^{-c})}^{d + 1}}

    for :math:`x >= 0` and :math:`c, d > 0`.

    `burr` takes ``c`` and ``d`` as shape parameters for :math:`c` and
    :math:`d`.

    This is the PDF corresponding to the third CDF given in Burr's list;
    specifically, it is equation (11) in Burr's paper [1]_. The distribution
    is also commonly referred to as the Dagum distribution [2]_. If the
    parameter :math:`c < 1` then the mean of the distribution does not
    exist and if :math:`c < 2` the variance does not exist [2]_.
    The PDF is finite at the left endpoint :math:`x = 0` if :math:`c * d >= 1`.

    %(after_notes)s

    References
    ----------
    .. [1] Burr, I. W. "Cumulative frequency functions", Annals of
       Mathematical Statistics, 13(2), pp 215-232 (1942).
    .. [2] https://en.wikipedia.org/wiki/Dagum_distribution
    .. [3] Kleiber, Christian. "A guide to the Dagum distributions."
       Modeling Income Distributions and Lorenz Curves  pp 97-117 (2008).

    %(example)s

    c                 C   s0   t dddtjfd}t dddtjfd}||gS Nrf  Fr   r   r=  rZ   r;   icidr.   r.   r/   r]   L  s    zburr_gen._shape_infoc                 C   s8   t |dk|||gdd dd d}|jdkr4|d S |S )Nr   c                 S   s$   || | || d   d| |   S rR   r.   rJ  Zc_Zd_r.   r.   r/   rL  U  rM  zburr_gen._pdf.<locals>.<lambda>c                 S   s,   || | | d   d| |   |d   S Nrn   r   r.   rz  r.   r.   r/   rL  V  s   rO  r.   r   ndimr;   r`   rf  r=  outputr.   r.   r/   ra   Q  s    
zburr_gen._pdfc                 C   s8   t |dk|||gdd dd d}|jdkr4|d S |S )Nr   c                 S   s>   t |t | t|| d |  |d t| |   S rR   )rE   r   rc   r   r  rz  r.   r.   r/   rL  _  s   &z"burr_gen._logpdf.<locals>.<lambda>c                 S   s<   t |t | t| d |  t|d | |   S rR   rE   r   rc   r   r   rz  r.   r.   r/   rL  a  s   rO  r.   r|  r~  r.   r.   r/   r   \  s    
zburr_gen._logpdfc                 C   s   d||   |  S rR   r.   r;   r`   rf  r=  r.   r.   r/   rb   h  s    zburr_gen._cdfc                 C   s   t ||  |  S rC   rg  r  r.   r.   r/   r   k  s    zburr_gen._logcdfc                 C   s   t | |||S rC   rE   r   r   r  r.   r.   r/   rd   n  s    zburr_gen._sfc                 C   s   t d||   |   S rR   rE   r  r  r.   r.   r/   r   q  s    zburr_gen._logsfc                 C   s   |d|  d d|  S N      r   r.   r;   rf   rf  r=  r.   r.   r/   rg   t  s    zburr_gen._ppfc                 C   s$   t d| | }t |d|  S Nr  rc   r   rj  )r;   rf   rf  r=  Z_qr.   r.   r/   rh   w  s    zburr_gen._isfc                 C   s   t dddd| }t|| d| | \}}}}t |dk|t j}||d  }	t |dk|	t j}
t|dk|||||	fdd	 t jd
}t|dk||||||	fdd	 t jd
}t |dkr|	 |
	 |	 |	 fS ||
||fS )Nr      r   rn   rK   r         @c                 S   s*   |d| |  d|d   t |d  S )Nr  rK   r  )rf  e1e2e3mu2_if_cr.   r.   r/   rL    s   z!burr_gen._stats.<locals>.<lambda>r`        @c                 S   s8   |d| |  d| |d   d|d   |d  d S )Nr   r  rK   r  r.   )rf  r  r  r  e4r  r.   r.   r/   rL    s    r   )
rE   arangereshaperc   r   wherer   r   r}  item)r;   rf  r=  ncr  r  r  r  r   r  r   r   r   r.   r.   r/   r   {  s(     zburr_gen._statsc                    s\   dd  t |t |t |  }}}t||k||k@ ||k@ |||f fddt jS )Nc                 S   s$   d|  | }|t d| ||  S r   rc   r   rV   rf  r=  r  r.   r.   r/   __munp  s    zburr_gen._munp.<locals>.__munpc                    s    || |S rC   r.   )rf  r=  rV   Z_burr_gen__munpr.   r/   rL    rM  z burr_gen._munp.<locals>.<lambda>)rE   r   r   r   )r;   rV   rf  r=  r.   r  r/   r     s    " 
zburr_gen._munpN)ri   rj   rk   rl   r]   ra   r   rb   r   rd   r   rg   rh   r   r   r.   r.   r.   r/   ru    s   0ru  burrc                   @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdS )
burr12_gena}  A Burr (Type XII) continuous random variable.

    %(before_notes)s

    See Also
    --------
    fisk : a special case of either `burr` or `burr12` with ``d=1``
    burr : Burr Type III distribution

    Notes
    -----
    The probability density function for `burr12` is:

    .. math::

        f(x; c, d) = c d \frac{x^{c-1}}
                              {(1 + x^c)^{d + 1}}

    for :math:`x >= 0` and :math:`c, d > 0`.

    `burr12` takes ``c`` and ``d`` as shape parameters for :math:`c`
    and :math:`d`.

    This is the PDF corresponding to the twelfth CDF given in Burr's list;
    specifically, it is equation (20) in Burr's paper [1]_.

    %(after_notes)s

    The Burr type 12 distribution is also sometimes referred to as
    the Singh-Maddala distribution from NIST [2]_.

    References
    ----------
    .. [1] Burr, I. W. "Cumulative frequency functions", Annals of
       Mathematical Statistics, 13(2), pp 215-232 (1942).

    .. [2] https://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/b12pdf.htm

    .. [3] "Burr distribution",
       https://en.wikipedia.org/wiki/Burr_distribution

    %(example)s

    c                 C   s0   t dddtjfd}t dddtjfd}||gS rv  rZ   rw  r.   r.   r/   r]     s    zburr12_gen._shape_infoc                 C   s   t | |||S rC   rG  r  r.   r.   r/   ra     s    zburr12_gen._pdfc                 C   s:   t |t | t|d | t| d ||  S rR   r  r  r.   r.   r/   r     s    zburr12_gen._logpdfc                 C   s   t | ||| S rC   rc   rj  r   r  r.   r.   r/   rb     s    zburr12_gen._cdfc                 C   s   t d||  |   S rR   rg  r  r.   r.   r/   r     s    zburr12_gen._logcdfc                 C   s   t | |||S rC   r  r  r.   r.   r/   rd     s    zburr12_gen._sfc                 C   s   t | || S rC   rc   r   r  r.   r.   r/   r     s    zburr12_gen._logsfc                 C   s"   t d| t |  d|  S )Nr.  r   ri  r  r.   r.   r/   rg     s    zburr12_gen._ppfc                 C   s(   dd }t || |k|||f|tjdS )Nc                 S   s$   d|  | }|t d| ||  S r   r  r  r.   r.   r/   moment_if_exists  s    z*burr12_gen._munp.<locals>.moment_if_existsr`  )r   rE   r   )r;   rV   rf  r=  r  r.   r.   r/   r     s    zburr12_gen._munpN)ri   rj   rk   rl   r]   ra   r   rb   r   rd   r   rg   r   r.   r.   r.   r/   r    s   ,r  burr12c                   @   sp   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )fisk_gena  A Fisk continuous random variable.

    The Fisk distribution is also known as the log-logistic distribution.

    %(before_notes)s

    See Also
    --------
    burr

    Notes
    -----
    The probability density function for `fisk` is:

    .. math::

        f(x, c) = \frac{c x^{c-1}}
                       {(1 + x^c)^2}

    for :math:`x >= 0` and :math:`c > 0`.

    Please note that the above expression can be transformed into the following
    one, which is also commonly used:

    .. math::

        f(x, c) = \frac{c x^{-c-1}}
                       {(1 + x^{-c})^2}

    `fisk` takes ``c`` as a shape parameter for :math:`c`.

    `fisk` is a special case of `burr` or `burr12` with ``d=1``.

    Suppose ``X`` is a logistic random variable with location ``l``
    and scale ``s``. Then ``Y = exp(X)`` is a Fisk (log-logistic)
    random variable with ``scale = exp(l)`` and shape ``c = 1/s``.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]   !  s    zfisk_gen._shape_infoc                 C   s   t ||dS r   )r  ra   rh  r.   r.   r/   ra   $  s    zfisk_gen._pdfc                 C   s   t ||dS r   )r  rb   rh  r.   r.   r/   rb   (  s    zfisk_gen._cdfc                 C   s   t ||dS r   )r  rd   rh  r.   r.   r/   rd   +  s    zfisk_gen._sfc                 C   s   t ||dS r   )r  r   rh  r.   r.   r/   r   .  s    zfisk_gen._logpdfc                 C   s   t ||dS r   )r  r   rh  r.   r.   r/   r   2  s    zfisk_gen._logcdfc                 C   s   t ||dS r   )r  r   rh  r.   r.   r/   r   5  s    zfisk_gen._logsfc                 C   s   t ||dS r   )r  rg   rh  r.   r.   r/   rg   8  s    zfisk_gen._ppfc                 C   s   t ||dS r   )r  rh   rk  r.   r.   r/   rh   ;  s    zfisk_gen._isfc                 C   s   t ||dS r   )r  r   r;   rV   rf  r.   r.   r/   r   >  s    zfisk_gen._munpc                 C   s   t |dS r   )r  r   r;   rf  r.   r.   r/   r   A  s    zfisk_gen._statsc                 C   s   dt | S r   r   r  r.   r.   r/   r   D  s    zfisk_gen._entropyN)ri   rj   rk   rl   r]   ra   rb   rd   r   r   r   rg   rh   r   r   r   r.   r.   r.   r/   r    s   *r  fiskc                   @   sZ   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdddZdS )
cauchy_gena	  A Cauchy continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `cauchy` is

    .. math::

        f(x) = \frac{1}{\pi (1 + x^2)}

    for a real number :math:`x`.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   _  s    zcauchy_gen._shape_infoc                 C   s   dt j d||   S r   r   r   r.   r.   r/   ra   b  s    zcauchy_gen._pdfc                 C   s   ddt j t |  S rt   rE   r   arctanr   r.   r.   r/   rb   f  s    zcauchy_gen._cdfc                 C   s   t t j| t jd  S r   rE   tanr   r   r.   r.   r/   rg   i  s    zcauchy_gen._ppfc                 C   s   ddt j t |  S rt   r  r   r.   r.   r/   rd   l  s    zcauchy_gen._sfc                 C   s   t t jd t j|  S r   r  r   r.   r.   r/   rh   o  s    zcauchy_gen._isfc                 C   s   t jt jt jt jfS rC   rE   r   r\   r.   r.   r/   r   r  s    zcauchy_gen._statsc                 C   s   t dt j S r   r   r\   r.   r.   r/   r   u  s    zcauchy_gen._entropyNc                 C   s8   t |tr| }t|g d\}}}||| d fS )N   2   K   rK   r5   r$   r
  rE   Z
percentile)r;   r<   r=   p25p50p75r.   r.   r/   r  x  s    
zcauchy_gen._fitstart)N)ri   rj   rk   rl   r]   ra   rb   rg   rd   rh   r   r   r  r.   r.   r.   r/   r  K  s   r  cauchyc                   @   sb   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )chi_gena  A chi continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `chi` is:

    .. math::

        f(x, k) = \frac{1}{2^{k/2-1} \Gamma \left( k/2 \right)}
                   x^{k-1} \exp \left( -x^2/2 \right)

    for :math:`x >= 0` and :math:`k > 0` (degrees of freedom, denoted ``df``
    in the implementation). :math:`\Gamma` is the gamma function
    (`scipy.special.gamma`).

    Special cases of `chi` are:

        - ``chi(1, loc, scale)`` is equivalent to `halfnorm`
        - ``chi(2, 0, scale)`` is equivalent to `rayleigh`
        - ``chi(3, 0, scale)`` is equivalent to `maxwell`

    `chi` takes ``df`` as a shape parameter.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS NdfFr   r   rZ   r\   r.   r.   r/   r]     s    zchi_gen._shape_infoNc                 C   s   t tj|||dS rA  )rE   r   chi2rD  r;   r  r   r   r.   r.   r/   r     s    zchi_gen._rvsc                 C   s   t | ||S rC   rG  r;   r`   r  r.   r.   r/   ra     s    zchi_gen._pdfc                 C   sJ   t ddt d |  td|  }|t|d | d|d   S )NrK   ru   rn   )rE   r   rc   r5  r   )r;   r`   r  lr.   r.   r/   r     s    *zchi_gen._logpdfc                 C   s   t d| d|d  S Nru   rK   rc   gammaincr  r.   r.   r/   rb     s    zchi_gen._cdfc                 C   s   t d| d|d  S r  rc   	gammainccr  r.   r.   r/   rd     s    zchi_gen._sfc                 C   s   t dtd| | S NrK   ru   rE   r   rc   gammaincinvr;   rf   r  r.   r.   r/   rg     s    zchi_gen._ppfc                 C   s   t dtd| | S r  rE   r   rc   gammainccinvr  r.   r.   r/   rh     s    zchi_gen._isfc                 C   s   t dtd| d }|||  }d|d  |dd|    t t |d }d| d|  d|d   d|d  d| d   }|t |d	  }||||fS )
NrK   ru   r  r         ?rn   r  r   r   )rE   r   rc   pochr   powerr;   r  r   r   r   r   r.   r.   r/   r     s    .4zchi_gen._statsc                 C   s&   dd }dd }t |dk |f||dS )Nc                 S   s6   t d|  d| td | d t d|      S r   )rc   r5  rE   r   digammar  r.   r.   r/   regular_formula  s    &z)chi_gen._entropy.<locals>.regular_formulac                 S   sD   dt t jd  | d d  | d d  d| d   | d d	  S )
Nru   rK   r.  r  r   gll?   r   r  r.   r.   r/   asymptotic_formula  s
    *

z,chi_gen._entropy.<locals>.asymptotic_formulag     r@rO  rQ  )r;   r  r  r  r.   r.   r/   r     s
    zchi_gen._entropy)NNri   rj   rk   rl   r]   r   ra   r   rb   rd   rg   rh   r   r   r.   r.   r.   r/   r    s   
	r  chic                   @   sb   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )chi2_gena  A chi-squared continuous random variable.

    For the noncentral chi-square distribution, see `ncx2`.

    %(before_notes)s

    See Also
    --------
    ncx2

    Notes
    -----
    The probability density function for `chi2` is:

    .. math::

        f(x, k) = \frac{1}{2^{k/2} \Gamma \left( k/2 \right)}
                   x^{k/2-1} \exp \left( -x/2 \right)

    for :math:`x > 0`  and :math:`k > 0` (degrees of freedom, denoted ``df``
    in the implementation).

    `chi2` takes ``df`` as a shape parameter.

    The chi-squared distribution is a special case of the gamma
    distribution, with gamma parameters ``a = df/2``, ``loc = 0`` and
    ``scale = 2``.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS r  rZ   r\   r.   r.   r/   r]     s    zchi2_gen._shape_infoNc                 C   s   | ||S rC   )Z	chisquarer  r.   r.   r/   r     s    zchi2_gen._rvsc                 C   s   t | ||S rC   rG  r  r.   r.   r/   ra      s    zchi2_gen._pdfc                 C   s<   t |d d ||d  t |d  td| d  S )Nr   r   rK   )rc   r   r5  rE   r   r  r.   r.   r/   r     s    zchi2_gen._logpdfc                 C   s   t ||S rC   )rc   Zchdtrr  r.   r.   r/   rb     s    zchi2_gen._cdfc                 C   s   t ||S rC   )rc   Zchdtrcr  r.   r.   r/   rd   
  s    zchi2_gen._sfc                 C   s   t ||S rC   )rc   Zchdtrir;   rT  r  r.   r.   r/   rh     s    zchi2_gen._isfc                 C   s   dt |d | S r   rc   r  r  r.   r.   r/   rg     s    zchi2_gen._ppfc                 C   s2   |}d| }dt d|  }d| }||||fS )NrK   r         (@r  r  r.   r.   r/   r     s
    zchi2_gen._statsc                 C   s.   d| }dd }dd }t |dk |f||dS )Nru   c                 S   s*   | t d t|  d|  t|   S NrK   r   )rE   r   rc   r5  r   )half_dfr.   r.   r/   r    s    z*chi2_gen._entropy.<locals>.regular_formulac                 S   s\   t dddt dt j    }d|  }|d|d|d|d       dt |   | S )NrK   ru   r   gUUUUUUUUUUUUտgllg      @r   )r  rf  hr.   r.   r/   r  !  s    "z-chi2_gen._entropy.<locals>.asymptotic_formula}   rO  rQ  )r;   r  r  r  r  r.   r.   r/   r     s    zchi2_gen._entropy)NN)ri   rj   rk   rl   r]   r   ra   r   rb   rd   rh   rg   r   r   r.   r.   r.   r/   r    s   !
r  r  c                   @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdS )
cosine_gena\  A cosine continuous random variable.

    %(before_notes)s

    Notes
    -----
    The cosine distribution is an approximation to the normal distribution.
    The probability density function for `cosine` is:

    .. math::

        f(x) = \frac{1}{2\pi} (1+\cos(x))

    for :math:`-\pi \le x \le \pi`.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   I  s    zcosine_gen._shape_infoc                 C   s   dt j dt |  S Nru   r   rE   r   r   r   r.   r.   r/   ra   L  s    zcosine_gen._pdfc                 C   s(   t |}t|dk|fdd t j dS )Nr.  c                 S   s   t | t dt j  S r   )rE   r  r   r   rf  r.   r.   r/   rL  S  rM  z$cosine_gen._logpdf.<locals>.<lambda>r`  )rE   r   r   r[   rh  r.   r.   r/   r   P  s
    
zcosine_gen._logpdfc                 C   s
   t |S rC   r^   Z_cosine_cdfr   r.   r.   r/   rb   V  s    zcosine_gen._cdfc                 C   s   t | S rC   r  r   r.   r.   r/   rd   Y  s    zcosine_gen._sfc                 C   s
   t |S rC   r^   Z_cosine_invcdfr;   rT  r.   r.   r/   rg   \  s    zcosine_gen._ppfc                 C   s   t | S rC   r  r  r.   r.   r/   rh   _  s    zcosine_gen._isfc                 C   sJ   t jt j d d }dt jd d  dt jt j d d   }d	|d	|fS )
Nr  r   r2  r   Z         @r  rK   rm   r   )r;   r:  ro  r.   r.   r/   r   b  s    *zcosine_gen._statsc                 C   s   t dt j d S )Nr   rn   r   r\   r.   r.   r/   r   g  s    zcosine_gen._entropyNri   rj   rk   rl   r]   ra   r   rb   rd   rg   rh   r   r   r.   r.   r.   r/   r  4  s   r  cosinec                   @   sb   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )
dgamma_gena  A double gamma continuous random variable.

    The double gamma distribution is also known as the reflected gamma
    distribution [1]_.

    %(before_notes)s

    Notes
    -----
    The probability density function for `dgamma` is:

    .. math::

        f(x, a) = \frac{1}{2\Gamma(a)} |x|^{a-1} \exp(-|x|)

    for a real number :math:`x` and :math:`a > 0`. :math:`\Gamma` is the
    gamma function (`scipy.special.gamma`).

    `dgamma` takes ``a`` as a shape parameter for :math:`a`.

    %(after_notes)s

    References
    ----------
    .. [1] Johnson, Kotz, and Balakrishnan, "Continuous Univariate
           Distributions, Volume 1", Second Edition, John Wiley and Sons
           (1994).

    %(example)s

    c                 C   s   t dddtjfdgS r   rZ   r\   r.   r.   r/   r]     s    zdgamma_gen._shape_infoNc                 C   s2   |j |d}tj|||d}|t|dkdd S Nr   rB  ru   r   r.  )uniformrC  rD  rE   r  )r;   rp   r   r   uZgmr.   r.   r/   r     s    zdgamma_gen._rvsc                 C   s2   t |}ddt|  ||d   t|  S r   )absrc   rC  rE   r   r;   r`   rp   axr.   r.   r/   ra     s    zdgamma_gen._pdfc                 C   s0   t |}t|d || td t| S r   )r  rc   r   rE   r   r5  r  r.   r.   r/   r     s    zdgamma_gen._logpdfc              	   C   s0   t |dkddt||  dt||  S Nr   ru   )rE   r  rc   r  r  r   r.   r.   r/   rb     s    
zdgamma_gen._cdfc              
   C   s0   t |dkdt|| ddt||   S r  )rE   r  rc   r  r  r   r.   r.   r/   rd     s    
zdgamma_gen._sfc                 C   s   t j|td S Nru   )rS  rC  r   rE   r   r   r.   r.   r/   r     s    zdgamma_gen._entropyc              	   C   s0   t |dkt|d| d t|d|  S r   rE   r  rc   r  r  r   r.   r.   r/   rg     s    
zdgamma_gen._ppfc              	   C   s0   t |dkt|d| d  t|d| S r   r  r   r.   r.   r/   rh     s    
zdgamma_gen._isfc                 C   s,   ||d  }d|d|d |d  | d fS )Nrn   rm   r   r  r.   )r;   rp   r   r.   r.   r/   r     s    zdgamma_gen._stats)NN)ri   rj   rk   rl   r]   r   ra   r   rb   rd   r   rg   rh   r   r.   r.   r.   r/   r  n  s   
r  dgammac                   @   sj   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )dweibull_genav  A double Weibull continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `dweibull` is given by

    .. math::

        f(x, c) = c / 2 |x|^{c-1} \exp(-|x|^c)

    for a real number :math:`x` and :math:`c > 0`.

    `dweibull` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]     s    zdweibull_gen._shape_infoNc                 C   s2   |j |d}tj|||d}|t|dkdd S r  )r  weibull_minrD  rE   r  )r;   rf  r   r   r  wr.   r.   r/   r     s    zdweibull_gen._rvsc                 C   s0   t |}|d ||d   t||   }|S Nr   rn   )r  rE   r   )r;   r`   rf  r  Pxr.   r.   r/   ra     s    $zdweibull_gen._pdfc                 C   s4   t |}t|td t|d | ||  S r  )r  rE   r   rc   r   )r;   r`   rf  r  r.   r.   r/   r     s    zdweibull_gen._logpdfc                 C   s.   dt t||   }t |dkd| |S Nru   r   r   )rE   r   r  r  )r;   r`   rf  ZCx1r.   r.   r/   rb     s    zdweibull_gen._cdfc                 C   sF   dt |dk|d|  }t t | d| }t |dk|| S Nr   ru   rn   )rE   r  r  r   )r;   rf   rf  r  r.   r.   r/   rg     s    zdweibull_gen._ppfc                 C   s.   dt jt|| }t|dk|d| S r  )rS  r  rd   rE   r  r  )r;   r`   rf  Zhalf_weibull_min_sfr.   r.   r/   rd     s    zdweibull_gen._sfc                 C   s<   dt |dk|d|  }tj||}t |dk| |S r  )rE   r  rS  r  rh   )r;   rf   rf  Zdouble_qZweibull_min_isfr.   r.   r/   rh     s    zdweibull_gen._isfc                 C   s"   d|d  t dd| |   S )Nr   rK   rn   rc   rC  r  r.   r.   r/   r     s    zdweibull_gen._munpc                 C   s   dS N)r   Nr   Nr.   r  r.   r.   r/   r     s    zdweibull_gen._statsc                 C   s   t j|td }|S r  )rS  r  r   rE   r   )r;   rf  r  r.   r.   r/   r     s    zdweibull_gen._entropy)NN)ri   rj   rk   rl   r]   r   ra   r   rb   rg   rd   rh   r   r   r   r.   r.   r.   r/   r    s   
r  dweibullc                   @   s   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zeeedddd ZdS )	expon_genaE  An exponential continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `expon` is:

    .. math::

        f(x) = \exp(-x)

    for :math:`x \ge 0`.

    %(after_notes)s

    A common parameterization for `expon` is in terms of the rate parameter
    ``lambda``, such that ``pdf = lambda * exp(-lambda * x)``. This
    parameterization corresponds to using ``scale = 1 / lambda``.

    The exponential distribution is a special case of the gamma
    distributions, with gamma shape parameter ``a = 1``.

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   $  s    zexpon_gen._shape_infoNc                 C   s
   | |S rC   )standard_exponentialr   r.   r.   r/   r   '  s    zexpon_gen._rvsc                 C   s   t | S rC   rE   r   r   r.   r.   r/   ra   *  s    zexpon_gen._pdfc                 C   s   | S rC   r.   r   r.   r.   r/   r   .  s    zexpon_gen._logpdfc                 C   s   t |  S rC   rc   rj  r   r.   r.   r/   rb   1  s    zexpon_gen._cdfc                 C   s   t |  S rC   rg  r   r.   r.   r/   rg   4  s    zexpon_gen._ppfc                 C   s   t | S rC   r  r   r.   r.   r/   rd   7  s    zexpon_gen._sfc                 C   s   | S rC   r.   r   r.   r.   r/   r   :  s    zexpon_gen._logsfc                 C   s   t | S rC   r   r   r.   r.   r/   rh   =  s    zexpon_gen._isfc                 C   s   dS )N)rn   rn   r         @r.   r\   r.   r.   r/   r   @  s    zexpon_gen._statsc                 C   s   dS r   r.   r\   r.   r.   r/   r   C  s    zexpon_gen._entropyz        When `method='MLE'`,
        this function uses explicit formulas for the maximum likelihood
        estimation of the exponential distribution parameters, so the
        `optimizer`, `loc` and `scale` keyword arguments are
        ignored.

r   c           	      O   s   t |dkrtd|dd }|dd }t| |d urL|d urLtdt|}t| sltd|	 }|d u r|}n|}||k rt
d|tjd|d u r| | }n|}t|t|fS )	Nr   Too many arguments.r   r   r   r   exponr  )r  r,   r+   r0   r   rE   r   r   r   minr   r[   r   float	r;   r<   r=   r-   r   r   data_minr'   r(   r.   r.   r/   r9   F  s(    
zexpon_gen.fit)NN)ri   rj   rk   rl   r]   r   ra   r   rb   rg   rd   r   rh   r   r   rB   r   r   r9   r.   r.   r.   r/   r  	  s   

r  r  c                   @   sJ   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dS )exponnorm_gena  An exponentially modified Normal continuous random variable.

    Also known as the exponentially modified Gaussian distribution [1]_.

    %(before_notes)s

    Notes
    -----
    The probability density function for `exponnorm` is:

    .. math::

        f(x, K) = \frac{1}{2K} \exp\left(\frac{1}{2 K^2} - x / K \right)
                  \text{erfc}\left(-\frac{x - 1/K}{\sqrt{2}}\right)

    where :math:`x` is a real number and :math:`K > 0`.

    It can be thought of as the sum of a standard normal random variable
    and an independent exponentially distributed random variable with rate
    ``1/K``.

    %(after_notes)s

    An alternative parameterization of this distribution (for example, in
    the Wikipedia article [1]_) involves three parameters, :math:`\mu`,
    :math:`\lambda` and :math:`\sigma`.

    In the present parameterization this corresponds to having ``loc`` and
    ``scale`` equal to :math:`\mu` and :math:`\sigma`, respectively, and
    shape parameter :math:`K = 1/(\sigma\lambda)`.

    .. versionadded:: 0.16.0

    References
    ----------
    .. [1] Exponentially modified Gaussian distribution, Wikipedia,
           https://en.wikipedia.org/wiki/Exponentially_modified_Gaussian_distribution

    %(example)s

    c                 C   s   t dddtjfdgS )NKFr   r   rZ   r\   r.   r.   r/   r]     s    zexponnorm_gen._shape_infoNc                 C   s    | || }||}|| S rC   )r  r   )r;   r  r   r   expvalZgvalr.   r.   r/   r     s    
zexponnorm_gen._rvsc                 C   s   t | ||S rC   rG  )r;   r`   r  r.   r.   r/   ra     s    zexponnorm_gen._pdfc                 C   s2   d| }|d| |  }|t ||  t| S Nrn   ru   r   rE   r   )r;   r`   r  invKZexpargr.   r.   r/   r     s    zexponnorm_gen._logpdfc                 C   s:   d| }|d| |  }|t ||  }t|t| S r
  r   r   rE   r   r;   r`   r  r  r	  Zlogprodr.   r.   r/   rb     s    zexponnorm_gen._cdfc                 C   s<   d| }|d| |  }|t ||  }t| t| S r
  r  r  r.   r.   r/   rd     s    zexponnorm_gen._sfc                 C   sD   || }d| }d|d  |d  }d| | |d  }||||fS )Nrn   rK   r  r   r   r   r.   )r;   r  ZK2ZopK2ZskwZkrtr.   r.   r/   r     s
    zexponnorm_gen._stats)NN)ri   rj   rk   rl   r]   r   ra   r   rb   rd   r   r.   r.   r.   r/   r  y  s   )
r  	exponnormc                 C   s   t t|| S )a'  
    Compute (1 + x)**y - 1.

    Uses expm1 and xlog1py to avoid loss of precision when
    (1 + x)**y is close to 1.

    Note that the inverse of this function with respect to x is
    ``_pow1pm1(x, 1/y)``.  That is, if

        t = _pow1pm1(x, y)

    then

        x = _pow1pm1(t, 1/y)
    )rE   rj  rc   r   r`   yr.   r.   r/   _pow1pm1  s    r  c                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )exponweib_gena  An exponentiated Weibull continuous random variable.

    %(before_notes)s

    See Also
    --------
    weibull_min, numpy.random.Generator.weibull

    Notes
    -----
    The probability density function for `exponweib` is:

    .. math::

        f(x, a, c) = a c [1-\exp(-x^c)]^{a-1} \exp(-x^c) x^{c-1}

    and its cumulative distribution function is:

    .. math::

        F(x, a, c) = [1-\exp(-x^c)]^a

    for :math:`x > 0`, :math:`a > 0`, :math:`c > 0`.

    `exponweib` takes :math:`a` and :math:`c` as shape parameters:

    * :math:`a` is the exponentiation parameter,
      with the special case :math:`a=1` corresponding to the
      (non-exponentiated) Weibull distribution `weibull_min`.
    * :math:`c` is the shape parameter of the non-exponentiated Weibull law.

    %(after_notes)s

    References
    ----------
    https://en.wikipedia.org/wiki/Exponentiated_Weibull_distribution

    %(example)s

    c                 C   s0   t dddtjfd}t dddtjfd}||gS Nrp   Fr   r   rf  rZ   r;   r   rx  r.   r.   r/   r]     s    zexponweib_gen._shape_infoc                 C   s   t | |||S rC   rG  r;   r`   rp   rf  r.   r.   r/   ra     s    zexponweib_gen._pdfc                 C   sR   ||  }t | }t|t| t |d | | t |d | }|S r   )rc   rj  rE   r   r   )r;   r`   rp   rf  Znegxcexm1cZlogpr.   r.   r/   r     s    
"zexponweib_gen._logpdfc                 C   s   t ||   }|| S rC   r  )r;   r`   rp   rf  r  r.   r.   r/   rb     s    zexponweib_gen._cdfc                 C   s$   t |d|    td|  S r   )rc   r  rE   r   )r;   rf   rp   rf  r.   r.   r/   rg     s    zexponweib_gen._ppfc                 C   s   t t||   | S rC   )r  rE   r   r  r.   r.   r/   rd     s    zexponweib_gen._sfc                 C   s"   t t| d|   d|  S rR   )rE   r   r  )r;   rT  rp   rf  r.   r.   r/   rh   !  s    zexponweib_gen._isfNri   rj   rk   rl   r]   ra   r   rb   rg   rd   rh   r.   r.   r.   r/   r    s   (r  	exponweibc                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )exponpow_gena  An exponential power continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `exponpow` is:

    .. math::

        f(x, b) = b x^{b-1} \exp(1 + x^b - \exp(x^b))

    for :math:`x \ge 0`, :math:`b > 0`.  Note that this is a different
    distribution from the exponential power distribution that is also known
    under the names "generalized normal" or "generalized Gaussian".

    `exponpow` takes ``b`` as a shape parameter for :math:`b`.

    %(after_notes)s

    References
    ----------
    http://www.math.wm.edu/~leemis/chart/UDR/PDFs/Exponentialpower.pdf

    %(example)s

    c                 C   s   t dddtjfdgS Nrq   Fr   r   rZ   r\   r.   r.   r/   r]   D  s    zexponpow_gen._shape_infoc                 C   s   t | ||S rC   rG  r;   r`   rq   r.   r.   r/   ra   G  s    zexponpow_gen._pdfc                 C   s8   || }dt | t|d | | t | }|S Nr   rn   )rE   r   rc   r   r   )r;   r`   rq   xbfr.   r.   r/   r   K  s    ,zexponpow_gen._logpdfc                 C   s   t t ||   S rC   r  r  r.   r.   r/   rb   P  s    zexponpow_gen._cdfc                 C   s   t t||  S rC   rE   r   rc   rj  r  r.   r.   r/   rd   S  s    zexponpow_gen._sfc                 C   s   t t| d|  S r   rc   r  rE   r   r  r.   r.   r/   rh   V  s    zexponpow_gen._isfc                 C   s   t tt|  d| S r   powrc   r  r;   rf   rq   r.   r.   r/   rg   Y  s    zexponpow_gen._ppfN)ri   rj   rk   rl   r]   ra   r   rb   rd   rh   rg   r.   r.   r.   r/   r  (  s   r  exponpowc                   @   s`   e Zd ZdZejZdd ZdddZdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd ZdS )fatiguelife_gena0  A fatigue-life (Birnbaum-Saunders) continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `fatiguelife` is:

    .. math::

        f(x, c) = \frac{x+1}{2c\sqrt{2\pi x^3}} \exp(-\frac{(x-1)^2}{2x c^2})

    for :math:`x >= 0` and :math:`c > 0`.

    `fatiguelife` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    References
    ----------
    .. [1] "Birnbaum-Saunders distribution",
           https://en.wikipedia.org/wiki/Birnbaum-Saunders_distribution

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]   }  s    zfatiguelife_gen._shape_infoNc                 C   sD   | |}d| | }|| }dd|  d| td|   }|S )Nru   rn   rK   r   )r   rE   r   )r;   rf  r   r   zr`   x2tr.   r.   r/   r     s
    
"zfatiguelife_gen._rvsc                 C   s   t | ||S rC   rG  rh  r.   r.   r/   ra     s    zfatiguelife_gen._pdfc                 C   sZ   t |d |d d d| |d    t d|  dt dt j dt |    S )Nr   rK   r   ru   r  r   rh  r.   r.   r/   r     s    6 zfatiguelife_gen._logpdfc                 C   s$   t d| t|dt|   S r   )r   rE   r   rh  r.   r.   r/   rb     s    zfatiguelife_gen._cdfc                 C   s*   |t | }d|t|d d  d  S N      ?rK   r   r   rE   r   r;   rf   rf  tmpr.   r.   r/   rg     s    zfatiguelife_gen._ppfc                 C   s$   t d| t|dt|   S r   )r   rE   r   rh  r.   r.   r/   rd     s    zfatiguelife_gen._sfc                 C   s,   | t | }d|t|d d  d  S r*  r,  r-  r.   r.   r/   rh     s    zfatiguelife_gen._isfc                 C   st   || }|d d }d| d }|| d }d| d| d  t |d }d	| d
| d  |d  }||||fS )Nr   rn   r  r  r      r   r  r  ]   g      D@rE   r  )r;   rf  c2r   denr   r   r   r.   r.   r/   r     s     zfatiguelife_gen._stats)NN)ri   rj   rk   rl   r   r   r   r]   r   ra   r   rb   rg   rd   rh   r   r.   r.   r.   r/   r&  `  s   
r&  fatiguelifec                   @   sJ   e Zd ZdZdd Zdd ZdddZd	d
 Zdd Zdd Z	dd Z
dS )foldcauchy_genao  A folded Cauchy continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `foldcauchy` is:

    .. math::

        f(x, c) = \frac{1}{\pi (1+(x-c)^2)} + \frac{1}{\pi (1+(x+c)^2)}

    for :math:`x \ge 0` and :math:`c \ge 0`.

    `foldcauchy` takes ``c`` as a shape parameter for :math:`c`.

    %(example)s

    c                 C   s   |dkS Nr   r.   r  r.   r.   r/   rW     s    zfoldcauchy_gen._argcheckc                 C   s   t dddtjfdgS Nrf  Fr   rY   rZ   r\   r.   r.   r/   r]     s    zfoldcauchy_gen._shape_infoNc                 C   s   t tj|||dS )Nr'   r   r   )r  r  rD  r;   rf  r   r   r.   r.   r/   r     s    
zfoldcauchy_gen._rvsc                 C   s2   dt j dd|| d   dd|| d     S Nrn   r   rK   r   rh  r.   r.   r/   ra     s    zfoldcauchy_gen._pdfc                 C   s&   dt j t || t ||   S r   r  rh  r.   r.   r/   rb     s    zfoldcauchy_gen._cdfc                 C   s&   t d|| t d||  t j S rR   )rE   arctan2r   rh  r.   r.   r/   rd     s    zfoldcauchy_gen._sfc                 C   s   t jt jt jt jfS rC   r   r  r.   r.   r/   r     s    zfoldcauchy_gen._stats)NNri   rj   rk   rl   rW   r]   r   ra   rb   rd   r   r.   r.   r.   r/   r5    s   
r5  
foldcauchyc                   @   sZ   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )f_gena  An F continuous random variable.

    For the noncentral F distribution, see `ncf`.

    %(before_notes)s

    See Also
    --------
    ncf

    Notes
    -----
    The F distribution with :math:`df_1 > 0` and :math:`df_2 > 0` degrees of freedom is
    the distribution of the ratio of two independent chi-squared distributions with
    :math:`df_1` and :math:`df_2` degrees of freedom, after rescaling by
    :math:`df_2 / df_1`.
    
    The probability density function for `f` is:

    .. math::

        f(x, df_1, df_2) = \frac{df_2^{df_2/2} df_1^{df_1/2} x^{df_1 / 2-1}}
                                {(df_2+df_1 x)^{(df_1+df_2)/2}
                                 B(df_1/2, df_2/2)}

    for :math:`x > 0`.

    `f` accepts shape parameters ``dfn`` and ``dfd`` for :math:`df_1`, the degrees of
    freedom of the chi-squared distribution in the numerator, and :math:`df_2`, the
    degrees of freedom of the chi-squared distribution in the denominator, respectively.

    %(after_notes)s

    %(example)s

    c                 C   s0   t dddtjfd}t dddtjfd}||gS )NdfnFr   r   dfdrZ   )r;   ZidfnZidfdr.   r.   r/   r]   	  s    zf_gen._shape_infoNc                 C   s   | |||S rC   )r  )r;   r?  r@  r   r   r.   r.   r/   r   	  s    z
f_gen._rvsc                 C   s   t | |||S rC   rG  r;   r`   r?  r@  r.   r.   r/   ra   	  s    z
f_gen._pdfc                 C   s~   d| }d| }|d t | |d t |  t|d d | || d t |||   t|d |d   }|S Nrn   rK   r   )rE   r   rc   r   r   )r;   r`   r?  r@  rV   mr  r.   r.   r/   r   	  s    60zf_gen._logpdfc                 C   s   t |||S rC   )rc   ZfdtrrA  r.   r.   r/   rb   	  s    z
f_gen._cdfc                 C   s   t |||S rC   )rc   ZfdtrcrA  r.   r.   r/   rd    	  s    z	f_gen._sfc                 C   s   t |||S rC   )rc   Zfdtri)r;   rf   r?  r@  r.   r.   r/   rg   #	  s    z
f_gen._ppfc                 C   s   d| d|  }}|d |d |d |d f\}}}}t |dk||fdd tj}	t |d	k||||fd
d tj}
t |dk||||fdd tj}|td9 }t |dk|||fdd tj}|d9 }|	|
||fS )Nrn   r   r  r          @rK   c                 S   s   | | S rC   r.   )v2v2_2r.   r.   r/   rL  ,	  rM  zf_gen._stats.<locals>.<lambda>r   c                 S   s$   d| | | |  | |d  |  S r   r.   )v1rE  rF  v2_4r.   r.   r/   rL  1	  s    r  c                 S   s&   d|  | | t || | |    S r   r  )rG  rF  rH  v2_6r.   r.   r/   rL  7	  s    r   c                 S   s   d| |  |  | S )Nr   r.   )r   rI  v2_8r.   r.   r/   rL  >	  rM  r  )r   rE   r[   r   r   )r;   r?  r@  rG  rE  rF  rH  rI  rJ  r   r   r   r   r.   r.   r/   r   &	  s2    $zf_gen._statsc                 C   sn   d| }d| }d||  }t |t | t|| d| t|  d| t|  |t|  S r  )rE   r   rc   r   r   )r;   r?  r@  Zhalf_dfnZhalf_dfdZhalf_sumr.   r.   r/   r   D	  s    zf_gen._entropy)NN)ri   rj   rk   rl   r]   r   ra   r   rb   rd   rg   r   r   r.   r.   r.   r/   r>    s   $
r>  r  c                   @   sJ   e Zd ZdZdd Zdd ZdddZd	d
 Zdd Zdd Z	dd Z
dS )foldnorm_genaz  A folded normal continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `foldnorm` is:

    .. math::

        f(x, c) = \sqrt{2/\pi} cosh(c x) \exp(-\frac{x^2+c^2}{2})

    for :math:`x \ge 0` and :math:`c \ge 0`.

    `foldnorm` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    %(example)s

    c                 C   s   |dkS r6  r.   r  r.   r.   r/   rW   r	  s    zfoldnorm_gen._argcheckc                 C   s   t dddtjfdgS r7  rZ   r\   r.   r.   r/   r]   u	  s    zfoldnorm_gen._shape_infoNc                 C   s   t ||| S rC   r  r   r9  r.   r.   r/   r   x	  s    zfoldnorm_gen._rvsc                 C   s   t || t ||  S rC   r   rh  r.   r.   r/   ra   {	  s    zfoldnorm_gen._pdfc                 C   s2   t d}dt|| | t|| |   S r  )rE   r   rc   erf)r;   r`   rf  Zsqrt_twor.   r.   r/   rb   	  s    
zfoldnorm_gen._cdfc                 C   s   t || t ||  S rC   r   rh  r.   r.   r/   rd   	  s    zfoldnorm_gen._sfc                 C   s   || }t d| t dt j  }d| |t|t d   }|d ||  }d|| | ||  |  }|t |d }||d  d d| |  }|d|d	  d	|d   |d  7 }||d  d	 }||||fS )
N      r   rK   r   r  r   r  rD  r  )rE   r   r   r   rc   rM  r  )r;   rf  r2  Zexpfacr   r   r   r   r.   r.   r/   r   	  s     $zfoldnorm_gen._stats)NNr<  r.   r.   r.   r/   rK  \	  s   
rK  foldnormc                       s|   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zeedd fddZ  ZS )weibull_min_gena  Weibull minimum continuous random variable.

    The Weibull Minimum Extreme Value distribution, from extreme value theory
    (Fisher-Gnedenko theorem), is also often simply called the Weibull
    distribution. It arises as the limiting distribution of the rescaled
    minimum of iid random variables.

    %(before_notes)s

    See Also
    --------
    weibull_max, numpy.random.Generator.weibull, exponweib

    Notes
    -----
    The probability density function for `weibull_min` is:

    .. math::

        f(x, c) = c x^{c-1} \exp(-x^c)

    for :math:`x > 0`, :math:`c > 0`.

    `weibull_min` takes ``c`` as a shape parameter for :math:`c`.
    (named :math:`k` in Wikipedia article and :math:`a` in
    ``numpy.random.weibull``).  Special shape values are :math:`c=1` and
    :math:`c=2` where Weibull distribution reduces to the `expon` and
    `rayleigh` distributions respectively.

    Suppose ``X`` is an exponentially distributed random variable with
    scale ``s``. Then ``Y = X**k`` is `weibull_min` distributed with shape
    ``c = 1/k`` and scale ``s**k``.

    %(after_notes)s

    References
    ----------
    https://en.wikipedia.org/wiki/Weibull_distribution

    https://en.wikipedia.org/wiki/Fisher-Tippett-Gnedenko_theorem

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]   	  s    zweibull_min_gen._shape_infoc                 C   s$   |t ||d  tt ||  S rR   r#  rE   r   rh  r.   r.   r/   ra   	  s    zweibull_min_gen._pdfc                 C   s$   t |t|d | t|| S rR   rE   r   rc   r   r#  rh  r.   r.   r/   r   	  s    zweibull_min_gen._logpdfc                 C   s   t t||  S rC   rc   rj  r#  rh  r.   r.   r/   rb   	  s    zweibull_min_gen._cdfc                 C   s   t t|  d| S r   r"  rk  r.   r.   r/   rg   	  s    zweibull_min_gen._ppfc                 C   s   t | ||S rC   r  rh  r.   r.   r/   rd   	  s    zweibull_min_gen._sfc                 C   s   t || S rC   r#  rh  r.   r.   r/   r   	  s    zweibull_min_gen._logsfc                 C   s   t | d|  S rR   r   rk  r.   r.   r/   rh   	  s    zweibull_min_gen._isfc                 C   s   t d|d |  S r   r  r  r.   r.   r/   r   	  s    zweibull_min_gen._munpc                 C   s   t  | t| t  d S rR   r   rE   r   r  r.   r.   r/   r   	  s    zweibull_min_gen._entropya          If ``method='mm'``, parameters fixed by the user are respected, and the
        remaining parameters are used to match distribution and sample moments
        where possible. For example, if the user fixes the location with
        ``floc``, the parameters will only match the distribution skewness and
        variance to the sample skewness and variance; no attempt will be made
        to match the means or minimize a norm of the errors.
        

r   c              	      s8  t |tr:| dkr | }nt j|g|R i |S |ddr`t j|g|R i |S t| |||\}}}}|dd	 }dd t
| d}|}	 |	k r|d	kr|d u r|st j|g|R i |S |d	krd
\}
}}n,t|r|d nd }
|dd }|dd }|d u rN|
d u rNt fddd|gddj}
n|d ur\|}
|d u r|d u rt|}t|tdd|
  tdd|
  d   }n|d ur|}|d u r|d u rt|}||tdd|
    }n|d ur|}|d	kr|
||fS t j||
f||d|S d S )Nr   superfitFr*   r1   c                 S   sj   t dd|   }t dd|   }t dd|   }d|d  d| |  | }||d  d }|| S )Nr   rK   r  r  r  )rf  Zgamma1Zgamma2Zgamma3numr3  r.   r.   r/   skew
  s    z!weibull_min_gen.fit.<locals>.skewg     @r2   NNNr'   r(   c                    s   |   S rC   r.   r  rm  rX  r.   r/   rL  %
  rM  z%weibull_min_gen.fit.<locals>.<lambda>g{Gz?bisect)bracketr*   r   rK   r'   r(   )r5   r$   r6   r
  r7   r9   r+   _check_fit_input_parametersr3   r4   rS  rX  r  r%   rootrE   r  r   rc   rC  r   )r;   r<   r=   r-   fcr   r   r*   Zmax_cZs_minrf  r'   r(   r:  rC  r  rZ  r/   r9   	  sP    






4




zweibull_min_gen.fit)ri   rj   rk   rl   r]   ra   r   rb   rg   rd   r   rh   r   r   r   r   r9   r?  r.   r.   r  r/   rP  	  s   ,
rP  r  c                       s   e Zd ZdZdd Zdd Z fddZdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Z  ZS )truncweibull_min_gena9  A doubly truncated Weibull minimum continuous random variable.

    %(before_notes)s

    See Also
    --------
    weibull_min, truncexpon

    Notes
    -----
    The probability density function for `truncweibull_min` is:

    .. math::

        f(x, a, b, c) = \frac{c x^{c-1} \exp(-x^c)}{\exp(-a^c) - \exp(-b^c)}

    for :math:`a < x <= b`, :math:`0 \le a < b` and :math:`c > 0`.

    `truncweibull_min` takes :math:`a`, :math:`b`, and :math:`c` as shape
    parameters.

    Notice that the truncation values, :math:`a` and :math:`b`, are defined in
    standardized form:

    .. math::

        a = (u_l - loc)/scale
        b = (u_r - loc)/scale

    where :math:`u_l` and :math:`u_r` are the specific left and right
    truncation values, respectively. In other words, the support of the
    distribution becomes :math:`(a*scale + loc) < x <= (b*scale + loc)` when
    :math:`loc` and/or :math:`scale` are provided.

    %(after_notes)s

    References
    ----------

    .. [1] Rinne, H. "The Weibull Distribution: A Handbook". CRC Press (2009).

    %(example)s

    c                 C   s   |dk||k@ |dk@ S Nrm   r.   r;   rf  rp   rq   r.   r.   r/   rW   n
  s    ztruncweibull_min_gen._argcheckc                 C   sF   t dddtjfd}t dddtjfd}t dddtjfd}|||gS )Nrf  Fr   r   rp   rY   rq   rZ   )r;   rx  r   r   r.   r.   r/   r]   q
  s    z truncweibull_min_gen._shape_infoc                    s   t  j|ddS )N)r   r   r   r   r7   r  r;   r<   r  r.   r/   r  w
  s    ztruncweibull_min_gen._fitstartc                 C   s   ||fS rC   r.   rc  r.   r.   r/   rv   {
  s    z!truncweibull_min_gen._get_supportc                 C   sL   t t|| t t||  }|t||d  t t||  | S rR   rE   r   r#  )r;   r`   rf  rp   rq   denumr.   r.   r/   ra   ~
  s    $ztruncweibull_min_gen._pdfc                 C   sR   t t t|| t t||  }t |t|d | t|| | S rR   )rE   r   r   r#  rc   r   )r;   r`   rf  rp   rq   logdenumr.   r.   r/   r   
  s    *ztruncweibull_min_gen._logpdfc                 C   sP   t t|| t t||  }t t|| t t||  }|| S rC   rf  r;   r`   rf  rp   rq   rW  rg  r.   r.   r/   rb   
  s    $$ztruncweibull_min_gen._cdfc                 C   s\   t t t|| t t||  }t t t|| t t||  }|| S rC   rE   r   r   r#  r;   r`   rf  rp   rq   Zlognumrh  r.   r.   r/   r   
  s    **ztruncweibull_min_gen._logcdfc                 C   sP   t t|| t t||  }t t|| t t||  }|| S rC   rf  ri  r.   r.   r/   rd   
  s    $$ztruncweibull_min_gen._sfc                 C   s\   t t t|| t t||  }t t t|| t t||  }|| S rC   rj  rk  r.   r.   r/   r   
  s    **ztruncweibull_min_gen._logsfc              
   C   sB   t td| tt ||  |tt ||    d| S rR   r#  rE   r   r   r;   rf   rf  rp   rq   r.   r.   r/   rh   
  s    <ztruncweibull_min_gen._isfc              
   C   sB   t td| tt ||  |tt ||    d| S rR   rl  rm  r.   r.   r/   rg   
  s    <ztruncweibull_min_gen._ppfc                 C   sr   t || d t || d t||t || d t||  }tt|| tt||  }|| S r   )rc   rC  r  r#  rE   r   )r;   rV   rf  rp   rq   Z	gamma_funrg  r.   r.   r/   r   
  s
    2$ztruncweibull_min_gen._munp)ri   rj   rk   rl   rW   r]   r  rv   ra   r   rb   r   rd   r   rh   rg   r   r?  r.   r.   r  r/   ra  A
  s   ,ra  truncweibull_minc                   @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdS )weibull_max_gena0  Weibull maximum continuous random variable.

    The Weibull Maximum Extreme Value distribution, from extreme value theory
    (Fisher-Gnedenko theorem), is the limiting distribution of rescaled
    maximum of iid random variables. This is the distribution of -X
    if X is from the `weibull_min` function.

    %(before_notes)s

    See Also
    --------
    weibull_min

    Notes
    -----
    The probability density function for `weibull_max` is:

    .. math::

        f(x, c) = c (-x)^{c-1} \exp(-(-x)^c)

    for :math:`x < 0`, :math:`c > 0`.

    `weibull_max` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    References
    ----------
    https://en.wikipedia.org/wiki/Weibull_distribution

    https://en.wikipedia.org/wiki/Fisher-Tippett-Gnedenko_theorem

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]   
  s    zweibull_max_gen._shape_infoc                 C   s(   |t | |d  tt | |  S rR   rQ  rh  r.   r.   r/   ra   
  s    zweibull_max_gen._pdfc                 C   s(   t |t|d |  t| | S rR   rR  rh  r.   r.   r/   r   
  s    zweibull_max_gen._logpdfc                 C   s   t t| | S rC   rf  rh  r.   r.   r/   rb   
  s    zweibull_max_gen._cdfc                 C   s   t | | S rC   rT  rh  r.   r.   r/   r   
  s    zweibull_max_gen._logcdfc                 C   s   t t| |  S rC   rS  rh  r.   r.   r/   rd   
  s    zweibull_max_gen._sfc                 C   s   t t| d|  S r   )r#  rE   r   rk  r.   r.   r/   rg   
  s    zweibull_max_gen._ppfc                 C   s4   t d|d |  }t|d r(d}nd}|| S )Nrn   rK   r.  r   )rc   rC  r9  )r;   rV   rf  valsgnr.   r.   r/   r   
  s
    zweibull_max_gen._munpc                 C   s   t  | t| t  d S rR   rU  r  r.   r.   r/   r   
  s    zweibull_max_gen._entropyN)ri   rj   rk   rl   r]   ra   r   rb   r   rd   rg   r   r   r.   r.   r.   r/   ro  
  s   $ro  weibull_max)rq   rr   c                   @   s`   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdS )genlogistic_gena  A generalized logistic continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `genlogistic` is:

    .. math::

        f(x, c) = c \frac{\exp(-x)}
                         {(1 + \exp(-x))^{c+1}}

    for real :math:`x` and :math:`c > 0`. In literature, different
    generalizations of the logistic distribution can be found. This is the type 1
    generalized logistic distribution according to [1]_. It is also referred to
    as the skew-logistic distribution [2]_.

    `genlogistic` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    References
    ----------
    .. [1] Johnson et al. "Continuous Univariate Distributions", Volume 2,
           Wiley. 1995.
    .. [2] "Generalized Logistic Distribution", Wikipedia,
           https://en.wikipedia.org/wiki/Generalized_logistic_distribution

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]     s    zgenlogistic_gen._shape_infoc                 C   s   t | ||S rC   rG  rh  r.   r.   r/   ra     s    zgenlogistic_gen._pdfc                 C   sL   |d  |dk  d }t |}t |||  |d tt |   S Nr   r   )rE   r  r   rc   r  r   )r;   r`   rf  ZmultZabsxr.   r.   r/   r   !  s    
zgenlogistic_gen._logpdfc                 C   s   dt |  |  }|S rR   r  )r;   r`   rf  ZCxr.   r.   r/   rb   )  s    zgenlogistic_gen._cdfc                 C   s   | t t |  S rC   )rE   r  r   rh  r.   r.   r/   r   -  s    zgenlogistic_gen._logcdfc                 C   s   t t|d|  S r  )rE   r   rc   powm1rk  r.   r.   r/   rg   0  s    zgenlogistic_gen._ppfc                 C   s   t | || S rC   rc   rj  r   rh  r.   r.   r/   rd   3  s    zgenlogistic_gen._sfc                 C   s   |  d| |S rR   rg   rk  r.   r.   r/   rh   6  s    zgenlogistic_gen._isfc                 C   s   t t| }tjtj d td| }dtd| dt  }|t|d }tjd d dtd|  }||d	  }||||fS )
Nr   rK   r   r  r  r         .@r  r   )r   rc   r   rE   r   zetar    r  r;   rf  r   r   r   r   r.   r.   r/   r   9  s    zgenlogistic_gen._statsc                 C   s   t |dk |fdd dd dS )Ng    ^Ac                 S   s"   t |  t| d  t d S rR   )rE   r   rc   r   r   r  r.   r.   r/   rL  D  rM  z*genlogistic_gen._entropy.<locals>.<lambda>c                 S   s   dd|   t  d S r   r   r  r.   r.   r/   rL  J  rM  rO  rQ  r  r.   r.   r/   r   B  s    zgenlogistic_gen._entropyN)ri   rj   rk   rl   r]   ra   r   rb   r   rg   rd   rh   r   r   r.   r.   r.   r/   rs  
  s    	rs  genlogisticc                   @   sz   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdddZdd Zdd ZdS )genpareto_gena  A generalized Pareto continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `genpareto` is:

    .. math::

        f(x, c) = (1 + c x)^{-1 - 1/c}

    defined for :math:`x \ge 0` if :math:`c \ge 0`, and for
    :math:`0 \le x \le -1/c` if :math:`c < 0`.

    `genpareto` takes ``c`` as a shape parameter for :math:`c`.

    For :math:`c=0`, `genpareto` reduces to the exponential
    distribution, `expon`:

    .. math::

        f(x, 0) = \exp(-x)

    For :math:`c=-1`, `genpareto` is uniform on ``[0, 1]``:

    .. math::

        f(x, -1) = 1

    %(after_notes)s

    %(example)s

    c                 C   s
   t |S rC   rE   r   r  r.   r.   r/   rW   t  s    zgenpareto_gen._argcheckc                 C   s   t ddtj tjfdgS Nrf  Fr   rZ   r\   r.   r.   r/   r]   w  s    zgenpareto_gen._shape_infoc                 C   sB   t |}t|dk |fdd t j}t |dk| j| j}||fS )Nr   c                 S   s   d|  S r  r.   r  r.   r.   r/   rL  }  rM  z,genpareto_gen._get_support.<locals>.<lambda>)rE   r   r   r[   r  rp   )r;   rf  rq   rp   r.   r.   r/   rv   z  s    
zgenpareto_gen._get_supportc                 C   s   t | ||S rC   rG  rh  r.   r.   r/   ra     s    zgenpareto_gen._pdfc                 C   s$   t ||k|dk@ ||fdd | S )Nr   c                 S   s   t |d ||   | S r   r  r`   rf  r.   r.   r/   rL    rM  z'genpareto_gen._logpdf.<locals>.<lambda>rQ  rh  r.   r.   r/   r     s    zgenpareto_gen._logpdfc                 C   s   t | |  S rC   )rc   Zinv_boxcox1prh  r.   r.   r/   rb     s    zgenpareto_gen._cdfc                 C   s   t | | S rC   )rc   Z
inv_boxcoxrh  r.   r.   r/   rd     s    zgenpareto_gen._sfc                 C   s$   t ||k|dk@ ||fdd | S )Nr   c                 S   s   t ||   | S rC   rg  r  r.   r.   r/   rL    rM  z&genpareto_gen._logsf.<locals>.<lambda>rQ  rh  r.   r.   r/   r     s    zgenpareto_gen._logsfc                 C   s   t | |  S rC   )rc   boxcox1prk  r.   r.   r/   rg     s    zgenpareto_gen._ppfc                 C   s   t ||  S rC   )rc   boxcoxrk  r.   r.   r/   rh     s    zgenpareto_gen._isfrl  c                 C   s   d|vrd }nt |dk |fdd tj}d|vr6d }nt |dk |fdd tj}d|vr^d }nt |d	k |fd
d tj}d|vrd }nt |dk |fdd tj}||||fS )NrC  r   c                 S   s   dd|   S rR   r.   xir.   r.   r/   rL    rM  z&genpareto_gen._stats.<locals>.<lambda>r:  ru   c                 S   s   dd|  d  dd|    S r   r.   r  r.   r.   r/   rL    rM  rm  gUUUUUU?c                 S   s*   dd|   t dd|    dd|    S )NrK   r   r  r  r  r.   r.   r/   rL    s   
ro  r+  c                 S   s@   ddd|    d| d  |  d  dd|    dd|    d S )Nr  r   rK   r   r.   r  r.   r.   r/   rL    s   "

r   rE   r[   r   )r;   rf  rr  rC  r:  rm  ro  r.   r.   r/   r     s2    zgenpareto_gen._statsc                    s0   dd  t |dk|f fddtd S )Nc                 S   sp   d}t d| d }t|t| |D ]$\}}||d|  d||    }q&t ||  dk |d| |   t jS )Nrm   r   r   r.  rn   r  )rE   r  ziprc   combr  r[   )rV   rf  rp  ro  ZkiZcnkr.   r.   r/   r    s
    z#genpareto_gen._munp.<locals>.__munpr   c                    s
    | S rC   r.   r  Z_genpareto_gen__munprV   r.   r/   rL    rM  z%genpareto_gen._munp.<locals>.<lambda>r   )r   rc   rC  r  r.   r  r/   r     s
    zgenpareto_gen._munpc                 C   s   d| S r   r.   r  r.   r.   r/   r     s    zgenpareto_gen._entropyN)rl  )ri   rj   rk   rl   rW   r]   rv   ra   r   rb   rd   r   rg   rh   r   r   r   r.   r.   r.   r/   r}  P  s   #
r}  	genparetoc                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )genexpon_gena!  A generalized exponential continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `genexpon` is:

    .. math::

        f(x, a, b, c) = (a + b (1 - \exp(-c x)))
                        \exp(-a x - b x + \frac{b}{c}  (1-\exp(-c x)))

    for :math:`x \ge 0`, :math:`a, b, c > 0`.

    `genexpon` takes :math:`a`, :math:`b` and :math:`c` as shape parameters.

    %(after_notes)s

    References
    ----------
    H.K. Ryu, "An Extension of Marshall and Olkin's Bivariate Exponential
    Distribution", Journal of the American Statistical Association, 1993.

    N. Balakrishnan, Asit P. Basu (editors), *The Exponential Distribution:
    Theory, Methods and Applications*, Gordon and Breach, 1995.
    ISBN 10: 2884491929

    %(example)s

    c                 C   sF   t dddtjfd}t dddtjfd}t dddtjfd}|||gS )Nrp   Fr   r   rq   rf  rZ   )r;   r   r   rx  r.   r.   r/   r]     s    zgenexpon_gen._shape_infoc              	   C   sH   ||t | |    t| | | |t | |   |   S rC   rc   rj  rE   r   r;   r`   rp   rq   rf  r.   r.   r/   ra     s    (zgenexpon_gen._pdfc                 C   sH   t ||t| |    | | |  |t| |   |  S rC   rE   r   rc   rj  r  r.   r.   r/   r     s    zgenexpon_gen._logpdfc                 C   s0   t | | | |t | |   |   S rC   r  r  r.   r.   r/   rb     s    zgenexpon_gen._cdfc                 C   sF   || }||t |   | }|t| | t |  j | S rC   )rE   r  rc   lambertwr   realr;   rT  rp   rq   rf  rm  r)  r.   r.   r/   rg     s    zgenexpon_gen._ppfc                 C   s.   t | | | |t| |   |  S rC   r   r  r.   r.   r/   rd     s    zgenexpon_gen._sfc                 C   sD   || }||t |  | }|t| | t |  j | S rC   )rE   r   rc   r  r   r  r  r.   r.   r/   rh     s    zgenexpon_gen._isfNr  r.   r.   r.   r/   r    s   r  genexponc                       s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Z fddZdd Zdd Z  ZS ) genextreme_genaB  A generalized extreme value continuous random variable.

    %(before_notes)s

    See Also
    --------
    gumbel_r

    Notes
    -----
    For :math:`c=0`, `genextreme` is equal to `gumbel_r` with
    probability density function

    .. math::

        f(x) = \exp(-\exp(-x)) \exp(-x),

    where :math:`-\infty < x < \infty`.

    For :math:`c \ne 0`, the probability density function for `genextreme` is:

    .. math::

        f(x, c) = \exp(-(1-c x)^{1/c}) (1-c x)^{1/c-1},

    where :math:`-\infty < x \le 1/c` if :math:`c > 0` and
    :math:`1/c \le x < \infty` if :math:`c < 0`.

    Note that several sources and software packages use the opposite
    convention for the sign of the shape parameter :math:`c`.

    `genextreme` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    %(example)s

    c                 C   s
   t |S rC   r~  r  r.   r.   r/   rW   5  s    zgenextreme_gen._argcheckc                 C   s   t ddtj tjfdgS r  rZ   r\   r.   r.   r/   r]   8  s    zgenextreme_gen._shape_infoc                 C   sL   t |dkdt |t t j}t |dk dt |t  t j }||fS Nr   rn   )rE   r  maximumr   r[   minimum)r;   rf  _b_ar.   r.   r/   rv   ;  s     $zgenextreme_gen._get_supportc                 C   s$   t ||k|dk@ ||fdd | S )Nr   c                 S   s   t | |  | S rC   rg  r  r.   r.   r/   rL  C  rM  z+genextreme_gen._loglogcdf.<locals>.<lambda>rQ  rh  r.   r.   r/   
_loglogcdf@  s    
zgenextreme_gen._loglogcdfc                 C   s   t | ||S rC   rG  rh  r.   r.   r/   ra   E  s    zgenextreme_gen._pdfc                 C   s   t ||k|dk@ ||fdd d}t| }| ||}t|}t||dk|tj k@ d t |dk|tj kB  |||fdd tj d}t||dk|dk@ d |S )Nr   c                 S   s   ||  S rC   r.   r  r.   r.   r/   rL  L  rM  z(genextreme_gen._logpdf.<locals>.<lambda>rm   r   c                 S   s   |  | | S rC   r.   )pex2Zlpex2Zlex2r.   r.   r/   rL  T  rM  r`  )r   rc   r  r  rE   r   Zputmaskr[   )r;   r`   rf  ZcxZlogex2Zlogpex2r  logpdfr.   r.   r/   r   K  s    "
zgenextreme_gen._logpdfc                 C   s   t | || S rC   )rE   r   r  rh  r.   r.   r/   r   Y  s    zgenextreme_gen._logcdfc                 C   s   t | ||S rC   rE   r   r   rh  r.   r.   r/   rb   \  s    zgenextreme_gen._cdfc                 C   s   t | || S rC   rv  rh  r.   r.   r/   rd   _  s    zgenextreme_gen._sfc                 C   s6   t t |  }t||k|dk@ ||fdd |S )Nr   c                 S   s   t | |   | S rC   r  r  r.   r.   r/   rL  e  rM  z%genextreme_gen._ppf.<locals>.<lambda>)rE   r   r   r;   rf   rf  r`   r.   r.   r/   rg   b  s    zgenextreme_gen._ppfc                 C   s8   t t|   }t||k|dk@ ||fdd |S )Nr   c                 S   s   t | |   | S rC   r  r  r.   r.   r/   rL  j  rM  z%genextreme_gen._isf.<locals>.<lambda>)rE   r   rc   r  r   r  r.   r.   r/   rh   g  s    zgenextreme_gen._isfc                    s   fdd}|d}|d}|d}|d}t t dk  t j d d	 ||d  }t t dk t jd d	 ttd  d
 dt d
    d  }d}	t t |	k t tt d   }
t  dk t j|
 }t  dk t j|d | }t	 dk ||||fdd t jd}t t |	d kdt 
d t t jd  |}t	 dk|||||fdd t jd}t t |	d kd|d }||||fS )Nc                    s   t |   d S rR   r  r_  r  r.   r/   gm  s    z genextreme_gen._stats.<locals>.gr   rK   r  r   gHz>r   r   rn   +=r  rN  r  c                 S   s(   t | | |d|  |   |d  S NrK   r  rD   )rf  r   r   g3g2mg12r.   r.   r/   rL    s    z'genextreme_gen._stats.<locals>.<lambda>r`  g(\?r/  r  g      пc                 S   s(   |d| d||  |   |   |d  S )Nr  r  rK   r.   )r   r   r  g4r  r.   r.   r/   rL    s    gq=
ףp?333333@r  )rE   r  r  r   rc   rj  r5  r   r   r   r   r    )r;   rf  r  r   r   r  r  r  Zgam2kZepsZgamkrC  r:  Zsk1r  Zku1r  r.   r  r/   r   l  s4    ,0,2zgenextreme_gen._statsc                    s>   t |tr| }t|}|dk r(d}nd}t j||fdS )Nr   ru   rN  r   r5   r$   r
  r   r7   r  )r;   r<   r  rp   r  r.   r/   r    s    
zgenextreme_gen._fitstartc                 C   sd   t d|d }d||  t jt||d|  t|| d  dd }t || dk|t jS )Nr   r   rn   r.  r\  )rE   r  r  rc   r  rC  r  r[   )r;   rV   rf  ro  valsr.   r.   r/   r     s    $zgenextreme_gen._munpc                 C   s   t d|  d S rR   r{  r  r.   r.   r/   r     s    zgenextreme_gen._entropy)ri   rj   rk   rl   rW   r]   rv   r  ra   r   r   rb   rd   rg   rh   r   r  r   r   r?  r.   r.   r  r/   r    s    &!r  
genextremec                    s   d} fdd} dkrDt  d } dk rntj||dd}|S n* d	kr`t  d
 d }nd  |  }tj||ddd\}}}}|dkrtd  |d S )af  Inverse of the digamma function (real positive arguments only).

    This function is used in the `fit` method of `gamma_gen`.
    The function uses either optimize.fsolve or optimize.newton
    to solve `sc.digamma(x) - y = 0`.  There is probably room for
    improvement, but currently it works over a wide range of y:

    >>> import numpy as np
    >>> rng = np.random.default_rng()
    >>> y = 64*rng.standard_normal(1000000)
    >>> y.min(), y.max()
    (-311.43592651416662, 351.77388222276869)
    >>> x = [_digammainv(t) for t in y]
    >>> np.abs(sc.digamma(x) - y).max()
    1.1368683772161603e-13

    gox?c                    s   t |   S rC   )rc   r  r   r  r.   r/   r     s    z_digammainv.<locals>.funcg      ru   r&  绽|=)Ztolr  g-@g뭁,?rn   dy=T)xtolr  r   z"_digammainv: fsolve failed, y = %rr   )rE   r   r   Znewtonr  RuntimeError)r  Z_emr   x0valuer  r  r   r.   r  r/   _digammainv  s     
r  c                       s   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Z fddZeedd fddZ  ZS )	gamma_gena  A gamma continuous random variable.

    %(before_notes)s

    See Also
    --------
    erlang, expon

    Notes
    -----
    The probability density function for `gamma` is:

    .. math::

        f(x, a) = \frac{x^{a-1} e^{-x}}{\Gamma(a)}

    for :math:`x \ge 0`, :math:`a > 0`. Here :math:`\Gamma(a)` refers to the
    gamma function.

    `gamma` takes ``a`` as a shape parameter for :math:`a`.

    When :math:`a` is an integer, `gamma` reduces to the Erlang
    distribution, and when :math:`a=1` to the exponential distribution.

    Gamma distributions are sometimes parameterized with two variables,
    with a probability density function of:

    .. math::

        f(x, \alpha, \beta) =
        \frac{\beta^\alpha x^{\alpha - 1} e^{-\beta x }}{\Gamma(\alpha)}

    Note that this parameterization is equivalent to the above, with
    ``scale = 1 / beta``.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS r   rZ   r\   r.   r.   r/   r]     s    zgamma_gen._shape_infoNc                 C   s   | ||S rC   standard_gamma)r;   rp   r   r   r.   r.   r/   r     s    zgamma_gen._rvsc                 C   s   t | ||S rC   rG  r   r.   r.   r/   ra     s    zgamma_gen._pdfc                 C   s   t |d || t | S r   )rc   r   r5  r   r.   r.   r/   r     s    zgamma_gen._logpdfc                 C   s   t ||S rC   r  r   r.   r.   r/   rb     s    zgamma_gen._cdfc                 C   s   t ||S rC   r  r   r.   r.   r/   rd     s    zgamma_gen._sfc                 C   s   t ||S rC   r  r   r.   r.   r/   rg     s    zgamma_gen._ppfc                 C   s   t ||S rC   rc   r  r   r.   r.   r/   rh     s    zgamma_gen._isfc                 C   s   ||dt | d| fS )Nr   r   r  r   r.   r.   r/   r     s    zgamma_gen._statsc                 C   s&   dd }dd }t |dk |f||dS )Nc                 S   s    t | d|   |  t |  S rR   rc   r   r5  rp   r.   r.   r/   r    s    z+gamma_gen._entropy.<locals>.regular_formulac                 S   sR   ddt dt j  t |   dd|    | d d  | d d	  | d
 d  S )Nru   rn   rK   r   r  r#  r/  r$  r  r%  r'  r   r  r.   r.   r/   r  "  s    ,


z.gamma_gen._entropy.<locals>.asymptotic_formula   rO  rQ  )r;   rp   r  r  r.   r.   r/   r     s
    zgamma_gen._entropyc                    s<   t |tr| }t|}dd|d   }t j||fdS )Nr   :0yE>rK   r   r  )r;   r<   r  rp   r  r.   r/   r  -  s
    
zgamma_gen._fitstarta<          When the location is fixed by using the argument `floc`
        and `method='MLE'`, this
        function uses explicit formulas or solves a simpler numerical
        problem than the full ML optimization problem.  So in that case,
        the `optimizer`, `loc` and `scale` arguments are ignored.
        

r   c                    s  | dd }| dd}t|ts6|d u rP| dkrPt j|g|R i |S |dd  t|g d}|dd }t| |d ur|d ur|d urt	dt
|}t
| st	d| dkrt
|}t
|}	t
|| d	 }
|||  }}}|d u r,|d u r,|d u r,|
d
|	  }|d u rN|d u rNt
|	| }|d u rn|d u rn|	||  }|d u r|d u r|	|d
  }|d u r|| | }|d u r|||  }|d u r|| | }|||fS t
||krtd|t
jd|dkr|| }| }|d u r|d ur.|}nlt
|t
|   d	  t
 d	 d
 d    d   }|d }|d }tj fdd||dd}|| }n$t
| t
| }t|}|}|||fS )Nr   r*   r1   r2   r  r   r   r   r  rK   rC  r  r   rp  r/  g333333?gffffff?c                    s   t | t|    S rC   )rE   r   rc   r  r  rm  r.   r/   rL    rM  zgamma_gen.fit.<locals>.<lambda>)Zdisp)r3   r5   r$   r4   r7   r9   r+   r   r0   r   rE   r   r   r   r   r  r   r  r   r[   r   r   brentqr  )r;   r<   r=   r-   r   r*   r  r   m1m2m3rp   r'   r(   r  ZaestZxar  rf  r  r  r/   r9   9  sr    











*
zgamma_gen.fit)NN)ri   rj   rk   rl   r]   r   ra   r   rb   rd   rg   rh   r   r   r  r   r   r9   r?  r.   r.   r  r/   r    s   (

r  rC  c                       sH   e Zd ZdZdd Zdd Z fddZeedd	 fd
dZ	  Z
S )
erlang_gena  An Erlang continuous random variable.

    %(before_notes)s

    See Also
    --------
    gamma

    Notes
    -----
    The Erlang distribution is a special case of the Gamma distribution, with
    the shape parameter `a` an integer.  Note that this restriction is not
    enforced by `erlang`. It will, however, generate a warning the first time
    a non-integer value is used for the shape parameter.

    Refer to `gamma` for examples.

    c                 C   s<   t t ||k}|s4d|d}tj|tdd |dkS )NzRThe shape parameter of the erlang distribution has been given a non-integer value .r  
stacklevelr   )rE   r   floorwarningswarnRuntimeWarning)r;   rp   Zallintmessager.   r.   r/   rW     s    zerlang_gen._argcheckc                 C   s   t dddtjfdgS )Nrp   Tr   rY   rZ   r\   r.   r.   r/   r]     s    zerlang_gen._shape_infoc                    s@   t |tr| }tddt|d   }tt| j||fdS )Nr  r  rK   r   )r5   r$   r
  r9  r   r7   r  r  )r;   r<   rp   r  r.   r/   r    s    
zerlang_gen._fitstarta          The Erlang distribution is generally defined to have integer values
        for the shape parameter.  This is not enforced by the `erlang` class.
        When fitting the distribution, it will generally return a non-integer
        value for the shape parameter.  By using the keyword argument
        `f0=<integer>`, the fit method can be constrained to fit the data to
        a specific integer shape parameter.r   c                    s   t  j|g|R i |S rC   )r7   r9   r;   r<   r=   r-   r  r.   r/   r9     s    zerlang_gen.fit)ri   rj   rk   rl   rW   r]   r  r   r   r9   r?  r.   r.   r  r/   r    s   

r  erlangc                   @   sj   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdddZ	dd Z
dd Zdd Zdd Zdd ZdS )gengamma_gena  A generalized gamma continuous random variable.

    %(before_notes)s

    See Also
    --------
    gamma, invgamma, weibull_min

    Notes
    -----
    The probability density function for `gengamma` is ([1]_):

    .. math::

        f(x, a, c) = \frac{|c| x^{c a-1} \exp(-x^c)}{\Gamma(a)}

    for :math:`x \ge 0`, :math:`a > 0`, and :math:`c \ne 0`.
    :math:`\Gamma` is the gamma function (`scipy.special.gamma`).

    `gengamma` takes :math:`a` and :math:`c` as shape parameters.

    %(after_notes)s

    References
    ----------
    .. [1] E.W. Stacy, "A Generalization of the Gamma Distribution",
       Annals of Mathematical Statistics, Vol 33(3), pp. 1187--1192.

    %(example)s

    c                 C   s   |dk|dk@ S r6  r.   )r;   rp   rf  r.   r.   r/   rW     s    zgengamma_gen._argcheckc                 C   s4   t dddtjfd}t ddtj tjfd}||gS r  rZ   r  r.   r.   r/   r]     s    zgengamma_gen._shape_infoc                 C   s   t | |||S rC   rG  r  r.   r.   r/   ra     s    zgengamma_gen._pdfc                    s,   t |dk|dkB ||f fddtj dS )Nr   c                    s4   t t|t|  d |  | |  t  S rR   )rE   r   r  rc   r   r5  r  r  r.   r/   rL    s    z&gengamma_gen._logpdf.<locals>.<lambda>r`  rb  r  r.   r  r/   r     s    
zgengamma_gen._logpdfc                 C   s2   || }t ||}t ||}t|dk||S r6  rc   r  r  rE   r  r;   r`   rp   rf  Zxcval1val2r.   r.   r/   rb     s    zgengamma_gen._cdfNc                 C   s   |j ||d}|d|  S )Nr  rn   r  )r;   rp   rf  r   r   rU  r.   r.   r/   r     s    zgengamma_gen._rvsc                 C   s2   || }t ||}t ||}t|dk||S r6  r  r  r.   r.   r/   rd      s    zgengamma_gen._sfc                 C   s2   t ||}t ||}t|dk||d|  S r  rc   r  r  rE   r  r;   rf   rp   rf  r  r  r.   r.   r/   rg   &  s    zgengamma_gen._ppfc                 C   s2   t ||}t ||}t|dk||d|  S r  r  r  r.   r.   r/   rh   +  s    zgengamma_gen._isfc                 C   s   t ||d | S r   )rc   r  )r;   rV   rp   rf  r.   r.   r/   r   0  s    zgengamma_gen._munpc                 C   s,   dd }dd }t |dk||f||d}|S )Nc                 S   sB   t | }| d|  ||  }t | tt| }|| }|S rR   )rc   r   r5  rE   r   r  )rp   rf  rp  ABr  r.   r.   r/   r   5  s
    
z&gengamma_gen._entropy.<locals>.regularc                 S   sp   t  t| d  tt| | d d  | d d  t| | d d  | d d  | d d	  |  S )
NrK   r  r  r$  r  r#  r/  r%  r'  )r   r   rE   r   r  )rp   rf  r.   r.   r/   
asymptotic<  s    

0z)gengamma_gen._entropy.<locals>.asymptotic      i@r  rP  rQ  )r;   rp   rf  r   r  r  r.   r.   r/   r   4  s    zgengamma_gen._entropy)NN)ri   rj   rk   rl   rW   r]   ra   r   rb   r   rd   rg   rh   r   r   r.   r.   r.   r/   r    s   
r  gengammac                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )genhalflogistic_gena  A generalized half-logistic continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `genhalflogistic` is:

    .. math::

        f(x, c) = \frac{2 (1 - c x)^{1/(c-1)}}{[1 + (1 - c x)^{1/c}]^2}

    for :math:`0 \le x \le 1/c`, and :math:`c > 0`.

    `genhalflogistic` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]   _  s    zgenhalflogistic_gen._shape_infoc                 C   s   | j d| fS r   r  r  r.   r.   r/   rv   b  s    z genhalflogistic_gen._get_supportc                 C   sB   d| }t d||  }||d  }|| }d| d| d  S r:  rE   r   )r;   r`   rf  limitr.  Ztmp0tmp2r.   r.   r/   ra   e  s
    zgenhalflogistic_gen._pdfc                 C   s2   d| }t d||  }|| }d| d|  S r{  r  )r;   r`   rf  r  r.  r  r.   r.   r/   rb   n  s    zgenhalflogistic_gen._cdfc                 C   s    d| dd| d|  |   S r{  r.   rk  r.   r.   r/   rg   t  s    zgenhalflogistic_gen._ppfc                 C   s   dd| d t d  S r  r   r  r.   r.   r/   r   w  s    zgenhalflogistic_gen._entropyN)
ri   rj   rk   rl   r]   rv   ra   rb   rg   r   r.   r.   r.   r/   r  I  s   	r  genhalflogisticc                       sv   e Zd ZdZdd Zdd Z fddZdd	 Zd
d Zdd e	dd Z
dd Zdd ZdddZdd Z  ZS )genhyperbolic_genu  A generalized hyperbolic continuous random variable.

    %(before_notes)s

    See Also
    --------
    t, norminvgauss, geninvgauss, laplace, cauchy

    Notes
    -----
    The probability density function for `genhyperbolic` is:

    .. math::

        f(x, p, a, b) =
            \frac{(a^2 - b^2)^{p/2}}
            {\sqrt{2\pi}a^{p-1/2}
            K_p\Big(\sqrt{a^2 - b^2}\Big)}
            e^{bx} \times \frac{K_{p - 1/2}
            (a \sqrt{1 + x^2})}
            {(\sqrt{1 + x^2})^{1/2 - p}}

    for :math:`x, p \in ( - \infty; \infty)`,
    :math:`|b| < a` if :math:`p \ge 0`,
    :math:`|b| \le a` if :math:`p < 0`.
    :math:`K_{p}(.)` denotes the modified Bessel function of the second
    kind and order :math:`p` (`scipy.special.kv`)

    `genhyperbolic` takes ``p`` as a tail parameter,
    ``a`` as a shape parameter,
    ``b`` as a skewness parameter.

    %(after_notes)s

    The original parameterization of the Generalized Hyperbolic Distribution
    is found in [1]_ as follows

    .. math::

        f(x, \lambda, \alpha, \beta, \delta, \mu) =
           \frac{(\gamma/\delta)^\lambda}{\sqrt{2\pi}K_\lambda(\delta \gamma)}
           e^{\beta (x - \mu)} \times \frac{K_{\lambda - 1/2}
           (\alpha \sqrt{\delta^2 + (x - \mu)^2})}
           {(\sqrt{\delta^2 + (x - \mu)^2} / \alpha)^{1/2 - \lambda}}

    for :math:`x \in ( - \infty; \infty)`,
    :math:`\gamma := \sqrt{\alpha^2 - \beta^2}`,
    :math:`\lambda, \mu \in ( - \infty; \infty)`,
    :math:`\delta \ge 0, |\beta| < \alpha` if :math:`\lambda \ge 0`,
    :math:`\delta > 0, |\beta| \le \alpha` if :math:`\lambda < 0`.

    The location-scale-based parameterization implemented in
    SciPy is based on [2]_, where :math:`a = \alpha\delta`,
    :math:`b = \beta\delta`, :math:`p = \lambda`,
    :math:`scale=\delta` and :math:`loc=\mu`

    Moments are implemented based on [3]_ and [4]_.

    For the distributions that are a special case such as Student's t,
    it is not recommended to rely on the implementation of genhyperbolic.
    To avoid potential numerical problems and for performance reasons,
    the methods of the specific distributions should be used.

    References
    ----------
    .. [1] O. Barndorff-Nielsen, "Hyperbolic Distributions and Distributions
       on Hyperbolae", Scandinavian Journal of Statistics, Vol. 5(3),
       pp. 151-157, 1978. https://www.jstor.org/stable/4615705

    .. [2] Eberlein E., Prause K. (2002) The Generalized Hyperbolic Model:
        Financial Derivatives and Risk Measures. In: Geman H., Madan D.,
        Pliska S.R., Vorst T. (eds) Mathematical Finance - Bachelier
        Congress 2000. Springer Finance. Springer, Berlin, Heidelberg.
        :doi:`10.1007/978-3-662-12429-1_12`

    .. [3] Scott, David J, Würtz, Diethelm, Dong, Christine and Tran,
       Thanh Tam, (2009), Moments of the generalized hyperbolic
       distribution, MPRA Paper, University Library of Munich, Germany,
       https://EconPapers.repec.org/RePEc:pra:mprapa:19081.

    .. [4] E. Eberlein and E. A. von Hammerstein. Generalized hyperbolic
       and inverse Gaussian distributions: Limiting cases and approximation
       of processes. FDM Preprint 80, April 2003. University of Freiburg.
       https://freidok.uni-freiburg.de/fedora/objects/freidok:7974/datastreams/FILE1/content

    %(example)s

    c                 C   s4   t t ||k |dkt t ||k|dk B S r6  )rE   logical_andr  )r;   rT  rp   rq   r.   r.   r/   rW     s    zgenhyperbolic_gen._argcheckc                 C   sN   t ddtj tjfd}t dddtjfd}t ddtj tjfd}|||gS )NrT  Fr   rp   r   rY   rq   rZ   )r;   ipr   r   r.   r.   r/   r]     s    zgenhyperbolic_gen._shape_infoc                    s   t  j|ddS )N)r   r   ru   r   rd  re  r  r.   r/   r    s    zgenhyperbolic_gen._fitstartc                 C   s   t jdd }|||||S )Nc                 S   s   t | |||S rC   )r   Zgenhyperbolic_logpdfr`   rT  rp   rq   r.   r.   r/   _logpdf_single  s    z1genhyperbolic_gen._logpdf.<locals>._logpdf_singlerE   	vectorize)r;   r`   rT  rp   rq   r  r.   r.   r/   r     s    
zgenhyperbolic_gen._logpdfc                 C   s   t jdd }|||||S )Nc                 S   s   t | |||S rC   )r   Zgenhyperbolic_pdfr  r.   r.   r/   _pdf_single  s    z+genhyperbolic_gen._pdf.<locals>._pdf_singler  )r;   r`   rT  rp   rq   r  r.   r.   r/   ra     s    
zgenhyperbolic_gen._pdfc                 C   s   t j| tt jgdS )NZotypes)rE   r  __get__objectfloat64r   r.   r.   r/   rL    rM  zgenhyperbolic_gen.<lambda>c                 C   s   t |||gtjtj}ttd|}t 	|| ||  }|| t
|d | t
|| }d}	d}
| |  k r|k rn n2tj|| ||	|
dd tj||||	|
dd  }ntj|| ||	|
dd }t |rd}tj|tdd td	td
|S )z
        Integrate the pdf of the genhyberbolic distribution from x0 to x1.
        This is a private function used by _cdf() and _sf() only; either x0
        will be -inf or x1 will be inf.
        Z_genhyperbolic_pdfr   r  r   )epsrelepsabszdInfinite values encountered in scipy.special.kve. Values replaced by NaN to avoid incorrect results.r  r  rm   rn   )rE   arrayr  ctypesdata_asc_void_pr
   from_cythonr   r   rc   kvr   quadisnanr  r  r  maxr  )r  x1rT  rp   rq   	user_datallcr=  r   r  r  ZintgrlrO   r.   r.   r/   _integrate_pdf  s:    $



z genhyperbolic_gen._integrate_pdfc                 C   s   |  tj ||||S rC   r  rE   r[   r;   r`   rT  rp   rq   r.   r.   r/   rb   !  s    zgenhyperbolic_gen._cdfc                 C   s   |  |tj|||S rC   r  r  r.   r.   r/   rd   $  s    zgenhyperbolic_gen._sfNc                 C   sh   t |dt |d }t |d}t |d}tj|||||d}	tj||d}
||	 t |	|
  S )NrK   ru   rN  )rT  rq   r(   r   r   rB  )rE   float_powergeninvgaussrD  r   r   )r;   rT  rp   rq   r   r   r*  r+  r,  ZgigZnormstr.   r.   r/   r   '  s    zgenhyperbolic_gen._rvsc                    sD  t |||\}}}t |dt |d }t |d}t ddt |d }t ddd}||jd|j  }t|| |\ }}}	}
 fd	d
|||	|
fD \}}}}|| | }|| t |dt |d |t |d   }t |dt |d |d| | t  d  dt |d   d| t |d |t |d   }|t |d }t |dt |d |d|	 | t  d  d| t |d t  d  dt |d   t |dt |d d| d| | t  d  dt |d    dt |d |  }|t |d d }||||fS )NrK   ru   r   r.  r   r   r  rX  c                 3   s   | ]}|  V  qd S rC   r.   )rZ  rq   b0r.   r/   	<genexpr>H  rM  z+genhyperbolic_gen._stats.<locals>.<genexpr>r  r   r   r  r  r/  )	rE   rR  r  Zlinspacer  shaper}  rc   r  )r;   rT  rp   rq   r*  r+  Zintegersb1b2Zb3Zb4r1r2Zr3Zr4rC  r:  Zm3erm  Zm4ero  r.   r  r/   r   <  sT    "
zgenhyperbolic_gen._stats)NN)ri   rj   rk   rl   rW   r]   r  r   ra   staticmethodr  rb   rd   r   r   r?  r.   r.   r  r/   r  ~  s   Y	 
r  genhyperbolicc                   @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )gompertz_genaq  A Gompertz (or truncated Gumbel) continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `gompertz` is:

    .. math::

        f(x, c) = c \exp(x) \exp(-c (e^x-1))

    for :math:`x \ge 0`, :math:`c > 0`.

    `gompertz` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]     s    zgompertz_gen._shape_infoc                 C   s   t | ||S rC   rG  rh  r.   r.   r/   ra     s    zgompertz_gen._pdfc                 C   s   t || |t|  S rC   r  rh  r.   r.   r/   r     s    zgompertz_gen._logpdfc                 C   s   t | t |  S rC   r  rh  r.   r.   r/   rb     s    zgompertz_gen._cdfc                 C   s   t d| t |  S r  rg  rk  r.   r.   r/   rg     s    zgompertz_gen._ppfc                 C   s   t | t| S rC   r   rh  r.   r.   r/   rd     s    zgompertz_gen._sfc                 C   s   t t| | S rC   r!  r;   rT  rf  r.   r.   r/   rh     s    zgompertz_gen._isfc                 C   s   dt | tj||  S r   )rE   r   rc   _ufuncs_scaled_exp1r  r.   r.   r/   r     s    zgompertz_gen._entropyNri   rj   rk   rl   r]   ra   r   rb   rg   rd   rh   r   r.   r.   r.   r/   r  i  s   r  gompertzc                 C   s8   t | } t |}| }t || }t j| |dS )N)weights)rE   r   r  r   Zaverage)r`   
logweightsZmaxlogwr	  r.   r.   r/   _average_with_log_weights  s
    

r  c                   @   st   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zeeedd ZdS )gumbel_r_gena  A right-skewed Gumbel continuous random variable.

    %(before_notes)s

    See Also
    --------
    gumbel_l, gompertz, genextreme

    Notes
    -----
    The probability density function for `gumbel_r` is:

    .. math::

        f(x) = \exp(-(x + e^{-x}))

    The Gumbel distribution is sometimes referred to as a type I Fisher-Tippett
    distribution.  It is also related to the extreme value distribution,
    log-Weibull and Gompertz distributions.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]     s    zgumbel_r_gen._shape_infoc                 C   s   t | |S rC   rG  r   r.   r.   r/   ra     s    zgumbel_r_gen._pdfc                 C   s   | t |  S rC   r  r   r.   r.   r/   r     s    zgumbel_r_gen._logpdfc                 C   s   t t |  S rC   r  r   r.   r.   r/   rb     s    zgumbel_r_gen._cdfc                 C   s   t |  S rC   r  r   r.   r.   r/   r     s    zgumbel_r_gen._logcdfc                 C   s   t t |  S rC   r   r   r.   r.   r/   rg     s    zgumbel_r_gen._ppfc                 C   s   t t|   S rC   r  r   r.   r.   r/   rd     s    zgumbel_r_gen._sfc                 C   s   t t |   S rC   rE   r   r  r  r.   r.   r/   rh     s    zgumbel_r_gen._isfc                 C   s0   t tjtj d dtd tjd  t dfS )Nr   r/  r  r  r  r   rE   r   r   r    r\   r.   r.   r/   r     s    zgumbel_r_gen._statsc                 C   s   t d S r   r{  r\   r.   r.   r/   r     s    zgumbel_r_gen._entropyc                    s   t |  ||\ }} fdd}|d ur6|}||n|d urR| fddn fdd|dd}|d |d  }	}
fd	d
}||	|
s|	dks|
tjk r|	d }	|
d9 }
qtj|	|
fddd}|j}|d ur|n|||fS )Nc                    s$   |  t   |  tt   S rC   )rc   	logsumexprE   r   r  )r(   r<   r.   r/   get_loc_from_scale  s    z,gumbel_r_gen.fit.<locals>.get_loc_from_scalec                    s:     t   |     }t |   }| | S rC   )rE   r   r  r  )r(   Zterm1Zterm2r<   r'   r.   r/   r     s    zgumbel_r_gen.fit.<locals>.funcc                    s&     |  }t  |d}  | |  S )N)r
  )r  r   )r(   ZsdataZwavgr  r.   r/   r     s    
r(   r   rK   c                    s   t  | t  |kS rC   rD   rG   r  r.   r/   rJ     s    z0gumbel_r_gen.fit.<locals>.interval_contains_rootr   r  )r\  rtolr  )r^  r3   rE   r[   r   r%   r_  )r;   r<   r=   r-   r   r   r  r(   brack_startrH   rI   rJ   resr.   )r<   r   r'   r/   r9     s6    




zgumbel_r_gen.fitN)ri   rj   rk   rl   r]   ra   r   rb   r   rg   rd   rh   r   r   rB   r	   r   r9   r.   r.   r.   r/   r    s   r  gumbel_rc                   @   st   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zeeedd ZdS )gumbel_l_gena  A left-skewed Gumbel continuous random variable.

    %(before_notes)s

    See Also
    --------
    gumbel_r, gompertz, genextreme

    Notes
    -----
    The probability density function for `gumbel_l` is:

    .. math::

        f(x) = \exp(x - e^x)

    The Gumbel distribution is sometimes referred to as a type I Fisher-Tippett
    distribution.  It is also related to the extreme value distribution,
    log-Weibull and Gompertz distributions.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   A  s    zgumbel_l_gen._shape_infoc                 C   s   t | |S rC   rG  r   r.   r.   r/   ra   D  s    zgumbel_l_gen._pdfc                 C   s   |t | S rC   r  r   r.   r.   r/   r   H  s    zgumbel_l_gen._logpdfc                 C   s   t t|  S rC   r  r   r.   r.   r/   rb   K  s    zgumbel_l_gen._cdfc                 C   s   t t|  S rC   rE   r   rc   r  r   r.   r.   r/   rg   N  s    zgumbel_l_gen._ppfc                 C   s   t | S rC   r  r   r.   r.   r/   r   Q  s    zgumbel_l_gen._logsfc                 C   s   t t | S rC   r  r   r.   r.   r/   rd   T  s    zgumbel_l_gen._sfc                 C   s   t t | S rC   r   r   r.   r.   r/   rh   W  s    zgumbel_l_gen._isfc                 C   s2   t  tjtj d dtd tjd  t dfS )Nr   r  r  r  r  r\   r.   r.   r/   r   Z  s    zgumbel_l_gen._statsc                 C   s   t d S r   r{  r\   r.   r.   r/   r   ^  s    zgumbel_l_gen._entropyc                 O   sJ   | dd ur|d  |d< tjt| g|R i |\}}| |fS )Nr   )r3   r  r9   rE   r   )r;   r<   r=   r-   Zloc_rZscale_rr.   r.   r/   r9   a  s    $zgumbel_l_gen.fitN)ri   rj   rk   rl   r]   ra   r   rb   rg   r   rd   rh   r   r   rB   r	   r   r9   r.   r.   r.   r/   r  &  s   r  gumbel_lc                       st   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zeee fddZ  ZS )halfcauchy_gena  A Half-Cauchy continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `halfcauchy` is:

    .. math::

        f(x) = \frac{2}{\pi (1 + x^2)}

    for :math:`x \ge 0`.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]     s    zhalfcauchy_gen._shape_infoc                 C   s   dt j d||   S r  r   r   r.   r.   r/   ra     s    zhalfcauchy_gen._pdfc                 C   s   t dt j t||  S r   rE   r   r   rc   r  r   r.   r.   r/   r     s    zhalfcauchy_gen._logpdfc                 C   s   dt j t | S r   r  r   r.   r.   r/   rb     s    zhalfcauchy_gen._cdfc                 C   s   t t jd | S r   r  r   r.   r.   r/   rg     s    zhalfcauchy_gen._ppfc                 C   s   dt j t d| S Nr   r   )rE   r   r;  r   r.   r.   r/   rd     s    zhalfcauchy_gen._sfc                 C   s   dt t j| d  S r   r  r  r.   r.   r/   rh     s    zhalfcauchy_gen._isfc                 C   s   t jt jt jt jfS rC   r   r\   r.   r.   r/   r     s    zhalfcauchy_gen._statsc                 C   s   t dt j S r   r   r\   r.   r.   r/   r     s    zhalfcauchy_gen._entropyc           
         s   | ddr&t j|g|R i |S t| |||\}}}t|}|d urj||k rdtd|tjd|}n|}dd }|d ur|}	n
|||}	||	fS )NrV  F
halfcauchyr  c                    sR   ||  }|j  t| fdd}tdjd }t||t|fd}|jS )Nc                    s"   | d  }dt |    S r   rE   r  )r(   denominatorrV   Zshifted_data_squaredr.   r/   fun_to_solve  s    z<halfcauchy_gen.fit.<locals>.find_scale.<locals>.fun_to_solvern   ru   r\  )r   rE   squarefinfotinyr%   r  r_  )r'   r<   Zshifted_datar"  Zsmallr  r.   r!  r/   
find_scale  s    
z&halfcauchy_gen.fit.<locals>.find_scaler+   r7   r9   r^  rE   r  r   r[   )
r;   r<   r=   r-   r   r   r  r'   r'  r(   r  r.   r/   r9     s     


zhalfcauchy_gen.fit)ri   rj   rk   rl   r]   ra   r   rb   rg   rd   rh   r   r   rB   r	   r   r9   r?  r.   r.   r  r/   r  u  s   r  r  c                       st   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zeee fddZ  ZS )halflogistic_gena  A half-logistic continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `halflogistic` is:

    .. math::

        f(x) = \frac{ 2 e^{-x} }{ (1+e^{-x})^2 }
             = \frac{1}{2} \text{sech}(x/2)^2

    for :math:`x \ge 0`.

    %(after_notes)s

    References
    ----------
    .. [1] Asgharzadeh et al (2011). "Comparisons of Methods of Estimation for the
           Half-Logistic Distribution". Selcuk J. Appl. Math. 93-108.

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]     s    zhalflogistic_gen._shape_infoc                 C   s   t | |S rC   rG  r   r.   r.   r/   ra     s    zhalflogistic_gen._pdfc                 C   s$   t d| dtt |   S r   )rE   r   rc   r  r   r   r.   r.   r/   r     s    zhalflogistic_gen._logpdfc                 C   s   t |d S r   )rE   tanhr   r.   r.   r/   rb     s    zhalflogistic_gen._cdfc                 C   s   dt | S r   rE   Zarctanhr   r.   r.   r/   rg     s    zhalflogistic_gen._ppfc                 C   s   dt |  S r   rc   expitr   r.   r.   r/   rd     s    zhalflogistic_gen._sfc                 C   s   t |dk |fdd dd dS )Nru   c                 S   s   t d|   S r  rc   logitr   r.   r.   r/   rL    rM  z'halflogistic_gen._isf.<locals>.<lambda>c                 S   s   dt d|   S r  r+  r   r.   r.   r/   rL    rM  rO  rQ  r   r.   r.   r/   rh      s    zhalflogistic_gen._isfc                 C   s   |dkrdt d S |dkr.t jt j d S |dkr>dt S |dkrXdt jd  d S ddtd	d|   t|d  t|d S )
Nr   rK   r  r  rn  r   r7  rx  r   )rE   r   r   r    r#  rc   rC  ry  rU   r.   r.   r/   r     s    zhalflogistic_gen._munpc                 C   s   dt d S r   r   r\   r.   r.   r/   r     s    zhalflogistic_gen._entropyc           
         s   | ddr&t j|g|R i |S t| |||\}}}dd }t|}|d urr||k rltd|tjd|}n|}|d ur|n|||}	||	fS )NrV  Fc                 S   s<  | j d }tj| dd}td|d |d  }d| }d| }|d| | t||   }d| | }|| }dt|dd  |dd    }	dt|dd  |dd  d   }
|	t|	d d| |
   d|  }d}d}| }||kr8|t	| |  }|d| |   }t
|| | }|}q|S )	Nr   r\  r   ru   rK   r   r   r  )r  rE   sortr  r   r  r   r   rc   r-  r  )r<   r'   Zn_observationsZsorted_datarT  rf   Zpp1r   r   r  Cr(   r  Zrelative_residualZshifted_meanZsum_termZ	scale_newr.   r.   r/   r'    s,    
"&
z(halflogistic_gen.fit.<locals>.find_scalehalflogisticr  r(  )
r;   r<   r=   r-   r   r   r'  r  r'   r(   r  r.   r/   r9     s    
"
zhalflogistic_gen.fit)ri   rj   rk   rl   r]   ra   r   rb   rg   rd   rh   r   r   rB   r	   r   r9   r?  r.   r.   r  r/   r)    s   r)  r2  c                       s~   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zeee fddZ  ZS )halfnorm_genaF  A half-normal continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `halfnorm` is:

    .. math::

        f(x) = \sqrt{2/\pi} \exp(-x^2 / 2)

    for :math:`x >= 0`.

    `halfnorm` is a special case of `chi` with ``df=1``.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   g  s    zhalfnorm_gen._shape_infoNc                 C   s   t |j|dS Nr  rL  r   r.   r.   r/   r   j  s    zhalfnorm_gen._rvsc                 C   s$   t dt j t | | d  S r   rE   r   r   r   r   r.   r.   r/   ra   m  s    zhalfnorm_gen._pdfc                 C   s    dt dt j  || d  S Nru   r   r   r   r.   r.   r/   r   q  s    zhalfnorm_gen._logpdfc                 C   s   t |td S r   rc   rM  rE   r   r   r.   r.   r/   rb   t  s    zhalfnorm_gen._cdfc                 C   s   t d| d S rs  r   r   r.   r.   r/   rg   w  s    zhalfnorm_gen._ppfc                 C   s   dt | S r   r   r   r.   r.   r/   rd   z  s    zhalfnorm_gen._sfc                 C   s   t |d S r   r   r  r.   r.   r/   rh   }  s    zhalfnorm_gen._isfc                 C   sX   t dt j ddt j  t ddt j  t jd d  dt jd  t jd d  fS )Nr   r   rK   r   r  r   r  rE   r   r   r\   r.   r.   r/   r     s
     zhalfnorm_gen._statsc                 C   s   dt t jd  d S r6  r   r\   r.   r.   r/   r     s    zhalfnorm_gen._entropyc           	         s   | ddr&t j|g|R i |S t| |||\}}}t|}|d urj||k rdtd|tjd|}n|}|d ur||}ntj	|d|dd }||fS )NrV  Fhalfnormr  rK   )ordercenterru   )
r+   r7   r9   r^  rE   r  r   r[   rS  Zmomentr  r  r.   r/   r9     s    

zhalfnorm_gen.fit)NN)ri   rj   rk   rl   r]   r   ra   r   rb   rg   rd   rh   r   r   rB   r	   r   r9   r?  r.   r.   r  r/   r3  Q  s   
r3  r9  c                   @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )hypsecant_gena  A hyperbolic secant continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `hypsecant` is:

    .. math::

        f(x) = \frac{1}{\pi} \text{sech}(x)

    for a real number :math:`x`.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]     s    zhypsecant_gen._shape_infoc                 C   s   dt jt |  S r   )rE   r   coshr   r.   r.   r/   ra     s    zhypsecant_gen._pdfc                 C   s   dt j t t | S r   rE   r   r  r   r   r.   r.   r/   rb     s    zhypsecant_gen._cdfc                 C   s   t t t j| d S r   rE   r   r  r   r   r.   r.   r/   rg     s    zhypsecant_gen._ppfc                 C   s   dt j t t |  S r   r>  r   r.   r.   r/   rd     s    zhypsecant_gen._sfc                 C   s   t t t j| d  S r   r?  r   r.   r.   r/   rh     s    zhypsecant_gen._isfc                 C   s   dt jt j d ddfS )Nr   r   rK   r   r\   r.   r.   r/   r     s    zhypsecant_gen._statsc                 C   s   t dt j S r   r   r\   r.   r.   r/   r     s    zhypsecant_gen._entropyN)ri   rj   rk   rl   r]   ra   rb   rg   rd   rh   r   r   r.   r.   r.   r/   r<    s   r<  	hypsecantc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )gausshyper_gena_  A Gauss hypergeometric continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `gausshyper` is:

    .. math::

        f(x, a, b, c, z) = C x^{a-1} (1-x)^{b-1} (1+zx)^{-c}

    for :math:`0 \le x \le 1`, :math:`a,b > 0`, :math:`c` a real number,
    :math:`z > -1`, and :math:`C = \frac{1}{B(a, b) F[2, 1](c, a; a+b; -z)}`.
    :math:`F[2, 1]` is the Gauss hypergeometric function
    `scipy.special.hyp2f1`.

    `gausshyper` takes :math:`a`, :math:`b`, :math:`c` and :math:`z` as shape
    parameters.

    %(after_notes)s

    References
    ----------
    .. [1] Armero, C., and M. J. Bayarri. "Prior Assessments for Prediction in
           Queues." *Journal of the Royal Statistical Society*. Series D (The
           Statistician) 43, no. 1 (1994): 139-53. doi:10.2307/2348939

    %(example)s

    c                 C   s    |dk|dk@ ||k@ |dk@ S )Nr   r.  r.   )r;   rp   rq   rf  r'  r.   r.   r/   rW     s    zgausshyper_gen._argcheckc                 C   s`   t dddtjfd}t dddtjfd}t ddtj tjfd}t dddtjfd}||||gS )	Nrp   Fr   r   rq   rf  r'  r.  rZ   )r;   r   r   rx  Zizr.   r.   r/   r]     s
    zgausshyper_gen._shape_infoc                 C   sV   t ||t |||| |  }d| ||d   d| |d   d||  |  S r   rc   r   Zhyp2f1)r;   r`   rp   rq   rf  r'  Znormalization_constantr.   r.   r/   ra     s    ""zgausshyper_gen._pdfc           	      C   s\   t || |t || }t ||| || | | }t |||| | }|| | S rC   rB  )	r;   rV   rp   rq   rf  r'  r  rW  r3  r.   r.   r/   r   	  s    zgausshyper_gen._munpN)ri   rj   rk   rl   rW   r]   ra   r   r.   r.   r.   r/   rA    s
    rA  
gausshyperc                   @   s`   e Zd ZdZejZdd Zdd Zdd Z	dd	 Z
d
d Zdd Zdd ZdddZdd ZdS )invgamma_gena_  An inverted gamma continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `invgamma` is:

    .. math::

        f(x, a) = \frac{x^{-a-1}}{\Gamma(a)} \exp(-\frac{1}{x})

    for :math:`x >= 0`, :math:`a > 0`. :math:`\Gamma` is the gamma function
    (`scipy.special.gamma`).

    `invgamma` takes ``a`` as a shape parameter for :math:`a`.

    `invgamma` is a special case of `gengamma` with ``c=-1``, and it is a
    different parameterization of the scaled inverse chi-squared distribution.
    Specifically, if the scaled inverse chi-squared distribution is
    parameterized with degrees of freedom :math:`\nu` and scaling parameter
    :math:`\tau^2`, then it can be modeled using `invgamma` with
    ``a=`` :math:`\nu/2` and ``scale=`` :math:`\nu \tau^2/2`.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]   3  s    zinvgamma_gen._shape_infoc                 C   s   t | ||S rC   rG  r   r.   r.   r/   ra   6  s    zinvgamma_gen._pdfc                 C   s&   |d  t | t| d|  S r  rE   r   rc   r5  r   r.   r.   r/   r   :  s    zinvgamma_gen._logpdfc                 C   s   t |d| S r   r  r   r.   r.   r/   rb   =  s    zinvgamma_gen._cdfc                 C   s   dt || S r   r  r   r.   r.   r/   rg   @  s    zinvgamma_gen._ppfc                 C   s   t |d| S r   r  r   r.   r.   r/   rd   C  s    zinvgamma_gen._sfc                 C   s   dt || S r   r  r   r.   r.   r/   rh   F  s    zinvgamma_gen._isfmvskc                 C   s   t |dk|fdd tj}t |dk|fdd tj}d\}}d|v r^t |dk|fd	d tj}d
|v rt |dk|fdd tj}||||fS )Nr   c                 S   s   d| d  S r   r.   r   r.   r.   r/   rL  J  rM  z%invgamma_gen._stats.<locals>.<lambda>rK   c                 S   s   d| d d  | d  S )Nrn   rK   r   r.   r   r.   r.   r/   rL  K  rM  )NNrm  r  c                 S   s   dt | d  | d  S )Nr  r   r  r  r   r.   r.   r/   rL  R  rM  ro  r   c                 S   s    dd|  d  | d  | d  S )Nr   r  g      &@r  r  r.   r   r.   r.   r/   rL  V  rM  r  )r;   rp   rr  r  r  r   r   r.   r.   r/   r   I  s     



zinvgamma_gen._statsc                 C   s*   dd }dd }t |dk|f||d}|S )Nc                 S   s$   | | d t |   t |  }|S r   r  rp   r  r.   r.   r/   r   Z  s     z&invgamma_gen._entropy.<locals>.regularc                 S   s`   ddt |   t d t t j d d| d   | d d  | d d	  | d
 d  }|S )Nr   r  rK   UUUUUU?r  r#  r/  r$  r  r%  r'  r   rG  r.   r.   r/   r  ^  s    *



z)invgamma_gen._entropy.<locals>.asymptoticr  r  rQ  )r;   rp   r   r  r  r.   r.   r/   r   Y  s    zinvgamma_gen._entropyN)rF  )ri   rj   rk   rl   r   r   r   r]   ra   r   rb   rg   rd   rh   r   r   r.   r.   r.   r/   rD    s   
rD  invgammac                       s   e Zd ZdZejZdd ZdddZdd Z	d	d
 Z
dd Zdd Zdd Zdd Z fddZ fddZdd Zee fddZdd Z  ZS )invgauss_gena`  An inverse Gaussian continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `invgauss` is:

    .. math::

        f(x; \mu) = \frac{1}{\sqrt{2 \pi x^3}}
                    \exp\left(-\frac{(x-\mu)^2}{2 \mu^2 x}\right)

    for :math:`x \ge 0` and :math:`\mu > 0`.

    `invgauss` takes ``mu`` as a shape parameter for :math:`\mu`.

    %(after_notes)s

    A common shape-scale parameterization of the inverse Gaussian distribution
    has density

    .. math::

        f(x; \nu, \lambda) = \sqrt{\frac{\lambda}{2 \pi x^3}}
                    \exp\left( -\frac{\lambda(x-\nu)^2}{2 \nu^2 x}\right)

    Using ``nu`` for :math:`\nu` and ``lam`` for :math:`\lambda`, this
    parameterization is equivalent to the one above with ``mu = nu/lam``,
    ``loc = 0``, and ``scale = lam``.

    %(example)s

    c                 C   s   t dddtjfdgS Nr   Fr   r   rZ   r\   r.   r.   r/   r]     s    zinvgauss_gen._shape_infoNc                 C   s   |j |d|dS Nrn   r  waldr;   r   r   r   r.   r.   r/   r     s    zinvgauss_gen._rvsc                 C   s>   dt dt j |d   t dd|  || | d   S )Nrn   rK   r  r  r5  r;   r`   r   r.   r.   r/   ra     s    zinvgauss_gen._pdfc                 C   s:   dt dt j  dt |  || | d d|   S )NrN  rK   r  r   rP  r.   r.   r/   r     s    zinvgauss_gen._logpdfc                 C   sX   dt | }t||| d  }d| t| || d   }|t t ||  S r   )rE   r   r   r  r   r;   r`   r   r  rp   rq   r.   r.   r/   r     s    zinvgauss_gen._logcdfc                 C   sZ   dt | }t||| d  }d| t| ||  |  }|t t ||   S r   )rE   r   r   r   r  r   rQ  r.   r.   r/   r     s    zinvgauss_gen._logsfc                 C   s   t | ||S rC   r  rP  r.   r.   r/   rd     s    zinvgauss_gen._sfc                 C   s   t | ||S rC   r  rP  r.   r.   r/   rb     s    zinvgauss_gen._cdfc                    s   t jddddx t ||\}}t||d}|dk}td||  || d||< t |}t || || ||< W d    n1 s0    Y  |S Nr   )r   r   invalidr   ru   )	rE   r   rR  r   _invgauss_ppf_invgauss_isfr  r7   rg   )r;   r`   r   ppfi_wti_nanr  r.   r/   rg     s    
8zinvgauss_gen._ppfc                    s   t jddddx t ||\}}t||d}|dk}td||  || d||< t |}t || || ||< W d    n1 s0    Y  |S rR  )	rE   r   rR  r   rU  rT  r  r7   rh   )r;   r`   r   ZisfrW  rX  r  r.   r/   rh     s    
8zinvgauss_gen._isfc                 C   s   ||d dt | d| fS )Nr  r  r  r  )r;   r   r.   r.   r/   r     s    zinvgauss_gen._statsc           	         s   | dd}t|ts.t| tks.| dkrHt j|g|R i |S t| |||\}}}}|d u sn|d urt j|g|R i |S t	
|| dk rtddt	jdn@|| }t	|}|d u rt|t	|d |d   }|| }|||fS )Nr*   r1   r2   r   invgaussr  r.  )r3   r5   r$   r8   wald_genr4   r7   r9   r^  rE   r  r   r[   r   r  r  )	r;   r<   r=   r-   r*   Zfshape_sr   r   Zfshape_nr  r.   r/   r9     s$    

zinvgauss_gen.fitc                 C   sJ   dt dt j  dt |  }d| }tj|| }d| d|  S )zV
        Ref.: https://moser-isi.ethz.ch/docs/papers/smos-2012-10.pdf (eq. 9)
        rn   rK   r  ru   r  )rE   r   r   rc   r  r  )r;   r   rp   rU  rq   r.   r.   r/   r     s    "zinvgauss_gen._entropy)NN)ri   rj   rk   rl   r   r   r   r]   r   ra   r   r   r   rd   rb   rg   rh   r   r	   r9   r   r?  r.   r.   r  r/   rJ  l  s    "


!rJ  rY  c                   @   sb   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dddZ
dd Zdd Zdd ZdS )geninvgauss_genaX  A Generalized Inverse Gaussian continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `geninvgauss` is:

    .. math::

        f(x, p, b) = x^{p-1} \exp(-b (x + 1/x) / 2) / (2 K_p(b))

    where `x > 0`, `p` is a real number and `b > 0`\([1]_).
    :math:`K_p` is the modified Bessel function of second kind of order `p`
    (`scipy.special.kv`).

    %(after_notes)s

    The inverse Gaussian distribution `stats.invgauss(mu)` is a special case of
    `geninvgauss` with `p = -1/2`, `b = 1 / mu` and `scale = mu`.

    Generating random variates is challenging for this distribution. The
    implementation is based on [2]_.

    References
    ----------
    .. [1] O. Barndorff-Nielsen, P. Blaesild, C. Halgreen, "First hitting time
       models for the generalized inverse gaussian distribution",
       Stochastic Processes and their Applications 7, pp. 49--54, 1978.

    .. [2] W. Hoermann and J. Leydold, "Generating generalized inverse Gaussian
       random variates", Statistics and Computing, 24(4), p. 547--557, 2014.

    %(example)s

    c                 C   s   ||k|dk@ S r6  r.   r;   rT  rq   r.   r.   r/   rW   $  s    zgeninvgauss_gen._argcheckc                 C   s4   t ddtj tjfd}t dddtjfd}||gS )NrT  Fr   rq   r   rZ   )r;   r  r   r.   r.   r/   r]   '  s    zgeninvgauss_gen._shape_infoc                 C   sL   dd }t j|t jgd}||||}t | rHd}tj|tdd |S )Nc                 S   s   t | ||S rC   )r   Zgeninvgauss_logpdfr`   rT  rq   r.   r.   r/   logpdf_single0  s    z.geninvgauss_gen._logpdf.<locals>.logpdf_singler  zjInfinite values encountered in scipy.special.kve(p, b). Values replaced by NaN to avoid incorrect results.r  r  )rE   r  r  r  r  r  r  r  )r;   r`   rT  rq   r^  r'  rO   r.   r.   r/   r   ,  s    zgeninvgauss_gen._logpdfc                 C   s   t | |||S rC   rG  r;   r`   rT  rq   r.   r.   r/   ra   <  s    zgeninvgauss_gen._pdfc                    s<   | j | \ } fdd}tj|tjgd}||g|R  S )Nc                    sB   |\}}t ||gtjtj}ttd|}t	
| | d S )NZ_geninvgauss_pdfr   )rE   r  r  r  r  r  r
   r  r   r   r  )r`   r=   rT  rq   r  r  r  r.   r/   _cdf_singleC  s    z)geninvgauss_gen._cdf.<locals>._cdf_singler  )rv   rE   r  r  )r;   r`   r=   r  ra  r.   r`  r/   rb   @  s    zgeninvgauss_gen._cdfc                 C   s    t |dk|||fdd tj S )Nr   c                 S   s&   |d t |  || d|    d  S r   r   r]  r.   r.   r/   rL  R  rM  z.geninvgauss_gen._logquasipdf.<locals>.<lambda>rb  r_  r.   r.   r/   _logquasipdfO  s    zgeninvgauss_gen._logquasipdfNc           	         s  t |r&t |r&| ||||}n|jdkrT|jdkrT| | | ||}nt ||\}}t|j|\} tt 	|}t 
|}t j||gdgdgdggdjst fddtt| dD }| d d |||||<   q|dkr| }|S )	Nr   multi_indexreadonlyflagsZop_flagsc                 3   s(   | ] } | sj | ntd V  qd S rC   rc  slicerZ  r;  bcitr.   r/   r    s   z'geninvgauss_gen._rvs.<locals>.<genexpr>r   r.   )rE   isscalar_rvs_scalarr   r  rR  r   r  r9  r]  emptynditerfinishedtupler^  r  r  iternext)	r;   rT  rq   r   r   rV  shp
numsamplesidxr.   rj  r/   r   U  s2    






zgeninvgauss_gen._rvsc           3   	      s  d}|sd}dk r d}  }d}dks> dkrDd}n* tddtd  d krjd}nd}tt|}	t|	}
t|
}d}|rV|rdd    | }d| d    d }||d d  }d|d  d	 || d  | }t| td
|d   d }td| d  }|t	|d tj
d   |d  }| t	|d  |d  }| |  }|  }|| td|  }|| td|  }d} fdd}|}nrtd|  }d td d  d     }d}|td|   }d} fdd}||krptd|dkrtdd}||
k r|
| }||j|d }|j|d} ||| |   } | | | }!dt| ||!k}"t|"}#|#dkr|!|" ||||# < ||#7 }|dkrF||
 dkrFd||
  d}$t|$|d7 }qn d  }%t|%d  f}&t| }'|'|% }(|%d  k rt  })dkr|)d   |%    }*n|)td d   }*nd\})}*|&d  }+d|+ t|&   d    },|(|* |, }-||
k r|
| }t|t| }.}!|j|d}|-|j|d } | |(k}/t|/| |(|* k@ }0t|/|0B }1|%| |/  |( |!|/< |'|.|/< dkr|% | |0 |(  |)  d  |!|0< n$ t| |0 |( t   |!|0< |)|!|0 d   |.|0< t|&   d  | |1 |( |*  d|+   }2d  t|2 |!|1< |+t|!|1    d  |.|1< t||. |! k}"t|"}#|#dkr*|!|" ||||# < ||#7 }q*t||	}!|rd|! }!|!S )NFr   r   Tru   rK   r  r      ir  c                    s    |   S rC   rb  r   rq   ZlmrT  r;   r.   r/   logqpdf  s    z,geninvgauss_gen._rvs_scalar.<locals>.logqpdfc                    s    |  S rC   rx  r   )rq   rT  r;   r.   r/   rz    s    zvmin must be smaller than vmax.zumax must be positive.r  iP  z2Not a single random variate could be generated in zH attempts. Sampling does not appear to work for the provided parameters.)r   r   )_moder  rE   r   rr  
atleast_1dr]  zerosZarccosr   r   rb  r   r   r  r   r  r  r  Zlogical_notr  )3r;   rT  rq   ru  r   Z
invert_resrC  Z
ratio_unifZ
mode_shiftsize1dNr`   	simulatedZa2Za1p1q1phir   Zroot1root2d1d2ZvminZvmaxZumaxrz  rf  ZxplusrW  ro  r  r:  rD  accept
num_acceptrO   r  xsZk1A1Zk2A2Zk3ZA3r  r  Zcond1Zcond2Zcond3r'  r.   ry  r/   rn    s     

 "$&





 

*$0 
zgeninvgauss_gen._rvs_scalarc                 C   sX   |dk r.|t |d d |d  d |  S t d| d |d  d|  | S d S r   r  r\  r.   r.   r/   r{  %  s    &zgeninvgauss_gen._modec           	      C   s   t || |}t ||}t|t|B }| r|d}tj|tdd tj|tj	tj
d}||  ||   || < n|| }|S )NzInfinite values encountered in the moment calculation involving scipy.special.kve. Values replaced by NaN to avoid incorrect results.r  r  dtype)rc   ZkverE   rL   r  r  r  r  	full_liker   r  )	r;   rV   rT  rq   rW  denomZinf_valsrO   rC  r.   r.   r/   r   ,  s    zgeninvgauss_gen._munp)NN)ri   rj   rk   rl   rW   r]   r   ra   rb   rb  r   rn  r{  r   r.   r.   r.   r/   r[    s   $
7 r[  r  c                       s`   e Zd ZdZejZdd Zdd Z fddZ	dd	 Z
d
d Zdd ZdddZdd Z  ZS )norminvgauss_gena  A Normal Inverse Gaussian continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `norminvgauss` is:

    .. math::

        f(x, a, b) = \frac{a \, K_1(a \sqrt{1 + x^2})}{\pi \sqrt{1 + x^2}} \,
                     \exp(\sqrt{a^2 - b^2} + b x)

    where :math:`x` is a real number, the parameter :math:`a` is the tail
    heaviness and :math:`b` is the asymmetry parameter satisfying
    :math:`a > 0` and :math:`|b| <= a`.
    :math:`K_1` is the modified Bessel function of second kind
    (`scipy.special.k1`).

    %(after_notes)s

    A normal inverse Gaussian random variable `Y` with parameters `a` and `b`
    can be expressed as a normal mean-variance mixture:
    `Y = b * V + sqrt(V) * X` where `X` is `norm(0,1)` and `V` is
    `invgauss(mu=1/sqrt(a**2 - b**2))`. This representation is used
    to generate random variates.

    Another common parametrization of the distribution (see Equation 2.1 in
    [2]_) is given by the following expression of the pdf:

    .. math::

        g(x, \alpha, \beta, \delta, \mu) =
        \frac{\alpha\delta K_1\left(\alpha\sqrt{\delta^2 + (x - \mu)^2}\right)}
        {\pi \sqrt{\delta^2 + (x - \mu)^2}} \,
        e^{\delta \sqrt{\alpha^2 - \beta^2} + \beta (x - \mu)}

    In SciPy, this corresponds to
    `a = alpha * delta, b = beta * delta, loc = mu, scale=delta`.

    References
    ----------
    .. [1] O. Barndorff-Nielsen, "Hyperbolic Distributions and Distributions on
           Hyperbolae", Scandinavian Journal of Statistics, Vol. 5(3),
           pp. 151-157, 1978.

    .. [2] O. Barndorff-Nielsen, "Normal Inverse Gaussian Distributions and
           Stochastic Volatility Modelling", Scandinavian Journal of
           Statistics, Vol. 24, pp. 1-13, 1997.

    %(example)s

    c                 C   s   |dkt ||k @ S r6  )rE   absoluter  r.   r.   r/   rW   w  s    znorminvgauss_gen._argcheckc                 C   s4   t dddtjfd}t ddtj tjfd}||gS r   rZ   r   r.   r.   r/   r]   z  s    znorminvgauss_gen._shape_infoc                    s   t  j|ddS )N)r   ru   r   rd  re  r  r.   r/   r    s    znorminvgauss_gen._fitstartc                 C   s\   t |d |d  }|t j }t d|}|t||  t || ||  |  | S r  )rE   r   r   hypotrc   Zk1er   )r;   r`   rp   rq   rC  fac1sqr.   r.   r/   ra     s    
znorminvgauss_gen._pdfc              	   C   s   t |r(tj| j|t j||fdd S t |}t |}g }t|||D ].\}}}|tj| j|t j||fdd  qLt 	|S d S )Nr   r   )
rE   rm  r   r  ra   r[   r|  r  appendr  )r;   r`   rp   rq   resultr  a0r  r.   r.   r/   rd     s    


znorminvgauss_gen._sfc           	         s^    fdd}t |r"||||S g }t|||D ]\}}}||||| q2t |S d S )Nc           
         s    fdd}  ||}||||| }|dkr2|S |dkrpd}|}|| }||||| dkrd| }|| }qJn4d}|}|| }||||| dk rd| }|| }qtj|||||| f jd}	|	S )Nc                    s     | ||| S rC   rd   )r`   rp   rq   rf   r\   r.   r/   eq  s    z6norminvgauss_gen._isf.<locals>._isf_scalar.<locals>.eqr   r   rK   )r=   r  )r   r   r  r  )
rf   rp   rq   r  xmZemdeltaleftrightr  r\   r.   r/   _isf_scalar  s,    
z*norminvgauss_gen._isf.<locals>._isf_scalar)rE   rm  r  r  r  )	r;   rf   rp   rq   r  r  q0r  r  r.   r\   r/   rh     s    !
znorminvgauss_gen._isfNc                 C   sJ   t |d |d  }tjd| ||d}|| t |tj||d  S )NrK   r   )r   r   r   rB  )rE   r   rY  rD  r   )r;   rp   rq   r   r   rC  Zigr.   r.   r/   r     s
    znorminvgauss_gen._rvsc                 C   sp   t |d |d  }|| }|d |d  }d| |t |  }ddd|d  |d    | }||||fS )NrK   r  r  r   r   r  )r;   rp   rq   rC  r   ZvarianceskewnessZkurtosisr.   r.   r/   r     s     znorminvgauss_gen._stats)NN)ri   rj   rk   rl   r   r   r   rW   r]   r  ra   rd   rh   r   r   r?  r.   r.   r  r/   r  ?  s   5*
r  norminvgaussc                       sh   e Zd ZdZejZdd Zdd Zdd Z	dd	 Z
d
d Zdd Zdd Zdd Zd fdd	Z  ZS )invweibull_genu  An inverted Weibull continuous random variable.

    This distribution is also known as the Fréchet distribution or the
    type II extreme value distribution.

    %(before_notes)s

    Notes
    -----
    The probability density function for `invweibull` is:

    .. math::

        f(x, c) = c x^{-c-1} \exp(-x^{-c})

    for :math:`x > 0`, :math:`c > 0`.

    `invweibull` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    References
    ----------
    F.R.S. de Gusmao, E.M.M Ortega and G.M. Cordeiro, "The generalized inverse
    Weibull distribution", Stat. Papers, vol. 52, pp. 591-619, 2011.

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]     s    zinvweibull_gen._shape_infoc                 C   s8   t || d }t || }t | }|| | S r   rE   r  r   )r;   r`   rf  xc1Zxc2r.   r.   r/   ra     s    zinvweibull_gen._pdfc                 C   s   t || }t | S rC   r  )r;   r`   rf  r  r.   r.   r/   rb     s    zinvweibull_gen._cdfc                 C   s   t ||    S rC   )rE   rj  rh  r.   r.   r/   rd     s    zinvweibull_gen._sfc                 C   s   t t | d| S r  )rE   r  r   rk  r.   r.   r/   rg     s    zinvweibull_gen._ppfc                 C   s   t |  d|  S Nr.  r  r  r.   r.   r/   rh   	  s    zinvweibull_gen._isfc                 C   s   t d||  S rR   r  r  r.   r.   r/   r     s    zinvweibull_gen._munpc                 C   s   dt  t |  t| S rR   rU  r  r.   r.   r/   r     s    zinvweibull_gen._entropyNc                    s    |d u rdn|}t  j||dS )N)r   r   rd  )r;   r<   r=   r  r.   r/   r    s    zinvweibull_gen._fitstart)N)ri   rj   rk   rl   r   r   r   r]   ra   rb   rd   rg   rh   r   r   r  r?  r.   r.   r  r/   r    s   r  
invweibullc                   @   sB   e Zd ZdZdd Zdd ZdddZd	d
 Zdd Zdd Z	dS )jf_skew_t_gena  Jones and Faddy skew-t distribution.

    %(before_notes)s

    Notes
    -----
    The probability density function for `jf_skew_t` is:

    .. math::

        f(x; a, b) = C_{a,b}^{-1}
                    \left(1+\frac{x}{\left(a+b+x^2\right)^{1/2}}\right)^{a+1/2}
                    \left(1-\frac{x}{\left(a+b+x^2\right)^{1/2}}\right)^{b+1/2}

    for real numbers :math:`a>0` and :math:`b>0`, where
    :math:`C_{a,b} = 2^{a+b-1}B(a,b)(a+b)^{1/2}`, and :math:`B` denotes the
    beta function (`scipy.special.beta`).

    When :math:`a<b`, the distribution is negatively skewed, and when
    :math:`a>b`, the distribution is positively skewed. If :math:`a=b`, then
    we recover the `t` distribution with :math:`2a` degrees of freedom.

    `jf_skew_t` takes :math:`a` and :math:`b` as shape parameters.

    %(after_notes)s

    References
    ----------
    .. [1] M.C. Jones and M.J. Faddy. "A skew extension of the t distribution,
           with applications" *Journal of the Royal Statistical Society*.
           Series B (Statistical Methodology) 65, no. 1 (2003): 159-174.
           :doi:`10.1111/1467-9868.00378`

    %(example)s

    c                 C   s0   t dddtjfd}t dddtjfd}||gS r   rZ   r   r.   r.   r/   r]   @  s    zjf_skew_t_gen._shape_infoc                 C   s   d|| d  t || t||  }d|t|| |d    |d  }d|t|| |d    |d  }|| | S NrK   r   ru   )rc   r   rE   r   )r;   r`   rp   rq   rf  r  r  r.   r.   r/   ra   E  s    *&&zjf_skew_t_gen._pdfNc                 C   sF   | |||}d| d t||  }dt|d|   }|| S r  )r   rE   r   )r;   rp   rq   r   r   r  r  d3r.   r.   r/   r   K  s    zjf_skew_t_gen._rvsc                 C   s0   d|t || |d    d }t|||S Nr   rK   ru   )rE   r   rc   Zbetainc)r;   r`   rp   rq   r  r.   r.   r/   rb   Q  s    "zjf_skew_t_gen._cdfc                 C   sF   t |||}d| d t||  }dt|d|   }|| S r  )r   rV  rE   r   )r;   rf   rp   rq   r  r  r  r.   r.   r/   rg   U  s    zjf_skew_t_gen._ppfc                 C   sL   dd }|d| k|d| k@ |dk@ }t ||||ftj|tjgdtjS )zReturns the n-th moment(s) where all the following hold:

        - n >= 0
        - a > n / 2
        - b > n / 2

        The result is np.nan in all other cases.
        c           	      S   s   || d|   }d|  t || }t| d }t|d dkdd}t |d|   | |d|   | }t | || | }|| |  S )zgComputes E[T^(n_k)] where T is skew-t distributed with
            parameters a_k and b_k.
            ru   rK   r   r   r.  )rc   r   rE   r  r  r  r  )	Zn_kZa_kZb_krW  r  indicesrq  r=  Z	sum_termsr.   r.   r/   
nth_momentd  s    $z'jf_skew_t_gen._munp.<locals>.nth_momentru   r   r  r   rE   r  r  r   )r;   rV   rp   rq   r  Znth_moment_validr.   r.   r/   r   [  s    	 zjf_skew_t_gen._munp)NN)
ri   rj   rk   rl   r]   ra   r   rb   rg   r   r.   r.   r.   r/   r    s   $
r  	jf_skew_tc                   @   sN   e Zd ZdZejZdd Zdd Zdd Z	dd	 Z
d
d Zdd Zdd ZdS )johnsonsb_gena!  A Johnson SB continuous random variable.

    %(before_notes)s

    See Also
    --------
    johnsonsu

    Notes
    -----
    The probability density function for `johnsonsb` is:

    .. math::

        f(x, a, b) = \frac{b}{x(1-x)}  \phi(a + b \log \frac{x}{1-x} )

    where :math:`x`, :math:`a`, and :math:`b` are real scalars; :math:`b > 0`
    and :math:`x \in [0,1]`.  :math:`\phi` is the pdf of the normal
    distribution.

    `johnsonsb` takes :math:`a` and :math:`b` as shape parameters.

    %(after_notes)s

    %(example)s

    c                 C   s   |dk||k@ S r6  r.   r  r.   r.   r/   rW     s    zjohnsonsb_gen._argcheckc                 C   s4   t ddtj tjfd}t dddtjfd}||gS Nrp   Fr   rq   r   rZ   r   r.   r.   r/   r]     s    zjohnsonsb_gen._shape_infoc                 C   s.   t ||t|  }|d |d|   | S r{  )r   rc   r/  )r;   r`   rp   rq   trmr.   r.   r/   ra     s    zjohnsonsb_gen._pdfc                 C   s   t ||t|  S rC   )r   rc   r/  r   r.   r.   r/   rb     s    zjohnsonsb_gen._cdfc                 C   s   t d| t||  S r   )rc   r-  r   r  r.   r.   r/   rg     s    zjohnsonsb_gen._ppfc                 C   s   t ||t|  S rC   )r   rc   r/  r   r.   r.   r/   rd     s    zjohnsonsb_gen._sfc                 C   s   t d| t||  S r   )rc   r-  r   r  r.   r.   r/   rh     s    zjohnsonsb_gen._isfN)ri   rj   rk   rl   r   r   r   rW   r]   ra   rb   rg   rd   rh   r.   r.   r.   r/   r  ~  s   r  	johnsonsbc                   @   sR   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dddZdS )johnsonsu_gena-  A Johnson SU continuous random variable.

    %(before_notes)s

    See Also
    --------
    johnsonsb

    Notes
    -----
    The probability density function for `johnsonsu` is:

    .. math::

        f(x, a, b) = \frac{b}{\sqrt{x^2 + 1}}
                     \phi(a + b \log(x + \sqrt{x^2 + 1}))

    where :math:`x`, :math:`a`, and :math:`b` are real scalars; :math:`b > 0`.
    :math:`\phi` is the pdf of the normal distribution.

    `johnsonsu` takes :math:`a` and :math:`b` as shape parameters.

    The first four central moments are calculated according to the formulas
    in [1]_.

    %(after_notes)s

    References
    ----------
    .. [1] Taylor Enterprises. "Johnson Family of Distributions".
       https://variation.com/wp-content/distribution_analyzer_help/hs126.htm

    %(example)s

    c                 C   s   |dk||k@ S r6  r.   r  r.   r.   r/   rW     s    zjohnsonsu_gen._argcheckc                 C   s4   t ddtj tjfd}t dddtjfd}||gS r  rZ   r   r.   r.   r/   r]     s    zjohnsonsu_gen._shape_infoc                 C   s8   || }t ||t|  }|d t|d  | S r   )r   rE   arcsinhr   )r;   r`   rp   rq   r(  r  r.   r.   r/   ra     s    zjohnsonsu_gen._pdfc                 C   s   t ||t|  S rC   )r   rE   r  r   r.   r.   r/   rb     s    zjohnsonsu_gen._cdfc                 C   s   t t|| | S rC   )rE   sinhr   r  r.   r.   r/   rg     s    zjohnsonsu_gen._ppfc                 C   s   t ||t|  S rC   )r   rE   r  r   r.   r.   r/   rd     s    zjohnsonsu_gen._sfc                 C   s   t t|| | S rC   )rE   r  r   r   r.   r.   r/   rh     s    zjohnsonsu_gen._isfrl  c                 C   s  d\}}}}|d }t |}	|| }
d|v rB|	d  t |
 }d|v rndt| |	t d|
  d  }d|v r|	d t|d  }d	t |
 }|	|	d  t d	|
  }t dd|	t d|
   d
  }| ||  | }d|v rd	d|	  }d|	d  |	d  t d|
  }|	d t d|
  }dd	|	d   d|	d	   |	d  }dd|	t d|
   d  }|| ||  | d	 }||||fS )NNNNNr#  rC  ru   r:  rK   r   rm  r  r  ro  r  r   r  )rE   r   r  rc   rj  r=  r   )r;   rp   rq   rr  r   r   r   r   Zbn2Zexpbn2Za_br*  r+  r,  r  Zt4r.   r.   r/   r     s,    
$$
"$zjohnsonsu_gen._statsN)rl  )ri   rj   rk   rl   rW   r]   ra   rb   rg   rd   rh   r   r.   r.   r.   r/   r    s   #r  	johnsonsuc                   @   sr   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zeeedddd ZdS )laplace_gena
  A Laplace continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `laplace` is

    .. math::

        f(x) = \frac{1}{2} \exp(-|x|)

    for a real number :math:`x`.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   -  s    zlaplace_gen._shape_infoNc                 C   s   |j dd|dS )Nr   r   r  )laplacer   r.   r.   r/   r   0  s    zlaplace_gen._rvsc                 C   s   dt t|  S r  )rE   r   r  r   r.   r.   r/   ra   3  s    zlaplace_gen._pdfc              	   C   s\   t jdd< t |dkddt |   dt | W  d    S 1 sN0    Y  d S )Nr   r   r   rn   ru   )rE   r   r  r   r   r.   r.   r/   rb   7  s    zlaplace_gen._cdfc                 C   s   |  | S rC   rb   r   r.   r.   r/   rd   ;  s    zlaplace_gen._sfc                 C   s,   t |dkt dd|   t d| S r   rE   r  r   r   r.   r.   r/   rg   ?  s    zlaplace_gen._ppfc                 C   s   |  | S rC   rw  r   r.   r.   r/   rh   B  s    zlaplace_gen._isfc                 C   s   dS )N)r   rK   r   r  r.   r\   r.   r.   r/   r   F  s    zlaplace_gen._statsc                 C   s   t dd S r  r   r\   r.   r.   r/   r   I  s    zlaplace_gen._entropyz        This function uses explicit formulas for the maximum likelihood
        estimation of the Laplace distribution parameters, so the keyword
        arguments `loc`, `scale`, and `optimizer` are ignored.

r   c                 O   sR   t | |||\}}}|d u r&t|}|d u rJtt|| t| }||fS rC   )r^  rE   medianr  r  r  )r;   r<   r=   r-   r   r   r.   r.   r/   r9   L  s    

zlaplace_gen.fit)NN)ri   rj   rk   rl   r]   r   ra   rb   rd   rg   rh   r   r   rB   r   r   r9   r.   r.   r.   r/   r    s   

r  r  c                   @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdS )laplace_asymmetric_genu  An asymmetric Laplace continuous random variable.

    %(before_notes)s

    See Also
    --------
    laplace : Laplace distribution

    Notes
    -----
    The probability density function for `laplace_asymmetric` is

    .. math::

       f(x, \kappa) &= \frac{1}{\kappa+\kappa^{-1}}\exp(-x\kappa),\quad x\ge0\\
                    &= \frac{1}{\kappa+\kappa^{-1}}\exp(x/\kappa),\quad x<0\\

    for :math:`-\infty < x < \infty`, :math:`\kappa > 0`.

    `laplace_asymmetric` takes ``kappa`` as a shape parameter for
    :math:`\kappa`. For :math:`\kappa = 1`, it is identical to a
    Laplace distribution.

    %(after_notes)s

    Note that the scale parameter of some references is the reciprocal of
    SciPy's ``scale``. For example, :math:`\lambda = 1/2` in the
    parameterization of [1]_ is equivalent to ``scale = 2`` with
    `laplace_asymmetric`.

    References
    ----------
    .. [1] "Asymmetric Laplace distribution", Wikipedia
            https://en.wikipedia.org/wiki/Asymmetric_Laplace_distribution

    .. [2] Kozubowski TJ and Podgórski K. A Multivariate and
           Asymmetric Generalization of Laplace Distribution,
           Computational Statistics 15, 531--540 (2000).
           :doi:`10.1007/PL00022717`

    %(example)s

    c                 C   s   t dddtjfdgS )NkappaFr   r   rZ   r\   r.   r.   r/   r]     s    z"laplace_asymmetric_gen._shape_infoc                 C   s   t | ||S rC   rG  r;   r`   r  r.   r.   r/   ra     s    zlaplace_asymmetric_gen._pdfc                 C   s6   d| }|t |dk| | }|t || 8 }|S rt  r  )r;   r`   r  kapinvr  r.   r.   r/   r     s    zlaplace_asymmetric_gen._logpdfc                 C   sL   d| }|| }t |dkdt | | ||   t || ||  S rt  rE   r  r   r;   r`   r  r  
kappkapinvr.   r.   r/   rb     s    
zlaplace_asymmetric_gen._cdfc              	   C   sL   d| }|| }t |dkt | | ||  dt || ||   S rt  r  r  r.   r.   r/   rd     s    
zlaplace_asymmetric_gen._sfc                 C   sP   d| }|| }t ||| kt d| | |  | t || | | S rR   r  r;   rf   r  r  r  r.   r.   r/   rg     s    zlaplace_asymmetric_gen._ppfc                 C   sP   d| }|| }t ||| kt || |  | t d| | | | S rR   r  r  r.   r.   r/   rh     s    zlaplace_asymmetric_gen._isfc                 C   s   d| }|| }|| ||  }ddt |d  t dt |d d }ddt |d  t dt |d d }||||fS )	Nr   r   r  r   r  r   r   rK   r1  )r;   r  r  mnr  r   r   r.   r.   r/   r     s    ,,zlaplace_asymmetric_gen._statsc                 C   s   dt |d|   S rR   r   r;   r  r.   r.   r/   r     s    zlaplace_asymmetric_gen._entropyNr  r.   r.   r.   r/   r  d  s   +r  laplace_asymmetricc                 C   sn  t |tst|}|dd }|dd }| jrBt| jdnd}g }g }| jr| jdd }	t	|	D ]T\}
}dt
|
 }|d| d| g}t||}|| || |d urn|||< qndd	d
dddh|}t||}|rtd| dt||krtdd ||h|vr*tdt |tr>| n|}t| sZtd|g|||R S )Nr   r   ,r    r  Zfix_r'   r(   r)   r*   zUnknown keyword arguments: r  zToo many positional arguments.r   r   )r5   r$   rE   r   r3   shapesr  splitr   	enumeratestrr   r  set
differencer,   r  r
  r   r   r   )distr<   r=   r-   r   r   Z
num_shapesZfshape_keysZfshapesr  r;  rm  keynamesrp  Z
known_keysZunknown_keysZ
uncensoredr.   r.   r/   r^    sB    





r^  c                   @   sN   e Zd ZdZejZdd Zdd Zdd Z	dd	 Z
d
d Zdd Zdd ZdS )levy_genag  A Levy continuous random variable.

    %(before_notes)s

    See Also
    --------
    levy_stable, levy_l

    Notes
    -----
    The probability density function for `levy` is:

    .. math::

        f(x) = \frac{1}{\sqrt{2\pi x^3}} \exp\left(-\frac{1}{2x}\right)

    for :math:`x > 0`.

    This is the same as the Levy-stable distribution with :math:`a=1/2` and
    :math:`b=1`.

    %(after_notes)s

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.stats import levy
    >>> import matplotlib.pyplot as plt
    >>> fig, ax = plt.subplots(1, 1)

    Calculate the first four moments:

    >>> mean, var, skew, kurt = levy.stats(moments='mvsk')

    Display the probability density function (``pdf``):

    >>> # `levy` is very heavy-tailed.
    >>> # To show a nice plot, let's cut off the upper 40 percent.
    >>> a, b = levy.ppf(0), levy.ppf(0.6)
    >>> x = np.linspace(a, b, 100)
    >>> ax.plot(x, levy.pdf(x),
    ...        'r-', lw=5, alpha=0.6, label='levy pdf')

    Alternatively, the distribution object can be called (as a function)
    to fix the shape, location and scale parameters. This returns a "frozen"
    RV object holding the given parameters fixed.

    Freeze the distribution and display the frozen ``pdf``:

    >>> rv = levy()
    >>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

    Check accuracy of ``cdf`` and ``ppf``:

    >>> vals = levy.ppf([0.001, 0.5, 0.999])
    >>> np.allclose([0.001, 0.5, 0.999], levy.cdf(vals))
    True

    Generate random numbers:

    >>> r = levy.rvs(size=1000)

    And compare the histogram:

    >>> # manual binning to ignore the tail
    >>> bins = np.concatenate((np.linspace(a, b, 20), [np.max(r)]))
    >>> ax.hist(r, bins=bins, density=True, histtype='stepfilled', alpha=0.2)
    >>> ax.set_xlim([x[0], x[-1]])
    >>> ax.legend(loc='best', frameon=False)
    >>> plt.show()

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   C  s    zlevy_gen._shape_infoc                 C   s.   dt dt j |  | t dd|   S Nr   rK   r.  r5  r   r.   r.   r/   ra   F  s    zlevy_gen._pdfc                 C   s   t td| S r  )rc   erfcrE   r   r   r.   r.   r/   rb   J  s    zlevy_gen._cdfc                 C   s   t td| S r  r7  r   r.   r.   r/   rd   N  s    zlevy_gen._sfc                 C   s   t |d }d||  S NrK   rn   r   r;   rf   rp  r.   r.   r/   rg   Q  s    zlevy_gen._ppfc                 C   s   ddt |d   S r   )rc   Zerfinvr  r.   r.   r/   rh   V  s    zlevy_gen._isfc                 C   s   t jt jt jt jfS rC   r   r\   r.   r.   r/   r   Y  s    zlevy_gen._statsNri   rj   rk   rl   r   r   r   r]   ra   rb   rd   rg   rh   r   r.   r.   r.   r/   r    s   Hr  levyc                   @   sN   e Zd ZdZejZdd Zdd Zdd Z	dd	 Z
d
d Zdd Zdd ZdS )
levy_l_gena  A left-skewed Levy continuous random variable.

    %(before_notes)s

    See Also
    --------
    levy, levy_stable

    Notes
    -----
    The probability density function for `levy_l` is:

    .. math::
        f(x) = \frac{1}{|x| \sqrt{2\pi |x|}} \exp{ \left(-\frac{1}{2|x|} \right)}

    for :math:`x < 0`.

    This is the same as the Levy-stable distribution with :math:`a=1/2` and
    :math:`b=-1`.

    %(after_notes)s

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.stats import levy_l
    >>> import matplotlib.pyplot as plt
    >>> fig, ax = plt.subplots(1, 1)

    Calculate the first four moments:

    >>> mean, var, skew, kurt = levy_l.stats(moments='mvsk')

    Display the probability density function (``pdf``):

    >>> # `levy_l` is very heavy-tailed.
    >>> # To show a nice plot, let's cut off the lower 40 percent.
    >>> a, b = levy_l.ppf(0.4), levy_l.ppf(1)
    >>> x = np.linspace(a, b, 100)
    >>> ax.plot(x, levy_l.pdf(x),
    ...        'r-', lw=5, alpha=0.6, label='levy_l pdf')

    Alternatively, the distribution object can be called (as a function)
    to fix the shape, location and scale parameters. This returns a "frozen"
    RV object holding the given parameters fixed.

    Freeze the distribution and display the frozen ``pdf``:

    >>> rv = levy_l()
    >>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

    Check accuracy of ``cdf`` and ``ppf``:

    >>> vals = levy_l.ppf([0.001, 0.5, 0.999])
    >>> np.allclose([0.001, 0.5, 0.999], levy_l.cdf(vals))
    True

    Generate random numbers:

    >>> r = levy_l.rvs(size=1000)

    And compare the histogram:

    >>> # manual binning to ignore the tail
    >>> bins = np.concatenate(([np.min(r)], np.linspace(a, b, 20)))
    >>> ax.hist(r, bins=bins, density=True, histtype='stepfilled', alpha=0.2)
    >>> ax.set_xlim([x[0], x[-1]])
    >>> ax.legend(loc='best', frameon=False)
    >>> plt.show()

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]     s    zlevy_l_gen._shape_infoc                 C   s6   t |}dtdtj |  | tdd|   S r  )r  rE   r   r   r   r;   r`   r  r.   r.   r/   ra     s    zlevy_l_gen._pdfc                 C   s"   t |}dtdt|  d S r  )r  r   rE   r   r  r.   r.   r/   rb     s    zlevy_l_gen._cdfc                 C   s   t |}dtdt|  S r  )r  r   rE   r   r  r.   r.   r/   rd     s    zlevy_l_gen._sfc                 C   s   t |d d }d||  S )Nrn   rK   r  r   r  r.   r.   r/   rg     s    zlevy_l_gen._ppfc                 C   s   dt |d d  S )Nr.  rK   r   r  r.   r.   r/   rh     s    zlevy_l_gen._isfc                 C   s   t jt jt jt jfS rC   r   r\   r.   r.   r/   r     s    zlevy_l_gen._statsNr  r.   r.   r.   r/   r  `  s   Gr  levy_lc                       s   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zeee fddZ  ZS )logistic_gena  A logistic (or Sech-squared) continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `logistic` is:

    .. math::

        f(x) = \frac{\exp(-x)}
                    {(1+\exp(-x))^2}

    `logistic` is a special case of `genlogistic` with ``c=1``.

    Remark that the survival function (``logistic.sf``) is equal to the
    Fermi-Dirac distribution describing fermionic statistics.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]     s    zlogistic_gen._shape_infoNc                 C   s   |j |dS r4  )logisticr   r.   r.   r/   r     s    zlogistic_gen._rvsc                 C   s   t | |S rC   rG  r   r.   r.   r/   ra     s    zlogistic_gen._pdfc                 C   s$   t | }|dtt |  S r   )rE   r  rc   r  r   )r;   r`   r  r.   r.   r/   r     s    zlogistic_gen._logpdfc                 C   s
   t |S rC   r,  r   r.   r.   r/   rb     s    zlogistic_gen._cdfc                 C   s
   t |S rC   rc   Z	log_expitr   r.   r.   r/   r     s    zlogistic_gen._logcdfc                 C   s
   t |S rC   r.  r   r.   r.   r/   rg     s    zlogistic_gen._ppfc                 C   s   t | S rC   r,  r   r.   r.   r/   rd     s    zlogistic_gen._sfc                 C   s   t | S rC   r  r   r.   r.   r/   r     s    zlogistic_gen._logsfc                 C   s   t | S rC   r.  r   r.   r.   r/   rh     s    zlogistic_gen._isfc                 C   s   dt jt j d ddfS )Nr   r  g333333?r   r\   r.   r.   r/   r      s    zlogistic_gen._statsc                 C   s   dS r   r.   r\   r.   r.   r/   r     s    zlogistic_gen._entropyc           
         sD  | ddr&t j g|R i |S t|  ||\ }}t |  \}}|d||d| }}|f fdd	|f fdd	fd	d
}|d ur|d u rt|f}	|	j	d }|}nH|d ur|d u rt|f}	|	j	d }|}nt|||f}	|	j	\}}t
|}|	jr*||fS t j g|R i |S )NrV  Fr'   r(   c                    s$    |  | }t t|d  S r   )rE   r  rc   r-  )r'   r(   rf  r<   rV   r.   r/   dl_dloc  s    z!logistic_gen.fit.<locals>.dl_dlocc                    s(    | |  }t |t |d   S r   )rE   r  r*  )r(   r'   rf  r  r.   r/   	dl_dscale  s    z#logistic_gen.fit.<locals>.dl_dscalec                    s   | \}} ||||fS rC   r.   )paramsr'   r(   )r  r  r.   r/   r   #  s    zlogistic_gen.fit.<locals>.funcr   )r+   r7   r9   r^  r  r  r3   r   r_  r`   r  success)
r;   r<   r=   r-   r   r   r'   r(   r   r  r  )r<   r  r  rV   r/   r9     s2    



zlogistic_gen.fit)NN)ri   rj   rk   rl   r]   r   ra   r   rb   r   rg   rd   r   rh   r   r   rB   r	   r   r9   r?  r.   r.   r  r/   r    s    
r  r  c                   @   sb   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )loggamma_gena  A log gamma continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `loggamma` is:

    .. math::

        f(x, c) = \frac{\exp(c x - \exp(x))}
                       {\Gamma(c)}

    for all :math:`x, c > 0`. Here, :math:`\Gamma` is the
    gamma function (`scipy.special.gamma`).

    `loggamma` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]   X  s    zloggamma_gen._shape_infoNc                 C   s.   t |j|d |dt |j|d|  S )Nr   r  )rE   r   rC  r  r9  r.   r.   r/   r   [  s    zloggamma_gen._rvsc                 C   s"   t || t | t| S rC   rE   r   rc   r5  rh  r.   r.   r/   ra   i  s    zloggamma_gen._pdfc                 C   s   || t | t| S rC   r  rh  r.   r.   r/   r   m  s    zloggamma_gen._logpdfc                 C   s    t |tk ||fdd dd dS )Nc                 S   s   t ||  t|d  S rR   r  r  r.   r.   r/   rL    rM  z#loggamma_gen._cdf.<locals>.<lambda>c                 S   s   t |t| S rC   )rc   r  rE   r   r  r.   r.   r/   rL    rM  rO  r   r   rh  r.   r.   r/   rb   p  s    zloggamma_gen._cdfc                 C   s.   t ||}t|tk |||fdd dd dS )Nc                 S   s   t |t|d  | S rR   rE  r  rf   rf  r.   r.   r/   rL    rM  z#loggamma_gen._ppf.<locals>.<lambda>c                 S   s
   t | S rC   r   r  r.   r.   r/   rL    rM  rO  )rc   r  r   r   r;   rf   rf  r  r.   r.   r/   rg     s
    zloggamma_gen._ppfc                 C   s    t |tk ||fdd dd dS )Nc                 S   s   t ||  t|d   S rR   )rE   rj  rc   r5  r  r.   r.   r/   rL    rM  z"loggamma_gen._sf.<locals>.<lambda>c                 S   s   t |t| S rC   )rc   r  rE   r   r  r.   r.   r/   rL    rM  rO  r  rh  r.   r.   r/   rd     s    zloggamma_gen._sfc                 C   s.   t ||}t|tk |||fdd dd dS )Nc                 S   s   t | t|d  | S rR   )rE   r  rc   r5  r  r.   r.   r/   rL    rM  z#loggamma_gen._isf.<locals>.<lambda>c                 S   s
   t | S rC   r   r  r.   r.   r/   rL    rM  rO  )rc   r  r   r   r  r.   r.   r/   rh     s
    zloggamma_gen._isfc                 C   sN   t |}t d|}t d|t|d }t d|||  }||||fS )Nr   rK   r  r  )rc   r  Z	polygammarE   r  )r;   rf  r   r  r  Zexcess_kurtosisr.   r.   r/   r     s
    
zloggamma_gen._statsc                 C   s*   dd }dd }t |dk|f||d}|S )Nc                 S   s    t | | t |   |  }|S rC   )rc   r5  r  )rf  r  r.   r.   r/   r     s    z&loggamma_gen._entropy.<locals>.regularc                 S   sB   dt |  | d d  | d d  | d d  }t | }|S )NrN  r  r  r$  r  r0     )rE   r   r   r   )rf  termr  r.   r.   r/   r    s    2z)loggamma_gen._entropy.<locals>.asymptotic-   r  rQ  )r;   rf  r   r  r  r.   r.   r/   r     s    zloggamma_gen._entropy)NNri   rj   rk   rl   r]   r   ra   r   rb   rg   rd   rh   r   r   r.   r.   r.   r/   r  ?  s   
	r  loggammac                       sl   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zeee fddZ  ZS )loglaplace_genaT  A log-Laplace continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `loglaplace` is:

    .. math::

        f(x, c) = \begin{cases}\frac{c}{2} x^{ c-1}  &\text{for } 0 < x < 1\\
                               \frac{c}{2} x^{-c-1}  &\text{for } x \ge 1
                  \end{cases}

    for :math:`c > 0`.

    `loglaplace` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    Suppose a random variable ``X`` follows the Laplace distribution with
    location ``a`` and scale ``b``.  Then ``Y = exp(X)`` follows the
    log-Laplace distribution with ``c = 1 / b`` and ``scale = exp(a)``.

    References
    ----------
    T.J. Kozubowski and K. Podgorski, "A log-Laplace growth rate model",
    The Mathematical Scientist, vol. 28, pp. 49-60, 2003.

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]     s    zloglaplace_gen._shape_infoc                 C   s,   |d }t |dk || }|||d   S r  rE   r  )r;   r`   rf  Zcd2r.   r.   r/   ra     s    zloglaplace_gen._pdfc                 C   s(   t |dk d||  dd||    S Nr   ru   r  rh  r.   r.   r/   rb     s    zloglaplace_gen._cdfc                 C   s(   t |dk dd||   d||   S r  r  rh  r.   r.   r/   rd     s    zloglaplace_gen._sfc                 C   s.   t |dk d| d|  dd|  d|  S Nru   r   rn   rK   r  r  rk  r.   r.   r/   rg     s    zloglaplace_gen._ppfc                 C   s.   t |dkdd|  d|  d| d|  S r  r  rk  r.   r.   r/   rh     s    zloglaplace_gen._isfc                 C   s^   t jdd> |d |d  }}t ||k |||  t jW  d    S 1 sP0    Y  d S )Nr   r   rK   )rE   r   r  r[   )r;   rV   rf  r2  Zn2r.   r.   r/   r     s    zloglaplace_gen._munpc                 C   s   t d| d S r  r   r  r.   r.   r/   r     s    zloglaplace_gen._entropyc                    s   t | |||\}}}}|d u r@tt| | j|g|R i |S t||kr^td|tjd|dkrn|| }tjt	||d urt	|nd |d urd| nd dd\}}|}	|d u rt
|n|}
|d u rd| n|}||	|
fS )N
loglaplacer  r   r   r1   )r   r   r*   )r^  r7   r8   r9   rE   r  r   r[   r  r   r   )r;   r<   r=   r-   r`  r   r   rp   rq   r'   r(   rf  r  r.   r/   r9     s$    "
zloglaplace_gen.fit)ri   rj   rk   rl   r]   ra   rb   rd   rg   rh   r   r   rB   r	   r   r9   r?  r.   r.   r  r/   r    s    r  r  c                 C   s   t | dk| |fdd tj S )Nr   c                 S   s:   t | d  d|d   t ||  t dt j   S r   )rE   r   r   r   r`   rm  r.   r.   r/   rL    s   z!_lognorm_logpdf.<locals>.<lambda>rb  r  r.   r.   r/   _lognorm_logpdf  s    r  c                       s   e Zd ZdZejZdd ZdddZdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zeeedd fddZ  ZS ) lognorm_gena  A lognormal continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `lognorm` is:

    .. math::

        f(x, s) = \frac{1}{s x \sqrt{2\pi}}
                  \exp\left(-\frac{\log^2(x)}{2s^2}\right)

    for :math:`x > 0`, :math:`s > 0`.

    `lognorm` takes ``s`` as a shape parameter for :math:`s`.

    %(after_notes)s

    Suppose a normally distributed random variable ``X`` has  mean ``mu`` and
    standard deviation ``sigma``. Then ``Y = exp(X)`` is lognormally
    distributed with ``s = sigma`` and ``scale = exp(mu)``.

    %(example)s

    The logarithm of a log-normally distributed random variable is
    normally distributed:

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy import stats
    >>> fig, ax = plt.subplots(1, 1)
    >>> mu, sigma = 2, 0.5
    >>> X = stats.norm(loc=mu, scale=sigma)
    >>> Y = stats.lognorm(s=sigma, scale=np.exp(mu))
    >>> x = np.linspace(*X.interval(0.999))
    >>> y = Y.rvs(size=10000)
    >>> ax.plot(x, X.pdf(x), label='X (pdf)')
    >>> ax.hist(np.log(y), density=True, bins=x, label='log(Y) (histogram)')
    >>> ax.legend()
    >>> plt.show()

    c                 C   s   t dddtjfdgS )Nrm  Fr   r   rZ   r\   r.   r.   r/   r]   L  s    zlognorm_gen._shape_infoNc                 C   s   t ||| S rC   rE   r   r   )r;   rm  r   r   r.   r.   r/   r   O  s    zlognorm_gen._rvsc                 C   s   t | ||S rC   rG  r;   r`   rm  r.   r.   r/   ra   R  s    zlognorm_gen._pdfc                 C   s
   t ||S rC   r  r  r.   r.   r/   r   V  s    zlognorm_gen._logpdfc                 C   s   t t|| S rC   r   rE   r   r  r.   r.   r/   rb   Y  s    zlognorm_gen._cdfc                 C   s   t t|| S rC   r  r  r.   r.   r/   r   \  s    zlognorm_gen._logcdfc                 C   s   t |t| S rC   rE   r   r   r;   rf   rm  r.   r.   r/   rg   _  s    zlognorm_gen._ppfc                 C   s   t t|| S rC   r   rE   r   r  r.   r.   r/   rd   b  s    zlognorm_gen._sfc                 C   s   t t|| S rC   )r   rE   r   r  r.   r.   r/   r   e  s    zlognorm_gen._logsfc                 C   s   t |t| S rC   rE   r   r   r  r.   r.   r/   rh   h  s    zlognorm_gen._isfc                 C   sV   t || }t |}||d  }t |d d|  }t g d|}||||fS Nr   rK   )r   rK   r  r   r2  )rE   r   r   polyval)r;   rm  rT  r   r   r   r   r.   r.   r/   r   k  s    
zlognorm_gen._statsc                 C   s&   ddt dt j  dt |   S Nru   r   rK   r   )r;   rm  r.   r.   r/   r   s  s    zlognorm_gen._entropyaF          When `method='MLE'` and
        the location parameter is fixed by using the `floc` argument,
        this function uses explicit formulas for the maximum likelihood
        estimation of the log-normal shape and scale parameters, so the
        `optimizer`, `loc` and `scale` keyword arguments are ignored.
        If the location is free, a likelihood maximum is found by
        setting its partial derivative wrt to location to 0, and
        solving by substituting the analytical expressions of shape
        and scale (or provided parameters).
        See, e.g., equation 3.1 in
        A. Clifford Cohen & Betty Jones Whitten (1980)
        Estimation in the Three-Parameter Lognormal Distribution,
        Journal of the American Statistical Association, 75:370, 399-404
        https://doi.org/10.2307/2287466
        

r   c                    sb  | ddr&t j g|R i |S t ||}|\ }t } fdd fdd} fdd}|d u rt|}	||	 }
||
}||
}d	|	 }|d
kr|| }
||
}|d	9 }qt|
rt|st j g|R i |S tt	|
tj
 |
d }||}d	|
|  }t|rvt|rvt|t|krv|
| }||}|d	9 }q,t|rt|st j g|R i |S t|||
fd}|jst j g|R i |S ||j}||kr|jn||	 }n||krtddtj
d|}|\}}|r>|dksXt j g|R i |S |||fS )NrV  Fc                    sZ   d u sd u rt  |  }p.t | }pPt t |t | d }||fS r   )rE   r   r   r   r   )r'   Zlndatar(   r  )r<   r   fshaper.   r/   get_shape_scale  s
    "z(lognorm_gen.fit.<locals>.get_shape_scalec                    s8   | \}} |  }t dt || |d   | S r   rE   r  r   )r'   r  r(   Zshifted)r<   r  r.   r/   dL_dLoc  s    z lognorm_gen.fit.<locals>.dL_dLocc                    s    | \}} || |f  S rC   )nnlf)r'   r  r(   )r<   r  r;   r.   r/   ll  s    zlognorm_gen.fit.<locals>.llrK   gưr   r#  lognormrm   r  r   )r+   r7   r9   r^  rE   r  spacingr   r  	nextafterr[   rF   r%   	convergedr_  r   rW   )r;   r<   r=   r-   
parametersr   r  r  r  r	  rI   ZdL_dLoc_rbrackZ	ll_rbrackr  rH   ZdL_dLoc_lbrackr  Zll_rootr'   r  r(   r  )r<   r   r  r  r;   r/   r9   v  sV    
	




zlognorm_gen.fit)NN)ri   rj   rk   rl   r   r   r   r]   r   ra   r   rb   r   rg   rd   r   rh   r   r   rB   r   r9   r?  r.   r.   r  r/   r    s"   +

r  r  c                   @   sh   e Zd ZdZejZdd ZdddZdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )
gibrat_genaB  A Gibrat continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `gibrat` is:

    .. math::

        f(x) = \frac{1}{x \sqrt{2\pi}} \exp(-\frac{1}{2} (\log(x))^2)

    `gibrat` is a special case of `lognorm` with ``s=1``.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]     s    zgibrat_gen._shape_infoNc                 C   s   t ||S rC   r  r   r.   r.   r/   r      s    zgibrat_gen._rvsc                 C   s   t | |S rC   rG  r   r.   r.   r/   ra     s    zgibrat_gen._pdfc                 C   s
   t |dS r   r  r   r.   r.   r/   r     s    zgibrat_gen._logpdfc                 C   s   t t|S rC   r  r   r.   r.   r/   rb   
  s    zgibrat_gen._cdfc                 C   s   t t|S rC   r  r   r.   r.   r/   rg     s    zgibrat_gen._ppfc                 C   s   t t|S rC   r  r   r.   r.   r/   rd     s    zgibrat_gen._sfc                 C   s   t t|S rC   r  r  r.   r.   r/   rh     s    zgibrat_gen._isfc                 C   sN   t j}t |}||d  }t |d d|  }t g d|}||||fS r  )rE   er   r   )r;   rT  r   r   r   r   r.   r.   r/   r     s    
zgibrat_gen._statsc                 C   s   dt dt j  d S r  r   r\   r.   r.   r/   r     s    zgibrat_gen._entropy)NN)ri   rj   rk   rl   r   r   r   r]   r   ra   r   rb   rg   rd   rh   r   r   r.   r.   r.   r/   r    s   
r  gibratc                   @   sb   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )maxwell_gena  A Maxwell continuous random variable.

    %(before_notes)s

    Notes
    -----
    A special case of a `chi` distribution,  with ``df=3``, ``loc=0.0``,
    and given ``scale = a``, where ``a`` is the parameter used in the
    Mathworld description [1]_.

    The probability density function for `maxwell` is:

    .. math::

        f(x) = \sqrt{2/\pi}x^2 \exp(-x^2/2)

    for :math:`x >= 0`.

    %(after_notes)s

    References
    ----------
    .. [1] http://mathworld.wolfram.com/MaxwellDistribution.html

    %(example)s
    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   @  s    zmaxwell_gen._shape_infoNc                 C   s   t jd||dS )Nr  rB  r  rD  r   r.   r.   r/   r   C  s    zmaxwell_gen._rvsc                 C   s    t | | t| | d  S r   )r"   rE   r   r   r.   r.   r/   ra   F  s    zmaxwell_gen._pdfc                 C   sN   t jdd. tdt |  d| |  W  d    S 1 s@0    Y  d S )Nr   r   rK   ru   )rE   r   r#   r   r   r.   r.   r/   r   J  s    zmaxwell_gen._logpdfc                 C   s   t d|| d S Nr  r   r  r   r.   r.   r/   rb   O  s    zmaxwell_gen._cdfc                 C   s   t dtd| S r  r  r   r.   r.   r/   rg   R  s    zmaxwell_gen._ppfc                 C   s   t d|| d S r  r  r   r.   r.   r/   rd   U  s    zmaxwell_gen._sfc                 C   s   t dtd| S r  r  r   r.   r.   r/   rh   X  s    zmaxwell_gen._isfc                 C   sr   dt j d }dt dt j  ddt j  t dddt j   |d  dt j t j d	t j  d
 |d  fS )Nr  r   rK   r       r&  r  r     i  rE   r   r   r;   rp  r.   r.   r/   r   [  s    $zmaxwell_gen._statsc                 C   s   t dtdtj   d S r  )r   rE   r   r   r\   r.   r.   r/   r   b  s    zmaxwell_gen._entropy)NNr  r.   r.   r.   r/   r  %  s   
r  maxwellc                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )
mielke_gena  A Mielke Beta-Kappa / Dagum continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `mielke` is:

    .. math::

        f(x, k, s) = \frac{k x^{k-1}}{(1+x^s)^{1+k/s}}

    for :math:`x > 0` and :math:`k, s > 0`. The distribution is sometimes
    called Dagum distribution ([2]_). It was already defined in [3]_, called
    a Burr Type III distribution (`burr` with parameters ``c=s`` and
    ``d=k/s``).

    `mielke` takes ``k`` and ``s`` as shape parameters.

    %(after_notes)s

    References
    ----------
    .. [1] Mielke, P.W., 1973 "Another Family of Distributions for Describing
           and Analyzing Precipitation Data." J. Appl. Meteor., 12, 275-280
    .. [2] Dagum, C., 1977 "A new model for personal income distribution."
           Economie Appliquee, 33, 327-367.
    .. [3] Burr, I. W. "Cumulative frequency functions", Annals of
           Mathematical Statistics, 13(2), pp 215-232 (1942).

    %(example)s

    c                 C   s0   t dddtjfd}t dddtjfd}||gS )Nro  Fr   r   rm  rZ   )r;   iki_sr.   r.   r/   r]     s    zmielke_gen._shape_infoc                 C   s,   |||d   d||  d|d |    S r   r.   r;   r`   ro  rm  r.   r.   r/   ra     s    zmielke_gen._pdfc                 C   sf   t jddF t |t ||d   t || d||    W  d    S 1 sX0    Y  d S )Nr   r   r   )rE   r   r   r  r  r.   r.   r/   r     s    zmielke_gen._logpdfc                 C   s    || d||  |d |   S r   r.   r  r.   r.   r/   rb     s    zmielke_gen._cdfc                 C   s(   t ||d | }t |d|  d| S r   rT  )r;   rf   ro  rm  Zqskr.   r.   r/   rg     s    zmielke_gen._ppfc                 C   s"   dd }t ||k |||f|tjS )Nc                 S   s2   t ||  | t d| |   t ||  S rR   r  )rV   ro  rm  r.   r.   r/   r    s    z$mielke_gen._munp.<locals>.nth_momentrb  )r;   rV   ro  rm  r  r.   r.   r/   r     s    zmielke_gen._munpN)
ri   rj   rk   rl   r]   ra   r   rb   rg   r   r.   r.   r.   r/   r  i  s   !r  mielkec                   @   sh   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )
kappa4_genap  Kappa 4 parameter distribution.

    %(before_notes)s

    Notes
    -----
    The probability density function for kappa4 is:

    .. math::

        f(x, h, k) = (1 - k x)^{1/k - 1} (1 - h (1 - k x)^{1/k})^{1/h-1}

    if :math:`h` and :math:`k` are not equal to 0.

    If :math:`h` or :math:`k` are zero then the pdf can be simplified:

    h = 0 and k != 0::

        kappa4.pdf(x, h, k) = (1.0 - k*x)**(1.0/k - 1.0)*
                              exp(-(1.0 - k*x)**(1.0/k))

    h != 0 and k = 0::

        kappa4.pdf(x, h, k) = exp(-x)*(1.0 - h*exp(-x))**(1.0/h - 1.0)

    h = 0 and k = 0::

        kappa4.pdf(x, h, k) = exp(-x)*exp(-exp(-x))

    kappa4 takes :math:`h` and :math:`k` as shape parameters.

    The kappa4 distribution returns other distributions when certain
    :math:`h` and :math:`k` values are used.

    +------+-------------+----------------+------------------+
    | h    | k=0.0       | k=1.0          | -inf<=k<=inf     |
    +======+=============+================+==================+
    | -1.0 | Logistic    |                | Generalized      |
    |      |             |                | Logistic(1)      |
    |      |             |                |                  |
    |      | logistic(x) |                |                  |
    +------+-------------+----------------+------------------+
    |  0.0 | Gumbel      | Reverse        | Generalized      |
    |      |             | Exponential(2) | Extreme Value    |
    |      |             |                |                  |
    |      | gumbel_r(x) |                | genextreme(x, k) |
    +------+-------------+----------------+------------------+
    |  1.0 | Exponential | Uniform        | Generalized      |
    |      |             |                | Pareto           |
    |      |             |                |                  |
    |      | expon(x)    | uniform(x)     | genpareto(x, -k) |
    +------+-------------+----------------+------------------+

    (1) There are at least five generalized logistic distributions.
        Four are described here:
        https://en.wikipedia.org/wiki/Generalized_logistic_distribution
        The "fifth" one is the one kappa4 should match which currently
        isn't implemented in scipy:
        https://en.wikipedia.org/wiki/Talk:Generalized_logistic_distribution
        https://www.mathwave.com/help/easyfit/html/analyses/distributions/gen_logistic.html
    (2) This distribution is currently not in scipy.

    References
    ----------
    J.C. Finney, "Optimization of a Skewed Logistic Distribution With Respect
    to the Kolmogorov-Smirnov Test", A Dissertation Submitted to the Graduate
    Faculty of the Louisiana State University and Agricultural and Mechanical
    College, (August, 2004),
    https://digitalcommons.lsu.edu/gradschool_dissertations/3672

    J.R.M. Hosking, "The four-parameter kappa distribution". IBM J. Res.
    Develop. 38 (3), 25 1-258 (1994).

    B. Kumphon, A. Kaew-Man, P. Seenoi, "A Rainfall Distribution for the Lampao
    Site in the Chi River Basin, Thailand", Journal of Water Resource and
    Protection, vol. 4, 866-869, (2012).
    :doi:`10.4236/jwarp.2012.410101`

    C. Winchester, "On Estimation of the Four-Parameter Kappa Distribution", A
    Thesis Submitted to Dalhousie University, Halifax, Nova Scotia, (March
    2000).
    http://www.nlc-bnc.ca/obj/s4/f2/dsk2/ftp01/MQ57336.pdf

    %(after_notes)s

    %(example)s

    c                 C   s    t ||d j}t j|ddS )Nr   T
fill_value)rE   rR  r  full)r;   r  ro  r  r.   r.   r/   rW     s    zkappa4_gen._argcheckc                 C   s8   t ddtj tjfd}t ddtj tjfd}||gS )Nr  Fr   ro  rZ   )r;   Zihr  r.   r.   r/   r]     s    zkappa4_gen._shape_infoc           
   
   C   s   t |dk|dkt |dk|dkt |dk|dk t |dk|dkt |dk|dkt |dk|dk g}dd }dd }dd }dd	 }t|||||||g||gt jd
}dd }dd }t|||||||g||gt jd
}	||	fS )Nr   c                 S   s   dt | |  | S r   )rE   r  r  ro  r.   r.   r/   r    s    z#kappa4_gen._get_support.<locals>.f0c                 S   s
   t | S rC   r   r!  r.   r.   r/   r    s    z#kappa4_gen._get_support.<locals>.f1c                 S   s$   t t | }t j |d d < |S rC   rE   ro  r  r[   r  ro  rp   r.   r.   r/   f3  s    z#kappa4_gen._get_support.<locals>.f3c                 S   s   d| S r   r.   r!  r.   r.   r/   f5  s    z#kappa4_gen._get_support.<locals>.f5defaultc                 S   s   d| S r   r.   r!  r.   r.   r/   r  '  s    c                 S   s"   t t | }t j|d d < |S rC   r"  r#  r.   r.   r/   r  *  s    rE   r  r   r   )
r;   r  ro  condlistr  r  r$  r%  r  r  r.   r.   r/   rv     s0    zkappa4_gen._get_supportc                 C   s   t | |||S rC   rG  r;   r`   r  ro  r.   r.   r/   ra   5  s    zkappa4_gen._pdfc           	      C   s   t |dk|dkt |dk|dkt |dk|dkt |dk|dkg}dd }dd }dd }dd	 }t|||||g|||gt jd
S )Nr   c                 S   sD   t d| d | |  t d| d | d||   d|    S )zpdf = (1.0 - k*x)**(1.0/k - 1.0)*(
                      1.0 - h*(1.0 - k*x)**(1.0/k))**(1.0/h-1.0)
               logpdf = ...
            rn   r  r`   r  ro  r.   r.   r/   r  @  s    (zkappa4_gen._logpdf.<locals>.f0c                 S   s.   t d| d | |  d||   d|   S )z~pdf = (1.0 - k*x)**(1.0/k - 1.0)*np.exp(-(
                      1.0 - k*x)**(1.0/k))
               logpdf = ...
            rn   r  r+  r.   r.   r/   r  H  s    zkappa4_gen._logpdf.<locals>.f1c                 S   s(   |  t d| d | t|    S )z]pdf = np.exp(-x)*(1.0 - h*np.exp(-x))**(1.0/h - 1.0)
               logpdf = ...
            rn   )rc   r   rE   r   r+  r.   r.   r/   rP  O  s    zkappa4_gen._logpdf.<locals>.f2c                 S   s   |  t |   S )zDpdf = np.exp(-x-np.exp(-x))
               logpdf = ...
            r  r+  r.   r.   r/   r$  U  s    zkappa4_gen._logpdf.<locals>.f3r&  r(  	r;   r`   r  ro  r)  r  r  rP  r$  r.   r.   r/   r   :  s    
zkappa4_gen._logpdfc                 C   s   t | |||S rC   r  r*  r.   r.   r/   rb   `  s    zkappa4_gen._cdfc           	      C   s   t |dk|dkt |dk|dkt |dk|dkt |dk|dkg}dd }dd }dd }dd	 }t|||||g|||gt jd
S )Nr   c                 S   s(   d| t | d||   d|    S )zVcdf = (1.0 - h*(1.0 - k*x)**(1.0/k))**(1.0/h)
               logcdf = ...
            rn   rg  r+  r.   r.   r/   r  i  s    zkappa4_gen._logcdf.<locals>.f0c                 S   s   d||   d|   S )zLcdf = np.exp(-(1.0 - k*x)**(1.0/k))
               logcdf = ...
            rn   r.   r+  r.   r.   r/   r  o  s    zkappa4_gen._logcdf.<locals>.f1c                 S   s    d| t | t|    S )zLcdf = (1.0 - h*np.exp(-x))**(1.0/h)
               logcdf = ...
            rn   )rc   r  rE   r   r+  r.   r.   r/   rP  u  s    zkappa4_gen._logcdf.<locals>.f2c                 S   s   t |   S )zBcdf = np.exp(-np.exp(-x))
               logcdf = ...
            r  r+  r.   r.   r/   r$  {  s    zkappa4_gen._logcdf.<locals>.f3r&  r(  r,  r.   r.   r/   r   c  s    
zkappa4_gen._logcdfc           	      C   s   t |dk|dkt |dk|dkt |dk|dkt |dk|dkg}dd }dd }dd }dd	 }t|||||g|||gt jd
S )Nr   c                 S   s    d| dd| |  | |   S r   r.   rf   r  ro  r.   r.   r/   r    s    zkappa4_gen._ppf.<locals>.f0c                 S   s   d| dt |  |   S r   r   r-  r.   r.   r/   r    s    zkappa4_gen._ppf.<locals>.f1c                 S   s   t | |   t| S )z,ppf = -np.log((1.0 - (q**h))/h)
            r!  r-  r.   r.   r/   rP    s    zkappa4_gen._ppf.<locals>.f2c                 S   s   t t |   S rC   r   r-  r.   r.   r/   r$    s    zkappa4_gen._ppf.<locals>.f3r&  r(  )	r;   rf   r  ro  r)  r  r  rP  r$  r.   r.   r/   rg     s    
zkappa4_gen._ppfc                 C   sD   t |dk |dk|dk g}dd }dd }t|||g||gddS )Nr   c                 S   s   d|  |  tS r  Zastyper9  r!  r.   r.   r/   r    s    z&kappa4_gen._get_stats_info.<locals>.f0c                 S   s   d|  tS r  r.  r!  r.   r.   r/   r    s    z&kappa4_gen._get_stats_info.<locals>.f1r  r&  )rE   r  r   )r;   r  ro  r)  r  r  r.   r.   r/   _get_stats_info  s    zkappa4_gen._get_stats_infoc                    s0   |  ||  fddtddD }|d d  S )Nc                    s$   g | ]}t | k rd nt jqS rC   rE   r  r   )rZ  rU  maxrr.   r/   r[    rM  z%kappa4_gen._stats.<locals>.<listcomp>r   r  )r/  r^  )r;   r  ro  outputsr.   r1  r/   r     s    zkappa4_gen._statsc                 G   s@   |  |d |d }||kr"tjS tj| jdd|f| dd S Nr   r   r   )r/  rE   r   r   r  _mom_integ1)r;   rC  r=   r2  r.   r.   r/   _mom1_sc  s    zkappa4_gen._mom1_scN)ri   rj   rk   rl   rW   r]   rv   ra   r   rb   r   rg   r/  r   r6  r.   r.   r.   r/   r    s   X)&#r  kappa4c                       sX   e Zd ZdZdd Zdd Zdd Z fdd	Zd
d Zdd Z	dd Z
dd Z  ZS )
kappa3_gena*  Kappa 3 parameter distribution.

    %(before_notes)s

    Notes
    -----
    The probability density function for `kappa3` is:

    .. math::

        f(x, a) = a (a + x^a)^{-(a + 1)/a}

    for :math:`x > 0` and :math:`a > 0`.

    `kappa3` takes ``a`` as a shape parameter for :math:`a`.

    References
    ----------
    P.W. Mielke and E.S. Johnson, "Three-Parameter Kappa Distribution Maximum
    Likelihood and Likelihood Ratio Tests", Methods in Weather Research,
    701-707, (September, 1973),
    :doi:`10.1175/1520-0493(1973)101<0701:TKDMLE>2.3.CO;2`

    B. Kumphon, "Maximum Entropy and Maximum Likelihood Estimation for the
    Three-Parameter Kappa Distribution", Open Journal of Statistics, vol 2,
    415-419 (2012), :doi:`10.4236/ojs.2012.24050`

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS r   rZ   r\   r.   r.   r/   r]     s    zkappa3_gen._shape_infoc                 C   s   ||||  d| d   S r  r.   r   r.   r.   r/   ra     s    zkappa3_gen._pdfc                 C   s   ||||  d|   S r  r.   r   r.   r.   r/   rb     s    zkappa3_gen._cdfc              	      s   t ||\}}t ||}d}||k }ttd||  || || ||     }||k}|| | ||< |||< |S )Ng{Gz?r  )rE   rR  r7   rd   rc   rj  r   )r;   r`   rp   sfcutoffrW  Zsf2i2r  r.   r/   rd     s    2zkappa3_gen._sfc                 C   s   |||  d  d|  S r   r.   r   r.   r.   r/   rg     s    zkappa3_gen._ppfc                 C   s*   t | | }t |}|| d|  S r   r  )r;   rf   rp   Zlgr  r.   r.   r/   rh     s    
zkappa3_gen._isfc                    s$    fddt ddD }|d d  S )Nc                    s$   g | ]}t | k rd nt jqS rC   r0  rY  r  r.   r/   r[     rM  z%kappa3_gen._stats.<locals>.<listcomp>r   r  )r^  )r;   rp   r3  r.   r  r/   r     s    zkappa3_gen._statsc                 G   s6   t ||d krt jS tj| jdd|f| dd S r4  )rE   r  r   r   r  r5  )r;   rC  r=   r.   r.   r/   r6    s    zkappa3_gen._mom1_sc)ri   rj   rk   rl   r]   ra   rb   rd   rg   rh   r   r6  r?  r.   r.   r  r/   r8    s    r8  kappa3c                   @   sR   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )	moyal_gena  A Moyal continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `moyal` is:

    .. math::

        f(x) = \exp(-(x + \exp(-x))/2) / \sqrt{2\pi}

    for a real number :math:`x`.

    %(after_notes)s

    This distribution has utility in high-energy physics and radiation
    detection. It describes the energy loss of a charged relativistic
    particle due to ionization of the medium [1]_. It also provides an
    approximation for the Landau distribution. For an in depth description
    see [2]_. For additional description, see [3]_.

    References
    ----------
    .. [1] J.E. Moyal, "XXX. Theory of ionization fluctuations",
           The London, Edinburgh, and Dublin Philosophical Magazine
           and Journal of Science, vol 46, 263-280, (1955).
           :doi:`10.1080/14786440308521076` (gated)
    .. [2] G. Cordeiro et al., "The beta Moyal: a useful skew distribution",
           International Journal of Research and Reviews in Applied Sciences,
           vol 10, 171-192, (2012).
           http://www.arpapress.com/Volumes/Vol10Issue2/IJRRAS_10_2_02.pdf
    .. [3] C. Walck, "Handbook on Statistical Distributions for
           Experimentalists; International Report SUF-PFY/96-01", Chapter 26,
           University of Stockholm: Stockholm, Sweden, (2007).
           http://www.stat.rice.edu/~dobelman/textfiles/DistributionsHandbook.pdf

    .. versionadded:: 1.1.0

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   7  s    zmoyal_gen._shape_infoNc                 C   s   t jdd||d}t| S )Nru   rK   )rp   r(   r   r   )rC  rD  rE   r   )r;   r   r   rE  r.   r.   r/   r   :  s    
zmoyal_gen._rvsc                 C   s*   t d|t |   t dt j  S NrN  rK   )rE   r   r   r   r   r.   r.   r/   ra   ?  s    zmoyal_gen._pdfc                 C   s   t td| td S r>  )rc   r  rE   r   r   r   r.   r.   r/   rb   B  s    zmoyal_gen._cdfc                 C   s   t td| td S r>  )rc   rM  rE   r   r   r   r.   r.   r/   rd   E  s    zmoyal_gen._sfc                 C   s   t dt|d   S r   )rE   r   rc   Zerfcinvr   r.   r.   r/   rg   H  s    zmoyal_gen._ppfc                 C   sP   t dt j }t jd d }dt d td t jd  }d}||||fS )NrK      r  r  )rE   r   euler_gammar   r   rc   ry  r   r.   r.   r/   r   K  s
    "zmoyal_gen._statsc                 C   s$  |dkrt dt j S |dkrBt jd d t dt j d  S |dkrdt jd  t dt j  }t dt j d }dtd }|| | S |dkrd	td t dt j  }dt jd  t dt j d  }t dt j d
 }dt jd
  d
 }|| | | S | |S d S )Nrn   rK   r   r  r  r  rq  r  8   r   r7  )rE   r   r@  r   rc   ry  r6  )r;   rV   Ztmp1r  Ztmp3Ztmp4r.   r.   r/   r   R  s     "
"zmoyal_gen._munp)NN)ri   rj   rk   rl   r]   r   ra   rb   rd   rg   r   r   r.   r.   r.   r/   r=    s   *
r=  moyalc                   @   st   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdddZdddZdS )nakagami_gena`  A Nakagami continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `nakagami` is:

    .. math::

        f(x, \nu) = \frac{2 \nu^\nu}{\Gamma(\nu)} x^{2\nu-1} \exp(-\nu x^2)

    for :math:`x >= 0`, :math:`\nu > 0`. The distribution was introduced in
    [2]_, see also [1]_ for further information.

    `nakagami` takes ``nu`` as a shape parameter for :math:`\nu`.

    %(after_notes)s

    References
    ----------
    .. [1] "Nakagami distribution", Wikipedia
           https://en.wikipedia.org/wiki/Nakagami_distribution
    .. [2] M. Nakagami, "The m-distribution - A general formula of intensity
           distribution of rapid fading", Statistical methods in radio wave
           propagation, Pergamon Press, 1960, 3-36.
           :doi:`10.1016/B978-0-08-009306-2.50005-4`

    %(example)s

    c                 C   s   |dkS r6  r.   )r;   nur.   r.   r/   rW     s    znakagami_gen._argcheckc                 C   s   t dddtjfdgS )NrD  Fr   r   rZ   r\   r.   r.   r/   r]     s    znakagami_gen._shape_infoc                 C   s   t | ||S rC   rG  r;   r`   rD  r.   r.   r/   ra     s    znakagami_gen._pdfc                 C   s@   t dt|| t| td| d | ||d   S r  )rE   r   rc   r   r5  rE  r.   r.   r/   r     s
    
znakagami_gen._logpdfc                 C   s   t ||| | S rC   r  rE  r.   r.   r/   rb     s    znakagami_gen._cdfc                 C   s   t d| t|| S r   r  )r;   rf   rD  r.   r.   r/   rg     s    znakagami_gen._ppfc                 C   s   t ||| | S rC   r  rE  r.   r.   r/   rd     s    znakagami_gen._sfc                 C   s   t d| t|| S rR   r  )r;   rT  rD  r.   r.   r/   rh     s    znakagami_gen._isfc                 C   s   t |dt| }d||  }|dd| |   d | t|d }d|d  | d| d	 |d	   d	|  d }|||d   }||||fS )
Nru   rn   r   r   r   r  r   rK   )rc   r  rE   r   r  )r;   rD  r   r   r   r   r.   r.   r/   r     s    (0znakagami_gen._statsc           	      C   s   t |}t |}t|}||d t|  }dt | t d }|| | }tj	 }|dk}|| | dd||    ||< |
|d S )Nru   rN  rK   g     j@r   r/  r.   )rE   r  r|  rc   r5  r  r   rS  r   r   r  )	r;   rD  r  r  r  r1  r  Znorm_entropyrW  r.   r.   r/   r     s    



 znakagami_gen._entropyNc                 C   s   t |j||d| S r4  )rE   r   r  )r;   rD  r   r   r.   r.   r/   r     s    znakagami_gen._rvsc                 C   sZ   t |tr| }|d u r$d| j }t|}tt|| d t| }|||f S )N)rn   rK   )	r5   r$   r
  ZnumargsrE   r  r   r  r  )r;   r<   r=   r'   r(   r.   r.   r/   r    s    


 znakagami_gen._fitstart)NN)N)ri   rj   rk   rl   rW   r]   ra   r   rb   rg   rd   rh   r   r   r   r  r.   r.   r.   r/   rC  k  s   
rC  nakagamic                 C   sz   |d d }t | t | }}t|d | | d|| d   }t||| d }t|dk||fdd t j dS )	Nr   rn   ru   rK   r   c                 S   s   | t | S rC   r   )rU  rf  r.   r.   r/   rL    rM  z_ncx2_log_pdf.<locals>.<lambda>)r  ra  )rE   r   rc   r   iver   r[   )r`   r  r  df2r  nsr  Zcorrr.   r.   r/   _ncx2_log_pdf  s    $rK  c                   @   sb   e Zd ZdZdd Zdd ZdddZd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )ncx2_gena  A non-central chi-squared continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `ncx2` is:

    .. math::

        f(x, k, \lambda) = \frac{1}{2} \exp(-(\lambda+x)/2)
            (x/\lambda)^{(k-2)/4}  I_{(k-2)/2}(\sqrt{\lambda x})

    for :math:`x >= 0`, :math:`k > 0` and :math:`\lambda \ge 0`.
    :math:`k` specifies the degrees of freedom (denoted ``df`` in the
    implementation) and :math:`\lambda` is the non-centrality parameter
    (denoted ``nc`` in the implementation). :math:`I_\nu` denotes the
    modified Bessel function of first order of degree :math:`\nu`
    (`scipy.special.iv`).

    `ncx2` takes ``df`` and ``nc`` as shape parameters.

    %(after_notes)s

    %(example)s

    c                 C   s   |dkt |@ |dk@ S r6  r~  r;   r  r  r.   r.   r/   rW     s    zncx2_gen._argcheckc                 C   s0   t dddtjfd}t dddtjfd}||gS )Nr  Fr   r   r  rY   rZ   r;   idfincr.   r.   r/   r]     s    zncx2_gen._shape_infoNc                 C   s   | |||S rC   )Znoncentral_chisquare)r;   r  r  r   r   r.   r.   r/   r     s    zncx2_gen._rvsc                 C   s0   t j|td|dk@ }t||||ftdd dS )Nr  r   c                 S   s   t | |S rC   )r  r   r`   r  _r.   r.   r/   rL    rM  z"ncx2_gen._logpdf.<locals>.<lambda>r  )rE   	ones_likeboolr   rK  r;   r`   r  r  condr.   r.   r/   r   
  s    zncx2_gen._logpdfc                 C   sb   t j|td|dk@ }t jdd, t||||ftjdd dW  d    S 1 sT0    Y  d S )Nr  r   r   r   c                 S   s   t | |S rC   )r  ra   rQ  r.   r.   r/   rL    rM  zncx2_gen._pdf.<locals>.<lambda>r  )rE   rS  rT  r   r   r   Z	_ncx2_pdfrU  r.   r.   r/   ra     s
    zncx2_gen._pdfc                 C   sb   t j|td|dk@ }t jdd, t||||ftjdd dW  d    S 1 sT0    Y  d S )Nr  r   r   r   c                 S   s   t | |S rC   )r  rb   rQ  r.   r.   r/   rL    rM  zncx2_gen._cdf.<locals>.<lambda>r  )rE   rS  rT  r   r   r   Z	_ncx2_cdfrU  r.   r.   r/   rb     s
    zncx2_gen._cdfc                 C   sb   t j|td|dk@ }t jdd, t||||ftjdd dW  d    S 1 sT0    Y  d S )Nr  r   r   r   c                 S   s   t | |S rC   )r  rg   rQ  r.   r.   r/   rL    rM  zncx2_gen._ppf.<locals>.<lambda>r  )rE   rS  rT  r   r   r   Z	_ncx2_ppf)r;   rf   r  r  rV  r.   r.   r/   rg     s
    zncx2_gen._ppfc                 C   sb   t j|td|dk@ }t jdd, t||||ftjdd dW  d    S 1 sT0    Y  d S )Nr  r   r   r   c                 S   s   t | |S rC   )r  rd   rQ  r.   r.   r/   rL  %  rM  zncx2_gen._sf.<locals>.<lambda>r  )rE   rS  rT  r   r   r   Z_ncx2_sfrU  r.   r.   r/   rd   !  s
    zncx2_gen._sfc                 C   sb   t j|td|dk@ }t jdd, t||||ftjdd dW  d    S 1 sT0    Y  d S )Nr  r   r   r   c                 S   s   t | |S rC   )r  rh   rQ  r.   r.   r/   rL  +  rM  zncx2_gen._isf.<locals>.<lambda>r  )rE   rS  rT  r   r   r   Z	_ncx2_isfrU  r.   r.   r/   rh   '  s
    zncx2_gen._isfc                 C   s,   t ||t ||t ||t ||fS rC   )r   Z
_ncx2_meanZ_ncx2_varianceZ_ncx2_skewnessZ_ncx2_kurtosis_excessrM  r.   r.   r/   r   -  s
    



zncx2_gen._stats)NN)ri   rj   rk   rl   rW   r]   r   r   ra   rb   rg   rd   rh   r   r.   r.   r.   r/   rL    s   
rL  ncx2c                   @   sd   e Zd ZdZdd Zdd ZdddZd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdddZdS )ncf_gena  A non-central F distribution continuous random variable.

    %(before_notes)s

    See Also
    --------
    scipy.stats.f : Fisher distribution

    Notes
    -----
    The probability density function for `ncf` is:

    .. math::

        f(x, n_1, n_2, \lambda) =
            \exp\left(\frac{\lambda}{2} +
                      \lambda n_1 \frac{x}{2(n_1 x + n_2)}
                \right)
            n_1^{n_1/2} n_2^{n_2/2} x^{n_1/2 - 1} \\
            (n_2 + n_1 x)^{-(n_1 + n_2)/2}
            \gamma(n_1/2) \gamma(1 + n_2/2) \\
            \frac{L^{\frac{n_1}{2}-1}_{n_2/2}
                \left(-\lambda n_1 \frac{x}{2(n_1 x + n_2)}\right)}
            {B(n_1/2, n_2/2)
                \gamma\left(\frac{n_1 + n_2}{2}\right)}

    for :math:`n_1, n_2 > 0`, :math:`\lambda \ge 0`.  Here :math:`n_1` is the
    degrees of freedom in the numerator, :math:`n_2` the degrees of freedom in
    the denominator, :math:`\lambda` the non-centrality parameter,
    :math:`\gamma` is the logarithm of the Gamma function, :math:`L_n^k` is a
    generalized Laguerre polynomial and :math:`B` is the beta function.

    `ncf` takes ``df1``, ``df2`` and ``nc`` as shape parameters. If ``nc=0``,
    the distribution becomes equivalent to the Fisher distribution.

    %(after_notes)s

    %(example)s

    c                 C   s   |dk|dk@ |dk@ S r6  r.   )r;   df1rI  r  r.   r.   r/   rW   b  s    zncf_gen._argcheckc                 C   sF   t dddtjfd}t dddtjfd}t dddtjfd}|||gS )NrY  Fr   r   rI  r  rY   rZ   )r;   Zidf1Zidf2rP  r.   r.   r/   r]   e  s    zncf_gen._shape_infoNc                 C   s   | ||||S rC   )Znoncentral_f)r;   r?  r@  r  r   r   r.   r.   r/   r   k  s    zncf_gen._rvsc                 C   s   t ||||S rC   )r   Z_ncf_pdfr;   r`   r?  r@  r  r.   r.   r/   ra   n  s    zncf_gen._pdfc                 C   s   t ||||S rC   )r   Z_ncf_cdfrZ  r.   r.   r/   rb   w  s    zncf_gen._cdfc                 C   s@   t jdd  t||||W  d    S 1 s20    Y  d S r   )rE   r   r   Z_ncf_ppf)r;   rf   r?  r@  r  r.   r.   r/   rg   z  s    zncf_gen._ppfc                 C   s   t ||||S rC   )r   Z_ncf_sfrZ  r.   r.   r/   rd   ~  s    zncf_gen._sfc                 C   s@   t jdd  t||||W  d    S 1 s20    Y  d S r   )rE   r   r   Z_ncf_isfrZ  r.   r.   r/   rh     s    zncf_gen._isfc                 C   s   |d | | }t |d|  t d| |  t |d  }|t| d | 9 }|t |d|  d| d| 9 }|S )Nrn   ru   r   )rc   r5  rE   r   hyp1f1)r;   rV   r?  r@  r  rp  r  r.   r.   r/   r     s
    2"zncf_gen._munprl  c           	      C   s\   t |||}t |||}d|v r2t |||nd }d|v rLt |||nd }||||fS Nrm  ro  )r   Z	_ncf_meanZ_ncf_varianceZ_ncf_skewnessZ_ncf_kurtosis_excess)	r;   r?  r@  r  rr  r   r   r   r   r.   r.   r/   r     s    zncf_gen._stats)NN)rl  )ri   rj   rk   rl   rW   r]   r   ra   rb   rg   rd   rh   r   r   r.   r.   r.   r/   rX  9  s   (
	rX  ncfc                   @   sb   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )t_gena  A Student's t continuous random variable.

    For the noncentral t distribution, see `nct`.

    %(before_notes)s

    See Also
    --------
    nct

    Notes
    -----
    The probability density function for `t` is:

    .. math::

        f(x, \nu) = \frac{\Gamma((\nu+1)/2)}
                        {\sqrt{\pi \nu} \Gamma(\nu/2)}
                    (1+x^2/\nu)^{-(\nu+1)/2}

    where :math:`x` is a real number and the degrees of freedom parameter
    :math:`\nu` (denoted ``df`` in the implementation) satisfies
    :math:`\nu > 0`. :math:`\Gamma` is the gamma function
    (`scipy.special.gamma`).

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS r  rZ   r\   r.   r.   r/   r]     s    zt_gen._shape_infoNc                 C   s   |j ||dS r4  )Z
standard_tr  r.   r.   r/   r     s    z
t_gen._rvsc                    s&   t |tjk||fdd  fdddS )Nc                 S   s
   t | S rC   )r   ra   r`   r  r.   r.   r/   rL    rM  zt_gen._pdf.<locals>.<lambda>c                    s   t  | |S rC   rG  r_  r\   r.   r/   rL    s    r  rb  r  r.   r\   r/   ra     s
    
z
t_gen._pdfc                 C   s*   dd }dd }t |tjk||f||dS )Nc                 S   sN   t td| ddt |t t j   |d d t | |  |   S r  )rE   r   rc   r  r   r  r_  r.   r.   r/   t_logpdf  s
    zt_gen._logpdf.<locals>.t_logpdfc                 S   s
   t | S rC   )r   r   r_  r.   r.   r/   norm_logpdf  s    z"t_gen._logpdf.<locals>.norm_logpdfr  rb  )r;   r`   r  r`  ra  r.   r.   r/   r     s    zt_gen._logpdfc                 C   s   t ||S rC   rc   Zstdtrr  r.   r.   r/   rb     s    z
t_gen._cdfc                 C   s   t || S rC   rb  r  r.   r.   r/   rd     s    z	t_gen._sfc                 C   s   t ||S rC   rc   Zstdtritr  r.   r.   r/   rg     s    z
t_gen._ppfc                 C   s   t || S rC   rc  r  r.   r.   r/   rh     s    z
t_gen._isfc           	      C   s   t |}t |dkdt j}|dk|dk@ |dkt |@ |f}dd dd dd f}t|||ft j}t |dkdt j}|dk|d	k@ |d	kt |@ |f}d
d dd dd f}t|||ft j}||||fS )Nr   rm   rK   c                 S   s   t t j| jS rC   rE   broadcast_tor[   r  r  r.   r.   r/   rL    rM  zt_gen._stats.<locals>.<lambda>c                 S   s   | | d  S r   r.   r  r.   r.   r/   rL    rM  c                 S   s   t d| jS rR   rE   re  r  r  r.   r.   r/   rL    rM  r  r   c                 S   s   t t j| jS rC   rd  r  r.   r.   r/   rL    rM  c                 S   s   d| d  S )Nr   r  r.   r  r.   r.   r/   rL    rM  c                 S   s   t d| jS r6  rf  r  r.   r.   r/   rL    rM  )rE   Zisposinfr  r[   r   r   r   )	r;   r  Zinfinite_dfr   r)  
choicelistr   r   r   r.   r.   r/   r     s,    
zt_gen._statsc                 C   s<   |t jkrt S dd }dd }t|dk|f||d}|S )Nc                 S   sH   | d }| d d }|t |t |  tt| t |d  S r  )rc   r  rE   r   r   r   )r  ZhalfZhalf1r.   r.   r/   r     s
    zt_gen._entropy.<locals>.regularc                 S   sP   t  d|   | d d  | d d  | d d  d| d	   | d
 d  }|S )Nr   r#  r   r$  r  r%  r   g333333?r0  r2  )r   r   )r  r  r.   r.   r/   r    s    &


z"t_gen._entropy.<locals>.asymptoticd   r  )rE   r[   r   r   r   )r;   r  r   r  r  r.   r.   r/   r     s    
zt_gen._entropy)NNr  r.   r.   r.   r/   r^    s   
	r^  r)  c                   @   s\   e Zd ZdZdd Zdd ZdddZd	d
 Zdd Zdd Z	dd Z
dd ZdddZdS )nct_gena  A non-central Student's t continuous random variable.

    %(before_notes)s

    Notes
    -----
    If :math:`Y` is a standard normal random variable and :math:`V` is
    an independent chi-square random variable (`chi2`) with :math:`k` degrees
    of freedom, then

    .. math::

        X = \frac{Y + c}{\sqrt{V/k}}

    has a non-central Student's t distribution on the real line.
    The degrees of freedom parameter :math:`k` (denoted ``df`` in the
    implementation) satisfies :math:`k > 0` and the noncentrality parameter
    :math:`c` (denoted ``nc`` in the implementation) is a real number.

    %(after_notes)s

    %(example)s

    c                 C   s   |dk||k@ S r6  r.   rM  r.   r.   r/   rW   *  s    znct_gen._argcheckc                 C   s4   t dddtjfd}t ddtj tjfd}||gS )Nr  Fr   r   r  rZ   rN  r.   r.   r/   r]   -  s    znct_gen._shape_infoNc                 C   s8   t j|||d}tj|||d}|t| t| S )Nr8  rB  )r   rD  r  rE   r   )r;   r  r  r   r   rV   r2  r.   r.   r/   r   2  s    znct_gen._rvsc                 C   s2  |d }|d }|| }|| | }|| }|d t | t|d  |t d || d  |d t |  t|d   }t |}	|d|  }
t d| | t|d d d|
 t |t|d d   }t|d d d|
t t |t|d d   }|	|| 9 }	t 	|	dd S )Nrn   r   r   rK   r  ru   r   )
rE   r   rc   r5  r   r   r[  r   rC  clip)r;   r`   r  r  rV   r(  rW  r  trm1r  ZvalFtrm2r.   r.   r/   ra   7  s(    *
& znct_gen._pdfc                 C   sH   t jdd( t t|||ddW  d    S 1 s:0    Y  d S Nr   r   r   r   )rE   r   rj  r   Z_nct_cdfr;   r`   r  r  r.   r.   r/   rb   J  s    znct_gen._cdfc                 C   s>   t jdd t|||W  d    S 1 s00    Y  d S r   )rE   r   r   Z_nct_ppf)r;   rf   r  r  r.   r.   r/   rg   N  s    znct_gen._ppfc                 C   sH   t jdd( t t|||ddW  d    S 1 s:0    Y  d S rm  )rE   r   rj  r   Z_nct_sfrn  r.   r.   r/   rd   R  s    znct_gen._sfc                 C   s>   t jdd t|||W  d    S 1 s00    Y  d S r   )rE   r   r   Z_nct_isfrn  r.   r.   r/   rh   V  s    znct_gen._isfrl  c                 C   sT   t ||}t ||}d|v r,t ||nd }d|v rDt ||nd }||||fS r\  )r   Z	_nct_meanZ_nct_varianceZ_nct_skewnessZ_nct_kurtosis_excess)r;   r  r  rr  r   r   r   r   r.   r.   r/   r   Z  s
    znct_gen._stats)NN)rl  )ri   rj   rk   rl   rW   r]   r   ra   rb   rg   rd   rh   r   r.   r.   r.   r/   ri    s   
ri  nctc                       sn   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dddZ
dd Zeee fddZ  ZS )
pareto_genaL  A Pareto continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `pareto` is:

    .. math::

        f(x, b) = \frac{b}{x^{b+1}}

    for :math:`x \ge 1`, :math:`b > 0`.

    `pareto` takes ``b`` as a shape parameter for :math:`b`.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS r  rZ   r\   r.   r.   r/   r]   {  s    zpareto_gen._shape_infoc                 C   s   ||| d   S rR   r.   r  r.   r.   r/   ra   ~  s    zpareto_gen._pdfc                 C   s   d||   S rR   r.   r  r.   r.   r/   rb     s    zpareto_gen._cdfc                 C   s   t d| d| S )Nr   r  rT  r$  r.   r.   r/   rg     s    zpareto_gen._ppfc                 C   s
   ||  S rC   r.   r  r.   r.   r/   rd     s    zpareto_gen._sfc                 C   s   t |d| S r  r1  r$  r.   r.   r/   rh     s    zpareto_gen._isfrl  c           
      C   s  d\}}}}d|v rT|dk}t ||}t jt |t jd}t ||||d   d|v r|dk}t ||}t jt |t jd}t ||||d  |d d   d	|v r|d
k}t ||}t jt |t jd}d|d  t |d  |d t |  }	t |||	 d|v r||dk}t ||}t jt |t jd}dt g d| t g d| }	t |||	 ||||fS )Nr  rC  r   r  rn   r:  rK   r   rm  r  r  ro  r   r   )rn   rn   rF  r   )rn   g      r  rm   )	rE   extractr   r  r[   Zplacer   r   r   )
r;   rq   rr  r   r   r   r   maskZbtr  r.   r.   r/   r     s4    "
,
zpareto_gen._statsc                 C   s   dd|  t | S r  r   r  r.   r.   r/   r     s    zpareto_gen._entropyc                    s  t | ||}|\}}|d urHt| |p4dk rHtddtjdjd fdd||  u rvd u rn nfddfd	d
  fddfdd}t|dd}|d |d  }	}
||	|
s|	dks|
tjk r|	d }	|
d9 }
qt|	|
gd}|j	r||j
}t| }pB||}|| tk srt| }t|d}|||fS t jfi |S n|d u rt| }n|}|pt| }p҈||}|||fS )Nr   paretor   r  c                    s   t t  | |   S rC   r  )r(   location)r<   ndatar.   r/   	get_shape  s    z!pareto_gen.fit.<locals>.get_shapec                    s    |  | S rC   r.   )r  r(   )ru  r.   r/   	dL_dScale  s    z!pareto_gen.fit.<locals>.dL_dScalec                    s   | d t d |   S rR   r  )r  rt  r  r.   r/   dL_dLocation  s    z$pareto_gen.fit.<locals>.dL_dLocationc                    s0   t |  }p| |} ||||  S rC   )rE   r  )r(   rt  r  )rx  rw  r<   r  rv  r.   r/   r"    s    z$pareto_gen.fit.<locals>.fun_to_solvec                    s   t  | t  |kS rC   rD   rG   r"  r.   r/   rJ     s    z.pareto_gen.fit.<locals>.interval_contains_rootr(   rK   r#  )r^  rE   r  r   r[   r  r  r3   r%   r  r_  r
  r7   r9   )r;   r<   r=   r-   r  r   r   rJ   r  rH   rI   r  r(   r'   r  r  )rx  rw  r<   r  r"  rv  ru  r/   r9     sH    



zpareto_gen.fit)rl  )ri   rj   rk   rl   r]   ra   rb   rg   rd   rh   r   r   rB   r	   r   r9   r?  r.   r.   r  r/   rp  e  s   
rp  rs  c                   @   s`   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdS )	lomax_gena  A Lomax (Pareto of the second kind) continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `lomax` is:

    .. math::

        f(x, c) = \frac{c}{(1+x)^{c+1}}

    for :math:`x \ge 0`, :math:`c > 0`.

    `lomax` takes ``c`` as a shape parameter for :math:`c`.

    `lomax` is a special case of `pareto` with ``loc=-1.0``.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]     s    zlomax_gen._shape_infoc                 C   s   |d d| |d   S r   r.   rh  r.   r.   r/   ra   !  s    zlomax_gen._pdfc                 C   s   t ||d t|  S rR   r  rh  r.   r.   r/   r   %  s    zlomax_gen._logpdfc                 C   s   t | t |  S rC   ri  rh  r.   r.   r/   rb   (  s    zlomax_gen._cdfc                 C   s   t | t| S rC   )rE   r   rc   r  rh  r.   r.   r/   rd   +  s    zlomax_gen._sfc                 C   s   | t | S rC   rg  rh  r.   r.   r/   r   .  s    zlomax_gen._logsfc                 C   s   t t |  | S rC   ri  rk  r.   r.   r/   rg   1  s    zlomax_gen._ppfc                 C   s   |d|  d S r  r.   rk  r.   r.   r/   rh   4  s    zlomax_gen._isfc                 C   s$   t j|ddd\}}}}||||fS )Nr  rF  )r'   rr  )rs  rS  rz  r.   r.   r/   r   7  s    zlomax_gen._statsc                 C   s   dd|  t | S r  r   r  r.   r.   r/   r   ;  s    zlomax_gen._entropyN)ri   rj   rk   rl   r]   ra   r   rb   rd   r   rg   rh   r   r   r.   r.   r.   r/   rz    s   rz  lomaxc                       s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdddZdd Zeeedd fddZ  ZS )pearson3_gena  A pearson type III continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `pearson3` is:

    .. math::

        f(x, \kappa) = \frac{|\beta|}{\Gamma(\alpha)}
                       (\beta (x - \zeta))^{\alpha - 1}
                       \exp(-\beta (x - \zeta))

    where:

    .. math::

            \beta = \frac{2}{\kappa}

            \alpha = \beta^2 = \frac{4}{\kappa^2}

            \zeta = -\frac{\alpha}{\beta} = -\beta

    :math:`\Gamma` is the gamma function (`scipy.special.gamma`).
    Pass the skew :math:`\kappa` into `pearson3` as the shape parameter
    ``skew``.

    %(after_notes)s

    %(example)s

    References
    ----------
    R.W. Vogel and D.E. McMartin, "Probability Plot Goodness-of-Fit and
    Skewness Estimation Procedures for the Pearson Type 3 Distribution", Water
    Resources Research, Vol.27, 3149-3158 (1991).

    L.R. Salvosa, "Tables of Pearson's Type III Function", Ann. Math. Statist.,
    Vol.1, 191-198 (1930).

    "Using Modern Computing Tools to Fit the Pearson Type III Distribution to
    Aviation Loads Data", Office of Aviation Research (2003).

    c                 C   s   d}d}d}t d||\}}}| }t ||k }| }d|| |  }	||	 d }
||
|	  }|	|| |  }||||||	|
|fS )Nrm   rn   g>r   rK   )rE   rR  copyr  )r;   r`   rX  r'   r(   Znorm2pearson_transitionansrr  invmaskr   r   ry  transxr.   r.   r/   _preprocessp  s    zpearson3_gen._preprocessc                 C   s
   t |S rC   r~  )r;   rX  r.   r.   r/   rW     s    zpearson3_gen._argcheckc                 C   s   t ddtj tjfdgS )NrX  Fr   rZ   r\   r.   r.   r/   r]     s    zpearson3_gen._shape_infoc                 C   s$   d}d}|}d|d  }||||fS )Nrm   rn   r  rK   r.   )r;   rX  rC  r:  rm  ro  r.   r.   r/   r     s
    zpearson3_gen._statsc                 C   s@   t | ||}|jdkr.t |r*dS |S d|t |< |S )Nr   rm   )rE   r   r   r}  r  )r;   r`   rX  r~  r.   r.   r/   ra     s    

zpearson3_gen._pdfc           
      C   sT   |  ||\}}}}}}}}	tt|| ||< tt|t|| ||< |S rC   )r  rE   r   r   r  rC  r  )
r;   r`   rX  r~  r  rr  r  r   r   rR  r.   r.   r/   r     s
    
zpearson3_gen._logpdfc                 C   s   |  ||\}}}}}}}}t|| ||< t||j}t||dk}	|| dk}
t||
 ||
 ||	< t||dk }|| dk }t|| || ||< |S r6  )	r  r   rE   re  r  r  rC  rz   r9  r;   r`   rX  r~  r  rr  r  rR  r   Z	invmask1aZ	invmask1bZ	invmask2aZ	invmask2br.   r.   r/   rb     s    
zpearson3_gen._cdfc                 C   s   |  ||\}}}}}}}}t|| ||< t||j}t||dk}	|| dk}
t||
 ||
 ||	< t||dk }|| dk }t|| || ||< |S r6  )	r  r   rE   re  r  r  rC  r9  rz   r  r.   r.   r/   rd     s    
zpearson3_gen._sfNc                 C   sv   t ||}| dg|\}}}}}}}	}
| }|j| }||||< ||	|| |
 ||< |dkrr|d }|S )Nr   r.   )rE   re  r  r  r   r   r  )r;   rX  r   r   r~  rR  rr  r  r   r   ry  ZnsmallZnbigr.   r.   r/   r     s    
zpearson3_gen._rvsc           
      C   sh   |  ||\}}}}}}}}	t|| ||< || }d||dk   ||dk < t||| |	 ||< |S rt  )r  r   rc   r  )
r;   rf   rX  r~  rR  rr  r  r   r   ry  r.   r.   r/   rg     s    
zpearson3_gen._ppfze        Note that method of moments (`method='MM'`) is not
        available for this distribution.

r   c                    s@   | dd dkrtdn"tt| | j|g|R i |S d S )Nr*   ZMMzhFit `method='MM'` is not available for the Pearson3 distribution. Please try the default `method='MLE'`.)r3   NotImplementedErrorr7   r8   r9   r  r  r.   r/   r9     s    
zpearson3_gen.fit)NN)ri   rj   rk   rl   r  rW   r]   r   ra   r   rb   rd   r   rg   rB   r   r   r9   r?  r.   r.   r  r/   r|  B  s   -
	
r|  pearson3c                       s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Z fddZeeedd fddZ  ZS )powerlaw_gena  A power-function continuous random variable.

    %(before_notes)s

    See Also
    --------
    pareto

    Notes
    -----
    The probability density function for `powerlaw` is:

    .. math::

        f(x, a) = a x^{a-1}

    for :math:`0 \le x \le 1`, :math:`a > 0`.

    `powerlaw` takes ``a`` as a shape parameter for :math:`a`.

    %(after_notes)s

    For example, the support of `powerlaw` can be adjusted from the default
    interval ``[0, 1]`` to the interval ``[c, c+d]`` by setting ``loc=c`` and
    ``scale=d``. For a power-law distribution with infinite support, see
    `pareto`.

    `powerlaw` is a special case of `beta` with ``b=1``.

    %(example)s

    c                 C   s   t dddtjfdgS r   rZ   r\   r.   r.   r/   r]   *   s    zpowerlaw_gen._shape_infoc                 C   s   |||d   S r   r.   r   r.   r.   r/   ra   -   s    zpowerlaw_gen._pdfc                 C   s   t |t|d | S rR   )rE   r   rc   r   r   r.   r.   r/   r   1   s    zpowerlaw_gen._logpdfc                 C   s   ||d  S r   r.   r   r.   r.   r/   rb   4   s    zpowerlaw_gen._cdfc                 C   s   |t | S rC   r   r   r.   r.   r/   r   7   s    zpowerlaw_gen._logcdfc                 C   s   t |d| S r   rT  r   r.   r.   r/   rg   :   s    zpowerlaw_gen._ppfc                 C   s   t || S rC   )rc   ru  )r;   rT  rp   r.   r.   r/   rd   =   s    zpowerlaw_gen._sfc                 C   s   |||  S rC   r.   )r;   rV   rp   r.   r.   r/   r   @   s    zpowerlaw_gen._munpc                 C   sn   ||d  ||d  |d d  d|d |d   t |d |  dt g d| ||d  |d   fS )	Nrn   r   rK   r#  r  r  )r   r.  rF  rK   r   )rE   r   r   r   r.   r.   r/   r   D   s
    
$&zpowerlaw_gen._statsc                 C   s   dd|  t | S r  r   r   r.   r.   r/   r   J   s    zpowerlaw_gen._entropyc                    s   t  |||dk|dkB @ S Nr   r   )r7   r   r   r  r.   r/   r   M   s    zpowerlaw_gen._support_maska:          Notes specifically for ``powerlaw.fit``: If the location is a free
        parameter and the value returned for the shape parameter is less than
        one, the true maximum likelihood approaches infinity. This causes
        numerical difficulties, and the resulting estimates are approximate.
        

r   c                    s
  | ddr&t jg|R i |S ttdkrRt jg|R i |S t| ||\}}| fg}| |i d }|d ur̈	 |kst
ddd|d ur̈ || kst
ddd|d ur|dkrtd|tkrd}t|dd	 d
d |d ur4|d ur4||||fS |d urt	 tj }	pb|	|}
||
|	|f}t | tj}p||}||||f}||k r|
|	|fS |||fS |d ur|}p||}|||fS fdd}dd dd   fdd fddfdd}d urvdkrv| S d urdkr| S | }| |}| }| |}||kr|d dkr|S ||kr|d dkr|S t jg|R i |S d S )NrV  Fr   powerlawr   zKNegative or zero `fscale` is outside the range allowed by the distribution.z0`fscale` must be greater than the range of data.c                 S   s0   t | }| tt| | |t|   S rC   )r  rE   r  r   )r<   r'   r(   r  r.   r.   r/   rv     s    z#powerlaw_gen.fit.<locals>.get_shapec                 S   s   |   | S rC   )r  r  r.   r.   r/   	get_scale   s    z#powerlaw_gen.fit.<locals>.get_scalec                     sr   t   t j } t | t | jjk rDt | t | jj } t  | t j}pf | |}|| |fS rC   )	rE   r
  r  r[   r  r%  r  r&  rF   r'   r(   r  )r<   r  r  rv  r.   r/   fit_loc_scale_w_shape_lt_1   s    z4powerlaw_gen.fit.<locals>.fit_loc_scale_w_shape_lt_1c                 S   s   | j d  | | S r6  )r  )r<   r  r(   r.   r.   r/   rw     s    z#powerlaw_gen.fit.<locals>.dL_dScalec                 S   s   |d t d||    S rR   r  )r<   r  r'   r.   r.   r/   rx     s    z&powerlaw_gen.fit.<locals>.dL_dLocationc                    s2   t | t j }p$| |} || S rC   rE   r
  r[   r  )rx  r<   r  r  rv  r.   r/   dL_dLocation_star   s    z+powerlaw_gen.fit.<locals>.dL_dLocation_starc                    s>   t | t j }p$| |}|| ||  S rC   r  r  )rx  rw  r<   r  r  rv  r.   r/   r"     s
    

z&powerlaw_gen.fit.<locals>.fun_to_solvec            	         s   t  t j }  |  } | dkrB | } |d9 }q fdd}| d }d}||| s|t j kr | }|d9 }qZtj|| fd}t |jt j }t |t j}p̈||}|||fS )Nr   rK   c                    s   t  | t  |kS rC   rD   rG   ry  r.   r/   rJ      s    zTpowerlaw_gen.fit.<locals>.fit_loc_scale_w_shape_gt_1.<locals>.interval_contains_rootr   rn   r#  )rE   r
  r  r[   r   r%   r_  )	rI   r  rJ   rH   rW  r_  r'   r(   r  )r  r<   r  r"  r  rv  r.   r/   fit_loc_scale_w_shape_gt_1   s$    



z4powerlaw_gen.fit.<locals>.fit_loc_scale_w_shape_gt_1)r+   r7   r9   r  rE   uniquer^  r  Z_reduce_funcr  r   r  r   ptpr
  r[   r  )r;   r<   r=   r-   r   r   Zpenalized_nllf_argsZpenalized_nllfrO   Zloc_lt1Z	shape_lt1Zll_lt1Zloc_gt1Z	shape_gt1Zll_gt1r(   r  r  r  Zfit_shape_lt1Zfit_shape_gt1r  )rx  r  rw  r<   r  r"  r  rv  r/   r9   Q   sr    (






$zpowerlaw_gen.fit)ri   rj   rk   rl   r]   ra   r   rb   r   rg   rd   r   r   r   r   rB   r   r   r9   r?  r.   r.   r  r/   r  	   s    
r  r  c                   @   sV   e Zd ZdZejZdd Zdd Zdd Z	dd	 Z
d
d Zdd Zdd Zdd ZdS )powerlognorm_gena  A power log-normal continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `powerlognorm` is:

    .. math::

        f(x, c, s) = \frac{c}{x s} \phi(\log(x)/s)
                     (\Phi(-\log(x)/s))^{c-1}

    where :math:`\phi` is the normal pdf, and :math:`\Phi` is the normal cdf,
    and :math:`x > 0`, :math:`s, c > 0`.

    `powerlognorm` takes :math:`c` and :math:`s` as shape parameters.

    %(after_notes)s

    %(example)s

    c                 C   s0   t dddtjfd}t dddtjfd}||gS )Nrf  Fr   r   rm  rZ   )r;   rx  r  r.   r.   r/   r]   @!  s    zpowerlognorm_gen._shape_infoc                 C   s   t | |||S rC   rG  r;   r`   rf  rm  r.   r.   r/   ra   E!  s    zpowerlognorm_gen._pdfc                 C   sL   t |t | t | tt ||  tt | | |d   S r   rE   r   r   r   r  r.   r.   r/   r   H!  s
    zpowerlognorm_gen._logpdfc                 C   s   t | ||| S rC   r  r  r.   r.   r/   rb   M!  s    zpowerlognorm_gen._cdfc                 C   s   |  d| ||S rR   )rh   r;   rf   rf  rm  r.   r.   r/   rg   P!  s    zpowerlognorm_gen._ppfc                 C   s   t | |||S rC   r  r  r.   r.   r/   rd   S!  s    zpowerlognorm_gen._sfc                 C   s   t t| | | S rC   r  r  r.   r.   r/   r   V!  s    zpowerlognorm_gen._logsfc                 C   s   t t|d|   | S rR   r  r  r.   r.   r/   rh   Y!  s    zpowerlognorm_gen._isfN)ri   rj   rk   rl   r   r   r   r]   ra   r   rb   rg   rd   r   rh   r.   r.   r.   r/   r  &!  s   r  powerlognormc                   @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )powernorm_genah  A power normal continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `powernorm` is:

    .. math::

        f(x, c) = c \phi(x) (\Phi(-x))^{c-1}

    where :math:`\phi` is the normal pdf, :math:`\Phi` is the normal cdf,
    :math:`x` is any real, and :math:`c > 0` [1]_.

    `powernorm` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    References
    ----------
    .. [1] NIST Engineering Statistics Handbook, Section 1.3.6.6.13,
           https://www.itl.nist.gov/div898/handbook//eda/section3/eda366d.htm

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]   |!  s    zpowernorm_gen._shape_infoc                 C   s   |t | t| |d   S r   r   r   rh  r.   r.   r/   ra   !  s    zpowernorm_gen._pdfc                 C   s$   t |t| |d t|   S rR   r  rh  r.   r.   r/   r   !  s    zpowernorm_gen._logpdfc                 C   s   t | || S rC   r  rh  r.   r.   r/   rb   !  s    zpowernorm_gen._cdfc                 C   s   t td| d|  S r   )r   r#  rk  r.   r.   r/   rg   !  s    zpowernorm_gen._ppfc                 C   s   t | ||S rC   r  rh  r.   r.   r/   rd   !  s    zpowernorm_gen._sfc                 C   s   |t |  S rC   r   rh  r.   r.   r/   r   !  s    zpowernorm_gen._logsfc                 C   s   t tt||  S rC   )r   rE   r   r   rk  r.   r.   r/   rh   !  s    zpowernorm_gen._isfN)ri   rj   rk   rl   r]   ra   r   rb   rg   rd   r   rh   r.   r.   r.   r/   r  `!  s   r  	powernormc                   @   sR   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dddZ
dd ZdS )	rdist_gena/  An R-distributed (symmetric beta) continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `rdist` is:

    .. math::

        f(x, c) = \frac{(1-x^2)^{c/2-1}}{B(1/2, c/2)}

    for :math:`-1 \le x \le 1`, :math:`c > 0`. `rdist` is also called the
    symmetric beta distribution: if B has a `beta` distribution with
    parameters (c/2, c/2), then X = 2*B - 1 follows a R-distribution with
    parameter c.

    `rdist` takes ``c`` as a shape parameter for :math:`c`.

    This distribution includes the following distribution kernels as
    special cases::

        c = 2:  uniform
        c = 3:  `semicircular`
        c = 4:  Epanechnikov (parabolic)
        c = 6:  quartic (biweight)
        c = 8:  triweight

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS re  rZ   r\   r.   r.   r/   r]   !  s    zrdist_gen._shape_infoc                 C   s   t | ||S rC   rG  rh  r.   r.   r/   ra   !  s    zrdist_gen._pdfc                 C   s*   t d t|d d |d |d  S r  )rE   r   r   r   rh  r.   r.   r/   r   !  s    zrdist_gen._logpdfc                 C   s   t |d d |d |d S r   rN  rh  r.   r.   r/   rb   !  s    zrdist_gen._cdfc                 C   s   t |d d |d |d S r   rH  rh  r.   r.   r/   rd   !  s    zrdist_gen._sfc                 C   s   dt ||d |d  d S r  )r   rg   rk  r.   r.   r/   rg   !  s    zrdist_gen._ppfNc                 C   s   d| |d |d | d S r  r   r9  r.   r.   r/   r   !  s    zrdist_gen._rvsc                 C   s8   d|d  t |d d |d  }|t d|d  S )Nr   rK   rn   r   ru   r  )r;   rV   rf  	numeratorr.   r.   r/   r   !  s    $zrdist_gen._munp)NN)ri   rj   rk   rl   r]   ra   r   rb   rd   rg   r   r   r.   r.   r.   r/   r  !  s   !
r  r  rdistc                       s   e Zd ZdZejZdd ZdddZdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zeeedd fddZ  ZS )rayleigh_gena7  A Rayleigh continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `rayleigh` is:

    .. math::

        f(x) = x \exp(-x^2/2)

    for :math:`x \ge 0`.

    `rayleigh` is a special case of `chi` with ``df=2``.

    %(after_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   !  s    zrayleigh_gen._shape_infoNc                 C   s   t jd||dS )NrK   rB  r  r   r.   r.   r/   r   !  s    zrayleigh_gen._rvsc                 C   s   t | |S rC   rG  r;   rU  r.   r.   r/   ra   !  s    zrayleigh_gen._pdfc                 C   s   t |d| |  S r  r   r  r.   r.   r/   r   !  s    zrayleigh_gen._logpdfc                 C   s   t d|d   S r>  r  r  r.   r.   r/   rb   !  s    zrayleigh_gen._cdfc                 C   s   t dt|  S Nr   )rE   r   rc   r  r   r.   r.   r/   rg   "  s    zrayleigh_gen._ppfc                 C   s   t | |S rC   r  r  r.   r.   r/   rd   "  s    zrayleigh_gen._sfc                 C   s   d| | S )NrN  r.   r  r.   r.   r/   r   "  s    zrayleigh_gen._logsfc                 C   s   t dt | S r  )rE   r   r   r   r.   r.   r/   rh   
"  s    zrayleigh_gen._isfc                 C   sZ   dt j }t t jd |d dt jd  t t j |d  dt j | d|d   fS )Nr   rK   r  r  r  r   r  r  r.   r.   r/   r   "  s    
 zrayleigh_gen._statsc                 C   s   t d d dtd  S )Nr   r   ru   rK   rU  r\   r.   r.   r/   r   "  s    zrayleigh_gen._entropya          Notes specifically for ``rayleigh.fit``: If the location is fixed with
        the `floc` parameter, this method uses an analytical formula to find
        the scale.  Otherwise, this function uses a numerical root finder on
        the first order conditions of the log-likelihood function to find the
        MLE.  Only the (optional) `loc` parameter is used as the initial guess
        for the root finder; the `scale` parameter and any other parameters
        for the optimizer are ignored.

r   c                    s*  | ddr&t j g|R i |S t|  ||\ }} fdd} fdd}|f fdd	}|d urt | d	krtd
dtjdn|||fS |d}	|	d u r| 	 d	 }	|d u r|n|}
t
t tj }t|
|}tj|
||fd}|jst|j|j}|p ||}||fS )NrV  Fc                    s"   t  |  d dt   d S r  )rE   r  r  r'   r  r.   r/   	scale_mle&"  s    z#rayleigh_gen.fit.<locals>.scale_mlec                    s@    |  }|  }|d   }d|   }||dt   |  S r  )r  r  )r'   r  r   r   Zs3r  r.   r/   loc_mle+"  s
    z!rayleigh_gen.fit.<locals>.loc_mlec                    s$    |  }|  |d d|     S r  )r  )r'   r(   r  r  r.   r/   loc_mle_scale_fixed4"  s    z-rayleigh_gen.fit.<locals>.loc_mle_scale_fixedr   rayleighr   r  r'   r#  )r+   r7   r9   r^  rE   r  r   r[   r3   r  r
  r  rP   r   r%   r  rM   flagr_  )r;   r<   r=   r-   r   r   r  r  r  Zloc0r@   rI   rH   r  r'   r(   r  r  r/   r9   "  s0    

	


zrayleigh_gen.fit)NN)ri   rj   rk   rl   r   r   r   r]   r   ra   r   rb   rg   rd   r   rh   r   r   rB   r   r9   r?  r.   r.   r  r/   r  !  s    

r  r  c                       s   e Zd ZdZdd Zdd Z fddZdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdZeeed fddZ  ZS )reciprocal_gena,  A loguniform or reciprocal continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for this class is:

    .. math::

        f(x, a, b) = \frac{1}{x \log(b/a)}

    for :math:`a \le x \le b`, :math:`b > a > 0`. This class takes
    :math:`a` and :math:`b` as shape parameters.

    %(after_notes)s

    %(example)s

    This doesn't show the equal probability of ``0.01``, ``0.1`` and
    ``1``. This is best when the x-axis is log-scaled:

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> fig, ax = plt.subplots(1, 1)
    >>> ax.hist(np.log10(r))
    >>> ax.set_ylabel("Frequency")
    >>> ax.set_xlabel("Value of random variable")
    >>> ax.xaxis.set_major_locator(plt.FixedLocator([-2, -1, 0]))
    >>> ticks = ["$10^{{ {} }}$".format(i) for i in [-2, -1, 0]]
    >>> ax.set_xticklabels(ticks)  # doctest: +SKIP
    >>> plt.show()

    This random variable will be log-uniform regardless of the base chosen for
    ``a`` and ``b``. Let's specify with base ``2`` instead:

    >>> rvs = %(name)s(2**-2, 2**0).rvs(size=1000)

    Values of ``1/4``, ``1/2`` and ``1`` are equally likely with this random
    variable.  Here's the histogram:

    >>> fig, ax = plt.subplots(1, 1)
    >>> ax.hist(np.log2(rvs))
    >>> ax.set_ylabel("Frequency")
    >>> ax.set_xlabel("Value of random variable")
    >>> ax.xaxis.set_major_locator(plt.FixedLocator([-2, -1, 0]))
    >>> ticks = ["$2^{{ {} }}$".format(i) for i in [-2, -1, 0]]
    >>> ax.set_xticklabels(ticks)  # doctest: +SKIP
    >>> plt.show()

    c                 C   s   |dk||k@ S r6  r.   r  r.   r.   r/   rW   "  s    zreciprocal_gen._argcheckc                 C   s0   t dddtjfd}t dddtjfd}||gS r   rZ   r   r.   r.   r/   r]   "  s    zreciprocal_gen._shape_infoc                    s2   t |tr| }t j|t|t|fdS Nr   r5   r$   r
  r7   r  rE   r  r  re  r  r.   r/   r  "  s    
zreciprocal_gen._fitstartc                 C   s   ||fS rC   r.   r  r.   r.   r/   rv   "  s    zreciprocal_gen._get_supportc                 C   s   t | |||S rC   rG  r   r.   r.   r/   ra   "  s    zreciprocal_gen._pdfc                 C   s&   t | t t |t |  S rC   r   r   r.   r.   r/   r   "  s    zreciprocal_gen._logpdfc                 C   s(   t |t | t |t |  S rC   r   r   r.   r.   r/   rb   "  s    zreciprocal_gen._cdfc                 C   s(   t t ||t |t |   S rC   rE   r   r   r  r.   r.   r/   rg   "  s    zreciprocal_gen._ppfc              
   C   sN   dt |t |  | }t t t|t | |t | }|| S rR   )rE   r   r  r   	_log_diff)r;   rV   rp   rq   r*  r+  r.   r.   r/   r   "  s    *zreciprocal_gen._munpc                 C   s2   dt |t |  t t |t |  S r  r   r  r.   r.   r/   r   "  s    zreciprocal_gen._entropyz        `loguniform`/`reciprocal` is over-parameterized. `fit` automatically
         fixes `scale` to 1 unless `fscale` is provided by the user.

r   c                    s*   | dd}t j|g|R d|i|S )Nr   r   )r+   r7   r9   )r;   r<   r=   r-   r   r  r.   r/   r9   "  s    zreciprocal_gen.fit)ri   rj   rk   rl   rW   r]   r  rv   ra   r   rb   rg   r   r   Zfit_noter   r   r9   r?  r.   r.   r  r/   r  U"  s   3
r  
loguniform
reciprocalc                   @   sJ   e Zd ZdZdd Zdd ZdddZd	d
 Zdd Zdd Z	dd Z
dS )rice_gena  A Rice continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `rice` is:

    .. math::

        f(x, b) = x \exp(- \frac{x^2 + b^2}{2}) I_0(x b)

    for :math:`x >= 0`, :math:`b > 0`. :math:`I_0` is the modified Bessel
    function of order zero (`scipy.special.i0`).

    `rice` takes ``b`` as a shape parameter for :math:`b`.

    %(after_notes)s

    The Rice distribution describes the length, :math:`r`, of a 2-D vector with
    components :math:`(U+u, V+v)`, where :math:`U, V` are constant, :math:`u,
    v` are independent Gaussian random variables with standard deviation
    :math:`s`.  Let :math:`R = \sqrt{U^2 + V^2}`. Then the pdf of :math:`r` is
    ``rice.pdf(x, R/s, scale=s)``.

    %(example)s

    c                 C   s   |dkS r6  r.   r;   rq   r.   r.   r/   rW   "  s    zrice_gen._argcheckc                 C   s   t dddtjfdgS )Nrq   Fr   rY   rZ   r\   r.   r.   r/   r]   "  s    zrice_gen._shape_infoNc                 C   s4   |t d |jd| d }t || jddS )NrK   )rK   r  r   r\  )rE   r   r   r  )r;   rq   r   r   r)  r.   r.   r/   r   "  s    zrice_gen._rvsc                 C   s   t t|dt|S r   )rc   ZchndtrrE   r$  r  r.   r.   r/   rb   "  s    zrice_gen._cdfc              	   C   s   t t|dt |S r   )rE   r   rc   Zchndtrixr$  r$  r.   r.   r/   rg   "  s    zrice_gen._ppfc                 C   s.   |t ||  ||  d  t||  S r   )rE   r   rc   i0er  r.   r.   r/   ra   "  s    zrice_gen._pdfc                 C   sH   |d }d| }|| d }d| t |  t| t|d| S r  )rE   r   rc   rC  r[  )r;   rV   rq   Znd2Zn1r  r.   r.   r/   r   "  s    zrice_gen._munp)NN)ri   rj   rk   rl   rW   r]   r   rb   rg   ra   r   r.   r.   r.   r/   r  "  s   
	r  ricec                   @   sB   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdddZ	dS )recipinvgauss_gena  A reciprocal inverse Gaussian continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `recipinvgauss` is:

    .. math::

        f(x, \mu) = \frac{1}{\sqrt{2\pi x}}
                    \exp\left(\frac{-(1-\mu x)^2}{2\mu^2x}\right)

    for :math:`x \ge 0`.

    `recipinvgauss` takes ``mu`` as a shape parameter for :math:`\mu`.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS rK  rZ   r\   r.   r.   r/   r]   #  s    zrecipinvgauss_gen._shape_infoc                 C   s   t | ||S rC   rG  rP  r.   r.   r/   ra   #  s    zrecipinvgauss_gen._pdfc                 C   s    t |dk||fdd tj dS )Nr   c                 S   s:   d||   d  d|  |d   dt dt j |    S )Nr   r   rK   ru   r   )r`   r   r.   r.   r/   rL  $#  s    z+recipinvgauss_gen._logpdf.<locals>.<lambda>r`  rb  rP  r.   r.   r/   r   "#  s    zrecipinvgauss_gen._logpdfc                 C   sP   d| | }d| | }dt | }t| | t d| t| |   S Nrn   r   rE   r   r   r   r;   r`   r   rk  rl  Zisqxr.   r.   r/   rb   (#  s    zrecipinvgauss_gen._cdfc                 C   sN   d| | }d| | }dt | }t|| t d| t| |   S r  r  r  r.   r.   r/   rd   .#  s    zrecipinvgauss_gen._sfNc                 C   s   d|j |d|d S rL  rM  rO  r.   r.   r/   r   4#  s    zrecipinvgauss_gen._rvs)NN)
ri   rj   rk   rl   r]   ra   r   rb   rd   r   r.   r.   r.   r/   r  #  s   r  recipinvgaussc                   @   sR   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdddZ	dd Z
dd ZdS )semicircular_gena  A semicircular continuous random variable.

    %(before_notes)s

    See Also
    --------
    rdist

    Notes
    -----
    The probability density function for `semicircular` is:

    .. math::

        f(x) = \frac{2}{\pi} \sqrt{1-x^2}

    for :math:`-1 \le x \le 1`.

    The distribution is a special case of `rdist` with `c = 3`.

    %(after_notes)s

    References
    ----------
    .. [1] "Wigner semicircle distribution",
           https://en.wikipedia.org/wiki/Wigner_semicircle_distribution

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   Z#  s    zsemicircular_gen._shape_infoc                 C   s   dt j t d||   S r  r  r   r.   r.   r/   ra   ]#  s    zsemicircular_gen._pdfc                 C   s$   t dt j dt| |   S r  r  r   r.   r.   r/   r   `#  s    zsemicircular_gen._logpdfc                 C   s.   ddt j |t d||   t |   S )Nru   rn   r   )rE   r   r   r   r   r.   r.   r/   rb   c#  s    zsemicircular_gen._cdfc                 C   s   t |dS Nr  )r  rg   r   r.   r.   r/   rg   f#  s    zsemicircular_gen._ppfNc                 C   s2   t |j|d}t t j|j|d }|| S r4  )rE   r   r  r   r   )r;   r   r   rU  rp   r.   r.   r/   r   i#  s    zsemicircular_gen._rvsc                 C   s   dS )N)r   r+  r   r  r.   r\   r.   r.   r/   r   p#  s    zsemicircular_gen._statsc                 C   s   dS )NgzCϑ?r.   r\   r.   r.   r/   r   s#  s    zsemicircular_gen._entropy)NN)ri   rj   rk   rl   r]   ra   r   rb   rg   r   r   r   r.   r.   r.   r/   r  ;#  s   
r  semicircularc                   @   sJ   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdddZ	dd Z
dS )skewcauchy_gena  A skewed Cauchy random variable.

    %(before_notes)s

    See Also
    --------
    cauchy : Cauchy distribution

    Notes
    -----

    The probability density function for `skewcauchy` is:

    .. math::

        f(x) = \frac{1}{\pi \left(\frac{x^2}{\left(a\, \text{sign}(x) + 1
                                                   \right)^2} + 1 \right)}

    for a real number :math:`x` and skewness parameter :math:`-1 < a < 1`.

    When :math:`a=0`, the distribution reduces to the usual Cauchy
    distribution.

    %(after_notes)s

    References
    ----------
    .. [1] "Skewed generalized *t* distribution", Wikipedia
       https://en.wikipedia.org/wiki/Skewed_generalized_t_distribution#Skewed_Cauchy_distribution

    %(example)s

    c                 C   s   t |dk S rR   )rE   r  r   r.   r.   r/   rW   #  s    zskewcauchy_gen._argcheckc                 C   s   t ddddgS )Nrp   F)r  rn   r   r   r\   r.   r.   r/   r]   #  s    zskewcauchy_gen._shape_infoc                 C   s,   dt j|d |t | d d  d   S r   )rE   r   rF   r   r.   r.   r/   ra   #  s    zskewcauchy_gen._pdfc                 C   sb   t |dkd| d d| t j t |d|    d| d d| t j t |d|    S Nr   r   rK   )rE   r  r   r  r   r.   r.   r/   rb   #  s    
**zskewcauchy_gen._cdfc              
   C   sn   ||  d|k }t|ttjd|  |d| d   d|  ttjd|  |d| d   d|  S r  )rb   rE   r  r  r   )r;   r`   rp   rW  r.   r.   r/   rg   #  s
    **zskewcauchy_gen._ppfrF  c                 C   s   t jt jt jt jfS rC   r  )r;   rp   rr  r.   r.   r/   r   #  s    zskewcauchy_gen._statsc                 C   s:   t |tr| }t|g d\}}}d||| d fS )Nr  rm   rK   r  )r;   r<   r  r  r  r.   r.   r/   r  #  s    
zskewcauchy_gen._fitstartN)rF  )ri   rj   rk   rl   rW   r]   ra   rb   rg   r   r  r.   r.   r.   r/   r  z#  s   !
r  
skewcauchyc                       s   e Zd ZdZdd Zdd Zdd Zdd	 Z fd
dZdd Z	dd Z
dd Zd ddZd!ddZedd Zdd Zeedd fddZ  ZS )"skewnorm_genaf  A skew-normal random variable.

    %(before_notes)s

    Notes
    -----
    The pdf is::

        skewnorm.pdf(x, a) = 2 * norm.pdf(x) * norm.cdf(a*x)

    `skewnorm` takes a real number :math:`a` as a skewness parameter
    When ``a = 0`` the distribution is identical to a normal distribution
    (`norm`). `rvs` implements the method of [1]_.

    %(after_notes)s

    %(example)s

    References
    ----------
    .. [1] A. Azzalini and A. Capitanio (1999). Statistical applications of
        the multivariate skew-normal distribution. J. Roy. Statist. Soc.,
        B 61, 579-602. :arxiv:`0911.2093`

    c                 C   s
   t |S rC   r~  r   r.   r.   r/   rW   #  s    zskewnorm_gen._argcheckc                 C   s   t ddtj tjfdgS )Nrp   Fr   rZ   r\   r.   r.   r/   r]   #  s    zskewnorm_gen._shape_infoc                 C   s    t |dk||fdd dd dS )Nr   c                 S   s   t | S rC   r   r`   rp   r.   r.   r/   rL  #  rM  z#skewnorm_gen._pdf.<locals>.<lambda>c                 S   s   dt |  t||   S r   r  r  r.   r.   r/   rL  #  rM  rO  rQ  r   r.   r.   r/   ra   #  s    zskewnorm_gen._pdfc                 C   s    t |dk||fdd dd dS )Nr   c                 S   s   t | S rC   r   r  r.   r.   r/   rL  #  rM  z&skewnorm_gen._logpdf.<locals>.<lambda>c                 S   s   t dt|  t||   S r   r  r  r.   r.   r/   rL  #  rM  rO  rQ  r   r.   r.   r/   r   #  s    zskewnorm_gen._logpdfc                    s`   t |}t|dd|}t ||j}|dk |dk@ }t || || ||< t |ddS )Nr   r   gư>)	rE   r|  r   Z_skewnorm_cdfre  r  r7   rb   rj  )r;   r`   rp   rz   Zi_small_cdfr  r.   r/   rb   #  s    
zskewnorm_gen._cdfc                 C   s   t |dd|S r  )r   Z_skewnorm_ppfr   r.   r.   r/   rg   #  s    zskewnorm_gen._ppfc                 C   s   |  | | S rC   r  r   r.   r.   r/   rd   #  s    zskewnorm_gen._sfc                 C   s   t |dd|S r  )r   Z_skewnorm_isfr   r.   r.   r/   rh   #  s    zskewnorm_gen._isfNc                 C   s`   |j |d}|j |d}|td|d   }|| |td|d    }t|dk|| S )Nr  r   rK   r   )normalrE   r   r  )r;   rp   r   r   Zu0r:  r=  rE  r.   r.   r/   r   $  s
    zskewnorm_gen._rvsrF  c                 C   s   g d}t dt j | t d|d   }d|v r>||d< d|v rVd|d  |d< d|v rdt j d |t d|d   d	  |d< d
|v rdt jd	  |d d|d  d   |d	< |S )Nr  rK   r   rC  r   r:  rm  r   r  ro  r8  )r;   rp   rr  r  constr.   r.   r/   r   $  s    &,*zskewnorm_gen._statsc                 C   sl   t dgt ddgt g dt g dt g dt g dt g dt g d	t g d
t g dd
}|S )Nr   r  r.  )r  ir  )i   i?   i)i  iin  ir  )(  iSi6Q  ii  iO)i iBi/ iio ir  ) iԷi iYei{Hx ii i!)	i!iׅi쇀iiViX'ilir  )
is_'il   </1 ldy( l   J8D l.~ l   -Rx iWi[i0)
r   r  r  r7  rn  r/     r        r   )r;   Zskewnorm_odd_momentsr.   r.   r/   _skewnorm_odd_moments$  s    








z"skewnorm_gen._skewnorm_odd_momentsc                 C   sn   |d@ rH|dkrt d|td|d   }|| j| |d  t S t|d d d|d   t S d S )Nr   r  zKskewnorm noncentral moments not implemented for odd orders greater than 19.rK   )r  rE   r   r  r"   rc   rC  r!   )r;   r:  rp   r  r.   r.   r/   r   3$  s    	zskewnorm_gen._munpa          If ``method='mm'``, parameters fixed by the user are respected, and the
        remaining parameters are used to match distribution and sample moments
        where possible. For example, if the user fixes the location with
        ``floc``, the parameters will only match the distribution skewness and
        variance to the sample skewness and variance; no attempt will be made
        to match the means or minimize a norm of the errors.
        Note that the maximum possible skewness magnitude of a
        `scipy.stats.skewnorm` distribution is approximately 0.9952717; if the
        magnitude of the data's sample skewness exceeds this, the returned
        shape parameter ``a`` will be infinite.
        

r   c              	      sz  | ddr&t j|g|R i |S t|tr`| dkrF| }nt j|g|R i |S t| |||\}}}}|dd	 }dd }dd	 }	|d
krd\}
}}n,t
|r|d nd }
| dd }| dd }|d u r|
d u rt|}|dkrt|dd}n|d}t|| |}|	|}tjdd8 tt|d d|d  t| }
W d    n1 sz0    Y  n(|d ur|n|
}
|
td|
d   }|d u r|d u rt|}t|dd|d  tj   }n|d ur|}|d u r8|d u r8t|}||| tdtj   }n|d urF|}|d
krZ|
||fS t j||
f||d|S d S )NrV  Fr   r*   r1   c                 S   s@   dt j d | t dt j  d dd| d  t j  d   S )Nr   rK   r  r   r  r  r=  r.   r.   r/   skew_dd$  s    "z skewnorm_gen.fit.<locals>.skew_dc                 S   sB   t | d }t | t t jd | |dt j d d    S )NrH  rK   r   )rE   r  rF   r   r   )rX  Zs_23r.   r.   r/   d_skewg$  s    "z skewnorm_gen.fit.<locals>.d_skewr2   rY  r'   r(   gGzgGz?r   r   r   rK   r]  )r+   r7   r9   r5   r$   r6   r
  r^  r3   r4   r  rS  rX  rE   rj  r   r   r   rF   r  r   r   )r;   r<   r=   r-   r  r   r   r*   r  r  rp   r'   r(   rm  Zs_maxr=  r:  rC  r  r.   r/   r9   G$  sR    



J
"




zskewnorm_gen.fit)NN)rF  )ri   rj   rk   rl   rW   r]   ra   r   rb   rg   rd   rh   r   r   r   r  r   r   r   r9   r?  r.   r.   r  r/   r  #  s    




r  skewnormc                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )trapezoid_gena  A trapezoidal continuous random variable.

    %(before_notes)s

    Notes
    -----
    The trapezoidal distribution can be represented with an up-sloping line
    from ``loc`` to ``(loc + c*scale)``, then constant to ``(loc + d*scale)``
    and then downsloping from ``(loc + d*scale)`` to ``(loc+scale)``.  This
    defines the trapezoid base from ``loc`` to ``(loc+scale)`` and the flat
    top from ``c`` to ``d`` proportional to the position along the base
    with ``0 <= c <= d <= 1``.  When ``c=d``, this is equivalent to `triang`
    with the same values for `loc`, `scale` and `c`.
    The method of [1]_ is used for computing moments.

    `trapezoid` takes :math:`c` and :math:`d` as shape parameters.

    %(after_notes)s

    The standard form is in the range [0, 1] with c the mode.
    The location parameter shifts the start to `loc`.
    The scale parameter changes the width from 1 to `scale`.

    %(example)s

    References
    ----------
    .. [1] Kacker, R.N. and Lawrence, J.F. (2007). Trapezoidal and triangular
       distributions for Type B evaluation of standard uncertainty.
       Metrologia 44, 117-127. :doi:`10.1088/0026-1394/44/2/003`


    c                 C   s(   |dk|dk@ |dk@ |dk@ ||k@ S r  r.   r;   rf  r=  r.   r.   r/   rW   $  s    ztrapezoid_gen._argcheckc                 C   s$   t dddd}t dddd}||gS )Nrf  Fr   rn   TTr=  r  rw  r.   r.   r/   r]   $  s    ztrapezoid_gen._shape_infoc                 C   sP   d|| d  }t ||k ||k||k@ ||kgdd dd dd g||||fS )NrK   r   c                 S   s   ||  | S rC   r.   r`   rf  r=  r  r.   r.   r/   rL  $  rM  z$trapezoid_gen._pdf.<locals>.<lambda>c                 S   s   |S rC   r.   r  r.   r.   r/   rL  $  rM  c                 S   s   |d|   d|  S rR   r.   r  r.   r.   r/   rL  $  rM  r   )r;   r`   rf  r=  r  r.   r.   r/   ra   $  s    
ztrapezoid_gen._pdfc                 C   s>   t ||k ||k||k@ ||kgdd dd dd g|||fS )Nc                 S   s   | d | || d  S r  r.   r`   rf  r=  r.   r.   r/   rL  $  rM  z$trapezoid_gen._cdf.<locals>.<lambda>c                 S   s   |d| |   || d  S r  r.   r  r.   r.   r/   rL  $  rM  c                 S   s$   dd|  d || d  d|   S r   r.   r  r.   r.   r/   rL  $  s   
r  r  r.   r.   r/   rb   $  s    ztrapezoid_gen._cdfc                 C   s   |  ||||  ||| }}||k ||k||kg}t|| d| |  d| d| |  d|  dtd| || d  d|   g}t||S r  )rb   rE   r   select)r;   rf   rf  r=  ZqcZqdr)  rg  r.   r.   r/   rg   $  s    $ztrapezoid_gen._ppfc                    sz   | d  }t |dkd|k |dk @ |dkgdd  fdd fddg|g}dd| |  ||   d  d	   }|S )
Nr   rm   rn   c                 S   s   dS r   r.   r  r.   r.   r/   rL  $  rM  z%trapezoid_gen._munp.<locals>.<lambda>c                    s    t  d t |  | d  S r  )rE   rj  r   r  r_  r.   r/   rL  $  rM  c                    s    d S r   r.   r  r_  r.   r/   rL  $  rM  r   rK   r  )r;   rV   rf  r=  Zab_termZdc_termrp  r.   r_  r/   r   $  s    

(ztrapezoid_gen._munpc                 C   s2   dd| |  d| |  t dd| |   S rt   r   r  r.   r.   r/   r   $  s    ztrapezoid_gen._entropyN)ri   rj   rk   rl   rW   r]   ra   rb   rg   r   r   r.   r.   r.   r/   r  $  s   !
r  	trapezoidtrapzz!trapz is an alias for `trapezoid`c                   @   sR   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )
triang_gena5  A triangular continuous random variable.

    %(before_notes)s

    Notes
    -----
    The triangular distribution can be represented with an up-sloping line from
    ``loc`` to ``(loc + c*scale)`` and then downsloping for ``(loc + c*scale)``
    to ``(loc + scale)``.

    `triang` takes ``c`` as a shape parameter for :math:`0 \le c \le 1`.

    %(after_notes)s

    The standard form is in the range [0, 1] with c the mode.
    The location parameter shifts the start to `loc`.
    The scale parameter changes the width from 1 to `scale`.

    %(example)s

    Nc                 C   s   | d|d|S r  )
triangularr9  r.   r.   r/   r   '%  s    ztriang_gen._rvsc                 C   s   |dk|dk@ S r  r.   r  r.   r.   r/   rW   *%  s    ztriang_gen._argcheckc                 C   s   t ddddgS )Nrf  Fr  r  r  r\   r.   r.   r/   r]   -%  s    ztriang_gen._shape_infoc                 C   sL   t |dk||k ||k|dk@ |dkgdd dd dd dd g||f}|S )Nr   r   c                 S   s   dd|   S r   r.   r  r.   r.   r/   rL  :%  rM  z!triang_gen._pdf.<locals>.<lambda>c                 S   s   d|  | S r   r.   r  r.   r.   r/   rL  ;%  rM  c                 S   s   dd|   d|  S r  r.   r  r.   r.   r/   rL  <%  rM  c                 S   s   d|  S r   r.   r  r.   r.   r/   rL  =%  rM  r  r;   r`   rf  rU  r.   r.   r/   ra   0%  s    	ztriang_gen._pdfc                 C   sL   t |dk||k ||k|dk@ |dkgdd dd dd dd g||f}|S )Nr   r   c                 S   s   d|  | |   S r   r.   r  r.   r.   r/   rL  F%  rM  z!triang_gen._cdf.<locals>.<lambda>c                 S   s   | |  | S rC   r.   r  r.   r.   r/   rL  G%  rM  c                 S   s   | |  d|   | |d  S r  r.   r  r.   r.   r/   rL  H%  rM  c                 S   s   | |  S rC   r.   r  r.   r.   r/   rL  I%  rM  r  r  r.   r.   r/   rb   A%  s    	ztriang_gen._cdfc              
   C   s2   t ||k t || dt d| d|   S rR   )rE   r  r   rk  r.   r.   r/   rg   M%  s    ztriang_gen._ppfc              	   C   sb   |d d d| ||  d t dd| d  |d  |d  dt d| ||  d  dfS )	Nrn   r     rK   r   r  r  g333333)rE   r   r  r  r.   r.   r/   r   P%  s
    
@ztriang_gen._statsc                 C   s   dt d S r  r   r  r.   r.   r/   r   V%  s    ztriang_gen._entropy)NN)ri   rj   rk   rl   r   rW   r]   ra   rb   rg   r   r   r.   r.   r.   r/   r  %  s   
r  triangc                       sh   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Z fddZdd Z  ZS )truncexpon_genad  A truncated exponential continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `truncexpon` is:

    .. math::

        f(x, b) = \frac{\exp(-x)}{1 - \exp(-b)}

    for :math:`0 <= x <= b`.

    `truncexpon` takes ``b`` as a shape parameter for :math:`b`.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS r  rZ   r\   r.   r.   r/   r]   s%  s    ztruncexpon_gen._shape_infoc                 C   s
   | j |fS rC   r  r  r.   r.   r/   rv   v%  s    ztruncexpon_gen._get_supportc                 C   s   t | t|   S rC   r   r  r.   r.   r/   ra   y%  s    ztruncexpon_gen._pdfc                 C   s   | t t|   S rC   r  r  r.   r.   r/   r   }%  s    ztruncexpon_gen._logpdfc                 C   s   t | t |  S rC   r  r  r.   r.   r/   rb   %  s    ztruncexpon_gen._cdfc                 C   s   t |t |   S rC   )rc   r  rj  r$  r.   r.   r/   rg   %  s    ztruncexpon_gen._ppfc                 C   s$   t | t |  t|  S rC   r   r  r.   r.   r/   rd   %  s    ztruncexpon_gen._sfc                 C   s$   t t | |t|    S rC   )rE   r   r   rc   rj  r$  r.   r.   r/   rh   %  s    ztruncexpon_gen._isfc                    s   |dkr.d|d t |   t|   S |dkrpddd|| d|  d  t |    t|   S t ||S d S r  )rE   r   rc   rj  r7   r   )r;   rV   rq   r  r.   r/   r   %  s
    &:ztruncexpon_gen._munpc                 C   s0   t |}t |d d||d   d|   S r  r  )r;   rq   ZeBr.   r.   r/   r   %  s    
ztruncexpon_gen._entropy)ri   rj   rk   rl   r]   rv   ra   r   rb   rg   rd   rh   r   r   r?  r.   r.   r  r/   r  ]%  s   r  
truncexponc                 C   s   t j| |gddS )Nr   r\  )rc   r  Zlog_pZlog_qr.   r.   r/   _log_sum%  s    r  c                 C   s   t j| |tjd  gddS )N              ?r   r\  )rc   r  rE   r   r  r.   r.   r/   r  %  s    r  c                    s   t | |\} }|dk}| dk}||B  }dd   fdd}dd }t j| t jt jd}| | jrz | | || ||< | | jr|| | || ||< | | jr|| | || ||< t |S )	z3Log of Gaussian probability mass within an intervalr   c                 S   s   t t|t| S rC   )r  r   r  r.   r.   r/   mass_case_left%  s    z'_log_gauss_mass.<locals>.mass_case_leftc                    s    | |  S rC   r.   r  r  r.   r/   mass_case_right%  s    z(_log_gauss_mass.<locals>.mass_case_rightc                 S   s   t t|  t|  S rC   )rc   r  r   r  r.   r.   r/   mass_case_central%  s    z*_log_gauss_mass.<locals>.mass_case_central)r  r  )rE   rR  r  r   Z
complex128r   r  )rp   rq   	case_left
case_rightZcase_centralr  r  rV  r.   r  r/   _log_gauss_mass%  s    



r  c                       s   e Zd ZdZdd Zdd Z fddZdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd!dd Z  ZS )"truncnorm_genaw
  A truncated normal continuous random variable.

    %(before_notes)s

    Notes
    -----
    This distribution is the normal distribution centered on ``loc`` (default
    0), with standard deviation ``scale`` (default 1), and truncated at ``a``
    and ``b`` *standard deviations* from ``loc``. For arbitrary ``loc`` and
    ``scale``, ``a`` and ``b`` are *not* the abscissae at which the shifted
    and scaled distribution is truncated.

    .. note::
        If ``a_trunc`` and ``b_trunc`` are the abscissae at which we wish
        to truncate the distribution (as opposed to the number of standard
        deviations from ``loc``), then we can calculate the distribution
        parameters ``a`` and ``b`` as follows::

            a, b = (a_trunc - loc) / scale, (b_trunc - loc) / scale

        This is a common point of confusion. For additional clarification,
        please see the example below.

    %(example)s

    In the examples above, ``loc=0`` and ``scale=1``, so the plot is truncated
    at ``a`` on the left and ``b`` on the right. However, suppose we were to
    produce the same histogram with ``loc = 1`` and ``scale=0.5``.

    >>> loc, scale = 1, 0.5
    >>> rv = truncnorm(a, b, loc=loc, scale=scale)
    >>> x = np.linspace(truncnorm.ppf(0.01, a, b),
    ...                 truncnorm.ppf(0.99, a, b), 100)
    >>> r = rv.rvs(size=1000)

    >>> fig, ax = plt.subplots(1, 1)
    >>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')
    >>> ax.hist(r, density=True, bins='auto', histtype='stepfilled', alpha=0.2)
    >>> ax.set_xlim(a, b)
    >>> ax.legend(loc='best', frameon=False)
    >>> plt.show()

    Note that the distribution is no longer appears to be truncated at
    abscissae ``a`` and ``b``. That is because the *standard* normal
    distribution is first truncated at ``a`` and ``b``, *then* the resulting
    distribution is scaled by ``scale`` and shifted by ``loc``. If we instead
    want the shifted and scaled distribution to be truncated at ``a`` and
    ``b``, we need to transform these values before passing them as the
    distribution parameters.

    >>> a_transformed, b_transformed = (a - loc) / scale, (b - loc) / scale
    >>> rv = truncnorm(a_transformed, b_transformed, loc=loc, scale=scale)
    >>> x = np.linspace(truncnorm.ppf(0.01, a, b),
    ...                 truncnorm.ppf(0.99, a, b), 100)
    >>> r = rv.rvs(size=10000)

    >>> fig, ax = plt.subplots(1, 1)
    >>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')
    >>> ax.hist(r, density=True, bins='auto', histtype='stepfilled', alpha=0.2)
    >>> ax.set_xlim(a-0.1, b+0.1)
    >>> ax.legend(loc='best', frameon=False)
    >>> plt.show()
    c                 C   s   ||k S rC   r.   r  r.   r.   r/   rW   &  s    ztruncnorm_gen._argcheckc                 C   s8   t ddtj tjfd}t ddtj tjfd}||gS )Nrp   FrY   rq   )FTrZ   r   r.   r.   r/   r]   &  s    ztruncnorm_gen._shape_infoc                    s2   t |tr| }t j|t|t|fdS r  r  re  r  r.   r/   r  &  s    
ztruncnorm_gen._fitstartc                 C   s   ||fS rC   r.   r  r.   r.   r/   rv    &  s    ztruncnorm_gen._get_supportc                 C   s   t | |||S rC   rG  r   r.   r.   r/   ra   #&  s    ztruncnorm_gen._pdfc                 C   s   t |t|| S rC   )r   r  r   r.   r.   r/   r   &&  s    ztruncnorm_gen._logpdfc                 C   s   t | |||S rC   r  r   r.   r.   r/   rb   )&  s    ztruncnorm_gen._cdfc              
   C   sp   t |||\}}}t t||t|| }|dk}t |rlt t | || || ||  ||< |S Ng)rE   rR  r   r  r  r  r   r   )r;   r`   rp   rq   ZlogcdfrW  r.   r.   r/   r   ,&  s    
,ztruncnorm_gen._logcdfc                 C   s   t | |||S rC   r  r   r.   r.   r/   rd   4&  s    ztruncnorm_gen._sfc              
   C   sp   t |||\}}}t t||t|| }|dk}t |rlt t | || || ||  ||< |S r  )rE   rR  r   r  r  r  r   r   )r;   r`   rp   rq   ZlogsfrW  r.   r.   r/   r   7&  s    
,ztruncnorm_gen._logsfc           	      C   sd   t |}t |}|| }ttdtj tj | }|t| |t|  d|  }|| }|S r   )r   rE   r   r   r   r  r   )	r;   rp   rq   r  r  Zr1  Dr  r.   r.   r/   r   ?&  s      ztruncnorm_gen._entropyc                 C   s   t |||\}}}|dk }| }dd }dd }t |}|| }	|| }
|	jrj||	|| || ||< |
jr||
|| || ||< |S )Nr   c                 S   s(   t t|t| t|| }t|S rC   )r  r   rE   r   r  rc   	ndtri_exprf   rp   rq   Z	log_Phi_xr.   r.   r/   ppf_leftN&  s    z$truncnorm_gen._ppf.<locals>.ppf_leftc                 S   s.   t t| t|  t|| }t| S rC   )r  r   rE   r  r  rc   r  r  r.   r.   r/   	ppf_rightS&  s    
z%truncnorm_gen._ppf.<locals>.ppf_rightrE   rR  
empty_liker   )r;   rf   rp   rq   r  r  r  r  rV  q_leftq_rightr.   r.   r/   rg   H&  s    
ztruncnorm_gen._ppfc                 C   s   t |||\}}}|dk }| }dd }dd }t |}|| }	|| }
|	jrj||	|| || ||< |
jr||
|| || ||< |S )Nr   c                 S   s.   t t|t| t|| }tt|S rC   )r  r   rE   r   r  rc   r  r  r  r.   r.   r/   isf_leftk&  s    z$truncnorm_gen._isf.<locals>.isf_leftc                 S   s4   t t| t|  t|| }tt| S rC   )r  r   rE   r  r  rc   r  r  r  r.   r.   r/   	isf_rightp&  s    
z%truncnorm_gen._isf.<locals>.isf_rightr  )r;   rf   rp   rq   r  r  r  r  rV  r  r  r.   r.   r/   rh   d&  s    
ztruncnorm_gen._isfc                    sD    fdd}t |dk||k@ ||k@ |||ftj|tjgdtjS )Nc           	         s    t||g||\}}|| g}ddg}td| d D ]H t||||gg fdddd}t| d |d   }|| q<|d S )z
            Returns n-th moment. Defined only if n >= 0.
            Function cannot broadcast due to the loop over n
            r   r   c                    s   | | d   S rR   r.   r  ro  r.   r/   rL  &  rM  z:truncnorm_gen._munp.<locals>.n_th_moment.<locals>.<lambda>r`  r   r.  )ra   rE   r   r^  r   r  r  )	rV   rp   rq   pApBprobsrr  r  mkr\   r  r/   n_th_moment&  s    
z(truncnorm_gen._munp.<locals>.n_th_momentr   r  r  )r;   rV   rp   rq   r  r.   r\   r/   r   &  s
     ztruncnorm_gen._munprl  c                 C   sB   |  t||g||\}}dd }tj|dd}||||||S )Nc                 S   s>  || }|}|| g}t ||| |ggdd dd}dt| }	t ||| | || ggdd dd}dt| }
t ||| |ggdd dd}d| t| }t ||| |ggd	d dd}d
|	 t| }||d|	 d|d     }|t|
d }||d| d
| d|	 |d      }||
d  d
 }||
||fS )Nc                 S   s   | | S rC   r.   r  r.   r.   r/   rL  &  rM  zGtruncnorm_gen._stats.<locals>._truncnorm_stats_scalar.<locals>.<lambda>r   r`  r   c                 S   s   | | S rC   r.   r  r.   r.   r/   rL  &  rM  c                 S   s   | |d  S r   r.   r  r.   r.   r/   rL  &  rM  rK   c                 S   s   | |d  S r  r.   r  r.   r.   r/   rL  &  rM  r  r  r  r  )r   rE   r  r  )rp   rq   r  r  rr  r  r   r  r  r  r   r  Zm4Zmu3r   Zmu4r   r.   r.   r/   _truncnorm_stats_scalar&  s0    
(z5truncnorm_gen._stats.<locals>._truncnorm_stats_scalar)rr  )excluded)ZpdfrE   r  r  )r;   rp   rq   rr  r  r  r  Z_truncnorm_statsr.   r.   r/   r   &  s    ztruncnorm_gen._stats)rl  )ri   rj   rk   rl   rW   r]   r  rv   ra   r   rb   r   rd   r   r   rg   rh   r   r   r?  r.   r.   r  r/   r  %  s    @	r  	truncnorm)rr   r}   c                       s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zeee fddZ  ZS ) truncpareto_genac  An upper truncated Pareto continuous random variable.

    %(before_notes)s

    See Also
    --------
    pareto : Pareto distribution

    Notes
    -----
    The probability density function for `truncpareto` is:

    .. math::

        f(x, b, c) = \frac{b}{1 - c^{-b}} \frac{1}{x^{b+1}}

    for :math:`b > 0`, :math:`c > 1` and :math:`1 \le x \le c`.

    `truncpareto` takes `b` and `c` as shape parameters for :math:`b` and
    :math:`c`.

    Notice that the upper truncation value :math:`c` is defined in
    standardized form so that random values of an unscaled, unshifted variable
    are within the range ``[1, c]``.
    If ``u_r`` is the upper bound to a scaled and/or shifted variable,
    then ``c = (u_r - loc) / scale``. In other words, the support of the
    distribution becomes ``(scale + loc) <= x <= (c*scale + loc)`` when
    `scale` and/or `loc` are provided.

    %(after_notes)s

    References
    ----------
    .. [1] Burroughs, S. M., and Tebbens S. F.
        "Upper-truncated power laws in natural systems."
        Pure and Applied Geophysics 158.4 (2001): 741-757.

    %(example)s

    c                 C   s0   t dddtjfd}t dddtjfd}||gS )Nrq   Frm   r   rf  rn   rZ   )r;   r   rx  r.   r.   r/   r]   &  s    ztruncpareto_gen._shape_infoc                 C   s   |dk|dk@ S Nrm   rn   r.   r;   rq   rf  r.   r.   r/   rW   &  s    ztruncpareto_gen._argcheckc                 C   s
   | j |fS rC   r  r  r.   r.   r/   rv   &  s    ztruncpareto_gen._get_supportc                 C   s"   |||d    dd||    S rR   r.   r;   r`   rq   rf  r.   r.   r/   ra   &  s    ztruncpareto_gen._pdfc              	   C   s:   t |t t | t |   |d t |  S rR   )rE   r   rj  r   r.   r.   r/   r   &  s    ztruncpareto_gen._logpdfc                 C   s   d||   dd||    S rR   r.   r   r.   r.   r/   rb   &  s    ztruncpareto_gen._cdfc                 C   s$   t ||   t d||   S r  r  r   r.   r.   r/   r   &  s    ztruncpareto_gen._logcdfc                 C   s"   t ddd||   |  d| S Nr   r.  rT  r;   rf   rq   rf  r.   r.   r/   rg   &  s    ztruncpareto_gen._ppfc                 C   s&   ||  d||   dd||    S rR   r.   r   r.   r.   r/   rd   '  s    ztruncpareto_gen._sfc                 C   s.   t ||  d||   t d||   S r  r  r   r.   r.   r/   r   '  s    ztruncpareto_gen._logsfc                 C   s*   t d||  dd||   |  d| S r  rT  r  r.   r.   r/   rh   '  s    ztruncpareto_gen._isfc                 C   sB   t |dd||    |d t ||| d  d|     S rR   r   r  r.   r.   r/   r   '  s    $ztruncpareto_gen._entropyc                 C   sV   ||k  r*|t| dd||    S |||  || ||   || d  S d S rR   )r   rE   r   )r;   rV   rq   rf  r.   r.   r/   r   '  s    ztruncpareto_gen._munpc                 C   s>   t |tr| }t|\}}}t|| | }||||fS rC   )r5   r$   r
  rs  r9   r  )r;   r<   rq   r'   r(   rf  r.   r.   r/   r  '  s
    
ztruncpareto_gen._fitstartc                    s<  | ddr&t j g|R i |S dd dd  fddfd	d
fdd}fddd  fdd	}dd }	fdd}t ||}|\ }	}
}}     ttj }|	d ur
|
d ur
|d ur
|d ur
t	dn:|
d u r|d u r|d u r|	d u r fdd}ttj }|}d}|d }|tj kr|||| dkr|d7 }|t
d| }qd|tj ks| g|R i |S t|||fd}|js| g|R i |S |jd }|d }d}|tj krL|||| dkrL|d7 }|t
d| }q|tj ksp| g|R i |S t|||fd}|js| g|R i |S |j}|}||}|||} | | }td| d|d  }||k s| g|R i |S n|}|d }d}|tj kr^|||	|||	 dkr^|d7 }|d|  }q|tj ks| g|R i |S t||	f||fd}|js| g|R i |S |j}|}||}|	}np|d ur|n||
|}|p|}|
p||}|d ur4  | dk r4tdd|d|
rt|d urt|rt  |
| | krttdd||d|	d u r@ | | }|}t|}d| |k s| g|R i |S d| d||   }td| d}z@t|||f||fd}|js| g|R i |W S |j}W n t	y<   |}Y n0 n|	}|| k s~|rjt|tj }n|}t|d}|| | ks||}t|tj}t||r|dks| g|R i |S ||||f}|d u r8|d u r8| g|R i |}| }| }||k r8|S |S )!NrV  Fc                 S   s   t t | S rC   )rE   r   r   r   r.   r.   r/   log_mean"'  s    z%truncpareto_gen.fit.<locals>.log_meanc                 S   s   dt d|   S rR   )rE   r   r   r.   r.   r/   	harm_mean%'  s    z&truncpareto_gen.fit.<locals>.harm_meanc                    sV    | | }|}|}|d | }d|d |dd|   | t |     | S rR   r   )rf  r'   r(   r  harm_mZlog_mquot)r<   r  r  r.   r/   get_b('  s
    z"truncpareto_gen.fit.<locals>.get_bc                    s    |  | S rC   r.   r]  )mxr.   r/   get_c/'  s    z"truncpareto_gen.fit.<locals>.get_cc                    s0   |r | }|S | r,|    | d  }|S d S rR   r.   )r`  r   r'   )r  r  r.   r/   get_loc2'  s    z$truncpareto_gen.fit.<locals>.get_locc                    s    |  S rC   r.   r  )r  r.   r/   r  :'  s    z&truncpareto_gen.fit.<locals>.get_scalec                    sn   | }| |}|d u r&|| |n|} |  | }dd|d ||d  |   dd|d    |  S rR   r.   )r'   rK  r(   rf  rq   r  )r<   r  r	  r  r  r.   r/   r  @'  s
    
z$truncpareto_gen.fit.<locals>.dL_dLocc                 S   s"   | t | | d| |   |  S rR   r  )rq   logclogmr.   r.   r/   dL_dBI'  s    z"truncpareto_gen.fit.<locals>.dL_dBc                    s   t tj| g|R i |S rC   )r7   r  r9   )r<   r=   kwargs)r  r;   r.   r/   fallbackO'  s    z%truncpareto_gen.fit.<locals>.fallbackz2All parameters fixed.There is nothing to optimize.c                    sD   | }| |} |  | }dd|d   t | | d S rR   r   )r'   r(   rf  r  )r<   r	  r  r  r.   r/   cond_b`'  s    
z#truncpareto_gen.fit.<locals>.cond_br   r   r   r#  gMbP?rK   truncparetor  )N)r+   r7   r9   r^  r  r  rE   r
  r[   r   r  r%   r  r_  r   r   r   rW   r  )r;   r<   r=   r-   r
  r  r  r  r  r  r`  r   r   Zmn_infr  rI   rW  rH   r  r'   r(   rf  rq   Zstd_dataZ
up_bound_br  r  Zparams_overrideZparams_superZnllf_overrideZ
nllf_superr  )	r<   r  r	  r  r  r  r  r  r;   r/   r9   '  s   	

	









ztruncpareto_gen.fit)ri   rj   rk   rl   r]   rW   rv   ra   r   rb   r   rg   rd   r   rh   r   r   r  rB   r	   r   r9   r?  r.   r.   r  r/   r  &  s$   )r  r  c                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )tukeylambda_gena*  A Tukey-Lamdba continuous random variable.

    %(before_notes)s

    Notes
    -----
    A flexible distribution, able to represent and interpolate between the
    following distributions:

    - Cauchy                (:math:`lambda = -1`)
    - logistic              (:math:`lambda = 0`)
    - approx Normal         (:math:`lambda = 0.14`)
    - uniform from -1 to 1  (:math:`lambda = 1`)

    `tukeylambda` takes a real number :math:`lambda` (denoted ``lam``
    in the implementation) as a shape parameter.

    %(after_notes)s

    %(example)s

    c                 C   s
   t |S rC   r~  r;   lamr.   r.   r/   rW   (  s    ztukeylambda_gen._argcheckc                 C   s   t ddtj tjfdgS )Nr  Fr   rZ   r\   r.   r.   r/   r]   (  s    ztukeylambda_gen._shape_infoc                 C   sj   t t||}||d  t d| |d   }dt | }t |dkt|dt | k B |dS )Nrn   r   r   rm   )rE   r   rc   tklmbdar  r  )r;   r`   r  ZFxr  r.   r.   r/   ra   (  s    "ztukeylambda_gen._pdfc                 C   s   t ||S rC   )rc   r  )r;   r`   r  r.   r.   r/   rb   !(  s    ztukeylambda_gen._cdfc                 C   s   t ||t | | S rC   )rc   r  r  )r;   rf   r  r.   r.   r/   rg   $(  s    ztukeylambda_gen._ppfc                 C   s   dt |dt|fS r6  )_tlvar_tlkurtr  r.   r.   r/   r   '(  s    ztukeylambda_gen._statsc                    s    fdd}t |ddd S )Nc                    s&   t t|  d td|   d  S rR   )rE   r   r#  )rT  r  r.   r/   integ+(  s    z'tukeylambda_gen._entropy.<locals>.integr   r   )r   r  )r;   r  r  r.   r  r/   r   *(  s    ztukeylambda_gen._entropyN)ri   rj   rk   rl   rW   r]   ra   rb   rg   r   r   r.   r.   r.   r/   r  '  s   r  tukeylambdac                   @   s   e Zd Zdd ZdS )FitUniformFixedScaleDataErrorc                 C   s   d| d| d| _ d S )NzInvalid values in `data`.  Maximum likelihood estimation with the uniform distribution and fixed scale requires that np.ptp(data) <= fscale, but np.ptp(data) = z and fscale = r  r   )r;   r  r   r.   r.   r/   r   4(  s    z&FitUniformFixedScaleDataError.__init__N)ri   rj   rk   r   r.   r.   r.   r/   r  3(  s   r  c                   @   sV   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dd Z
edd ZdS )uniform_gena  A uniform continuous random variable.

    In the standard form, the distribution is uniform on ``[0, 1]``. Using
    the parameters ``loc`` and ``scale``, one obtains the uniform distribution
    on ``[loc, loc + scale]``.

    %(before_notes)s

    %(example)s

    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   I(  s    zuniform_gen._shape_infoNc                 C   s   | dd|S r  )r  r   r.   r.   r/   r   L(  s    zuniform_gen._rvsc                 C   s   d||k S r   r.   r   r.   r.   r/   ra   O(  s    zuniform_gen._pdfc                 C   s   |S rC   r.   r   r.   r.   r/   rb   R(  s    zuniform_gen._cdfc                 C   s   |S rC   r.   r   r.   r.   r/   rg   U(  s    zuniform_gen._ppfc                 C   s   dS )N)ru   gUUUUUU?r   g333333r.   r\   r.   r.   r/   r   X(  s    zuniform_gen._statsc                 C   s   dS rb  r.   r\   r.   r.   r/   r   [(  s    zuniform_gen._entropyc           	      O   s  t |dkrtd|dd}|dd}t| |durL|durLtdt|}t| sltd|du r|du r|	 }t
|}q|}| | }|	 |k rtd||| d	n6t
|}||krt||d
|	 d||   }|}t|t|fS )a	  
        Maximum likelihood estimate for the location and scale parameters.

        `uniform.fit` uses only the following parameters.  Because exact
        formulas are used, the parameters related to optimization that are
        available in the `fit` method of other distributions are ignored
        here.  The only positional argument accepted is `data`.

        Parameters
        ----------
        data : array_like
            Data to use in calculating the maximum likelihood estimate.
        floc : float, optional
            Hold the location parameter fixed to the specified value.
        fscale : float, optional
            Hold the scale parameter fixed to the specified value.

        Returns
        -------
        loc, scale : float
            Maximum likelihood estimates for the location and scale.

        Notes
        -----
        An error is raised if `floc` is given and any values in `data` are
        less than `floc`, or if `fscale` is given and `fscale` is less
        than ``data.max() - data.min()``.  An error is also raised if both
        `floc` and `fscale` are given.

        Examples
        --------
        >>> import numpy as np
        >>> from scipy.stats import uniform

        We'll fit the uniform distribution to `x`:

        >>> x = np.array([2, 2.5, 3.1, 9.5, 13.0])

        For a uniform distribution MLE, the location is the minimum of the
        data, and the scale is the maximum minus the minimum.

        >>> loc, scale = uniform.fit(x)
        >>> loc
        2.0
        >>> scale
        11.0

        If we know the data comes from a uniform distribution where the support
        starts at 0, we can use `floc=0`:

        >>> loc, scale = uniform.fit(x, floc=0)
        >>> loc
        0.0
        >>> scale
        13.0

        Alternatively, if we know the length of the support is 12, we can use
        `fscale=12`:

        >>> loc, scale = uniform.fit(x, fscale=12)
        >>> loc
        1.5
        >>> scale
        12.0

        In that last example, the support interval is [1.5, 13.5].  This
        solution is not unique.  For example, the distribution with ``loc=2``
        and ``scale=12`` has the same likelihood as the one above.  When
        `fscale` is given and it is larger than ``data.max() - data.min()``,
        the parameters returned by the `fit` method center the support over
        the interval ``[data.min(), data.max()]``.

        r   r  r   Nr   r   r   r  r  )r  r   ru   )r  r,   r+   r0   r   rE   r   r   r   r  r  r  r   r  r  )	r;   r<   r=   r-   r   r   r'   r(   r  r.   r.   r/   r9   ^(  s0    K

zuniform_gen.fit)NN)ri   rj   rk   rl   r]   r   ra   rb   rg   r   r   rB   r9   r.   r.   r.   r/   r  =(  s   
r  r  c                       s   e Zd ZdZdd Zdd Zd ddZee fd	d
Z	dd Z
dd Zdd Zdd Zdd Zeeddd! fdd	Zeeedd fddZ  ZS )"vonmises_genaU  A Von Mises continuous random variable.

    %(before_notes)s

    See Also
    --------
    scipy.stats.vonmises_fisher : Von-Mises Fisher distribution on a
                                  hypersphere

    Notes
    -----
    The probability density function for `vonmises` and `vonmises_line` is:

    .. math::

        f(x, \kappa) = \frac{ \exp(\kappa \cos(x)) }{ 2 \pi I_0(\kappa) }

    for :math:`-\pi \le x \le \pi`, :math:`\kappa \ge 0`. :math:`I_0` is the
    modified Bessel function of order zero (`scipy.special.i0`).

    `vonmises` is a circular distribution which does not restrict the
    distribution to a fixed interval. Currently, there is no circular
    distribution framework in SciPy. The ``cdf`` is implemented such that
    ``cdf(x + 2*np.pi) == cdf(x) + 1``.

    `vonmises_line` is the same distribution, defined on :math:`[-\pi, \pi]`
    on the real line. This is a regular (i.e. non-circular) distribution.

    Note about distribution parameters: `vonmises` and `vonmises_line` take
    ``kappa`` as a shape parameter (concentration) and ``loc`` as the location
    (circular mean). A ``scale`` parameter is accepted but does not have any
    effect.

    Examples
    --------
    Import the necessary modules.

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy.stats import vonmises

    Define distribution parameters.

    >>> loc = 0.5 * np.pi  # circular mean
    >>> kappa = 1  # concentration

    Compute the probability density at ``x=0`` via the ``pdf`` method.

    >>> vonmises.pdf(0, loc=loc, kappa=kappa)
    0.12570826359722018

    Verify that the percentile function ``ppf`` inverts the cumulative
    distribution function ``cdf`` up to floating point accuracy.

    >>> x = 1
    >>> cdf_value = vonmises.cdf(x, loc=loc, kappa=kappa)
    >>> ppf_value = vonmises.ppf(cdf_value, loc=loc, kappa=kappa)
    >>> x, cdf_value, ppf_value
    (1, 0.31489339900904967, 1.0000000000000004)

    Draw 1000 random variates by calling the ``rvs`` method.

    >>> sample_size = 1000
    >>> sample = vonmises(loc=loc, kappa=kappa).rvs(sample_size)

    Plot the von Mises density on a Cartesian and polar grid to emphasize
    that it is a circular distribution.

    >>> fig = plt.figure(figsize=(12, 6))
    >>> left = plt.subplot(121)
    >>> right = plt.subplot(122, projection='polar')
    >>> x = np.linspace(-np.pi, np.pi, 500)
    >>> vonmises_pdf = vonmises.pdf(x, loc=loc, kappa=kappa)
    >>> ticks = [0, 0.15, 0.3]

    The left image contains the Cartesian plot.

    >>> left.plot(x, vonmises_pdf)
    >>> left.set_yticks(ticks)
    >>> number_of_bins = int(np.sqrt(sample_size))
    >>> left.hist(sample, density=True, bins=number_of_bins)
    >>> left.set_title("Cartesian plot")
    >>> left.set_xlim(-np.pi, np.pi)
    >>> left.grid(True)

    The right image contains the polar plot.

    >>> right.plot(x, vonmises_pdf, label="PDF")
    >>> right.set_yticks(ticks)
    >>> right.hist(sample, density=True, bins=number_of_bins,
    ...            label="Histogram")
    >>> right.set_title("Polar plot")
    >>> right.legend(bbox_to_anchor=(0.15, 1.06))

    c                 C   s   t dddtjfdgS )Nr  Fr   rY   rZ   r\   r.   r.   r/   r]   W)  s    zvonmises_gen._shape_infoc                 C   s   |dkS r6  r.   r  r.   r.   r/   rW   Z)  s    zvonmises_gen._argcheckNc                 C   s   |j d||dS )Nrm   r  )vonmises)r;   r  r   r   r.   r.   r/   r   ])  s    zvonmises_gen._rvsc                    s0   t  j|i |}t|tj dtj tj S r   )r7   rD  rE   modr   )r;   r=   r-   rD  r  r.   r/   rD  `)  s    zvonmises_gen.rvsc                 C   s(   t |t| dt j t|  S r   )rE   r   rc   cosm1r   r  r  r.   r.   r/   ra   e)  s    zvonmises_gen._pdfc                 C   s.   |t | tdtj  tt | S r   )rc   r   rE   r   r   r  r  r.   r.   r/   r   l)  s    zvonmises_gen._logpdfc                 C   s   t ||S rC   )r   Zvon_mises_cdfr  r.   r.   r/   rb   p)  s    zvonmises_gen._cdfc                 C   s   dS r  r.   r  r.   r.   r/   _stats_skips)  s    zvonmises_gen._stats_skipc                 C   s8   | t | t | tdtj t |  | S r   )rc   i1er  rE   r   r   r  r.   r.   r/   r   v)  s
    	zvonmises_gen._entropyz        The default limits of integration are endpoints of the interval
        of width ``2*pi`` centered at `loc` (e.g. ``[-pi, pi]`` when
        ``loc=0``).

r   r.   r   r   Fc                    sP   t j t j }	}
|d u r ||	 }|d u r0||
 }t j|||||||fi |S rC   )rE   r   r7   expect)r;   r   r=   r'   r(   ZlbZubZconditionalr-   r  r  r  r.   r/   r#  )  s    zvonmises_gen.expecta          Fit data is assumed to represent angles and will be wrapped onto the
        unit circle. `f0` and `fscale` are ignored; the returned shape is
        always the maximum likelihood estimate and the scale is always
        1. Initial guesses are ignored.

c                    s   | ddr&t j|g|R i |S t| |||\}}}}| jtj krdt j|g|R i |S t|dtj }dd }dd }|d ur|n||}	|d ur|n|||	}
t|	tj dtj tj }	|
|	dfS )	NrV  FrK   c                 S   s
   t | S rC   )rS  Zcircmeanr  r.   r.   r/   find_mu)  s    z!vonmises_gen.fit.<locals>.find_muc                    s   t t ||  t|    dkr(dS  dkr fdd} d   d   }d| }||dkrh|S ||dkrx|S t|d||fd}|jS nt tjS d S )	Nr   g 7yACr   c                    s   t | t |    S rC   )rc   r"  r  )r  rU  r.   r/   solve_for_kappa)  s    z=vonmises_gen.fit.<locals>.find_kappa.<locals>.solve_for_kapparK   r  )r*   r\  )	rE   r  r   r  r%   r_  r%  r  r&  )r<   r'   r&  lower_boundupper_boundZroot_resr.   r%  r/   
find_kappa)  s     
z$vonmises_gen.fit.<locals>.find_kappar   )r+   r7   r9   r^  rp   rE   r   r  )r;   r<   r=   r-   r  r   r   r$  r)  r'   r  r  r.   r/   r9   )  s    9zvonmises_gen.fit)NN)Nr.   r   r   NNF)ri   rj   rk   rl   r]   rW   r   r	   r   rD  ra   r   rb   r!  r   r   r#  rB   r9   r?  r.   r.   r  r/   r  (  s$   _

  
r  r  vonmises_linec                   @   sx   e Zd ZdZejZdd ZdddZdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )rZ  aX  A Wald continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `wald` is:

    .. math::

        f(x) = \frac{1}{\sqrt{2\pi x^3}} \exp(- \frac{ (x-1)^2 }{ 2x })

    for :math:`x >= 0`.

    `wald` is a special case of `invgauss` with ``mu=1``.

    %(after_notes)s

    %(example)s
    c                 C   s   g S rC   r.   r\   r.   r.   r/   r]   *  s    zwald_gen._shape_infoNc                 C   s   |j dd|dS rL  rM  r   r.   r.   r/   r   *  s    zwald_gen._rvsc                 C   s   t |dS r   )rY  ra   r   r.   r.   r/   ra   
*  s    zwald_gen._pdfc                 C   s   t |dS r   )rY  rb   r   r.   r.   r/   rb   *  s    zwald_gen._cdfc                 C   s   t |dS r   )rY  rd   r   r.   r.   r/   rd   *  s    zwald_gen._sfc                 C   s   t |dS r   )rY  rg   r   r.   r.   r/   rg   *  s    zwald_gen._ppfc                 C   s   t |dS r   )rY  rh   r   r.   r.   r/   rh   *  s    zwald_gen._isfc                 C   s   t |dS r   )rY  r   r   r.   r.   r/   r   *  s    zwald_gen._logpdfc                 C   s   t |dS r   )rY  r   r   r.   r.   r/   r   *  s    zwald_gen._logcdfc                 C   s   t |dS r   )rY  r   r   r.   r.   r/   r    *  s    zwald_gen._logsfc                 C   s   dS )N)rn   rn   r  rx  r.   r\   r.   r.   r/   r   #*  s    zwald_gen._statsc                 C   s
   t dS r   )rY  r   r\   r.   r.   r/   r   &*  s    zwald_gen._entropy)NN)ri   rj   rk   rl   r   r   r   r]   r   ra   rb   rd   rg   rh   r   r   r   r   r   r.   r.   r.   r/   rZ  )  s   
rZ  rN  c                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )wrapcauchy_gena  A wrapped Cauchy continuous random variable.

    %(before_notes)s

    Notes
    -----
    The probability density function for `wrapcauchy` is:

    .. math::

        f(x, c) = \frac{1-c^2}{2\pi (1+c^2 - 2c \cos(x))}

    for :math:`0 \le x \le 2\pi`, :math:`0 < c < 1`.

    `wrapcauchy` takes ``c`` as a shape parameter for :math:`c`.

    %(after_notes)s

    %(example)s

    c                 C   s   |dk|dk @ S r  r.   r  r.   r.   r/   rW   C*  s    zwrapcauchy_gen._argcheckc                 C   s   t ddddgS )Nrf  F)r   r   r   r  r\   r.   r.   r/   r]   F*  s    zwrapcauchy_gen._shape_infoc                 C   s4   d||  dt j d||  d| t |    S rB  r  rh  r.   r.   r/   ra   I*  s    zwrapcauchy_gen._pdfc                 C   s:   dd }dd }d| d|  }t |tjk ||f||dS )Nc                 S   s"   dt j t |t | d   S r   rE   r   r  r  r`   crr.   r.   r/   r  O*  s    zwrapcauchy_gen._cdf.<locals>.f1c              	   S   s0   ddt j t |t dt j |  d    S r   r,  r-  r.   r.   r/   rP  S*  s    zwrapcauchy_gen._cdf.<locals>.f2r   r  )r   rE   r   )r;   r`   rf  r  rP  r.  r.   r.   r/   rb   M*  s    zwrapcauchy_gen._cdfc              
   C   sl   d| d|  }dt |t t j|   }dt j dt |t t jd|     }t |dk ||S )Nrn   rK   r   ru   )rE   r  r  r   r  )r;   rf   rf  rp  ZrcqZrcmqr.   r.   r/   rg   Z*  s    ,zwrapcauchy_gen._ppfc                 C   s   t dt j d||   S r  r   r  r.   r.   r/   r   `*  s    zwrapcauchy_gen._entropyc                 C   s2   t |tr| }dt|t|dtj  fS r  )r5   r$   r
  rE   r  r  r   re  r.   r.   r/   r  c*  s    
zwrapcauchy_gen._fitstartN)ri   rj   rk   rl   rW   r]   ra   rb   rg   r   r  r.   r.   r.   r/   r+  -*  s   r+  
wrapcauchyc                   @   sb   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdddZdS )gennorm_gena0  A generalized normal continuous random variable.

    %(before_notes)s

    See Also
    --------
    laplace : Laplace distribution
    norm : normal distribution

    Notes
    -----
    The probability density function for `gennorm` is [1]_:

    .. math::

        f(x, \beta) = \frac{\beta}{2 \Gamma(1/\beta)} \exp(-|x|^\beta),

    where :math:`x` is a real number, :math:`\beta > 0` and
    :math:`\Gamma` is the gamma function (`scipy.special.gamma`).

    `gennorm` takes ``beta`` as a shape parameter for :math:`\beta`.
    For :math:`\beta = 1`, it is identical to a Laplace distribution.
    For :math:`\beta = 2`, it is identical to a normal distribution
    (with ``scale=1/sqrt(2)``).

    References
    ----------

    .. [1] "Generalized normal distribution, Version 1",
           https://en.wikipedia.org/wiki/Generalized_normal_distribution#Version_1

    .. [2] Nardon, Martina, and Paolo Pianca. "Simulation techniques for
           generalized Gaussian densities." Journal of Statistical
           Computation and Simulation 79.11 (2009): 1317-1329

    .. [3] Wicklin, Rick. "Simulate data from a generalized Gaussian
           distribution" in The DO Loop blog, September 21, 2016,
           https://blogs.sas.com/content/iml/2016/09/21/simulate-generalized-gaussian-sas.html

    %(example)s

    c                 C   s   t dddtjfdgS Nr   Fr   r   rZ   r\   r.   r.   r/   r]   *  s    zgennorm_gen._shape_infoc                 C   s   t | ||S rC   rG  r;   r`   r   r.   r.   r/   ra   *  s    zgennorm_gen._pdfc                 C   s(   t d| td|  t||  S rt   )rE   r   rc   r5  r  r2  r.   r.   r/   r   *  s    zgennorm_gen._logpdfc                 C   s2   dt | }d| |td| t||   S rt   )rE   rF   rc   r  r  r;   r`   r   rf  r.   r.   r/   rb   *  s    zgennorm_gen._cdfc                 C   s:   t |d }|td| d| d| |  d|   S )Nru   rn   r   )rE   rF   rc   r  r3  r.   r.   r/   rg   *  s    zgennorm_gen._ppfc                 C   s   |  | |S rC   r  r2  r.   r.   r/   rd   *  s    zgennorm_gen._sfc                 C   s   |  || S rC   rw  r2  r.   r.   r/   rh   *  s    zgennorm_gen._isfc                 C   sN   t d| d| d| g\}}}dt|| dt|| d|  d fS )Nrn   r  r  rm   r   )rc   r5  rE   r   )r;   r   c1c3Zc5r.   r.   r/   r   *  s    "zgennorm_gen._statsc                 C   s$   d| t d|  td|  S r
  rE  r;   r   r.   r.   r/   r   *  s    zgennorm_gen._entropyNc                 C   sL   |j d| |d}|d|  }t|}|j|jddk }||  ||< |S )Nr   r  ru   )rC  rE   r   randomr  )r;   r   r   r   r'  r  rr  r.   r.   r/   r   *  s    
zgennorm_gen._rvs)NN)ri   rj   rk   rl   r]   ra   r   rb   rg   rd   rh   r   r   r   r.   r.   r.   r/   r0  o*  s   *r0  gennormc                   @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )halfgennorm_gena  The upper half of a generalized normal continuous random variable.

    %(before_notes)s

    See Also
    --------
    gennorm : generalized normal distribution
    expon : exponential distribution
    halfnorm : half normal distribution

    Notes
    -----
    The probability density function for `halfgennorm` is:

    .. math::

        f(x, \beta) = \frac{\beta}{\Gamma(1/\beta)} \exp(-|x|^\beta)

    for :math:`x, \beta > 0`. :math:`\Gamma` is the gamma function
    (`scipy.special.gamma`).

    `halfgennorm` takes ``beta`` as a shape parameter for :math:`\beta`.
    For :math:`\beta = 1`, it is identical to an exponential distribution.
    For :math:`\beta = 2`, it is identical to a half normal distribution
    (with ``scale=1/sqrt(2)``).

    References
    ----------

    .. [1] "Generalized normal distribution, Version 1",
           https://en.wikipedia.org/wiki/Generalized_normal_distribution#Version_1

    %(example)s

    c                 C   s   t dddtjfdgS r1  rZ   r\   r.   r.   r/   r]   *  s    zhalfgennorm_gen._shape_infoc                 C   s   t | ||S rC   rG  r2  r.   r.   r/   ra   *  s    zhalfgennorm_gen._pdfc                 C   s    t |td|  ||  S r   rE  r2  r.   r.   r/   r   *  s    zhalfgennorm_gen._logpdfc                 C   s   t d| || S r   r  r2  r.   r.   r/   rb   *  s    zhalfgennorm_gen._cdfc                 C   s   t d| |d|  S r   r  r2  r.   r.   r/   rg   *  s    zhalfgennorm_gen._ppfc                 C   s   t d| || S r   r  r2  r.   r.   r/   rd   *  s    zhalfgennorm_gen._sfc                 C   s   t d| |d|  S r   r  r2  r.   r.   r/   rh   +  s    zhalfgennorm_gen._isfc                 C   s    d| t | td|  S r   rE  r6  r.   r.   r/   r   +  s    zhalfgennorm_gen._entropyNr  r.   r.   r.   r/   r9  *  s   #r9  halfgennormc                       sX   e Zd ZdZdd Zdd Z fddZdd	 Zd
d Zdd Z	dd Z
dd Z  ZS )crystalball_gena  
    Crystalball distribution

    %(before_notes)s

    Notes
    -----
    The probability density function for `crystalball` is:

    .. math::

        f(x, \beta, m) =  \begin{cases}
                            N \exp(-x^2 / 2),  &\text{for } x > -\beta\\
                            N A (B - x)^{-m}  &\text{for } x \le -\beta
                          \end{cases}

    where :math:`A = (m / |\beta|)^m  \exp(-\beta^2 / 2)`,
    :math:`B = m/|\beta| - |\beta|` and :math:`N` is a normalisation constant.

    `crystalball` takes :math:`\beta > 0` and :math:`m > 1` as shape
    parameters.  :math:`\beta` defines the point where the pdf changes
    from a power-law to a Gaussian distribution.  :math:`m` is the power
    of the power-law tail.

    %(after_notes)s

    .. versionadded:: 0.19.0

    References
    ----------
    .. [1] "Crystal Ball Function",
           https://en.wikipedia.org/wiki/Crystal_Ball_function

    %(example)s
    c                 C   s   |dk|dk@ S )z@
        Shape parameter bounds are m > 1 and beta > 0.
        r   r   r.   )r;   r   rC  r.   r.   r/   rW   0+  s    zcrystalball_gen._argcheckc                 C   s0   t dddtjfd}t dddtjfd}||gS )Nr   Fr   r   rC  r   rZ   )r;   ZibetaZimr.   r.   r/   r]   6+  s    zcrystalball_gen._shape_infoc                    s   t  j|ddS )N)r   r  r   rd  re  r  r.   r/   r  ;+  s    zcrystalball_gen._fitstartc                 C   sd   d|| |d  t |d  d  tt|   }dd }dd }|t|| k|||f||d	 S )
a`  
        Return PDF of the crystalball function.

                                            --
                                           | exp(-x**2 / 2),  for x > -beta
        crystalball.pdf(x, beta, m) =  N * |
                                           | A * (B - x)**(-m), for x <= -beta
                                            --
        rn   r   rK   r   c                 S   s   t | d  d S r   r  r`   r   rC  r.   r.   r/   rhsL+  s    z!crystalball_gen._pdf.<locals>.rhsc                 S   s6   || | t |d  d  || | |  |   S r   r  r<  r.   r.   r/   lhsO+  s    z!crystalball_gen._pdf.<locals>.lhsr  rE   r   r   r   r   r;   r`   r   rC  r  r=  r>  r.   r.   r/   ra   ?+  s    
$
zcrystalball_gen._pdfc                 C   sj   d|| |d  t |d  d  tt|   }dd }dd }t |t|| k|||f||d	 S )
zH
        Return the log of the PDF of the crystalball function.
        rn   r   rK   r   c                 S   s   | d  d S r   r.   r<  r.   r.   r/   r=  \+  s    z$crystalball_gen._logpdf.<locals>.rhsc                 S   s8   |t ||  |d d  |t || | |    S r   r   r<  r.   r.   r/   r>  _+  s    z$crystalball_gen._logpdf.<locals>.lhsr  )rE   r   r   r   r   r   r@  r.   r.   r/   r   U+  s    $
zcrystalball_gen._logpdfc                 C   sd   d|| |d  t |d  d  tt|   }dd }dd }|t|| k|||f||d	 S )
z8
        Return CDF of the crystalball function
        rn   r   rK   r   c                 S   s:   || t |d  d  |d  tt| t|    S NrK   r   r   rE   r   r   r   r<  r.   r.   r/   r=  k+  s    "z!crystalball_gen._cdf.<locals>.rhsc                 S   sB   || | t |d  d  || | |  | d   |d  S rA  r  r<  r.   r.   r/   r>  o+  s
    z!crystalball_gen._cdf.<locals>.lhsr  r?  r@  r.   r.   r/   rb   d+  s    $
zcrystalball_gen._cdfc                 C   s   d|| |d  t |d  d  tt|   }|||  t |d  d  |d  }dd }dd }t||k |||f||d	S )
Nrn   r   rK   r   c                 S   sv   t |d  d }|| | |d  }d|tt|   }|| | |d || |   | |  | dd|    S r  rB  rT  r   rC  Zeb2r1  r  r.   r.   r/   ppf_lessz+  s    
,z&crystalball_gen._ppf.<locals>.ppf_lessc                 S   s^   t |d  d }|| | |d  }d|tt|   }tt| dt | | |   S r  )rE   r   r   r   r   rC  r.   r.   r/   ppf_greater+  s    z)crystalball_gen._ppf.<locals>.ppf_greaterr  r?  )r;   rT  r   rC  r  ZpbetarD  rE  r.   r.   r/   rg   u+  s    $
(zcrystalball_gen._ppfc                 C   sl   d|| |d  t |d  d  tt|   }dd }|t|d |k |||ft j|t jgdt j S )zR
        Returns the n-th non-central moment of the crystalball function.
        rn   r   rK   r   c                 S   s   || | t |d  d  }|| | }d| d d  t| d d  dd|  t| d d |d d    }t |j}t| d D ]J}|t| ||| |   d|  || d  || | | d   7 }q|| | S )z
            Returns n-th moment. Defined only if n+1 < m
            Function cannot broadcast due to the loop over n
            rK   r   r   rn   r.  )	rE   r   rc   rC  r  r}  r  r^  Zbinom)rV   r   rC  r  r  r=  r>  ro  r.   r.   r/   r  +  s      &,z*crystalball_gen._munp.<locals>.n_th_momentr  )rE   r   r   r   r   r  r  r[   )r;   rV   r   rC  r  r  r.   r.   r/   r   +  s    $
zcrystalball_gen._munp)ri   rj   rk   rl   rW   r]   r  ra   r   rb   rg   r   r?  r.   r.   r  r/   r;  +  s   #r;  crystalballzA Crystalball Function)rr   longnamec                 C   s   t d| d d d S )a  
    Utility function for the argus distribution used in the pdf, sf and
    moment calculation.
    Note that for all x > 0:
    gammainc(1.5, x**2/2) = 2 * (_norm_cdf(x) - x * _norm_pdf(x) - 0.5).
    This can be verified directly by noting that the cdf of Gamma(1.5) can
    be written as erf(sqrt(x)) - 2*sqrt(x)*exp(-x)/sqrt(Pi).
    We use gammainc instead of the usual definition because it is more precise
    for small chi.
    r  rK   r  )r  r.   r.   r/   
_argus_phi+  s    rH  c                   @   sT   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdddZ	dddZ
dd ZdS )	argus_gena  
    Argus distribution

    %(before_notes)s

    Notes
    -----
    The probability density function for `argus` is:

    .. math::

        f(x, \chi) = \frac{\chi^3}{\sqrt{2\pi} \Psi(\chi)} x \sqrt{1-x^2}
                     \exp(-\chi^2 (1 - x^2)/2)

    for :math:`0 < x < 1` and :math:`\chi > 0`, where

    .. math::

        \Psi(\chi) = \Phi(\chi) - \chi \phi(\chi) - 1/2

    with :math:`\Phi` and :math:`\phi` being the CDF and PDF of a standard
    normal distribution, respectively.

    `argus` takes :math:`\chi` as shape a parameter. Details about sampling
    from the ARGUS distribution can be found in [2]_.

    %(after_notes)s

    References
    ----------
    .. [1] "ARGUS distribution",
           https://en.wikipedia.org/wiki/ARGUS_distribution
    .. [2] Christoph Baumgarten "Random variate generation by fast numerical
           inversion in the varying parameter case." Research in Statistics,
           vol. 1, 2023, doi:10.1080/27684520.2023.2279060.

    .. versionadded:: 0.19.0

    %(example)s
    c                 C   s   t dddtjfdgS )Nr  Fr   r   rZ   r\   r.   r.   r/   r]   +  s    zargus_gen._shape_infoc                 C   s   t jddn d||  }dt | t t t| }|t | dt | |   |d | d  W  d    S 1 s0    Y  d S )Nr   r   rn   r  ru   rK   )rE   r   r   r   rH  r  )r;   r`   r  r  r  r.   r.   r/   r   +  s     zargus_gen._logpdfc                 C   s   t | ||S rC   rG  r;   r`   r  r.   r.   r/   ra   +  s    zargus_gen._pdfc                 C   s   d|  || S r   r  rJ  r.   r.   r/   rb   +  s    zargus_gen._cdfc                 C   s"   t |td|d   t | S r   )rH  rE   r   rJ  r.   r.   r/   rd   +  s    zargus_gen._sfNc           	         s   t |}|jdkr&| j|||d}nt|j|\} tt |}t |}t j	|gdgdggdj
st fddtt| dD }| jd ||d}||||<   qf|d	kr|d	 }|S )
Nr   )ru  r   rc  rd  re  c                 3   s(   | ] } | sj | ntd V  qd S rC   rg  ri  rj  r.   r/   r  +  s   z!argus_gen._rvs.<locals>.<genexpr>r   r.   )rE   r   r   rn  r   r  r9  r]  ro  rp  rq  rr  r^  r  r  rs  )	r;   r  r   r   rV  rt  ru  rv  rU  r.   rj  r/   r   +  s0    



zargus_gen._rvsc                 C   s  t t|}tt|}t|}d}|| }|dkr| d }	||k r|| }
|j|
d}|j|
d}|d }t||	| k}t|}|dkrDt	d||  }||||| < ||7 }qDn(|dkrzt
| d }||k r|| }
|j|
d}|j|
d}dt|d|  |  | }|d | dk}t|}|dkrt	d||  }||||| < ||7 }qnv||k r|| }
|jd|
d}||d k}t|}|dkrz|| |||| < ||7 }qzt	dd| |  }t||S )	Nr   ru   rK   r  rH  r   g?r  )rr  rE   r|  r9  r]  r}  r  r   r  r   r   r  r  )r;   r  ru  r   r~  r  r`   r  r  r=  ro  r  r:  r'  r  r  rD  Zechir  r.   r.   r/   rn  	,  sR    4








zargus_gen._rvs_scalarc                 C   s   t j|td}t|}t t jd | td|d d  | }t |}|dk}|| }dd|d   |t	| ||   ||< ||  }g d}t 
|||| < |||d  d d fS )	Nr  r   r   rK   r   g?r  )	g_1g־r   gWBar   gp|RH?r   gE'卡?r   g?)rE   r   r  rH  r   r   rc   rH  r  r   r   )r;   r  r  rC  r   rr  rf  Zcoefr.   r.   r/   r   n,  s    ,
(
zargus_gen._stats)NN)NN)ri   rj   rk   rl   r]   r   ra   rb   rd   r   rn  r   r.   r.   r.   r/   rI  +  s   (

erI  arguszAn Argus Function)rr   rG  rp   rq   c                       s`   e Zd ZdZejZdd fdd
Zdd Zdd	 Zd
d Z	dd Z
dd Z fddZ  ZS )rv_histograma3  
    Generates a distribution given by a histogram.
    This is useful to generate a template distribution from a binned
    datasample.

    As a subclass of the `rv_continuous` class, `rv_histogram` inherits from it
    a collection of generic methods (see `rv_continuous` for the full list),
    and implements them based on the properties of the provided binned
    datasample.

    Parameters
    ----------
    histogram : tuple of array_like
        Tuple containing two array_like objects.
        The first containing the content of n bins,
        the second containing the (n+1) bin boundaries.
        In particular, the return value of `numpy.histogram` is accepted.

    density : bool, optional
        If False, assumes the histogram is proportional to counts per bin;
        otherwise, assumes it is proportional to a density.
        For constant bin widths, these are equivalent, but the distinction
        is important when bin widths vary (see Notes).
        If None (default), sets ``density=True`` for backwards compatibility,
        but warns if the bin widths are variable. Set `density` explicitly
        to silence the warning.

        .. versionadded:: 1.10.0

    Notes
    -----
    When a histogram has unequal bin widths, there is a distinction between
    histograms that are proportional to counts per bin and histograms that are
    proportional to probability density over a bin. If `numpy.histogram` is
    called with its default ``density=False``, the resulting histogram is the
    number of counts per bin, so ``density=False`` should be passed to
    `rv_histogram`. If `numpy.histogram` is called with ``density=True``, the
    resulting histogram is in terms of probability density, so ``density=True``
    should be passed to `rv_histogram`. To avoid warnings, always pass
    ``density`` explicitly when the input histogram has unequal bin widths.

    There are no additional shape parameters except for the loc and scale.
    The pdf is defined as a stepwise function from the provided histogram.
    The cdf is a linear interpolation of the pdf.

    .. versionadded:: 0.19.0

    Examples
    --------

    Create a scipy.stats distribution from a numpy histogram

    >>> import scipy.stats
    >>> import numpy as np
    >>> data = scipy.stats.norm.rvs(size=100000, loc=0, scale=1.5,
    ...                             random_state=123)
    >>> hist = np.histogram(data, bins=100)
    >>> hist_dist = scipy.stats.rv_histogram(hist, density=False)

    Behaves like an ordinary scipy rv_continuous distribution

    >>> hist_dist.pdf(1.0)
    0.20538577847618705
    >>> hist_dist.cdf(2.0)
    0.90818568543056499

    PDF is zero above (below) the highest (lowest) bin of the histogram,
    defined by the max (min) of the original dataset

    >>> hist_dist.pdf(np.max(data))
    0.0
    >>> hist_dist.cdf(np.max(data))
    1.0
    >>> hist_dist.pdf(np.min(data))
    7.7591907244498314e-05
    >>> hist_dist.cdf(np.min(data))
    0.0

    PDF and CDF follow the histogram

    >>> import matplotlib.pyplot as plt
    >>> X = np.linspace(-5.0, 5.0, 100)
    >>> fig, ax = plt.subplots()
    >>> ax.set_title("PDF from Template")
    >>> ax.hist(data, density=True, bins=100)
    >>> ax.plot(X, hist_dist.pdf(X), label='PDF')
    >>> ax.plot(X, hist_dist.cdf(X), label='CDF')
    >>> ax.legend()
    >>> fig.show()

    N)densityc                   sb  || _ || _t|dkr tdt|d | _t|d | _t| jd t| jkr`td| jdd | jdd  | _t	| j| jd  }|du r|rd}t
j|tdd	 d
}n|s| j| j | _| jtt| j| j  | _t| j| j | _td| jdg| _td| jg| _| jd  |d< | _| jd  |d< | _t j|i | dS )a5  
        Create a new distribution using the given histogram

        Parameters
        ----------
        histogram : tuple of array_like
            Tuple containing two array_like objects.
            The first containing the content of n bins,
            the second containing the (n+1) bin boundaries.
            In particular, the return value of np.histogram is accepted.
        density : bool, optional
            If False, assumes the histogram is proportional to counts per bin;
            otherwise, assumes it is proportional to a density.
            For constant bin widths, these are equivalent.
            If None (default), sets ``density=True`` for backward
            compatibility, but warns if the bin widths are variable. Set
            `density` explicitly to silence the warning.
        rK   z)Expected length 2 for parameter histogramr   r   zbNumber of elements in histogram content and histogram boundaries do not match, expected n and n+1.Nr.  zjBin widths are not constant. Assuming `density=True`.Specify `density` explicitly to silence this warning.r  Trm   rp   rq   )
_histogram_densityr  r   rE   r   _hpdf_hbins_hbin_widthsZallcloser  r  r  r  r  Zcumsum_hcdfZhstackrp   rq   r7   r   )r;   	histogramrM  r=   r  Z	bins_varyr  r  r.   r/   r   ,  s.    zrv_histogram.__init__c                 C   s   | j tj| j|dd S )z&
        PDF of the histogram
        r  )Zside)rP  rE   ZsearchsortedrQ  r   r.   r.   r/   ra   -  s    zrv_histogram._pdfc                 C   s   t || j| jS )z3
        CDF calculated from the histogram
        )rE   interprQ  rS  r   r.   r.   r/   rb   -  s    zrv_histogram._cdfc                 C   s   t || j| jS )zC
        Percentile function calculated from the histogram
        )rE   rU  rS  rQ  r   r.   r.   r/   rg   -  s    zrv_histogram._ppfc                 C   sL   | j dd |d  | j dd |d   |d  }t| jdd | S )z$Compute the n-th non-central moment.r   Nr.  )rQ  rE   r  rP  )r;   rV   Z	integralsr.   r.   r/   r   "-  s    4zrv_histogram._munpc                 C   sJ   t | jdd dk| jdd ftjd}t| jdd | | j  S )zCompute entropy of distributionr   r.  rm   )r   rP  rE   r   r  rR  )r;   r  r.   r.   r/   r   '-  s    zrv_histogram._entropyc                    s"   t   }| j|d< | j|d< |S )zF
        Set the histogram as additional constructor argument
        rT  rM  )r7   _updated_ctor_paramrN  rO  )r;   dctr  r.   r/   rV  /-  s    


z rv_histogram._updated_ctor_param)ri   rj   rk   rl   r   r   r   ra   rb   rg   r   r   rV  r?  r.   r.   r  r/   rL  ,  s   [0rL  c                       sH   e Zd ZdZdd Zdd Z fddZdd	 Zd
d Zdd Z	  Z
S )studentized_range_genu  A studentized range continuous random variable.

    %(before_notes)s

    See Also
    --------
    t: Student's t distribution

    Notes
    -----
    The probability density function for `studentized_range` is:

    .. math::

         f(x; k, \nu) = \frac{k(k-1)\nu^{\nu/2}}{\Gamma(\nu/2)
                        2^{\nu/2-1}} \int_{0}^{\infty} \int_{-\infty}^{\infty}
                        s^{\nu} e^{-\nu s^2/2} \phi(z) \phi(sx + z)
                        [\Phi(sx + z) - \Phi(z)]^{k-2} \,dz \,ds

    for :math:`x ≥ 0`, :math:`k > 1`, and :math:`\nu > 0`.

    `studentized_range` takes ``k`` for :math:`k` and ``df`` for :math:`\nu`
    as shape parameters.

    When :math:`\nu` exceeds 100,000, an asymptotic approximation (infinite
    degrees of freedom) is used to compute the cumulative distribution
    function [4]_ and probability distribution function.

    %(after_notes)s

    References
    ----------

    .. [1] "Studentized range distribution",
           https://en.wikipedia.org/wiki/Studentized_range_distribution
    .. [2] Batista, Ben Dêivide, et al. "Externally Studentized Normal Midrange
           Distribution." Ciência e Agrotecnologia, vol. 41, no. 4, 2017, pp.
           378-389., doi:10.1590/1413-70542017414047716.
    .. [3] Harter, H. Leon. "Tables of Range and Studentized Range." The Annals
           of Mathematical Statistics, vol. 31, no. 4, 1960, pp. 1122-1147.
           JSTOR, www.jstor.org/stable/2237810. Accessed 18 Feb. 2021.
    .. [4] Lund, R. E., and J. R. Lund. "Algorithm AS 190: Probabilities and
           Upper Quantiles for the Studentized Range." Journal of the Royal
           Statistical Society. Series C (Applied Statistics), vol. 32, no. 2,
           1983, pp. 204-210. JSTOR, www.jstor.org/stable/2347300. Accessed 18
           Feb. 2021.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.stats import studentized_range
    >>> import matplotlib.pyplot as plt
    >>> fig, ax = plt.subplots(1, 1)

    Calculate the first four moments:

    >>> k, df = 3, 10
    >>> mean, var, skew, kurt = studentized_range.stats(k, df, moments='mvsk')

    Display the probability density function (``pdf``):

    >>> x = np.linspace(studentized_range.ppf(0.01, k, df),
    ...                 studentized_range.ppf(0.99, k, df), 100)
    >>> ax.plot(x, studentized_range.pdf(x, k, df),
    ...         'r-', lw=5, alpha=0.6, label='studentized_range pdf')

    Alternatively, the distribution object can be called (as a function)
    to fix the shape, location and scale parameters. This returns a "frozen"
    RV object holding the given parameters fixed.

    Freeze the distribution and display the frozen ``pdf``:

    >>> rv = studentized_range(k, df)
    >>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

    Check accuracy of ``cdf`` and ``ppf``:

    >>> vals = studentized_range.ppf([0.001, 0.5, 0.999], k, df)
    >>> np.allclose([0.001, 0.5, 0.999], studentized_range.cdf(vals, k, df))
    True

    Rather than using (``studentized_range.rvs``) to generate random variates,
    which is very slow for this distribution, we can approximate the inverse
    CDF using an interpolator, and then perform inverse transform sampling
    with this approximate inverse CDF.

    This distribution has an infinite but thin right tail, so we focus our
    attention on the leftmost 99.9 percent.

    >>> a, b = studentized_range.ppf([0, .999], k, df)
    >>> a, b
    0, 7.41058083802274

    >>> from scipy.interpolate import interp1d
    >>> rng = np.random.default_rng()
    >>> xs = np.linspace(a, b, 50)
    >>> cdf = studentized_range.cdf(xs, k, df)
    # Create an interpolant of the inverse CDF
    >>> ppf = interp1d(cdf, xs, fill_value='extrapolate')
    # Perform inverse transform sampling using the interpolant
    >>> r = ppf(rng.uniform(size=1000))

    And compare the histogram:

    >>> ax.hist(r, density=True, histtype='stepfilled', alpha=0.2)
    >>> ax.legend(loc='best', frameon=False)
    >>> plt.show()

    c                 C   s   |dk|dk@ S rt  r.   )r;   ro  r  r.   r.   r/   rW   -  s    zstudentized_range_gen._argcheckc                 C   s0   t dddtjfd}t dddtjfd}||gS )Nro  Fr   r   r  r   rZ   )r;   r  rO  r.   r.   r/   r]   -  s    z!studentized_range_gen._shape_infoc                    s   t  j|ddS )N)rK   r   r   rd  re  r  r.   r/   r  -  s    zstudentized_range_gen._fitstartc                    sJ   d|   \  fdd}t|dd}tj||||tjdd S )NZ_studentized_range_momentc           	         sz   t ||}| |||g}t|tjtj}t	t |}tj
 tj
fdtj
f fg}tddd}tj|||dd S )Nr   r  -q=r  r  rangesopts)r   _studentized_range_pdf_logconstrE   r  r  r  r  r  r
   r  r[   dictr   nquad)	r  ro  r  	log_constargusr_datar  r\  r]  r  r  cython_symbolr.   r/   _single_moment-  s    z3studentized_range_gen._munp.<locals>._single_momentr  r   r  r.   )rv   rE   
frompyfuncr   r  )r;   r  ro  r  rf  ufuncr.   rd  r/   r   -  s
    zstudentized_range_gen._munpc                 C   s2   dd }t |dd}t j||||t jdd S )Nc           
      S   s   |dk rTd}t ||}| |||g}t|tjtj}tj tjfdtjfg}n2d}| |g}t|tjtj}tj tjfg}t	
t ||}tddd}	tj|||	dd S )	N順 Z_studentized_range_pdfr   Z!_studentized_range_pdf_asymptoticr  rY  rZ  r[  )r   r^  rE   r  r  r  r  r  r[   r
   r  r_  r   r`  
rf   ro  r  re  ra  rb  rc  r\  r  r]  r.   r.   r/   _single_pdf-  s    z/studentized_range_gen._pdf.<locals>._single_pdfr  r   r  r.   )rE   rg  r   r  )r;   r`   ro  r  rk  rh  r.   r.   r/   ra   -  s    zstudentized_range_gen._pdfc                 C   s<   dd }t |dd}t t j||||t jdd ddS )Nc           
      S   s   |dk rTd}t ||}| |||g}t|tjtj}tj tjfdtjfg}n2d}| |g}t|tjtj}tj tjfg}t	
t ||}tddd}	tj|||	dd S )	Nri  Z_studentized_range_cdfr   Z!_studentized_range_cdf_asymptoticr  rY  rZ  r[  )r   Z_studentized_range_cdf_logconstrE   r  r  r  r  r  r[   r
   r  r_  r   r`  rj  r.   r.   r/   _single_cdf-  s    z/studentized_range_gen._cdf.<locals>._single_cdfr  r   r  r.   r   )rE   rg  rj  r   r  )r;   r`   ro  r  rl  rh  r.   r.   r/   rb   -  s    zstudentized_range_gen._cdf)ri   rj   rk   rl   rW   r]   r  r   ra   rb   r?  r.   r.   r  r/   rX  9-  s   nrX  studentized_range)rr   rp   rq   c                       sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	e
e fddZ  ZS )rel_breitwigner_gena  A relativistic Breit-Wigner random variable.

    %(before_notes)s

    See Also
    --------
    cauchy: Cauchy distribution, also known as the Breit-Wigner distribution.

    Notes
    -----

    The probability density function for `rel_breitwigner` is

    .. math::

        f(x, \rho) = \frac{k}{(x^2 - \rho^2)^2 + \rho^2}

    where

    .. math::
        k = \frac{2\sqrt{2}\rho^2\sqrt{\rho^2 + 1}}
            {\pi\sqrt{\rho^2 + \rho\sqrt{\rho^2 + 1}}}

    The relativistic Breit-Wigner distribution is used in high energy physics
    to model resonances [1]_. It gives the uncertainty in the invariant mass,
    :math:`M` [2]_, of a resonance with characteristic mass :math:`M_0` and
    decay-width :math:`\Gamma`, where :math:`M`, :math:`M_0` and :math:`\Gamma`
    are expressed in natural units. In SciPy's parametrization, the shape
    parameter :math:`\rho` is equal to :math:`M_0/\Gamma` and takes values in
    :math:`(0, \infty)`.

    Equivalently, the relativistic Breit-Wigner distribution is said to give
    the uncertainty in the center-of-mass energy :math:`E_{\text{cm}}`. In
    natural units, the speed of light :math:`c` is equal to 1 and the invariant
    mass :math:`M` is equal to the rest energy :math:`Mc^2`. In the
    center-of-mass frame, the rest energy is equal to the total energy [3]_.

    %(after_notes)s

    :math:`\rho = M/\Gamma` and :math:`\Gamma` is the scale parameter. For
    example, if one seeks to model the :math:`Z^0` boson with :math:`M_0
    \approx 91.1876 \text{ GeV}` and :math:`\Gamma \approx 2.4952\text{ GeV}`
    [4]_ one can set ``rho=91.1876/2.4952`` and ``scale=2.4952``.

    To ensure a physically meaningful result when using the `fit` method, one
    should set ``floc=0`` to fix the location parameter to 0.

    References
    ----------
    .. [1] Relativistic Breit-Wigner distribution, Wikipedia,
           https://en.wikipedia.org/wiki/Relativistic_Breit-Wigner_distribution
    .. [2] Invariant mass, Wikipedia,
           https://en.wikipedia.org/wiki/Invariant_mass
    .. [3] Center-of-momentum frame, Wikipedia,
           https://en.wikipedia.org/wiki/Center-of-momentum_frame
    .. [4] M. Tanabashi et al. (Particle Data Group) Phys. Rev. D 98, 030001 -
           Published 17 August 2018

    %(example)s

    c                 C   s   |dkS r6  r.   r;   rhor.   r.   r/   rW   B.  s    zrel_breitwigner_gen._argcheckc                 C   s   t dddtjfdgS )Nrp  Fr   r   rZ   r\   r.   r.   r/   r]   E.  s    zrel_breitwigner_gen._shape_infoc              
   C   s   t ddd|d    dt dd|d     d t j }t jdd0 ||| ||  | d d  W  d    S 1 s0    Y  d S )NrK   r   r   r   )rE   r   r   r   )r;   r`   rp  r1  r.   r.   r/   ra   H.  s    ,zrel_breitwigner_gen._pdfc              
   C   sz   t ddt dd|d     t j }t dd|  t |t | |d    }|d t | }t |d dS )NrK   r   r.  r  )rE   r   r   r  imagrj  )r;   r`   rp  r1  r  r.   r.   r/   rb   P.  s    *zrel_breitwigner_gen._cdfc                 C   s   |dkr^t ddd|d    dt dd|d     t j | }|t jd t |  S |dkrt dd|d   ddt dd|d      | }d|d  t dd|   }d| t | S t jS d S )Nr   rK   r  r.  )rE   r   r   r  r  r[   )r;   rV   rp  r1  r  r.   r.   r/   r   [.  s$    ,,zrel_breitwigner_gen._munpc                 C   s   d d t jt jfS rC   r  ro  r.   r.   r/   r   l.  s    zrel_breitwigner_gen._statsc                    s   t | |||\}}}}t|t}|r:| dkr:|j}d}|d u sF|r`t j|g|R i |S |d u rt|| g d\}}	}
|
| }|	| }|s|g}d|vr||d< n t	|| }|| }|s|g}t j|g|R i |S )Nr   F)r+  ru   g      ?r(   )
r^  r5   r$   r6   r:   r7   r9   rE   Zquantiler  )r;   r<   r=   r-   rR  r   r   r>   r  r  r  Zscale_0Zrho_0ZM_0r  r.   r/   r9   r.  s.    

zrel_breitwigner_gen.fit)ri   rj   rk   rl   rW   r]   ra   rb   r   r   r	   r   r9   r?  r.   r.   r  r/   rn  .  s   =rn  rel_breitwigner)N(@  r  collections.abcr   	functoolsr   r   r  numpyrE   Znumpy.polynomialr   Zscipy._lib.doccerr   r   r	   Zscipy._lib._ccallbackr
   Zscipyr   r   Zscipy.specialZspecialrc   Zscipy.special._ufuncsr  r^   Zscipy._lib._utilr   r   r   r   Z_tukeylambda_statsr   r  r   r  Z_distn_infrastructurer   r   r   r   r   r   r   Z_ksstatsr   r   r   
_constantsr   r   r   r    r!   r"   r#   Z_censored_datar$   Zscipy.stats._boostrS  r   Zscipy.optimizer%   Zscipy.stats._warnings_errorsr&   Zscipy.statsr0   rB   rP   rQ   ro   rs   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r@  rc  rd  rt  ru  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r&  r4  r5  r=  r>  r  rK  rO  rP  r  ra  rn  ro  rr  rs  r|  r}  r  r  r  r  r  r  r  rC  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r)  r2  r3  r9  r<  r@  rA  rC  rD  rI  rJ  rY  r[  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r^  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r7  r8  r<  r=  rB  rC  rG  rK  rL  rW  rX  r]  r^  r)  ri  ro  rp  rs  rz  r{  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rl   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r*  rZ  rN  r+  r/  r0  r8  r9  r:  r;  rF  rH  rI  rK  rL  rX  r[   rm  rn  rr  listglobalsr}  itemspairsZ_distn_namesZ_distn_gen_names__all__r.   r.   r.   r/   <module>   sR  $$<@8
n
6+-	 ll7 TR5
RY7M
H
mN
H5M0n> "k
GT
x@ 
2 Q7a2 i
0
L
Z|S.
8V   ? 
C`
8]
H
`
1eet
r
` G;A>  M\dS\vQ 9 E  76=yh?5<C ]jI?( k  ?2
 8 s=?W@  K 8 H

 