U
    GvfG                    @   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l0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 d dl7m8  m9Z9 d dl:m;Z; d dl<m=Z= d dl>m8Z8 dd Z?dd Z@dddZAG dd de'ZBeBddddZCG dd de'ZDeDd ddd d!ZEG d"d# d#e'ZFeFdd$d%ZGeHd&ejI ZJeKeJZLd'd( ZMd)d* ZNd+d, ZOd-d. ZPd/d0 ZQd1d2 ZRd3d4 ZSd5d6 ZTG d7d8 d8e'ZUeUd9d:ZVG d;d< d<e'ZWeWdd=d%ZXG d>d? d?e'ZYeYejI d@ ejId@ dAdZZG dBdC dCe'Z[e[dddDdZ\G dEdF dFe]Z^G dGdH dHe=Z_dIdJ Z`dKdL ZaG dMdN dNe'ZbebdddOdZcG dPdQ dQe'ZdedddRd%ZeG dSdT dTe'ZfefdddUdZgG dVdW dWe'ZhehddXd%ZiG dYdZ dZe'Zjejdd[d%ZkG d\d] d]ehZleldd^d%ZmG d_d` d`e'Znendad:ZoG dbdc dce'Zpepdddd%ZqG dedf dfe'Zrerddgd%ZsG dhdi die'ZtetejI ejIdjdZuG dkdl dle'Zvevdmd:ZwG dndo doe'Zxexdpd:ZyG dqdr dre'Zzezddsd%Z{G dtdu due'Z|e|dvd:Z}G dwdx dxe'Z~e~ddyd%ZG 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'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'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dd%ZG dd de'ZdZG dd deԃZedd d%Zeddd%Zؐdddddddd	d
ddddddddddgZeD ]8Zeeeeڃdeڛ deڛ eաZeeee݃ 	qvG 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d0d%ZG d1d2 d2e'Zed3d:ZG d4d5 d5e'Zed6d:ZG d7d8 d8e'Zedd9d%ZG d:d; d;e'Zedd<d%ZG d=d> d>e'Zed?d:ZG d@dA dAe'ZedddBdZG dCdD dDe'ZeddEd%ZG dFdG dGe'ZedHd:ZG dIdJ dJe'Z e dKddLdZG dMdN dNe'ZeddOd%ZG dPdQ dQe'ZedRd:ZedSd:ZG dTdU dUe'ZeddVd%ZG dWdX dXe'Z	e	ddYd%Z
G dZd[ d[e'ZedKdd\dZG d]d^ d^e'Zed_d:ZG d`da dae'Zedbd:ZG dcdd dde'ZedddedZedddfdZejrdge_G dhdi die'ZedddjdZG dkdl dle'Zeddmd%Zdndo Zdpdq Zdrds ZG dtdu due'Zedvd
dwZG dxdy dye'Zeddzd%ZG d{d| d|e'Z e d}d:Z!G d~d de^Z"G dd de'Z#e#ddddZ$G dd de'Z%e%dd:Z&e%ejI ejIddZ'G dd deZ(e(ddd%Z)G dd de'Z*e*dd&ejI ddZ+G dd de'Z,e,dd:Z-G dd de'Z.e.d dd%Z/G dd de'Z0e0dddZ1dd Z2G dd de'Z3e3dddddZ4G dd de'Z5G dd de'Z6e6dd ej7dZ8e9e: ; < 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_EULER_ZETA3_SQRT_PI_SQRT_2_OVER_PI_LOG_SQRT_2_OVER_PI)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methodUnknown arguments: %s.)pop	TypeError)kwds r-   B/tmp/pip-unpacked-wheel-96ln3f52/scipy/stats/_continuous_distns.py_remove_optimizer_parameters&   s    r/   c                    s   t   fdd}|S )Nc                    sB   | dd }|dkr.tt| | j||S  | f||S d S )Nr(   mle)getlowersupertypefit)selfargsr,   r(   funr-   r.   wrapper<   s    z _call_super_mom.<locals>.wrapper)r   )r9   r:   r-   r8   r.   _call_super_mom9   s    r;   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rbrackr8   r-   r.   interval_contains_rootM   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.)r>   isinfFitSolverError)r9   rB   rA   ZdiffrC   msgr-   r8   r.   _get_left_bracketF   s    


rH   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   r>   roundr6   nr-   r-   r.   	_argcheck   s    zksone_gen._argcheckc                 C   s   t dddtjfdgS NrN   Tr   TFr   r>   infr6   r-   r-   r.   _shape_info   s    zksone_gen._shape_infoc                 C   s   t || S r<   )scuZ	_smirnovpr6   xrN   r-   r-   r.   _pdf   s    zksone_gen._pdfc                 C   s   t ||S r<   )rV   Z	_smirnovcrW   r-   r-   r.   _cdf   s    zksone_gen._cdfc                 C   s   t ||S r<   )scZsmirnovrW   r-   r-   r.   _sf   s    zksone_gen._sfc                 C   s   t ||S r<   )rV   Z
_smirnovcir6   qrN   r-   r-   r.   _ppf   s    zksone_gen._ppfc                 C   s   t ||S r<   )r[   Zsmirnovir]   r-   r-   r.   _isf   s    zksone_gen._isfN)__name__
__module____qualname____doc__rO   rU   rY   rZ   r\   r_   r`   r-   r-   r-   r.   rI   ]   s   %rI                 ?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 rJ   rK   rM   r-   r-   r.   rO      s    zkstwo_gen._argcheckc                 C   s   t dddtjfdgS rP   rR   rT   r-   r-   r.   rU      s    zkstwo_gen._shape_infoc                 C   s    dt |ts|nt| dfS N      ?rf   )
isinstancer   r>   Z
asanyarrayrM   r-   r-   r.   _get_support   s    zkstwo_gen._get_supportc                 C   s
   t ||S r<   )r   rW   r-   r-   r.   rY      s    zkstwo_gen._pdfc                 C   s
   t ||S r<   r   rW   r-   r-   r.   rZ      s    zkstwo_gen._cdfc                 C   s   t ||ddS NFcdfrp   rW   r-   r-   r.   r\      s    zkstwo_gen._sfc                 C   s   t ||ddS )NTrr   r   r]   r-   r-   r.   r_      s    zkstwo_gen._ppfc                 C   s   t ||ddS rq   rt   r]   r-   r-   r.   r`      s    zkstwo_gen._isfN)ra   rb   rc   rd   rO   rU   ro   rY   rZ   r\   r_   r`   r-   r-   r-   r.   rk      s   $rk   kstwo)momtyperh   ri   rj   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 r<   r-   rT   r-   r-   r.   rU     s    zkstwobign_gen._shape_infoc                 C   s   t | S r<   )rV   Z_kolmogpr6   rX   r-   r-   r.   rY     s    zkstwobign_gen._pdfc                 C   s
   t |S r<   )rV   Z_kolmogcrx   r-   r-   r.   rZ   
  s    zkstwobign_gen._cdfc                 C   s
   t |S r<   )r[   Z
kolmogorovrx   r-   r-   r.   r\     s    zkstwobign_gen._sfc                 C   s
   t |S r<   )rV   Z	_kolmogcir6   r^   r-   r-   r.   r_     s    zkstwobign_gen._ppfc                 C   s
   t |S r<   )r[   Zkolmogiry   r-   r-   r.   r`     s    zkstwobign_gen._isfN)
ra   rb   rc   rd   rU   rY   rZ   r\   r_   r`   r-   r-   r-   r.   rw      s   $rw   	kstwobign)rh   rj   rD   c                 C   s   t | d  d t S NrD          @)r>   exp_norm_pdf_CrX   r-   r-   r.   	_norm_pdf#  s    r   c                 C   s   | d  d t  S r{   )_norm_pdf_logCr   r-   r-   r.   _norm_logpdf'  s    r   c                 C   s
   t | S r<   )r[   ndtrr   r-   r-   r.   	_norm_cdf+  s    r   c                 C   s
   t | S r<   )r[   log_ndtrr   r-   r-   r.   _norm_logcdf/  s    r   c                 C   s
   t | S r<   r[   ndtrir^   r-   r-   r.   	_norm_ppf3  s    r   c                 C   s
   t |  S r<   r   r   r-   r-   r.   _norm_sf7  s    r   c                 C   s
   t |  S r<   r   r   r-   r-   r.   _norm_logsf;  s    r   c                 C   s
   t |  S r<   r   r   r-   r-   r.   	_norm_isf?  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 r<   r-   rT   r-   r-   r.   rU   Z  s    znorm_gen._shape_infoNc                 C   s
   | |S r<   )standard_normalr6   sizerandom_stater-   r-   r.   _rvs]  s    znorm_gen._rvsc                 C   s   t |S r<   r   rx   r-   r-   r.   rY   `  s    znorm_gen._pdfc                 C   s   t |S r<   )r   rx   r-   r-   r.   _logpdfd  s    znorm_gen._logpdfc                 C   s   t |S r<   r   rx   r-   r-   r.   rZ   g  s    znorm_gen._cdfc                 C   s   t |S r<   r   rx   r-   r-   r.   _logcdfj  s    znorm_gen._logcdfc                 C   s   t |S r<   )r   rx   r-   r-   r.   r\   m  s    znorm_gen._sfc                 C   s   t |S r<   )r   rx   r-   r-   r.   _logsfp  s    znorm_gen._logsfc                 C   s   t |S r<   r   ry   r-   r-   r.   r_   s  s    znorm_gen._ppfc                 C   s   t |S r<   r   ry   r-   r-   r.   r`   v  s    znorm_gen._isfc                 C   s   dS )N)re   rf   re   re   r-   rT   r-   r-   r.   r   y  s    znorm_gen._statsc                 C   s   dt dt j d  S Nrm   rD   r   r>   logpirT   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.

Znotesc                 K   s   | dd }| dd }t| |d k	r8|d k	r8tdt|}t| sXtd|d krj| }n|}|d krt|| d  }n|}||fS )Nflocfscale3All parameters fixed. There is nothing to optimize.$The data contains non-finite values.rD   )	r*   r/   
ValueErrorr>   asarrayisfiniteallmeansqrt)r6   datar,   r   r   r%   r&   r-   r-   r.   r5     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
        rD   r   r   re   N)r[   Z
factorial2rM   r-   r-   r.   _munp  s    znorm_gen._munp)NN)ra   rb   rc   rd   rU   r   rY   r   rZ   r   r\   r   r_   r`   r   r   r;   r   r   r5   r   r-   r-   r-   r.   r   C  s"   

r   norm)rj   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 Nrh   Fr   FFrR   rT   r-   r-   r.   rU     s    zalpha_gen._shape_infoc                 C   s$   d|d  t | t|d|   S Nrf   rD   )r   r   r6   rX   rh   r-   r-   r.   rY     s    zalpha_gen._pdfc                 C   s,   dt | t|d|   t t| S )Nrf   )r>   r   r   r   r   r-   r-   r.   r     s    zalpha_gen._logpdfc                 C   s   t |d|  t | S Nrf   r   r   r-   r-   r.   rZ     s    zalpha_gen._cdfc              	   C   s    dt |t|t|   S r   )r>   r   r[   r   r   r6   r^   rh   r-   r-   r.   r_     s    zalpha_gen._ppfc                 C   s   t jgd t jgd  S NrD   r>   rS   nanr6   rh   r-   r-   r.   r     s    zalpha_gen._statsN)ra   rb   rc   rd   r   _open_support_mask_support_maskrU   rY   r   rZ   r_   r   r-   r-   r-   r.   r     s   r   alphac                   @   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 )
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 r<   r-   rT   r-   r-   r.   rU     s    zanglit_gen._shape_infoc                 C   s   t d| S r   )r>   cosrx   r-   r-   r.   rY     s    zanglit_gen._pdfc                 C   s   t |t jd  d S )N   r|   r>   sinr   rx   r-   r-   r.   rZ   	  s    zanglit_gen._cdfc                 C   s   t t |t jd  S Nr   )r>   arcsinr   r   ry   r-   r-   r.   r_     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 )	Nre      rm   r   r   `      rD   r>   r   rT   r-   r-   r.   r     s    zanglit_gen._statsc                 C   s   dt d S Nr   rD   r>   r   rT   r-   r-   r.   r     s    zanglit_gen._entropyN
ra   rb   rc   rd   rU   rY   rZ   r_   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 r<   r-   rT   r-   r-   r.   rU   -  s    zarcsine_gen._shape_infoc              
   C   s@   t jdd* dt j t |d|   W  5 Q R  S Q R X d S )Nignoredividerf   r   )r>   errstater   r   rx   r-   r-   r.   rY   0  s    zarcsine_gen._pdfc                 C   s   dt j t t | S Nr|   )r>   r   r   r   rx   r-   r-   r.   rZ   5  s    zarcsine_gen._cdfc                 C   s   t t jd | d S r   r   ry   r-   r-   r.   r_   8  s    zarcsine_gen._ppfc                 C   s   d}d}d}d}||||fS )Nrm   g      ?r         r-   r6   mumu2g1g2r-   r-   r.   r   ;  s
    zarcsine_gen._statsc                 C   s   dS )Ngοr-   rT   r-   r-   r.   r   B  s    zarcsine_gen._entropyNr   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j |||df| _d S )NzInvalid values in `data`.  Maximum likelihood estimation with {distr!r} requires that {lower!r} < (x - loc)/scale  < {upper!r} for each x in `data`.)distrr2   upper)formatr7   )r6   r   r2   r   r-   r-   r.   __init__N  s      zFitDataError.__init__Nra   rb   rc   rd   r   r-   r-   r-   r.   r   I  s   r   c                   @   s   e Zd ZdZdd ZdS )rF   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: 
 )replacer7   )r6   mesgemsgr-   r-   r.   r   ]  s    zFitSolverError.__init__Nr   r-   r-   r-   r.   rF   W  s   rF   c                 C   s*   t | | }||| t |    }|S r<   r[   psi)rh   ri   rN   s1psiabfuncr-   r-   r.   _beta_mle_ac  s    r   c                 C   sJ   | \}}t || }||| t |   ||| t |   g}|S r<   r   )thetarN   r   s2rh   ri   r   r   r-   r-   r.   _beta_mle_abl  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  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 Nrh   Fr   r   ri   rR   r6   iaibr-   r-   r.   rU     s    zbeta_gen._shape_infoNc                 C   s   | |||S r<   beta)r6   rh   ri   r   r   r-   r-   r.   r     s    zbeta_gen._rvsc                 C   s   t |||S r<   )_boostZ	_beta_pdfr6   rX   rh   ri   r-   r-   r.   rY     s    zbeta_gen._pdfc                 C   s6   t |d | t |d | }|t ||8 }|S r   )r[   xlog1pyxlogybetaln)r6   rX   rh   ri   lPxr-   r-   r.   r     s    "zbeta_gen._logpdfc                 C   s   t |||S r<   )r   Z	_beta_cdfr   r-   r-   r.   rZ     s    zbeta_gen._cdfc                 C   s   t |||S r<   )r   Z_beta_sfr   r-   r-   r.   r\     s    zbeta_gen._sfc              
   C   s@   t  . d}t jd|d t|||W  5 Q R  S Q R X d S )Nz!overflow encountered in _beta_isfr   message)warningscatch_warningsfilterwarningsr   Z	_beta_isf)r6   rX   rh   ri   r   r-   r-   r.   r`     s    
zbeta_gen._isfc              
   C   s@   t  . d}t jd|d t|||W  5 Q R  S Q R X d S )Nz!overflow encountered in _beta_ppfr   r   )r   r   r   r   Z	_beta_ppf)r6   r^   rh   ri   r   r-   r-   r.   r_     s    
zbeta_gen._ppfc                 C   s,   t ||t ||t ||t ||fS r<   )r   Z
_beta_meanZ_beta_varianceZ_beta_skewnessZ_beta_kurtosis_excessr6   rh   ri   r-   r-   r.   r     s
    



zbeta_gen._statsc                    sB   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 )NrD   r         r>   r   )rX   rh   ri   skkur   r   r-   r.   r     s    8@$z beta_gen._fitstart.<locals>.func)rf   rf   r7   )r   r   r   fsolver3   	_fitstart)r6   r   r   rh   ri   	__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                    s8  | dd }| dd }|d ks(|d kr<t j|f||S |dd  |dd  t|dddg}t|dddg}t| |d k	r|d k	rtd	t|	 std
t
|| | }t|dkst|dkrtd||| d| }|d k	s|d k	r|d k	r&|}	d| }d| }n|}	|	| d|  }
tjt|
|	t|t| fdd\}}}}|dkr|t|d|d }
|d k	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fafix_af1ZfbZfix_br   r   r   r   r   r2   r   T)r7   full_output)r   )Zddof)r1   r3   r5   r*   r   r/   r   r>   r   r   Zravelanyr   r   r   r  r   lenr   sumrF   r[   log1pvarr   )r6   r   r7   r,   r   r   r  r  xbarri   rh   r   infoierr   r   r   facr
  r-   r.   r5     sd    
	

 


 

zbeta_gen.fit)NN)ra   rb   rc   rd   rU   r   rY   r   rZ   r\   r`   r_   r   r	  r;   r   r   r5   __classcell__r-   r-   r
  r.   r   z  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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.

    %(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 r   rR   r   r-   r-   r.   rU   U  s    zbetaprime_gen._shape_infoNc                 C   s(   t j|||d}t j|||d}|| S Nr   r   )gammarvs)r6   rh   ri   r   r   u1u2r-   r-   r.   r   Z  s    zbetaprime_gen._rvsc                 C   s   t | |||S r<   r>   r}   r   r   r-   r-   r.   rY   _  s    zbetaprime_gen._pdfc                 C   s,   t |d |t || | t || S r   )r[   r   r   r   r   r-   r-   r.   r   c  s    zbetaprime_gen._logpdfc                 C   s   t |||d|  S r   )r[   Zbetaincr   r-   r-   r.   rZ   f  s    zbetaprime_gen._cdfc                 C   s   |dkr$t |dk||d  t jS |dkrXt |dk||d  |d |d   t jS |dkrt |dk||d  |d  |d |d  |d   t jS |dkrt |dk||d  |d  |d  |d |d  |d  |d   t jS td S )	Nrf   r   r|   rD         @r        @r   )r>   whererS   NotImplementedErrorr6   rN   rh   ri   r-   r-   r.   r   i  s.    



*
zbetaprime_gen._munp)NN)ra   rb   rc   rd   r   r   r   rU   r   rY   r   rZ   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   rR   rT   r-   r-   r.   rU     s    zbradford_gen._shape_infoc                 C   s   ||| d  t | S r   r[   r  r6   rX   r,  r-   r-   r.   rY     s    zbradford_gen._pdfc                 C   s   t || t | S r<   r-  r.  r-   r-   r.   rZ     s    zbradford_gen._cdfc                 C   s   t |t | | S r<   r[   expm1r  r6   r^   r,  r-   r-   r.   r_     s    zbradford_gen._ppfmvc                 C   sx  t d| }|| ||  }|d | d|  d| | |  }d }d }d|krt dd| | d| | |d   d| | ||d  d    }|t |||d  d|   d| |d  d|    }d	|krl|d |d  |d| d
  d  d| | | |d  |d   d| | | d| d   d|d   }|d| ||d  d|  d   }||||fS )Nrf   r|   rD   s   	   r  r  kr      r      )r>   r   r   )r6   r,  momentsr6  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   )r6   r,  r6  r-   r-   r.   r     s    zbradford_gen._entropyN)r2  r   r-   r-   r-   r.   r*    s   
r*  bradfordc                   @   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 )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 Nr,  Fr   r   drR   r6   icidr-   r-   r.   rU     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 rJ   r-   Zx_Zc_Zd_r-   r-   r.   <lambda>      zburr_gen._pdf.<locals>.<lambda>c                 S   s,   || | | d   d| |   |d   S Nrf   r   r-   rB  r-   r-   r.   rC    s   f2r-   r   ndimr6   rX   r,  r>  outputr-   r-   r.   rY     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 rJ   )r>   r   r[   r   r  rB  r-   r-   r.   rC    s   &z"burr_gen._logpdf.<locals>.<lambda>c                 S   s<   t |t | t| d |  t|d | |   S rJ   r>   r   r[   r   r   rB  r-   r-   r.   rC    s   rF  r-   rH  rJ  r-   r-   r.   r     s     
zburr_gen._logpdfc                 C   s   d||   |  S rJ   r-   r6   rX   r,  r>  r-   r-   r.   rZ     s    zburr_gen._cdfc                 C   s   t ||  |  S r<   r-  rM  r-   r-   r.   r     s    zburr_gen._logcdfc                 C   s   t | |||S r<   r>   r}   r   rM  r-   r-   r.   r\     s    zburr_gen._sfc                 C   s   t d||   |   S rJ   r>   r  rM  r-   r-   r.   r     s    zburr_gen._logsfc                 C   s   |d|  d d|  S N      r   r-   r6   r^   r,  r>  r-   r-   r.   r_     s    zburr_gen._ppfc                 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   rf   rD   r|   r$  c                 S   s*   |d| |  d|d   t |d  S )Nr  rD   r  )r,  e1e2e3mu2_if_cr-   r-   r.   rC  !  rD  z!burr_gen._stats.<locals>.<lambda>	fillvaluer%  c                 S   s8   |d| |  d| |d   d|d   |d  d S )Nr   r  rD   r  r-   )r,  rT  rU  rV  e4rW  r-   r-   r.   rC  &  s    r   )
r>   arangereshaper[   r   r&  r   r   rI  item)r6   r,  r>  ncrT  rU  rV  rZ  r   rW  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   r[   r   )rN   r,  r>  r^  r-   r-   r.   __munp.  s    zburr_gen._munp.<locals>.__munpc                    s    || |S r<   r-   )r,  r>  rN   Z_burr_gen__munpr-   r.   rC  3  rD  z burr_gen._munp.<locals>.<lambda>)r>   r   r   r   )r6   rN   r,  r>  r-   ra  r.   r   -  s    " 
zburr_gen._munpN)ra   rb   rc   rd   rU   rY   r   rZ   r   r\   r   r_   r   r   r-   r-   r-   r.   r<    s   0
r<  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 r=  rR   r?  r-   r-   r.   rU   g  s    zburr12_gen._shape_infoc                 C   s   t | |||S r<   r#  rM  r-   r-   r.   rY   l  s    zburr12_gen._pdfc                 C   s:   t |t | t|d | t| d ||  S rJ   rL  rM  r-   r-   r.   r   p  s    zburr12_gen._logpdfc                 C   s   t | ||| S r<   )r[   r0  r   rM  r-   r-   r.   rZ   s  s    zburr12_gen._cdfc                 C   s   t d||  |   S rJ   r-  rM  r-   r-   r.   r   v  s    zburr12_gen._logcdfc                 C   s   t | |||S r<   rN  rM  r-   r-   r.   r\   y  s    zburr12_gen._sfc                 C   s   t | || S r<   r[   r   rM  r-   r-   r.   r   |  s    zburr12_gen._logsfc                 C   s"   t d| t |  d|  S )Nr   r/  rR  r-   r-   r.   r_     s    zburr12_gen._ppfc                 C   s$   d| | }|t d| ||  S r   r_  )r6   rN   r,  r>  r^  r-   r-   r.   r     s    zburr12_gen._munpN)ra   rb   rc   rd   rU   rY   r   rZ   r   r\   r   r_   r   r-   r-   r-   r.   rc  :  s   ,rc  burr12c                   @   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 )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``.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS r+  rR   rT   r-   r-   r.   rU     s    zfisk_gen._shape_infoc                 C   s   t ||dS r   )rb  rY   r.  r-   r-   r.   rY     s    zfisk_gen._pdfc                 C   s   t ||dS r   )rb  rZ   r.  r-   r-   r.   rZ     s    zfisk_gen._cdfc                 C   s   t ||dS r   )rb  r\   r.  r-   r-   r.   r\     s    zfisk_gen._sfc                 C   s   t ||dS r   )rb  r   r.  r-   r-   r.   r     s    zfisk_gen._logpdfc                 C   s   t ||dS r   )rb  r   r.  r-   r-   r.   r     s    zfisk_gen._logcdfc                 C   s   t ||dS r   )rb  r   r.  r-   r-   r.   r     s    zfisk_gen._logsfc                 C   s   t ||dS r   )rb  r_   r.  r-   r-   r.   r_     s    zfisk_gen._ppfc                 C   s   t ||dS r   )rb  r   r6   rN   r,  r-   r-   r.   r     s    zfisk_gen._munpc                 C   s   t |dS r   )rb  r   r6   r,  r-   r-   r.   r     s    zfisk_gen._statsc                 C   s   dt | S r   r   ri  r-   r-   r.   r     s    zfisk_gen._entropyN)ra   rb   rc   rd   rU   rY   rZ   r\   r   r   r   r_   r   r   r   r-   r-   r-   r.   rg    s   &rg  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 r<   r-   rT   r-   r-   r.   rU     s    zcauchy_gen._shape_infoc                 C   s   dt j d||   S r   r   rx   r-   r-   r.   rY     s    zcauchy_gen._pdfc                 C   s   ddt j t |  S rl   r>   r   arctanrx   r-   r-   r.   rZ     s    zcauchy_gen._cdfc                 C   s   t t j| t jd  S r   r>   tanr   ry   r-   r-   r.   r_     s    zcauchy_gen._ppfc                 C   s   ddt j t |  S rl   rl  rx   r-   r-   r.   r\     s    zcauchy_gen._sfc                 C   s   t t jd t j|  S r   rn  ry   r-   r-   r.   r`     s    zcauchy_gen._isfc                 C   s   t jt jt jt jfS r<   r>   r   rT   r-   r-   r.   r     s    zcauchy_gen._statsc                 C   s   t dt j S r   r   rT   r-   r-   r.   r     s    zcauchy_gen._entropyNc                 C   s(   t |dddg\}}}||| d fS )N   2   K   rD   r>   Z
percentile)r6   r   r7   p25p50p75r-   r-   r.   r	    s    zcauchy_gen._fitstart)N)ra   rb   rc   rd   rU   rY   rZ   r_   r\   r`   r   r   r	  r-   r-   r-   r.   rk    s   rk  cauchyc                   @   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 )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   rR   rT   r-   r-   r.   rU   0  s    zchi_gen._shape_infoNc                 C   s   t tj|||dS r  )r>   r   chi2r   r6   r{  r   r   r-   r-   r.   r   3  s    zchi_gen._rvsc                 C   s   t | ||S r<   r#  r6   rX   r{  r-   r-   r.   rY   6  s    zchi_gen._pdfc                 C   sJ   t ddt d |  td|  }|t|d | d|d   S )NrD   rm   rf   )r>   r   r[   gammalnr   )r6   rX   r{  lr-   r-   r.   r   <  s    *zchi_gen._logpdfc                 C   s   t d| d|d  S Nrm   rD   r[   gammaincr~  r-   r-   r.   rZ   @  s    zchi_gen._cdfc                 C   s   t d| d|d  S r  r[   	gammainccr~  r-   r-   r.   r\   C  s    zchi_gen._sfc                 C   s   t dtd| | S NrD   rm   r>   r   r[   gammaincinvr6   r^   r{  r-   r-   r.   r_   F  s    zchi_gen._ppfc                 C   s   t dtd| | S r  r>   r   r[   gammainccinvr  r-   r-   r.   r`   I  s    zchi_gen._isfc                 C   s   t dt t|d d t|d   }|||  }d|d  |dd|    t t |d }d| d|  d|d	   d	|d  d| d   }|t |d  }||||fS )
NrD   r|   rm   r$  r         ?rf   r  r   )r>   r   r}   r[   r  r   powerr6   r{  r   r   r   r   r-   r-   r.   r   L  s    0.4zchi_gen._stats)NN)ra   rb   rc   rd   rU   r   rY   r   rZ   r\   r_   r`   r   r-   r-   r-   r.   ry    s   
ry  chic                   @   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 )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 rz  rR   rT   r-   r-   r.   rU   z  s    zchi2_gen._shape_infoNc                 C   s   | ||S r<   )Z	chisquarer}  r-   r-   r.   r   }  s    zchi2_gen._rvsc                 C   s   t | ||S r<   r#  r~  r-   r-   r.   rY     s    zchi2_gen._pdfc                 C   s<   t |d d ||d  t |d  td| d  S )Nr|   r   rD   )r[   r   r  r>   r   r~  r-   r-   r.   r     s    zchi2_gen._logpdfc                 C   s   t ||S r<   )r[   Zchdtrr~  r-   r-   r.   rZ     s    zchi2_gen._cdfc                 C   s   t ||S r<   )r[   Zchdtrcr~  r-   r-   r.   r\     s    zchi2_gen._sfc                 C   s   t ||S r<   )r[   Zchdtrir6   pr{  r-   r-   r.   r`     s    zchi2_gen._isfc                 C   s   dt |d | S r   r[   r  r  r-   r-   r.   r_     s    zchi2_gen._ppfc                 C   s2   |}d| }dt d|  }d| }||||fS )NrD   r|         (@r  r  r-   r-   r.   r     s
    zchi2_gen._stats)NN)ra   rb   rc   rd   rU   r   rY   r   rZ   r\   r`   r_   r   r-   r-   r-   r.   r  X  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 r<   r-   rT   r-   r-   r.   rU     s    zcosine_gen._shape_infoc                 C   s   dt j dt |  S )Nrm   r   r>   r   r   rx   r-   r-   r.   rY     s    zcosine_gen._pdfc                 C   s(   t |}t|dk|fdd t j dS )Nre  c                 S   s   t | t dt j  S r   )r>   r  r   r   r,  r-   r-   r.   rC    rD  z$cosine_gen._logpdf.<locals>.<lambda>rX  )r>   r   r   rS   r.  r-   r-   r.   r     s
    
zcosine_gen._logpdfc                 C   s
   t |S r<   rV   Z_cosine_cdfrx   r-   r-   r.   rZ     s    zcosine_gen._cdfc                 C   s   t | S r<   r  rx   r-   r-   r.   r\     s    zcosine_gen._sfc                 C   s
   t |S r<   rV   Z_cosine_invcdfr6   r  r-   r-   r.   r_     s    zcosine_gen._ppfc                 C   s   t | S r<   r  r  r-   r-   r.   r`     s    zcosine_gen._isfc                 C   sB   dt jt j d d ddt jd d  dt jt j d d	   fS )
Nre   r$  r|         r   Z         @r  rD   r   rT   r-   r-   r.   r     s    zcosine_gen._statsc                 C   s   t dt j d S )Nr   rf   r   rT   r-   r-   r.   r     s    zcosine_gen._entropyNra   rb   rc   rd   rU   rY   r   rZ   r\   r_   r`   r   r   r-   r-   r-   r.   r    s   r  cosinec                   @   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 )
dgamma_gena  A double gamma continuous random variable.

    %(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

    %(example)s

    c                 C   s   t dddtjfdgS r   rR   rT   r-   r-   r.   rU     s    zdgamma_gen._shape_infoNc                 C   s2   |j |d}tj|||d}|t|dkdd S Nr   r  rm   r   re  )uniformr  r   r>   r&  )r6   rh   r   r   uZgmr-   r-   r.   r     s    zdgamma_gen._rvsc                 C   s2   t |}ddt|  ||d   t|  S r   )absr[   r  r>   r}   r6   rX   rh   axr-   r-   r.   rY     s    zdgamma_gen._pdfc                 C   s0   t |}t|d || td t| S r   )r  r[   r   r>   r   r  r  r-   r-   r.   r     s    zdgamma_gen._logpdfc                 C   s.   dt |t| }t|dkd| d| S Nrm   r   r[   r  r  r>   r&  r6   rX   rh   r  r-   r-   r.   rZ     s    zdgamma_gen._cdfc                 C   s.   dt |t| }t|dkd| d| S r  r  r  r-   r-   r.   r\     s    zdgamma_gen._sfc                 C   s0   t |dtd| d  }t|dk|| S Nr   rD   rm   )r[   r  r  r>   r&  )r6   r^   rh   r  r-   r-   r.   r_     s    zdgamma_gen._ppfc                 C   s,   ||d  }d|d|d |d  | d fS )Nrf   re   r|   r$  r-   )r6   rh   r   r-   r-   r.   r   
  s    zdgamma_gen._stats)NNra   rb   rc   rd   rU   r   rY   r   rZ   r\   r_   r   r-   r-   r-   r.   r    s   
r  dgammac                   @   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 )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 r+  rR   rT   r-   r-   r.   rU   (  s    zdweibull_gen._shape_infoNc                 C   s2   |j |d}tj|||d}|t|dkdd S r  )r  weibull_minr   r>   r&  )r6   r,  r   r   r  wr-   r-   r.   r   +  s    zdweibull_gen._rvsc                 C   s0   t |}|d ||d   t||   }|S Nr|   rf   )r  r>   r}   )r6   rX   r,  r  Pxr-   r-   r.   rY   0  s    $zdweibull_gen._pdfc                 C   s4   t |}t|td t|d | ||  S r  )r  r>   r   r[   r   )r6   rX   r,  r  r-   r-   r.   r   6  s    zdweibull_gen._logpdfc                 C   s.   dt t||   }t |dkd| |S )Nrm   r   r   )r>   r}   r  r&  )r6   rX   r,  ZCx1r-   r-   r.   rZ   :  s    zdweibull_gen._cdfc                 C   sF   dt |dk|d|  }t t | d| }t |dk|| S )Nr|   rm   rf   )r>   r&  r  r   )r6   r^   r,  r  r-   r-   r.   r_   >  s    zdweibull_gen._ppfc                 C   s"   d|d  t dd| |   S )Nr   rD   rf   r[   r  rh  r-   r-   r.   r   C  s    zdweibull_gen._munpc                 C   s   dS N)r   Nr   Nr-   ri  r-   r-   r.   r   I  s    zdweibull_gen._stats)NN)ra   rb   rc   rd   rU   r   rY   r   rZ   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 r<   r-   rT   r-   r-   r.   rU   k  s    zexpon_gen._shape_infoNc                 C   s
   | |S r<   )standard_exponentialr   r-   r-   r.   r   n  s    zexpon_gen._rvsc                 C   s   t | S r<   r>   r}   rx   r-   r-   r.   rY   q  s    zexpon_gen._pdfc                 C   s   | S r<   r-   rx   r-   r-   r.   r   u  s    zexpon_gen._logpdfc                 C   s   t |  S r<   r[   r0  rx   r-   r-   r.   rZ   x  s    zexpon_gen._cdfc                 C   s   t |  S r<   r-  ry   r-   r-   r.   r_   {  s    zexpon_gen._ppfc                 C   s   t | S r<   r  rx   r-   r-   r.   r\   ~  s    zexpon_gen._sfc                 C   s   | S r<   r-   rx   r-   r-   r.   r     s    zexpon_gen._logsfc                 C   s   t | S r<   r   ry   r-   r-   r.   r`     s    zexpon_gen._isfc                 C   s   dS )N)rf   rf   r|         @r-   rT   r-   r-   r.   r     s    zexpon_gen._statsc                 C   s   dS r   r-   rT   r-   r-   r.   r     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 k	rL|d k	rLtdt|}t| sltd|	 }|d kr|}n|}||k rt
d|tjd|d kr| | }n|}t|t|fS )	Nr   Too many arguments.r   r   r   r   exponr  )r  r+   r*   r/   r   r>   r   r   r   minr   rS   r   float)	r6   r   r7   r,   r   r   Zdata_minr%   r&   r-   r-   r.   r5     s(    
zexpon_gen.fit)NN)ra   rb   rc   rd   rU   r   rY   r   rZ   r_   r\   r   r`   r   r   r;   r   r   r5   r-   r-   r-   r.   r  P  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 Wikpedia 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   rR   rT   r-   r-   r.   rU     s    zexponnorm_gen._shape_infoNc                 C   s    | || }||}|| S r<   )r  r   )r6   r  r   r   expvalZgvalr-   r-   r.   r     s    
zexponnorm_gen._rvsc                 C   s   t | ||S r<   r#  )r6   rX   r  r-   r-   r.   rY     s    zexponnorm_gen._pdfc                 C   s2   d| }|d| |  }|t ||  t| S Nrf   rm   r   r>   r   )r6   rX   r  invKZexpargr-   r-   r.   r     s    zexponnorm_gen._logpdfc                 C   s:   d| }|d| |  }|t ||  }t|t| S r  r   r   r>   r}   r6   rX   r  r  r  Zlogprodr-   r-   r.   rZ     s    zexponnorm_gen._cdfc                 C   s<   d| }|d| |  }|t ||  }t| t| S r  r  r  r-   r-   r.   r\      s    zexponnorm_gen._sfc                 C   sD   || }d| }d|d  |d  }d| | |d  }||||fS )Nrf   rD   r  r   r  r   r-   )r6   r  ZK2ZopK2ZskwZkrtr-   r-   r.   r     s
    zexponnorm_gen._stats)NN)ra   rb   rc   rd   rU   r   rY   r   rZ   r\   r   r-   r-   r-   r.   r    s   )
r  	exponnormc                   @   s8   e Zd Z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 Nrh   Fr   r   r,  rR   r6   r   r@  r-   r-   r.   rU   :  s    zexponweib_gen._shape_infoc                 C   s   t | |||S r<   r#  r6   rX   rh   r,  r-   r-   r.   rY   ?  s    zexponweib_gen._pdfc                 C   sR   ||  }t | }t|t| t |d | | t |d | }|S r   )r[   r0  r>   r   r   )r6   rX   rh   r,  Znegxcexm1cZlogpr-   r-   r.   r   D  s    
"zexponweib_gen._logpdfc                 C   s   t ||   }|| S r<   r  )r6   rX   rh   r,  r  r-   r-   r.   rZ   K  s    zexponweib_gen._cdfc                 C   s$   t |d|    td|  S r   )r[   r  r>   r   )r6   r^   rh   r,  r-   r-   r.   r_   O  s    zexponweib_gen._ppfN	ra   rb   rc   rd   rU   rY   r   rZ   r_   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 Nri   Fr   r   rR   rT   r-   r-   r.   rU   r  s    zexponpow_gen._shape_infoc                 C   s   t | ||S r<   r#  r6   rX   ri   r-   r-   r.   rY   u  s    zexponpow_gen._pdfc                 C   s8   || }dt | t|d | | t | }|S Nr   rf   )r>   r   r[   r   r}   )r6   rX   ri   xbfr-   r-   r.   r   y  s    ,zexponpow_gen._logpdfc                 C   s   t t ||   S r<   r  r  r-   r-   r.   rZ   ~  s    zexponpow_gen._cdfc                 C   s   t t||  S r<   r>   r}   r[   r0  r  r-   r-   r.   r\     s    zexponpow_gen._sfc                 C   s   t t| d|  S r   r[   r  r>   r   r  r-   r-   r.   r`     s    zexponpow_gen._isfc                 C   s   t tt|  d| S r   powr[   r  r6   r^   ri   r-   r-   r.   r_     s    zexponpow_gen._ppfN)ra   rb   rc   rd   rU   rY   r   rZ   r\   r`   r_   r-   r-   r-   r.   r  V  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 r+  rR   rT   r-   r-   r.   rU     s    zfatiguelife_gen._shape_infoNc                 C   sD   | |}d| | }|| }dd|  d| td|   }|S )Nrm   rf   rD   r   )r   r>   r   )r6   r,  r   r   zrX   x2tr-   r-   r.   r     s
    
"zfatiguelife_gen._rvsc                 C   s   t | ||S r<   r#  r.  r-   r-   r.   rY     s    zfatiguelife_gen._pdfc                 C   sZ   t |d |d d d| |d    t d|  dt dt j dt |    S )Nr   rD   r|   rm   r  r   r.  r-   r-   r.   r     s    6 zfatiguelife_gen._logpdfc                 C   s$   t d| t|dt|   S r   )r   r>   r   r.  r-   r-   r.   rZ     s    zfatiguelife_gen._cdfc                 C   s,   |t | }d|t|d d  d  S N      ?rD   r   r[   r   r>   r   r6   r^   r,  tmpr-   r-   r.   r_     s    zfatiguelife_gen._ppfc                 C   s$   t d| t|dt|   S r   )r   r>   r   r.  r-   r-   r.   r\     s    zfatiguelife_gen._sfc                 C   s.   | t | }d|t|d d  d  S r  r  r  r-   r-   r.   r`     s    zfatiguelife_gen._isfc                 C   st   || }|d d }d| d }|| d }d| d| d  t |d }d	| d
| d  |d  }||||fS )Nr|   rf   r  r%  r      r  r  r  ]   g      D@r>   r  )r6   r,  c2r   denr   r   r   r-   r-   r.   r     s     zfatiguelife_gen._stats)NN)ra   rb   rc   rd   r   r   r   rU   r   rY   r   rZ   r_   r\   r`   r   r-   r-   r-   r.   r    s   
r  fatiguelifec                   @   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 )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-   ri  r-   r-   r.   rO     s    zfoldcauchy_gen._argcheckc                 C   s   t dddtjfdgS Nr,  Fr   rQ   rR   rT   r-   r-   r.   rU     s    zfoldcauchy_gen._shape_infoNc                 C   s   t tj|||dS )Nr%   r   r   )r  rx  r   r6   r,  r   r   r-   r-   r.   r     s    
zfoldcauchy_gen._rvsc                 C   s2   dt j dd|| d   dd|| d     S Nrf   r   rD   r   r.  r-   r-   r.   rY     s    zfoldcauchy_gen._pdfc                 C   s&   dt j t || t ||   S r   rl  r.  r-   r-   r.   rZ      s    zfoldcauchy_gen._cdfc                 C   s   t jt jt jt jfS r<   r   ri  r-   r-   r.   r     s    zfoldcauchy_gen._stats)NN
ra   rb   rc   rd   rO   rU   r   rY   rZ   r   r-   r-   r-   r.   r    s   
r  
foldcauchyc                   @   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 )f_genaE  An F continuous random variable.

    For the noncentral F distribution, see `ncf`.

    %(before_notes)s

    See Also
    --------
    ncf

    Notes
    -----
    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` and parameters :math:`df_1, df_2 > 0` .

    `f` takes ``dfn`` and ``dfd`` 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 )NdfnFr   r   dfdrR   )r6   ZidfnZidfdr-   r-   r.   rU   (  s    zf_gen._shape_infoNc                 C   s   | |||S r<   )r  )r6   r  r  r   r   r-   r-   r.   r   -  s    z
f_gen._rvsc                 C   s   t | |||S r<   r#  r6   rX   r  r  r-   r-   r.   rY   0  s    z
f_gen._pdfc                 C   s~   d| }d| }|d t | |d t |  t|d d | || d t |||   t|d |d   }|S Nrf   rD   r   )r>   r   r[   r   r   )r6   rX   r  r  rN   mr   r-   r-   r.   r   6  s    60zf_gen._logpdfc                 C   s   t |||S r<   )r[   Zfdtrr  r-   r-   r.   rZ   =  s    z
f_gen._cdfc                 C   s   t |||S r<   )r[   Zfdtrcr  r-   r-   r.   r\   @  s    z	f_gen._sfc                 C   s   t |||S r<   )r[   Zfdtri)r6   r^   r  r  r-   r-   r.   r_   C  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 )Nrf   r|   r%  r         @rD   c                 S   s   | | S r<   r-   )v2v2_2r-   r-   r.   rC  L  rD  zf_gen._stats.<locals>.<lambda>r   c                 S   s$   d| | | |  | |d  |  S r   r-   )v1r  r  v2_4r-   r-   r.   rC  Q  s    r  c                 S   s&   d|  | | t || | |    S r   r  )r  r  r  v2_6r-   r-   r.   rC  W  s    r   c                 S   s   d| |  |  | S )Nr   r-   )r   r  v2_8r-   r-   r.   rC  ^  rD  r  )r   r>   rS   r   r   )r6   r  r  r  r  r  r  r  r  r   r   r   r   r-   r-   r.   r   F  s:    $  
 
 zf_gen._stats)NNr  r-   r-   r-   r.   r  
  s   
r  r  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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 r  r-   ri  r-   r-   r.   rO     s    zfoldnorm_gen._argcheckc                 C   s   t dddtjfdgS r  rR   rT   r-   r-   r.   rU     s    zfoldnorm_gen._shape_infoNc                 C   s   t ||| S r<   r  r   r  r-   r-   r.   r     s    zfoldnorm_gen._rvsc                 C   s   t || t ||  S r<   r   r.  r-   r-   r.   rY     s    zfoldnorm_gen._pdfc                 C   s   t || t ||  d S r   r   r.  r-   r-   r.   rZ     s    zfoldnorm_gen._cdfc                 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|   rD   r   r  r  r  r  r$  )r>   r}   r   r   r[   erfr  )r6   r,  r  Zexpfacr   r   r   r   r-   r-   r.   r     s     $zfoldnorm_gen._stats)NNr  r-   r-   r-   r.   r  p  s   
r  foldnormc                       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dd fddZ  ZS )weibull_min_genaF  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.

    %(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 r+  rR   rT   r-   r-   r.   rU     s    zweibull_min_gen._shape_infoc                 C   s$   |t ||d  tt ||  S rJ   r  r>   r}   r.  r-   r-   r.   rY     s    zweibull_min_gen._pdfc                 C   s$   t |t|d | t|| S rJ   r>   r   r[   r   r  r.  r-   r-   r.   r     s    zweibull_min_gen._logpdfc                 C   s   t t||  S r<   r[   r0  r  r.  r-   r-   r.   rZ     s    zweibull_min_gen._cdfc                 C   s   t t|| S r<   r>   r}   r  r.  r-   r-   r.   r\     s    zweibull_min_gen._sfc                 C   s   t || S r<   r  r.  r-   r-   r.   r     s    zweibull_min_gen._logsfc                 C   s   t t|  d| S r   r  r1  r-   r-   r.   r_     s    zweibull_min_gen._ppfc                 C   s   t d|d |  S r   r  rh  r-   r-   r.   r     s    zweibull_min_gen._munpc                 C   s   t  | t| t  d S rJ   r   r>   r   ri  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              	      s  | ddr t j|f||S t| |||\}}}}|dd }dd t| d}|}	 |	k r|dkr|d kr|st j|f||S |dkrd	\}
}}n,t|r|d
 nd }
| dd }| dd }|d kr|
d krt	 fddd|gddj
}
n|d k	r|}
|d krh|d krht|}t|tdd|
  tdd|
  d   }n|d k	rv|}|d kr|d krt|}||tdd|
    }n|d k	r|}|dkr|
||fS t j||
f||d|S d S )NsuperfitFr(   r0   c                 S   sj   t dd|   }t dd|   }t dd|   }d|d  d| |  | }||d  d }|| S )Nr   rD   r  r  r  )r,  Zgamma1Zgamma2Zgamma3numr  r-   r-   r.   skew	  s    z!weibull_min_gen.fit.<locals>.skewg     @mmNNNr   r%   r&   c                    s   |   S r<   r-   r  r3  r  r-   r.   rC  '	  rD  z%weibull_min_gen.fit.<locals>.<lambda>g{Gz?bisect)bracketr(   r   rD   r%   r&   )r*   r3   r5   _check_fit_input_parametersr1   r2   statsr  r  r#   rootr>   r  r   r[   r  r   )r6   r   r7   r,   Zfcr   r   r(   Zmax_cZs_minr,  r%   r&   vr  r
  r  r.   r5     sJ    	 



4




zweibull_min_gen.fit)ra   rb   rc   rd   rU   rY   r   rZ   r\   r   r_   r   r   r   r   r5   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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 Nre   r-   r6   r,  rh   ri   r-   r-   r.   rO   p	  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 )Nr,  Fr   r   rh   rQ   ri   rR   )r6   r@  r   r   r-   r-   r.   rU   s	  s    z truncweibull_min_gen._shape_infoc                    s   t  j|ddS )N)r   r   r   r  r3   r	  r6   r   r
  r-   r.   r	  y	  s    ztruncweibull_min_gen._fitstartc                 C   s   ||fS r<   r-   r  r-   r-   r.   ro   }	  s    z!truncweibull_min_gen._get_supportc                 C   sL   t t|| t t||  }|t||d  t t||  | S rJ   r  )r6   rX   r,  rh   ri   denumr-   r-   r.   rY   	  s    $ztruncweibull_min_gen._pdfc                 C   sR   t t t|| t t||  }t |t|d | t|| | S rJ   )r>   r   r}   r  r[   r   )r6   rX   r,  rh   ri   logdenumr-   r-   r.   r   	  s    *ztruncweibull_min_gen._logpdfc                 C   sP   t t|| t t||  }t t|| t t||  }|| S r<   r  r6   rX   r,  rh   ri   r  r  r-   r-   r.   rZ   	  s    $$ztruncweibull_min_gen._cdfc                 C   s\   t t t|| t t||  }t t t|| t t||  }|| S r<   r>   r   r}   r  r6   rX   r,  rh   ri   Zlognumr  r-   r-   r.   r   	  s    **ztruncweibull_min_gen._logcdfc                 C   sP   t t|| t t||  }t t|| t t||  }|| S r<   r  r  r-   r-   r.   r\   	  s    $$ztruncweibull_min_gen._sfc                 C   s\   t t t|| t t||  }t t t|| t t||  }|| S r<   r   r!  r-   r-   r.   r   	  s    **ztruncweibull_min_gen._logsfc              
   C   sB   t td| tt ||  |tt ||    d| S rJ   r  r>   r   r}   r6   r^   r,  rh   ri   r-   r-   r.   r`   	  s    6 ztruncweibull_min_gen._isfc              
   C   sB   t td| tt ||  |tt ||    d| S rJ   r"  r#  r-   r-   r.   r_   	  s    6 ztruncweibull_min_gen._ppfc                 C   sr   t || d t || d t||t || d t||  }tt|| tt||  }|| S r   )r[   r  r  r  r>   r}   )r6   rN   r,  rh   ri   Z	gamma_funr  r-   r-   r.   r   	  s
    2$ztruncweibull_min_gen._munp)ra   rb   rc   rd   rO   rU   r	  ro   rY   r   rZ   r   r\   r   r`   r_   r   r  r-   r-   r
  r.   r  C	  s   ,r  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 r+  rR   rT   r-   r-   r.   rU   	  s    zweibull_max_gen._shape_infoc                 C   s(   |t | |d  tt | |  S rJ   r  r.  r-   r-   r.   rY   	  s    zweibull_max_gen._pdfc                 C   s(   t |t|d |  t| | S rJ   r  r.  r-   r-   r.   r   	  s    zweibull_max_gen._logpdfc                 C   s   t t| | S r<   r  r.  r-   r-   r.   rZ   	  s    zweibull_max_gen._cdfc                 C   s   t | | S r<   r	  r.  r-   r-   r.   r   	  s    zweibull_max_gen._logcdfc                 C   s   t t| |  S r<   r  r.  r-   r-   r.   r\   	  s    zweibull_max_gen._sfc                 C   s   t t| d|  S r   )r  r>   r   r1  r-   r-   r.   r_   	  s    zweibull_max_gen._ppfc                 C   s4   t d|d |  }t|d r(d}nd}|| S )Nrf   rD   re  r   )r[   r  int)r6   rN   r,  valZsgnr-   r-   r.   r   	  s
    zweibull_max_gen._munpc                 C   s   t  | t| t  d S rJ   r
  ri  r-   r-   r.   r   	  s    zweibull_max_gen._entropyN)ra   rb   rc   rd   rU   rY   r   rZ   r   r\   r_   r   r   r-   r-   r-   r.   r%  	  s   $r%  weibull_max)ri   rj   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 )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 :math:`x >= 0`, :math:`c > 0`.

    `genlogistic` 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 r+  rR   rT   r-   r-   r.   rU   
  s    zgenlogistic_gen._shape_infoc                 C   s   t | ||S r<   r#  r.  r-   r-   r.   rY   
  s    zgenlogistic_gen._pdfc                 C   sL   |d  |dk  d }t |}t |||  |d tt |   S Nr   r   )r>   r  r   r[   r  r}   )r6   rX   r,  ZmultZabsxr-   r-   r.   r   
  s    
zgenlogistic_gen._logpdfc                 C   s   dt |  |  }|S rJ   r  )r6   rX   r,  ZCxr-   r-   r.   rZ   !
  s    zgenlogistic_gen._cdfc                 C   s   t t|d| d  }|S rP  r>   r   r  )r6   r^   r,  valsr-   r-   r.   r_   %
  s    zgenlogistic_gen._ppfc                 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  rD   r   r  r  r         .@r  r|   )r   r[   r   r>   r   zetar   r  r6   r,  r   r   r   r   r-   r-   r.   r   )
  s    zgenlogistic_gen._statsN)
ra   rb   rc   rd   rU   rY   r   rZ   r_   r   r-   r-   r-   r.   r)  	  s   r)  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 r<   r>   r   ri  r-   r-   r.   rO   Z
  s    zgenpareto_gen._argcheckc                 C   s   t ddtj tjfdgS Nr,  Fr   rR   rT   r-   r-   r.   rU   ]
  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 NrQ  r-   r  r-   r-   r.   rC  c
  rD  z,genpareto_gen._get_support.<locals>.<lambda>)r>   r   r   rS   r&  rh   )r6   r,  ri   rh   r-   r-   r.   ro   `
  s    
zgenpareto_gen._get_supportc                 C   s   t | ||S r<   r#  r.  r-   r-   r.   rY   h
  s    zgenpareto_gen._pdfc                 C   s$   t ||k|dk@ ||fdd | S )Nr   c                 S   s   t |d ||   | S r   rd  rX   r,  r-   r-   r.   rC  n
  rD  z'genpareto_gen._logpdf.<locals>.<lambda>r   r.  r-   r-   r.   r   l
  s    zgenpareto_gen._logpdfc                 C   s   t | |  S r<   )r[   Zinv_boxcox1pr.  r-   r-   r.   rZ   q
  s    zgenpareto_gen._cdfc                 C   s   t | | S r<   )r[   Z
inv_boxcoxr.  r-   r-   r.   r\   t
  s    zgenpareto_gen._sfc                 C   s$   t ||k|dk@ ||fdd | S )Nr   c                 S   s   t ||   | S r<   r-  r5  r-   r-   r.   rC  y
  rD  z&genpareto_gen._logsf.<locals>.<lambda>r6  r.  r-   r-   r.   r   w
  s    zgenpareto_gen._logsfc                 C   s   t | |  S r<   )r[   boxcox1pr1  r-   r-   r.   r_   |
  s    zgenpareto_gen._ppfc                 C   s   t ||  S r<   )r[   boxcoxr1  r-   r-   r.   r`   
  s    zgenpareto_gen._isfr2  c                 C   s   d|krd }nt |dk |fdd tj}d|kr6d }nt |dk |fdd tj}d|kr^d }nt |d	k |fd
d tj}d|krd }nt |dk |fdd tj}||||fS )Nr  r   c                 S   s   dd|   S rJ   r-   xir-   r-   r.   rC  
  rD  z&genpareto_gen._stats.<locals>.<lambda>r  rm   c                 S   s   dd|  d  dd|    S r   r-   r9  r-   r-   r.   rC  
  rD  r3  gUUUUUU?c                 S   s*   dd|   t dd|    dd|    S )NrD   r   r  r  r9  r-   r-   r.   rC  
  s   
r6  r  c                 S   s@   ddd|    d| d  |  d  dd|    dd|    d S )Nr  r   rD   r   r-   r9  r-   r-   r.   rC  
  s   "

r   r>   rS   r   )r6   r,  r9  r  r  r3  r6  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 )Nre   r   r   re  rf   rQ  )r>   r[  zipr[   combr&  rS   )rN   r,  r'  r6  ZkiZcnkr-   r-   r.   r`  
  s
    z#genpareto_gen._munp.<locals>.__munpr   c                    s
    | S r<   r-   r  Z_genpareto_gen__munprN   r-   r.   rC  
  rD  z%genpareto_gen._munp.<locals>.<lambda>r   )r   r[   r  rh  r-   r>  r.   r   
  s
    zgenpareto_gen._munpc                 C   s   d| S r   r-   ri  r-   r-   r.   r   
  s    zgenpareto_gen._entropyN)r2  )ra   rb   rc   rd   rO   rU   ro   rY   r   rZ   r\   r   r_   r`   r   r   r   r-   r-   r-   r.   r1  6
  s   #
r1  	genparetoc                   @   s8   e Zd Z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, "The Exponential Distribution: Theory, Methods and
    Applications", Asit P. Basu.

    %(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 )Nrh   Fr   r   ri   r,  rR   )r6   r   r   r@  r-   r-   r.   rU   
  s    zgenexpon_gen._shape_infoc              	   C   sH   ||t | |    t| | | |t | |   |   S r<   r[   r0  r>   r}   r6   rX   rh   ri   r,  r-   r-   r.   rY   
  s    (zgenexpon_gen._pdfc                 C   sH   t ||t| |    | | |  |t| |   |  S r<   r>   r   r[   r0  rB  r-   r-   r.   r   
  s    zgenexpon_gen._logpdfc                 C   s0   t | | | |t | |   |   S r<   r  rB  r-   r-   r.   rZ   
  s    zgenexpon_gen._cdfc                 C   s.   t | | | |t| |   |  S r<   r  rB  r-   r-   r.   r\   
  s    zgenexpon_gen._sfN)	ra   rb   rc   rd   rU   rY   r   rZ   r\   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 r<   r2  ri  r-   r-   r.   rO     s    zgenextreme_gen._argcheckc                 C   s   t ddtj tjfdgS r3  rR   rT   r-   r-   r.   rU     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   rf   )r>   r&  maximumr   rS   Zminimum)r6   r,  _b_ar-   r-   r.   ro     s     $zgenextreme_gen._get_supportc                 C   s$   t ||k|dk@ ||fdd | S )Nr   c                 S   s   t | |  | S r<   r-  r5  r-   r-   r.   rC    rD  z+genextreme_gen._loglogcdf.<locals>.<lambda>r6  r.  r-   r-   r.   
_loglogcdf  s     zgenextreme_gen._loglogcdfc                 C   s   t | ||S r<   r#  r.  r-   r-   r.   rY      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 r<   r-   r5  r-   r-   r.   rC  '  rD  z(genextreme_gen._logpdf.<locals>.<lambda>re   r   c                 S   s   |  | | S r<   r-   )pex2Zlpex2Zlex2r-   r-   r.   rC  /  rD  rX  )r   r[   r  rJ  r>   r}   ZputmaskrS   )r6   rX   r,  ZcxZlogex2Zlogpex2rK  logpdfr-   r-   r.   r   &  s    "
zgenextreme_gen._logpdfc                 C   s   t | || S r<   )r>   r}   rJ  r.  r-   r-   r.   r   4  s    zgenextreme_gen._logcdfc                 C   s   t | ||S r<   r>   r}   r   r.  r-   r-   r.   rZ   7  s    zgenextreme_gen._cdfc                 C   s   t | || S r<   )r[   r0  r   r.  r-   r-   r.   r\   :  s    zgenextreme_gen._sfc                 C   s6   t t |  }t||k|dk@ ||fdd |S )Nr   c                 S   s   t | |   | S r<   r  r5  r-   r-   r.   rC  @  rD  z%genextreme_gen._ppf.<locals>.<lambda>)r>   r   r   r6   r^   r,  rX   r-   r-   r.   r_   =  s
     zgenextreme_gen._ppfc                 C   s8   t t|   }t||k|dk@ ||fdd |S )Nr   c                 S   s   t | |   | S r<   r  r5  r-   r-   r.   rC  E  rD  z%genextreme_gen._isf.<locals>.<lambda>)r>   r   r[   r  r   rN  r-   r-   r.   r`   B  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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 rJ   r  rN   r  r-   r.   rC  H  rD  z'genextreme_gen._stats.<locals>.<lambda>r   rD   r  r   gHz>r|   r  rf   +=rQ  r  gUUUUUUտc                    s(   t | | |d   |    d  S NrD   r  r=   )r,  r   r   g3Zg2gm12)g2mg12r-   r.   rC  Y  s    rX  g(\?r4  r  g      пc                 S   s(   |d| d||  |   |   |d  S )Nr  rD   r-   )r   r   rR  g4rS  r-   r-   r.   rC  a  s    gq=
ףp?333333@r$  )r>   r&  r  r   r[   r0  r  r   r   r   r   r   )r6   r,  gr   r   rR  rU  Zgam2kZepsZgamkr  r  Zsk1r  Zku1r  r-   )r,  rS  r.   r   G  s4    ,0,
2zgenextreme_gen._statsc                    s,   t |}|dk rd}nd}t j||fdS )Nr   rm   r  r  r   r3   r	  )r6   r   rW  rh   r
  r-   r.   r	  g  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   rf   re  Zaxis)r>   r[  r  r[   r=  r  r&  rS   )r6   rN   r,  r6  r,  r-   r-   r.   r   p  s    $zgenextreme_gen._munpc                 C   s   t d|  d S rJ   r   ri  r-   r-   r.   r   w  s    zgenextreme_gen._entropy)ra   rb   rc   rd   rO   rU   ro   rJ  rY   r   r   rZ   r\   r_   r`   r   r	  r   r   r  r-   r-   r
  r.   rE  
  s    & 	rE  
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 r<   )r[   digammar   yr-   r.   rC    rD  z_digammainv.<locals>.<lambda>g      rm   
   g|=)Ztolg-@g뭁,?rf   dy=T)xtolr  r   z"_digammainv: fsolve failed, y = %rr   )r>   r}   r   Znewtonr  RuntimeError)r^  Z_emr   x0valuer  r  r   r-   r]  r.   _digammainv~  s     
rf  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   rR   rT   r-   r-   r.   rU     s    zgamma_gen._shape_infoNc                 C   s   | ||S r<   standard_gamma)r6   rh   r   r   r-   r-   r.   r     s    zgamma_gen._rvsc                 C   s   t | ||S r<   r#  r   r-   r-   r.   rY     s    zgamma_gen._pdfc                 C   s   t |d || t | S r   )r[   r   r  r   r-   r-   r.   r     s    zgamma_gen._logpdfc                 C   s   t ||S r<   r  r   r-   r-   r.   rZ     s    zgamma_gen._cdfc                 C   s   t ||S r<   r  r   r-   r-   r.   r\     s    zgamma_gen._sfc                 C   s   t ||S r<   r  r   r-   r-   r.   r_     s    zgamma_gen._ppfc                 C   s   t ||S r<   r[   r  r   r-   r-   r.   r`     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    t |d|  | t | S rJ   r[   r   r  r   r-   r-   r.   r     s    zgamma_gen._entropyc                    s&   ddt |d   }t j||fdS )Nr   :0yE>rD   r  rX  r6   r   rh   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}|d ks,| dkr@t j|f||S |dd  t|dddg}|dd }t| |d k	r|d k	rtd	t	|}t
| std
t||krtd|tjd|dkr|| }| }|d krp|d k	r|}	npt|t|    fdd}
d  t d d d    d   }|d }|d }tj|
||dd}	||	 }n$t| t| }t|}	|}|	||fS )Nr   r(   r0   r  r  r  r  r   r   r   r  r  r   c                    s   t | t|    S r<   )r>   r   r[   r\  rh   r3  r-   r.   rC  <  rD  zgamma_gen.fit.<locals>.<lambda>r  rD   r7  r4  g333333?gffffff?)Zdisp)r1   r2   r3   r5   r*   r   r/   r   r>   r   r   r   r  r   rS   r   r   r   r   brentqrf  )r6   r   r7   r,   r   r(   r  r   r  rh   r   ZaestZxar  r&   r,  r
  ro  r.   r5     s@    

*
zgamma_gen.fit)NN)ra   rb   rc   rd   rU   r   rY   r   rZ   r\   r_   r`   r   r   r	  r   r   r5   r  r-   r-   r
  r.   rg    s   '
	
rg  r  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   s2   t t ||k}|s*td|f t |dkS )NzUThe shape parameter of the erlang distribution has been given a non-integer value %r.r   )r>   r   floorr   warnRuntimeWarning)r6   rh   Zallintr-   r-   r.   rO   g  s    zerlang_gen._argcheckc                 C   s   t dddtjfdgS )Nrh   Tr   rQ   rR   rT   r-   r-   r.   rU   r  s    zerlang_gen._shape_infoc                    s.   t ddt|d   }tt| j||fdS )Nr%  rl  rD   r  )r&  r   r3   rg  r	  rm  r
  r-   r.   r	  u  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|f||S r<   )r3   r5   r6   r   r7   r,   r
  r-   r.   r5   ~  s    zerlang_gen.fit)ra   rb   rc   rd   rO   rU   r	  r   r   r5   r  r-   r-   r
  r.   rq  S  s   	
rq  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 r  r-   )r6   rh   r,  r-   r-   r.   rO     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  rR   r  r-   r-   r.   rU     s    zgengamma_gen._shape_infoc                 C   s   t | |||S r<   r#  r  r-   r-   r.   rY     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 rJ   )r>   r   r  r[   r   r  r5  rn  r-   r.   rC    s    z&gengamma_gen._logpdf.<locals>.<lambda>rX  r   r>   rS   r  r-   rn  r.   r     s    
zgengamma_gen._logpdfc                 C   s2   || }t ||}t ||}t|dk||S r  r[   r  r  r>   r&  r6   rX   rh   r,  Zxcval1val2r-   r-   r.   rZ     s    zgengamma_gen._cdfNc                 C   s   |j ||d}|d|  S )Nr  rf   rh  )r6   rh   r,  r   r   rr-   r-   r.   r     s    zgengamma_gen._rvsc                 C   s2   || }t ||}t ||}t|dk||S r  ry  rz  r-   r-   r.   r\     s    zgengamma_gen._sfc                 C   s2   t ||}t ||}t|dk||d|  S rF  r[   r  r  r>   r&  r6   r^   rh   r,  r{  r|  r-   r-   r.   r_     s    zgengamma_gen._ppfc                 C   s2   t ||}t ||}t|dk||d|  S rF  r~  r  r-   r-   r.   r`     s    zgengamma_gen._isfc                 C   s   t ||d | S r   )r[   Zpoch)r6   rN   rh   r,  r-   r-   r.   r     s    zgengamma_gen._munpc                 C   s:   t |}|d|  d| |  t | tt| S r  )r[   r   r  r>   r   r  )r6   rh   r,  r'  r-   r-   r.   r     s    
zgengamma_gen._entropy)NN)ra   rb   rc   rd   rO   rU   rY   r   rZ   r   r\   r_   r`   r   r   r-   r-   r-   r.   rw    s   
rw  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 r+  rR   rT   r-   r-   r.   rU     s    zgenhalflogistic_gen._shape_infoc                 C   s   | j d| fS r   rn  ri  r-   r-   r.   ro     s    z genhalflogistic_gen._get_supportc                 C   sB   d| }t d||  }||d  }|| }d| d| d  S r  r>   r   )r6   rX   r,  limitr  Ztmp0tmp2r-   r-   r.   rY     s
    zgenhalflogistic_gen._pdfc                 C   s2   d| }t d||  }|| }d| d|  S rE  r  )r6   rX   r,  r  r  r  r-   r-   r.   rZ     s    zgenhalflogistic_gen._cdfc                 C   s    d| dd| d|  |   S rE  r-   r1  r-   r-   r.   r_     s    zgenhalflogistic_gen._ppfc                 C   s   dd| d t d  S NrD   r   r   ri  r-   r-   r.   r     s    zgenhalflogistic_gen._entropyN)
ra   rb   rc   rd   rU   ro   rY   rZ   r_   r   r-   r-   r-   r.   r    s   	r  genhalflogisticc                       sZ   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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-0.5}
            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.kn`)

    `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 r  )r>   logical_andr  )r6   r  rh   ri   r-   r-   r.   rO   r  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 )Nr  Fr   rh   r   rQ   ri   rR   )r6   ipr   r   r-   r-   r.   rU   v  s    zgenhyperbolic_gen._shape_infoc                    s   t  j|ddS )N)r   r   rm   r  r  r  r
  r-   r.   r	  |  s    zgenhyperbolic_gen._fitstartc                 C   s   t jdd }|||||S )Nc                 S   s   t | |||S r<   )r   Zgenhyperbolic_logpdfrX   r  rh   ri   r-   r-   r.   _logpdf_single  s    z1genhyperbolic_gen._logpdf.<locals>._logpdf_singler>   	vectorize)r6   rX   r  rh   ri   r  r-   r-   r.   r     s    
zgenhyperbolic_gen._logpdfc                 C   s   t jdd }|||||S )Nc                 S   s   t | |||S r<   )r   Zgenhyperbolic_pdfr  r-   r-   r.   _pdf_single  s    z+genhyperbolic_gen._pdf.<locals>._pdf_singler  )r6   rX   r  rh   ri   r  r-   r-   r.   rY     s    
zgenhyperbolic_gen._pdfc                 C   s   t jdd }|||||S )Nc                 S   s^   t |||gtjtj}ttd|}t	
|t j | d }t |rZd}t|t |S )NZ_genhyperbolic_pdfr   zdInfinite values encountered in scipy.special.kve. Values replaced by NaN to avoid incorrect results.)r>   arrayr  ctypesdata_asc_void_pr
   from_cythonr   r   quadrS   isnanr   rs  rt  )rX   r  rh   ri   	user_datallct1rG   r-   r-   r.   _cdf_single  s        
z+genhyperbolic_gen._cdf.<locals>._cdf_singler  )r6   rX   r  rh   ri   r  r-   r-   r.   rZ     s    
zgenhyperbolic_gen._cdfNc                 C   sh   t |dt |d }t |d}t |d}tj|||||d}	tj||d}
||	 t |	|
  S )NrD   rm   r  )r  ri   r&   r   r   r  )r>   float_powergeninvgaussr   r   r   )r6   r  rh   ri   r   r   r  t2t3Z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 )NrD   rm   r   re  r   r   rS  )r   c                    s   g | ]}|  qS r-   r-   ).0ri   b0r-   r.   
<listcomp>  s     z,genhyperbolic_gen._stats.<locals>.<listcomp>r  r   r   r  r`  r4  )	r>   broadcast_arraysr  Zlinspacer\  shaperI  r[   kv)r6   r  rh   ri   r  r  ZintegersZb1b2Zb3Zb4Zr1Zr2Zr3Zr4r  r  Zm3er3  Zm4er6  r-   r  r.   r     sT    "
zgenhyperbolic_gen._stats)NN)ra   rb   rc   rd   rO   rU   r	  r   rY   rZ   r   r   r  r-   r-   r
  r.   r    s   Y		
r  genhyperbolicc                   @   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 )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 r+  rR   rT   r-   r-   r.   rU      s    zgompertz_gen._shape_infoc                 C   s   t | ||S r<   r#  r.  r-   r-   r.   rY     s    zgompertz_gen._pdfc                 C   s   t || |t|  S r<   rC  r.  r-   r-   r.   r     s    zgompertz_gen._logpdfc                 C   s   t | t |  S r<   r  r.  r-   r-   r.   rZ   
  s    zgompertz_gen._cdfc                 C   s   t d| t |  S r4  r-  r1  r-   r-   r.   r_     s    zgompertz_gen._ppfc                 C   s$   dt | t |td|  S rE  )r>   r   r}   r[   Zexpnri  r-   r-   r.   r     s    zgompertz_gen._entropyN)
ra   rb   rc   rd   rU   rY   r   rZ   r_   r   r-   r-   r-   r.   r    s   r  gompertzc                 C   s8   t | } t |}| }t || }t j| |dS )N)weights)r>   r   maxr}   Zaverage)rX   
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 r<   r-   rT   r-   r-   r.   rU   9  s    zgumbel_r_gen._shape_infoc                 C   s   t | |S r<   r#  rx   r-   r-   r.   rY   <  s    zgumbel_r_gen._pdfc                 C   s   | t |  S r<   r  rx   r-   r-   r.   r   @  s    zgumbel_r_gen._logpdfc                 C   s   t t |  S r<   r  rx   r-   r-   r.   rZ   C  s    zgumbel_r_gen._cdfc                 C   s   t |  S r<   r  rx   r-   r-   r.   r   F  s    zgumbel_r_gen._logcdfc                 C   s   t t |  S r<   r   ry   r-   r-   r.   r_   I  s    zgumbel_r_gen._ppfc                 C   s   t t|   S r<   rA  rx   r-   r-   r.   r\   L  s    zgumbel_r_gen._sfc                 C   s   t t |   S r<   r>   r   r  r  r-   r-   r.   r`   O  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  r4  r  r  rV  r   r>   r   r   r   rT   r-   r-   r.   r   R  s    zgumbel_r_gen._statsc                 C   s   t d S r   rZ  rT   r-   r-   r.   r   U  s    zgumbel_r_gen._entropyc                    s   t |  ||\ }} fdd}|d k	r6|}||n|d k	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 k	r|n|||fS )Nc                    s$   |  t   |  tt   S r<   )r[   	logsumexpr>   r   r  )r&   r   r-   r.   get_loc_from_scalef  s    z,gumbel_r_gen.fit.<locals>.get_loc_from_scalec                    s:     t   |     }t |   }| | S r<   )r>   r}   r  r  )r&   Zterm1Zterm2r   r%   r-   r.   r   y  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   rD   c                    s   t  | t  |kS r<   r=   r@   )r   r-   r.   rC     s    z0gumbel_r_gen.fit.<locals>.interval_contains_rootr   rP  )r  Zrtolrb  )r  r1   r>   rS   r   r#   r  )r6   r   r7   r,   r   r   r  r&   brack_startrA   rB   rC   resr-   )r   r   r%   r.   r5   Y  s:     




 zgumbel_r_gen.fitN)ra   rb   rc   rd   rU   rY   r   rZ   r   r_   r\   r`   r   r   r;   r	   r   r5   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 r<   r-   rT   r-   r-   r.   rU     s    zgumbel_l_gen._shape_infoc                 C   s   t | |S r<   r#  rx   r-   r-   r.   rY     s    zgumbel_l_gen._pdfc                 C   s   |t | S r<   r  rx   r-   r-   r.   r     s    zgumbel_l_gen._logpdfc                 C   s   t t|  S r<   rA  rx   r-   r-   r.   rZ     s    zgumbel_l_gen._cdfc                 C   s   t t|  S r<   r>   r   r[   r  ry   r-   r-   r.   r_     s    zgumbel_l_gen._ppfc                 C   s   t | S r<   r  rx   r-   r-   r.   r     s    zgumbel_l_gen._logsfc                 C   s   t t | S r<   r  rx   r-   r-   r.   r\     s    zgumbel_l_gen._sfc                 C   s   t t | S r<   r   rx   r-   r-   r.   r`     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  rV  r  rT   r-   r-   r.   r     s     zgumbel_l_gen._statsc                 C   s   t d S r   rZ  rT   r-   r-   r.   r     s    zgumbel_l_gen._entropyc                 O   sD   | dd k	r|d  |d< tjt| f||\}}| |fS )Nr   )r1   r  r5   r>   r   )r6   r   r7   r,   Zloc_rZscale_rr-   r-   r.   r5     s    zgumbel_l_gen.fitN)ra   rb   rc   rd   rU   rY   r   rZ   r_   r   r\   r`   r   r   r;   r	   r   r5   r-   r-   r-   r.   r    s   r  gumbel_lc                   @   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 )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 r<   r-   rT   r-   r-   r.   rU     s    zhalfcauchy_gen._shape_infoc                 C   s   dt j d||   S r  r   rx   r-   r-   r.   rY     s    zhalfcauchy_gen._pdfc                 C   s   t dt j t||  S r   r>   r   r   r[   r  rx   r-   r-   r.   r     s    zhalfcauchy_gen._logpdfc                 C   s   dt j t | S r   rl  rx   r-   r-   r.   rZ     s    zhalfcauchy_gen._cdfc                 C   s   t t jd | S r   rn  ry   r-   r-   r.   r_     s    zhalfcauchy_gen._ppfc                 C   s   t jt jt jt jfS r<   r   rT   r-   r-   r.   r     s    zhalfcauchy_gen._statsc                 C   s   t dt j S r   r   rT   r-   r-   r.   r     s    zhalfcauchy_gen._entropyN)ra   rb   rc   rd   rU   rY   r   rZ   r_   r   r   r-   r-   r-   r.   r    s   r  
halfcauchyc                   @   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 )halflogistic_genaG  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

    %(example)s

    c                 C   s   g S r<   r-   rT   r-   r-   r.   rU   3  s    zhalflogistic_gen._shape_infoc                 C   s   t | |S r<   r#  rx   r-   r-   r.   rY   6  s    zhalflogistic_gen._pdfc                 C   s$   t d| dtt |   S r{   )r>   r   r[   r  r}   rx   r-   r-   r.   r   ;  s    zhalflogistic_gen._logpdfc                 C   s   t |d S r   )r>   tanhrx   r-   r-   r.   rZ   >  s    zhalflogistic_gen._cdfc                 C   s   dt | S r   )r>   Zarctanhry   r-   r-   r.   r_   A  s    zhalflogistic_gen._ppfc                 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   rD   r$  r  r5  r      r-  r|   )r>   r   r   r   r  r[   r  r.  rM   r-   r-   r.   r   D  s    zhalflogistic_gen._munpc                 C   s   dt d S r   r   rT   r-   r-   r.   r   O  s    zhalflogistic_gen._entropyN)ra   rb   rc   rd   rU   rY   r   rZ   r_   r   r   r-   r-   r-   r.   r    s   r  halflogisticc                   @   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 )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 r<   r-   rT   r-   r-   r.   rU   l  s    zhalfnorm_gen._shape_infoNc                 C   s   t |j|dS Nr  r   r   r-   r-   r.   r   o  s    zhalfnorm_gen._rvsc                 C   s$   t dt j t | | d  S r   r>   r   r   r}   rx   r-   r-   r.   rY   r  s    zhalfnorm_gen._pdfc                 C   s    dt dt j  || d  S Nrm   r|   r   rx   r-   r-   r.   r   v  s    zhalfnorm_gen._logpdfc                 C   s   t |d d S NrD   rf   r   rx   r-   r-   r.   rZ   y  s    zhalfnorm_gen._cdfc                 C   s   t d| d S r:  r   ry   r-   r-   r.   r_   |  s    zhalfnorm_gen._ppfc                 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   rD   r   r  r   r  r>   r   r   rT   r-   r-   r.   r     s
     zhalfnorm_gen._statsc                 C   s   dt t jd  d S r  r   rT   r-   r-   r.   r     s    zhalfnorm_gen._entropy)NNra   rb   rc   rd   rU   r   rY   r   rZ   r_   r   r   r-   r-   r-   r.   r  V  s   
r  halfnormc                   @   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 )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 r<   r-   rT   r-   r-   r.   rU     s    zhypsecant_gen._shape_infoc                 C   s   dt jt |  S r   )r>   r   coshrx   r-   r-   r.   rY     s    zhypsecant_gen._pdfc                 C   s   dt j t t | S r   )r>   r   rm  r}   rx   r-   r-   r.   rZ     s    zhypsecant_gen._cdfc                 C   s   t t t j| d S r   )r>   r   ro  r   ry   r-   r-   r.   r_     s    zhypsecant_gen._ppfc                 C   s   dt jt j d ddfS )Nr   r   rD   r   rT   r-   r-   r.   r     s    zhypsecant_gen._statsc                 C   s   t dt j S r   r   rT   r-   r-   r.   r     s    zhypsecant_gen._entropyNr   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   re  r-   )r6   rh   ri   r,  r  r-   r-   r.   rO     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 )	Nrh   Fr   r   ri   r,  r  re  rR   )r6   r   r   r@  Zizr-   r-   r.   rU     s
    zgausshyper_gen._shape_infoc                 C   sl   t |t | t ||  t |||| |  }d| ||d   d| |d   d||  |  S r   )r[   r  hyp2f1)r6   rX   rh   ri   r,  r  ZCinvr-   r-   r.   rY     s    8zgausshyper_gen._pdfc           	      C   s\   t || |t || }t ||| || | | }t |||| | }|| | S r<   )r[   r   r  )	r6   rN   rh   ri   r,  r  r  r  r  r-   r-   r.   r     s    zgausshyper_gen._munpN)ra   rb   rc   rd   rO   rU   rY   r   r-   r-   r-   r.   r    s
    r  
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 r+  rR   rT   r-   r-   r.   rU     s    zinvgamma_gen._shape_infoc                 C   s   t | ||S r<   r#  r   r-   r-   r.   rY     s    zinvgamma_gen._pdfc                 C   s&   |d  t | t| d|  S r  r>   r   r[   r  r   r-   r-   r.   r     s    zinvgamma_gen._logpdfc                 C   s   t |d| S r   r  r   r-   r-   r.   rZ     s    zinvgamma_gen._cdfc                 C   s   dt || S r   rj  r   r-   r-   r.   r_      s    zinvgamma_gen._ppfc                 C   s   t |d| S r   r  r   r-   r-   r.   r\   #  s    zinvgamma_gen._sfc                 C   s   dt || S r   r  r   r-   r-   r.   r`   &  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|kr^t |dk|fd	d tj}d
|krt |dk|fdd tj}||||fS )Nr   c                 S   s   d| d  S r   r-   r   r-   r-   r.   rC  *  rD  z%invgamma_gen._stats.<locals>.<lambda>rD   c                 S   s   d| d d  | d  S )Nrf   rD   r|   r-   r   r-   r-   r.   rC  +  rD  )NNr3  r  c                 S   s   dt | d  | d  S )Nr%  r|   r$  r  r   r-   r-   r.   rC  2  rD  r6  r   c                 S   s    dd|  d  | d  | d  S )Nr  r  g      &@r$  r%  r-   r   r-   r-   r.   rC  6  rD  r;  )r6   rh   r9  m1m2r   r   r-   r-   r.   r   )  s(        zinvgamma_gen._statsc                 C   s    ||d t |  t | S r   rk  r   r-   r-   r.   r   9  s    zinvgamma_gen._entropyN)r  )ra   rb   rc   rd   r   r   r   rU   rY   r   rZ   r_   r\   r`   r   r   r-   r-   r-   r.   r    s   
r  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  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(-\frac{(x-\mu)^2}{2 x \mu^2})

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

    `invgauss` 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 Nr   Fr   r   rR   rT   r-   r-   r.   rU   Y  s    zinvgauss_gen._shape_infoNc                 C   s   |j |d|dS Nrf   r  waldr6   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 )Nrf   rD   r$  rQ  r  r6   rX   r   r-   r-   r.   rY   _  s    zinvgauss_gen._pdfc                 C   s:   dt dt j  dt |  || | d d|   S )Nr  rD   r  r   r  r-   r-   r.   r   d  s    zinvgauss_gen._logpdfc                 C   sX   dt | }t||| d  }d| t| || d   }|t t ||  S r   )r>   r   r   r  r}   r6   rX   r   r  rh   ri   r-   r-   r.   r   k  s    zinvgauss_gen._logcdfc                 C   sZ   dt | }t||| d  }d| t| ||  |  }|t t ||   S r   )r>   r   r   r   r  r}   r  r-   r-   r.   r   q  s    zinvgauss_gen._logsfc                 C   s   t | ||S r<   rN  r  r-   r-   r.   r\   w  s    zinvgauss_gen._sfc                 C   s   t | ||S r<   rM  r  r-   r-   r.   rZ   z  s    zinvgauss_gen._cdfc              	      s   t jddddn t ||\}}t||d}|dk}td||  || d||< t |}t || || ||< W 5 Q R X |S Nr   )r   overinvalidr   rm   )	r>   r   r  r   _invgauss_ppf_invgauss_isfr  r3   r_   )r6   rX   r   ppfi_wti_nanr
  r-   r.   r_   }  s    
$zinvgauss_gen._ppfc              	      s   t jddddn t ||\}}t||d}|dk}td||  || d||< t |}t || || ||< W 5 Q R X |S r  )	r>   r   r  r   r  r  r  r3   r`   )r6   rX   r   isfr  r  r
  r-   r.   r`     s    
$zinvgauss_gen._isfc                 C   s   ||d dt | d| fS )Nr$  r     r  )r6   r   r-   r-   r.   r     s    zinvgauss_gen._statsc           	         s   | dd}t| tks$| dkr8t j|f||S t| |||\}}}}|d ks^|d k	rrt j|f||S t|| dk rt	ddtj
dn@|| }t|}|d krt|t|d |d   }|| }|||fS )Nr(   r0   r  r   invgaussr  re  )r1   r4   wald_genr2   r3   r5   r  r>   r  r   rS   r   r  r  )	r6   r   r7   r,   r(   Zfshape_sr   r   Zfshape_nr
  r-   r.   r5     s"     
zinvgauss_gen.fit)NN)ra   rb   rc   rd   r   r   r   rU   r   rY   r   r   r   r\   rZ   r_   r`   r   r	   r5   r  r-   r-   r
  r.   r  @  s   


r  r  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_genaW  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 r  r-   r6   r  ri   r-   r-   r.   rO     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 )Nr  Fr   ri   r   rR   )r6   r  r   r-   r-   r.   rU     s    zgeninvgauss_gen._shape_infoc                 C   s<   t jdd }||||}t | r8d}t|t |S )Nc                 S   s   t | ||S r<   )r   Zgeninvgauss_logpdfrX   r  ri   r-   r-   r.   logpdf_single  s    z.geninvgauss_gen._logpdf.<locals>.logpdf_singlezjInfinite values encountered in scipy.special.kve(p, b). Values replaced by NaN to avoid incorrect results.)r>   r  r  r  r   rs  rt  )r6   rX   r  ri   r  r  rG   r-   r-   r.   r     s    
zgeninvgauss_gen._logpdfc                 C   s   t | |||S r<   r#  r6   rX   r  ri   r-   r-   r.   rY     s    zgeninvgauss_gen._pdfc                    s.   | j | \ }tj fdd}||f| S )Nc                    sB   |\}}t ||gtjtj}ttd|}t	
| | d S )NZ_geninvgauss_pdfr   )r>   r  r  r  r  r  r
   r  r   r   r  )rX   r7   r  ri   r  r  rI  r-   r.   r    s    z)geninvgauss_gen._cdf.<locals>._cdf_single)ro   r>   r  )r6   rX   r7   rH  r  r-   r  r.   rZ     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.   rC  
  rD  z.geninvgauss_gen._logquasipdf.<locals>.<lambda>rx  r  r-   r-   r.   _logquasipdf  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 r<   r  slicer  jZbcitr-   r.   	<genexpr>:  s   z'geninvgauss_gen._rvs.<locals>.<genexpr>r   r-   )r>   isscalar_rvs_scalarr   r]  r  r   r  r&  prodemptynditerfinishedtupleranger  r\  iternext)	r6   r  ri   r   r   outshp
numsamplesidxr-   r  r.   r     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}|rT|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rD||
 dkrDd||
 }$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   Trm   rD   r  r      irT  c                    s    |   S r<   r  r   ri   Zlmr  r6   r-   r.   rC  }  rD  z-geninvgauss_gen._rvs_scalar.<locals>.<lambda>c                    s    |  S r<   r
  r   )ri   r  r6   r-   r.   rC    rD  zvmin must be smaller than vmax.zumax must be positive.r  iP  z|Not a single random variate could be generated in {} attempts. Sampling does not appear to work for the provided parameters.)r   r   )_moder  r>   r   r  
atleast_1dr  zerosZarccosr   r   r  r}   r   r  r   r  r   rc  r  Zlogical_notr\  )3r6   r  ri   r  r   Z
invert_resr  Z
ratio_unifZ
mode_shiftsize1dNrX   	simulatedZa2Za1p1Zq1phir   Zroot1root2d1Zd2ZvminZvmaxZumaxZlogqpdfr,  Zxplusir6  r  r  r   accept
num_acceptrG   rd  xsZk1A1Zk2A2Zk3ZA3AhZcond1Zcond2Zcond3r  r-   r  r.   r  D  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 }| rxd}t|t 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.dtype)r[   Zkver>   rE   r  r   rs  rt  	full_liker   double)	r6   rN   r  ri   r  ZdenomZinf_valsrG   r  r-   r-   r.   r     s    zgeninvgauss_gen._munp)NN)ra   rb   rc   rd   rO   rU   r   rY   rZ   r  r   r  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 r  )r>   absoluter   r-   r-   r.   rO   +  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   rR   r   r-   r-   r.   rU   .  s    znorminvgauss_gen._shape_infoc                    s   t  j|ddS )N)r   rm   r  r  r  r
  r-   r.   r	  3  s    znorminvgauss_gen._fitstartc                 C   sb   t |d |d  }|t j t | }t d|}|t||  t || ||   | S r  )r>   r   r   r}   hypotr[   Zk1e)r6   rX   rh   ri   r  fac1sqr-   r-   r.   rY   7  s    znorminvgauss_gen._pdfc              	   C   sv   t |r(tj| j|t j||fdd S g }t|||D ].\}}}|tj| j|t j||fdd  q8t |S d S )Nr  r   )	r>   r  r   r  rY   rS   r<  appendr  )r6   rX   rh   ri   resultrd  a0r  r-   r-   r.   r\   =  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 r<   r\   )rX   rh   ri   r^   rT   r-   r.   eqK  s    z6norminvgauss_gen._isf.<locals>._isf_scalar.<locals>.eqr   r   rD   )r7   rb  )r   r   rp  rb  )
r^   rh   ri   r+  xmemdeltaleftrightr(  rT   r-   r.   _isf_scalarI  s,    
z*norminvgauss_gen._isf.<locals>._isf_scalar)r>   r  r<  r'  r  )	r6   r^   rh   ri   r1  r(  Zq0r)  r  r-   rT   r.   r`   H  s    !
znorminvgauss_gen._isfNc                 C   sJ   t |d |d  }tjd| ||d}|| t |tj||d  S )NrD   r   )r   r   r   r  )r>   r   r  r   r   )r6   rh   ri   r   r   r  Zigr-   r-   r.   r   r  s
    znorminvgauss_gen._rvsc                 C   sp   t |d |d  }|| }|d |d  }d| |t |  }ddd|d  |d    | }||||fS )NrD   r  r$  r   r   r  )r6   rh   ri   r  r   ZvarianceskewnessZkurtosisr-   r-   r.   r   z  s     znorminvgauss_gen._stats)NN)ra   rb   rc   rd   r   r   r   rO   rU   r	  rY   r\   r`   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 r+  rR   rT   r-   r-   r.   rU     s    zinvweibull_gen._shape_infoc                 C   s8   t || d }t || }t | }|| | S r   r>   r  r}   )r6   rX   r,  xc1Zxc2r-   r-   r.   rY     s    zinvweibull_gen._pdfc                 C   s   t || }t | S r<   r5  )r6   rX   r,  r6  r-   r-   r.   rZ     s    zinvweibull_gen._cdfc                 C   s   t ||    S r<   )r>   r0  r.  r-   r-   r.   r\     s    zinvweibull_gen._sfc                 C   s   t t | d| S r4  )r>   r  r   r1  r-   r-   r.   r_     s    zinvweibull_gen._ppfc                 C   s   t |  d|  S )Nre  rO  )r6   r  r,  r-   r-   r.   r`     s    zinvweibull_gen._isfc                 C   s   t d||  S rJ   r  rh  r-   r-   r.   r     s    zinvweibull_gen._munpc                 C   s   dt  t |  t| S rJ   r
  ri  r-   r-   r.   r     s    zinvweibull_gen._entropyNc                    s$   |d krdn|}t t| j||dS )N)r|   r  )r3   r4  r	  )r6   r   r7   r
  r-   r.   r	    s    zinvweibull_gen._fitstart)N)ra   rb   rc   rd   r   r   r   rU   rY   rZ   r\   r_   r`   r   r   r	  r  r-   r-   r
  r.   r4    s   r4  
invweibullc                   @   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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 r  r-   r   r-   r-   r.   rO     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 Nrh   Fr   ri   r   rR   r   r-   r-   r.   rU     s    zjohnsonsb_gen._shape_infoc                 C   s6   t ||t|d|    }|d |d|   | S rE  )r   r>   r   )r6   rX   rh   ri   trmr-   r-   r.   rY     s    zjohnsonsb_gen._pdfc                 C   s   t ||t|d|    S r   r   r>   r   r   r-   r-   r.   rZ     s    zjohnsonsb_gen._cdfc                 C   s"   ddt d| t||    S )Nrf   r   rQ  r>   r}   r   r6   r^   rh   ri   r-   r-   r.   r_     s    zjohnsonsb_gen._ppfN)ra   rb   rc   rd   r   r   r   rO   rU   rY   rZ   r_   r-   r-   r-   r.   r8    s   r8  	johnsonsbc                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Z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.

    %(after_notes)s

    %(example)s

    c                 C   s   |dk||k@ S r  r-   r   r-   r-   r.   rO     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 r9  rR   r   r-   r-   r.   rU      s    zjohnsonsu_gen._shape_infoc              
   C   sF   || }t ||t|t|d    }|d t|d  | S r  )r   r>   r   r   )r6   rX   rh   ri   r  r:  r-   r-   r.   rY   %  s    $zjohnsonsu_gen._pdfc              
   C   s(   t ||t|t|| d    S rJ   )r   r>   r   r   r   r-   r-   r.   rZ   ,  s    zjohnsonsu_gen._cdfc                 C   s   t t|| | S r<   )r>   sinhr   r=  r-   r-   r.   r_   /  s    zjohnsonsu_gen._ppfN)	ra   rb   rc   rd   rO   rU   rY   rZ   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 r<   r-   rT   r-   r-   r.   rU   J  s    zlaplace_gen._shape_infoNc                 C   s   |j dd|dS )Nr   r   r  )laplacer   r-   r-   r.   r   M  s    zlaplace_gen._rvsc                 C   s   dt t|  S Nrm   )r>   r}   r  rx   r-   r-   r.   rY   P  s    zlaplace_gen._pdfc              
   C   sP   t jdd: t |dkddt |   dt | W  5 Q R  S Q R X d S )Nr   )r  r   rf   rm   )r>   r   r&  r}   rx   r-   r-   r.   rZ   T  s    zlaplace_gen._cdfc                 C   s   |  | S r<   rZ   rx   r-   r-   r.   r\   X  s    zlaplace_gen._sfc                 C   s,   t |dkt dd|   t d| S r   r>   r&  r   ry   r-   r-   r.   r_   \  s    zlaplace_gen._ppfc                 C   s   |  | S r<   r_   ry   r-   r-   r.   r`   _  s    zlaplace_gen._isfc                 C   s   dS )N)r   rD   r   r  r-   rT   r-   r-   r.   r   c  s    zlaplace_gen._statsc                 C   s   t dd S r  r   rT   r-   r-   r.   r   f  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 kr&t|}|d krJtt|| t| }||fS r<   )r  r>   medianr  r  r  )r6   r   r7   r,   r   r   r-   r-   r.   r5   i  s     

zlaplace_gen.fit)NN)ra   rb   rc   rd   rU   r   rY   rZ   r\   r_   r`   r   r   r;   r   r   r5   r-   r-   r-   r.   rB  6  s   

rB  rC  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

    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   rR   rT   r-   r-   r.   rU     s    z"laplace_asymmetric_gen._shape_infoc                 C   s   t | ||S r<   r#  r6   rX   rK  r-   r-   r.   rY     s    zlaplace_asymmetric_gen._pdfc                 C   s6   d| }|t |dk| | }|t || 8 }|S r*  rF  )r6   rX   rK  kapinvr   r-   r-   r.   r     s    zlaplace_asymmetric_gen._logpdfc                 C   sL   d| }|| }t |dkdt | | ||   t || ||  S r*  r>   r&  r}   r6   rX   rK  rM  
kappkapinvr-   r-   r.   rZ     s    
zlaplace_asymmetric_gen._cdfc              	   C   sL   d| }|| }t |dkt | | ||  dt || ||   S r*  rN  rO  r-   r-   r.   r\     s    
zlaplace_asymmetric_gen._sfc                 C   sP   d| }|| }t ||| kt d| | |  | t || | | S rJ   rF  r6   r^   rK  rM  rP  r-   r-   r.   r_     s    zlaplace_asymmetric_gen._ppfc                 C   sP   d| }|| }t ||| kt || |  | t d| | | | S rJ   rF  rQ  r-   r-   r.   r`     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   rD   r  )r6   rK  rM  mnr  r   r   r-   r-   r.   r     s    ,,zlaplace_asymmetric_gen._statsc                 C   s   dt |d|   S rJ   r   r6   rK  r-   r-   r.   r     s    zlaplace_asymmetric_gen._entropyNr  r-   r-   r-   r.   rI    s   &rI  laplace_asymmetricc                 C   sH  t |}|dd }|dd }| jr8t| jdnd}g }g }| jr| jdd }	t|	D ]T\}
}dt|
 }|d| d| g}t	||}|
| |
| |d k	rd|||< qddd	d
dddh|}t||}|rtd| dt||krtdd ||h|kr tdt | s8td|f|||fS )Nr   r   ,r    r  Zfix_r%   r&   r'   r(   zUnknown keyword arguments: .zToo many positional arguments.r   r   )r>   r   r1   shapesr  splitr   	enumeratestrr   r'  set
differencer+   rc  r   r   r   )distr   r7   r,   r   r   Z
num_shapesZfshape_keysZfshapesrX  r  r3  keynamesr'  Z
known_keysZunknown_keysr-   r-   r.   r    s@    




 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_genah  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 r<   r-   rT   r-   r-   r.   rU   X  s    zlevy_gen._shape_infoc                 C   s.   dt dt j |  | t dd|   S Nr   rD   re  r  rx   r-   r-   r.   rY   [  s    zlevy_gen._pdfc                 C   s   t td| S rD  )r[   erfcr>   r   rx   r-   r-   r.   rZ   _  s    zlevy_gen._cdfc                 C   s   t td| S rD  )r[   r  r>   r   rx   r-   r-   r.   r\   c  s    zlevy_gen._sfc                 C   s   t |d  }d||  S r  r   r6   r^   r'  r-   r-   r.   r_   f  s    zlevy_gen._ppfc                 C   s   ddt |d   S r   )r[   Zerfinvr  r-   r-   r.   r`   k  s    zlevy_gen._isfc                 C   s   t jt jt jt jfS r<   r   rT   r-   r-   r.   r   n  s    zlevy_gen._statsNra   rb   rc   rd   r   r   r   rU   rY   rZ   r\   r_   r`   r   r-   r-   r-   r.   ra    s   Hra  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 r<   r-   rT   r-   r-   r.   rU     s    zlevy_l_gen._shape_infoc                 C   s6   t |}dtdtj |  | tdd|   S rb  )r  r>   r   r   r}   r6   rX   r  r-   r-   r.   rY     s    zlevy_l_gen._pdfc                 C   s"   t |}dtdt|  d S r  )r  r   r>   r   rh  r-   r-   r.   rZ     s    zlevy_l_gen._cdfc                 C   s   t |}dtdt|  S r  )r  r   r>   r   rh  r-   r-   r.   r\     s    zlevy_l_gen._sfc                 C   s   t |d d }d||  S )Nrf   rD   rQ  r   rd  r-   r-   r.   r_     s    zlevy_l_gen._ppfc                 C   s   dt |d d  S )Nre  rD   r   r  r-   r-   r.   r`     s    zlevy_l_gen._isfc                 C   s   t jt jt jt jfS r<   r   rT   r-   r-   r.   r     s    zlevy_l_gen._statsNre  r-   r-   r-   r.   rg  u  s   Grg  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 r<   r-   rT   r-   r-   r.   rU     s    zlogistic_gen._shape_infoNc                 C   s   |j |dS r  )logisticr   r-   r-   r.   r     s    zlogistic_gen._rvsc                 C   s   t | |S r<   r#  rx   r-   r-   r.   rY     s    zlogistic_gen._pdfc                 C   s$   t | }|dtt |  S r   )r>   r  r[   r  r}   )r6   rX   r^  r-   r-   r.   r     s    zlogistic_gen._logpdfc                 C   s
   t |S r<   r[   expitrx   r-   r-   r.   rZ     s    zlogistic_gen._cdfc                 C   s
   t |S r<   r[   Z	log_expitrx   r-   r-   r.   r     s    zlogistic_gen._logcdfc                 C   s
   t |S r<   r[   Zlogitry   r-   r-   r.   r_   	  s    zlogistic_gen._ppfc                 C   s   t | S r<   rl  rx   r-   r-   r.   r\     s    zlogistic_gen._sfc                 C   s   t | S r<   rn  rx   r-   r-   r.   r     s    zlogistic_gen._logsfc                 C   s   t | S r<   ro  ry   r-   r-   r.   r`     s    zlogistic_gen._isfc                 C   s   dt jt j d ddfS )Nr   r$  g333333?r   rT   r-   r-   r.   r     s    zlogistic_gen._statsc                 C   s   dS r   r-   rT   r-   r-   r.   r     s    zlogistic_gen._entropyc           
         s0  | ddr t j f||S t|  ||\ }}t |  \}}|d||d| }}|f fdd	|f fdd	fd	d
}|d k	r|d krt|f}	|	j	d }|}nH|d k	r|d krt|f}	|	j	d }|}nt|||f}	|	j	\}}|	j
r||fS t j f||S )Nr  Fr%   r&   c                    s$    |  | }t t|d  S r   )r>   r  r[   rm  )r%   r&   r,  r   rN   r-   r.   dl_dloc/  s    z!logistic_gen.fit.<locals>.dl_dlocc                    s(    | |  }t |t |d   S r   )r>   r  r  )r&   r%   r,  rp  r-   r.   	dl_dscale3  s    z#logistic_gen.fit.<locals>.dl_dscalec                    s   | \}} ||||fS r<   r-   )paramsr%   r&   )rq  rr  r-   r.   r   7  s    zlogistic_gen.fit.<locals>.funcr   )r*   r3   r5   r  r  r	  r1   r   r  rX   success)
r6   r   r7   r,   r   r   r%   r&   r   r  r
  )r   rq  rr  rN   r.   r5     s2     



zlogistic_gen.fit)NN)ra   rb   rc   rd   rU   r   rY   r   rZ   r   r_   r\   r   r`   r   r   r;   r	   r   r5   r  r-   r-   r
  r.   rj    s    
rj  rk  c                   @   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 )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 r+  rR   rT   r-   r-   r.   rU   g  s    zloggamma_gen._shape_infoNc                 C   s.   t |j|d |dt |j|d|  S )Nr   r  )r>   r   r  r  r  r-   r-   r.   r   j  s    zloggamma_gen._rvsc                 C   s"   t || t | t| S r<   r>   r}   r[   r  r.  r-   r-   r.   rY   x  s    zloggamma_gen._pdfc                 C   s   || t | t| S r<   rv  r.  r-   r-   r.   r   |  s    zloggamma_gen._logpdfc                 C   s   t |t|S r<   )r[   r  r>   r}   r.  r-   r-   r.   rZ     s    zloggamma_gen._cdfc                 C   s   t t||S r<   )r>   r   r[   r  r1  r-   r-   r.   r_     s    zloggamma_gen._ppfc                 C   s   t |t|S r<   )r[   r  r>   r}   r.  r-   r-   r.   r\     s    zloggamma_gen._sfc                 C   s   t t||S r<   )r>   r   r[   r  r1  r-   r-   r.   r`     s    zloggamma_gen._isfc                 C   sN   t |}t d|}t d|t|d }t d|||  }||||fS )Nr   rD   r  r  )r[   r\  Z	polygammar>   r  )r6   r,  r   r  r2  Zexcess_kurtosisr-   r-   r.   r     s
    
zloggamma_gen._stats)NN)ra   rb   rc   rd   rU   r   rY   r   rZ   r_   r\   r`   r   r-   r-   r-   r.   ru  N  s   
ru  loggammac                   @   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 )loglaplace_gena|  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

    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 r+  rR   rT   r-   r-   r.   rU     s    zloglaplace_gen._shape_infoc                 C   s,   |d }t |dk || }|||d   S Nr|   r   r>   r&  )r6   rX   r,  Zcd2r-   r-   r.   rY     s    zloglaplace_gen._pdfc                 C   s(   t |dk d||  dd||    S Nr   rm   rz  r.  r-   r-   r.   rZ     s    zloglaplace_gen._cdfc                 C   s.   t |dk d| d|  dd|  d|  S )Nrm   r|   rf   rD   rQ  rz  r1  r-   r-   r.   r_     s    zloglaplace_gen._ppfc                 C   s   |d |d |d   S r   r-   rh  r-   r-   r.   r     s    zloglaplace_gen._munpc                 C   s   t d| d S r  r   ri  r-   r-   r.   r     s    zloglaplace_gen._entropyN)
ra   rb   rc   rd   rU   rY   rZ   r_   r   r   r-   r-   r-   r.   rx    s   rx  
loglaplacec                 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   )r>   r   r   r   rX   r3  r-   r-   r.   rC    rD  z!_lognorm_logpdf.<locals>.<lambda>rx  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eeedd fddZ  ZS )lognorm_genab  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

    c                 C   s   t dddtjfdgS )Nr3  Fr   r   rR   rT   r-   r-   r.   rU     s    zlognorm_gen._shape_infoNc                 C   s   t ||| S r<   r>   r}   r   )r6   r3  r   r   r-   r-   r.   r     s    zlognorm_gen._rvsc                 C   s   t | ||S r<   r#  r6   rX   r3  r-   r-   r.   rY     s    zlognorm_gen._pdfc                 C   s
   t ||S r<   r~  r  r-   r-   r.   r     s    zlognorm_gen._logpdfc                 C   s   t t|| S r<   r;  r  r-   r-   r.   rZ     s    zlognorm_gen._cdfc                 C   s   t t|| S r<   r  r  r-   r-   r.   r     s    zlognorm_gen._logcdfc                 C   s   t |t| S r<   r<  )r6   r^   r3  r-   r-   r.   r_     s    zlognorm_gen._ppfc                 C   s   t t|| S r<   )r   r>   r   r  r-   r-   r.   r\     s    zlognorm_gen._sfc                 C   s   t t|| S r<   )r   r>   r   r  r-   r-   r.   r     s    zlognorm_gen._logsfc                 C   s\   t || }t |}||d  }t |d d|  }t dddddg|}||||fS Nr   rD   r  r   r  )r>   r}   r   polyval)r6   r3  r  r   r   r   r   r-   r-   r.   r     s    
zlognorm_gen._statsc                 C   s&   ddt dt j  dt |   S )Nrm   r   rD   r   )r6   r3  r-   r-   r.   r     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.
        

r   c                    sp  | dd }|d kr(t j|f||S | dd pJ| dd pJ| dd }| dd }t|dkrltddD ]}||d  qp|rtd	| |d k	r|d k	rtd
t|}t	|
 stdt|}|dkr|| }t|dkrtd|tjdt|}|d krBt| }	|d kr8| }
nt|}
n$t|}	t|t|	 d  }
|
||	fS )Nr   r  fsfix_sr   r   zToo many input arguments.)	r  r  r  r   r   r%   r&   r'   r(   r)   r   r   r   lognormr  rD   )r1   r3   r5   r  r+   r*   r   r>   r   r   r   r  r  r   rS   r   r}   r   stdr   )r6   r   r7   r,   r   r  r   rj   Zlndatar&   r  r
  r-   r.   r5     s@    	






zlognorm_gen.fit)NN)ra   rb   rc   rd   r   r   r   rU   r   rY   r   rZ   r   r_   r\   r   r   r   r;   r   r5   r  r-   r-   r
  r.   r    s    

r  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 )
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 r<   r-   rT   r-   r-   r.   rU   x  s    zgibrat_gen._shape_infoNc                 C   s   t ||S r<   r  r   r-   r-   r.   r   {  s    zgibrat_gen._rvsc                 C   s   t | |S r<   r#  rx   r-   r-   r.   rY   ~  s    zgibrat_gen._pdfc                 C   s
   t |dS r   r  rx   r-   r-   r.   r     s    zgibrat_gen._logpdfc                 C   s   t t|S r<   r;  rx   r-   r-   r.   rZ     s    zgibrat_gen._cdfc                 C   s   t t|S r<   r<  ry   r-   r-   r.   r_     s    zgibrat_gen._ppfc                 C   sT   t j}t |}||d  }t |d d|  }t dddddg|}||||fS r  )r>   er   r  )r6   r  r   r   r   r   r-   r-   r.   r     s    
zgibrat_gen._statsc                 C   s   dt dt j  d S r  r   rT   r-   r-   r.   r     s    zgibrat_gen._entropy)NN)ra   rb   rc   rd   r   r   r   rU   r   rY   r   rZ   r_   r   r   r-   r-   r-   r.   r  b  s   
r  zp`gilbrat` is a misspelling of the correct name for the `gibrat` distribution, and will be removed in SciPy 1.11.c                   @   s   e Zd ZdZdd ZdS )gilbrat_genz

    .. deprecated:: 1.9.0
        `gilbrat` is deprecated, use `gibrat` instead!
        `gilbrat` is a misspelling of the correct name for the `gibrat`
        distribution, and will be removed in SciPy 1.11.

    c                 O   s$   dt  }tj|tdd | j||S )Nz/`gilbrat` is deprecated, use `gibrat` instead!
rD   
stacklevel)deprmsgr   rs  DeprecationWarningfreeze)r6   r7   r,   rG   r-   r-   r.   __call__  s    zgilbrat_gen.__call__N)ra   rb   rc   rd   r  r-   r-   r-   r.   r    s   r  gibratgilbratrs   Zentropyexpectr5   intervalr  logcdfrL  logsfr   rH  Zmomentpdfr  r   sfr  r  r  zgilbrat.zgibrat.c                   @   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 )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 r<   r-   rT   r-   r-   r.   rU     s    zmaxwell_gen._shape_infoNc                 C   s   t jd||dS )Nr$  r  r  r   r   r-   r-   r.   r     s    zmaxwell_gen._rvsc                 C   s    t | | t| | d  S r   )r!   r>   r}   rx   r-   r-   r.   rY     s    zmaxwell_gen._pdfc              
   C   sB   t jdd, tdt |  d| |  W  5 Q R  S Q R X d S )Nr   r   rD   rm   )r>   r   r"   r   rx   r-   r-   r.   r     s    zmaxwell_gen._logpdfc                 C   s   t d|| d S )Nr  r|   r  rx   r-   r-   r.   rZ     s    zmaxwell_gen._cdfc                 C   s   t dtd| S rQ  r  ry   r-   r-   r.   r_     s    zmaxwell_gen._ppfc                 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   rD   r|       r_  r  r     i  r>   r   r   r6   r'  r-   r-   r.   r     s    $zmaxwell_gen._statsc                 C   s   t dtdtj   d S r  )r   r>   r   r   rT   r-   r-   r.   r     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 )Nr6  Fr   r   r3  rR   )r6   iki_sr-   r-   r.   rU      s    zmielke_gen._shape_infoc                 C   s,   |||d   d||  d|d |    S r   r-   r6   rX   r6  r3  r-   r-   r.   rY   %  s    zmielke_gen._pdfc              
   C   sZ   t jddD t |t ||d   t || d||    W  5 Q R  S Q R X d S )Nr   r   r   )r>   r   r   r  r  r-   r-   r.   r   (  s    zmielke_gen._logpdfc                 C   s    || d||  |d |   S r   r-   r  r-   r-   r.   rZ   -  s    zmielke_gen._cdfc                 C   s(   t ||d | }t |d|  d| S r   r	  )r6   r^   r6  r3  Zqskr-   r-   r.   r_   0  s    zmielke_gen._ppfc                 C   s"   dd }t ||k |||f|tjS )Nc                 S   s2   t ||  | t d| |   t ||  S rJ   r  )rN   r6  r3  r-   r-   r.   
nth_moment5  s    z$mielke_gen._munp.<locals>.nth_momentrx  )r6   rN   r6  r3  r  r-   r-   r.   r   4  s    zmielke_gen._munpN)
ra   rb   rc   rd   rU   rY   r   rZ   r_   r   r-   r-   r-   r.   r    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)r>   r  r  full)r6   r  r6  r  r-   r-   r.   rO     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   r6  rR   )r6   Zihr  r-   r-   r.   rU     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   )r>   r  r  r6  r-   r-   r.   r    s    z#kappa4_gen._get_support.<locals>.f0c                 S   s
   t | S r<   r   r  r-   r-   r.   r    s    z#kappa4_gen._get_support.<locals>.f1c                 S   s$   t t | }t j |d d < |S r<   r>   r  r  rS   r  r6  rh   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 r<   r  r  r-   r-   r.   r    s    r>   r  r   r   )
r6   r  r6  condlistr  r  r  r  rI  rH  r-   r-   r.   ro     s0    zkappa4_gen._get_supportc                 C   s   t | |||S r<   r#  r6   rX   r  r6  r-   r-   r.   rY     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 = ...
            rf   rd  rX   r  r6  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 = ...
            rf   rd  r  r-   r-   r.   r    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 = ...
            rf   )r[   r   r>   r}   r  r-   r-   r.   rG    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    s    zkappa4_gen._logpdf.<locals>.f3r  r  	r6   rX   r  r6  r  r  r  rG  r  r-   r-   r.   r     s    
zkappa4_gen._logpdfc                 C   s   t | |||S r<   rM  r  r-   r-   r.   rZ     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 = ...
            rf   r-  r  r-   r-   r.   r    s    zkappa4_gen._logcdf.<locals>.f0c                 S   s   d||   d|   S )zLcdf = np.exp(-(1.0 - k*x)**(1.0/k))
               logcdf = ...
            rf   r-   r  r-   r-   r.   r    s    zkappa4_gen._logcdf.<locals>.f1c                 S   s    d| t | t|    S )zLcdf = (1.0 - h*np.exp(-x))**(1.0/h)
               logcdf = ...
            rf   )r[   r  r>   r}   r  r-   r-   r.   rG  
  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     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-   r^   r  r6  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.   rG  '  s    zkappa4_gen._ppf.<locals>.f2c                 S   s   t t |   S r<   r   r  r-   r-   r.   r  ,  s    zkappa4_gen._ppf.<locals>.f3r  r  )	r6   r^   r  r6  r  r  r  rG  r  r-   r-   r.   r_     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 r4  Zastyper&  r  r-   r-   r.   r  :  s    z&kappa4_gen._get_stats_info.<locals>.f0c                 S   s   d|  tS r4  r  r  r-   r-   r.   r  =  s    z&kappa4_gen._get_stats_info.<locals>.f1rS  r  )r>   r  r   )r6   r  r6  r  r  r  r-   r-   r.   _get_stats_info4  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 r<   r>   r  r   )r  r}  maxrr-   r.   r  D  s     z%kappa4_gen._stats.<locals>.<listcomp>r   rS  )r  r  )r6   r  r6  outputsr-   r  r.   r   B  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  r>   r   r   r  _mom_integ1)r6   r  r7   r  r-   r-   r.   _mom1_scG  s    zkappa4_gen._mom1_scN)ra   rb   rc   rd   rO   rU   ro   rY   r   rZ   r   r_   r  r   r  r-   r-   r-   r.   r  ?  s   X)&#r  kappa4c                   @   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 )
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   rR   rT   r-   r-   r.   rU   r  s    zkappa3_gen._shape_infoc                 C   s   ||||  d| d   S rP  r-   r   r-   r-   r.   rY   u  s    zkappa3_gen._pdfc                 C   s   ||||  d|   S r4  r-   r   r-   r-   r.   rZ   y  s    zkappa3_gen._cdfc                 C   s   |||  d  d|  S r   r-   r   r-   r-   r.   r_   |  s    zkappa3_gen._ppfc                    s$    fddt ddD }|d d  S )Nc                    s$   g | ]}t | k rd nt jqS r<   r  )r  r  rn  r-   r.   r    s     z%kappa3_gen._stats.<locals>.<listcomp>r   rS  )r  )r6   rh   r  r-   rn  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 r  )r>   r  r   r   r  r  )r6   r  r7   r-   r-   r.   r    s    zkappa3_gen._mom1_scN)
ra   rb   rc   rd   rU   rY   rZ   r_   r   r  r-   r-   r-   r.   r  Q  s    r  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 r<   r-   rT   r-   r-   r.   rU     s    zmoyal_gen._shape_infoNc                 C   s   t jdd||d}t| S )Nrm   rD   )rh   r&   r   r   )r  r   r>   r   )r6   r   r   r!  r-   r-   r.   r     s    
zmoyal_gen._rvsc                 C   s*   t d|t |   t dt j  S Nr  rD   )r>   r}   r   r   rx   r-   r-   r.   rY     s    zmoyal_gen._pdfc                 C   s   t td| td S r  )r[   rc  r>   r}   r   rx   r-   r-   r.   rZ     s    zmoyal_gen._cdfc                 C   s   t td| td S r  )r[   r  r>   r}   r   rx   r-   r-   r.   r\     s    zmoyal_gen._sfc                 C   s   t dt|d   S r   )r>   r   r[   Zerfcinvrx   r-   r-   r.   r_     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 )NrD      r  r%  )r>   r   euler_gammar   r   r[   r.  r   r-   r-   r.   r     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 )Nrf   rD   r|   r$  r  r  r8  r%  8   r   r  )r>   r   r  r   r[   r.  r  )r6   rN   Ztmp1r  Ztmp3Ztmp4r-   r-   r.   r     s     "
"zmoyal_gen._munp)NN)ra   rb   rc   rd   rU   r   rY   rZ   r\   r_   r   r   r-   r-   r-   r.   r    s   *
r  moyalc                   @   sd   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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   t dddtjfdgS )NnuFr   r   rR   rT   r-   r-   r.   rU     s    znakagami_gen._shape_infoc                 C   s   t | ||S r<   r#  r6   rX   r  r-   r-   r.   rY     s    znakagami_gen._pdfc                 C   s@   t dt|| t| td| d | ||d   S r  )r>   r   r[   r   r  r  r-   r-   r.   r     s
    
znakagami_gen._logpdfc                 C   s   t ||| | S r<   r  r  r-   r-   r.   rZ     s    znakagami_gen._cdfc                 C   s   t d| t|| S r   r  )r6   r^   r  r-   r-   r.   r_     s    znakagami_gen._ppfc                 C   s   t ||| | S r<   r  r  r-   r-   r.   r\     s    znakagami_gen._sfc                 C   s   t d| t|| S rJ   r  )r6   r  r  r-   r-   r.   r`      s    znakagami_gen._isfc                 C   s   t |d t | t| }d||  }|dd| |   d | t|d }d|d  | d| d	 |d	   d	|  d }|||d   }||||fS )
Nrm   rf   r   r   r|   r  r   rD   )r[   r  r>   r   r  )r6   r  r   r   r   r   r-   r-   r.   r   #  s    "(0znakagami_gen._statsNc                 C   s   t |j||d| S r  )r>   r   ri  )r6   r  r   r   r-   r-   r.   r   +  s    znakagami_gen._rvsc                 C   sH   |d krd| j  }t|}tt|| d t| }|||f S )N)rf   rD   )Znumargsr>   r  r   r  r  )r6   r   r7   r%   r&   r-   r-   r.   r	  /  s
    

 znakagami_gen._fitstart)NN)N)ra   rb   rc   rd   rU   rY   r   rZ   r_   r\   r`   r   r   r	  r-   r-   r-   r.   r    s   
r  nakagamic                 C   sz   |d d }t | t | }}t|d | | d|| d   }t||| d }t|dk||fdd t j dS )	Nr|   rf   rm   rD   r   c                 S   s   | t | S r<   r   )r}  r,  r-   r-   r.   rC  I  rD  z_ncx2_log_pdf.<locals>.<lambda>)r  rY  )r>   r   r[   r   iver   rS   )rX   r{  r^  df2r  nsr  Zcorrr-   r-   r.   _ncx2_log_pdf=  s    $r  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 r  r2  r6   r{  r^  r-   r-   r.   rO   i  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^  rQ   rR   r6   idfincr-   r-   r.   rU   l  s    zncx2_gen._shape_infoNc                 C   s   | |||S r<   )Znoncentral_chisquare)r6   r{  r^  r   r   r-   r-   r.   r   q  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 r<   )r|  r   rX   r{  _r-   r-   r.   rC  w  rD  z"ncx2_gen._logpdf.<locals>.<lambda>r  rG  )r>   	ones_likeboolr   r  r6   rX   r{  r^  condr-   r-   r.   r   t  s    zncx2_gen._logpdfc              
   C   sd   t j|td|dk@ }t < d}tjd|d t||||ftjdd dW  5 Q R  S Q R X d S )	Nr  r   z!overflow encountered in _ncx2_pdfr   r   c                 S   s   t | |S r<   )r|  rY   r  r-   r-   r.   rC    rD  zncx2_gen._pdf.<locals>.<lambda>r  )	r>   r  r  r   r   r   r   r   Z	_ncx2_pdfr6   rX   r{  r^  r  r   r-   r-   r.   rY   y  s    
zncx2_gen._pdfc                 C   s2   t j|td|dk@ }t||||ftjdd dS )Nr  r   c                 S   s   t | |S r<   )r|  rZ   r  r-   r-   r.   rC    rD  zncx2_gen._cdf.<locals>.<lambda>r  )r>   r  r  r   r   Z	_ncx2_cdfr  r-   r-   r.   rZ     s    zncx2_gen._cdfc              
   C   sd   t j|td|dk@ }t < d}tjd|d t||||ftjdd dW  5 Q R  S Q R X d S )	Nr  r   z!overflow encountered in _ncx2_ppfr   r   c                 S   s   t | |S r<   )r|  r_   r  r-   r-   r.   rC    rD  zncx2_gen._ppf.<locals>.<lambda>r  )	r>   r  r  r   r   r   r   r   Z	_ncx2_ppf)r6   r^   r{  r^  r  r   r-   r-   r.   r_     s    
zncx2_gen._ppfc                 C   s2   t j|td|dk@ }t||||ftjdd dS )Nr  r   c                 S   s   t | |S r<   )r|  r\   r  r-   r-   r.   rC    rD  zncx2_gen._sf.<locals>.<lambda>r  )r>   r  r  r   r   Z_ncx2_sfr  r-   r-   r.   r\     s    zncx2_gen._sfc              
   C   sd   t j|td|dk@ }t < d}tjd|d t||||ftjdd dW  5 Q R  S Q R X d S )	Nr  r   z!overflow encountered in _ncx2_isfr   r   c                 S   s   t | |S r<   )r|  r`   r  r-   r-   r.   rC    rD  zncx2_gen._isf.<locals>.<lambda>r  )	r>   r  r  r   r   r   r   r   Z	_ncx2_isfr  r-   r-   r.   r`     s    
zncx2_gen._isfc                 C   s,   t ||t ||t ||t ||fS r<   )r   Z
_ncx2_meanZ_ncx2_varianceZ_ncx2_skewnessZ_ncx2_kurtosis_excessr  r-   r-   r.   r     s
    



zncx2_gen._stats)NN)ra   rb   rc   rd   rO   rU   r   r   rY   rZ   r_   r\   r`   r   r-   r-   r-   r.   r  M  s   
r  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 r  r-   )r6   df1r  r^  r-   r-   r.   rO     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 )Nr  Fr   r   r  r^  rQ   rR   )r6   Zidf1Zidf2r  r-   r-   r.   rU     s    zncf_gen._shape_infoNc                 C   s   | ||||S r<   )Znoncentral_f)r6   r  r  r^  r   r   r-   r-   r.   r     s    zncf_gen._rvsc                 C   s   t ||||S r<   )r   Z_ncf_pdfr6   rX   r  r  r^  r-   r-   r.   rY     s    zncf_gen._pdfc                 C   s   t ||||S r<   )r   Z_ncf_cdfr  r-   r-   r.   rZ     s    zncf_gen._cdfc                 C   s   t ||||S r<   )r   Z_ncf_ppf)r6   r^   r  r  r^  r-   r-   r.   r_     s    zncf_gen._ppfc                 C   s   t ||||S r<   )r   Z_ncf_sfr  r-   r-   r.   r\     s    zncf_gen._sfc                 C   s   t ||||S r<   )r   Z_ncf_isfr  r-   r-   r.   r`     s    zncf_gen._isfc                 C   s   |d | | }t |d|  t d| |  t |d  }|t| d | 9 }|t |d|  d| d| 9 }|S )Nrf   rm   r|   )r[   r  r>   r}   hyp1f1)r6   rN   r  r  r^  r'  Ztermr-   r-   r.   r     s
    2"zncf_gen._munpr2  c           	      C   s\   t |||}t |||}d|kr2t |||nd }d|krLt |||nd }||||fS )Nr3  r6  )r   Z	_ncf_meanZ_ncf_varianceZ_ncf_skewnessZ_ncf_kurtosis_excess)	r6   r  r  r^  r9  r   r   r   r   r-   r-   r.   r     s      zncf_gen._stats)NN)r2  )ra   rb   rc   rd   rO   rU   r   rY   rZ   r_   r\   r`   r   r   r-   r-   r-   r.   r    s   (
	r  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 rz  rR   rT   r-   r-   r.   rU   #  s    zt_gen._shape_infoNc                 C   s   |j ||dS r  )Z
standard_tr}  r-   r-   r.   r   &  s    z
t_gen._rvsc                 C   s"   t |tjk||fdd dd dS )Nc                 S   s
   t | S r<   )r   rY   rX   r{  r-   r-   r.   rC  ,  rD  zt_gen._pdf.<locals>.<lambda>c                 S   sR   t t|d d t|d  t |t j d| d |  |d d    S r   )r>   r}   r[   r  r   r   r  r-   r-   r.   rC  -  s    $*r  rx  r~  r-   r-   r.   rY   )  s     z
t_gen._pdfc                 C   s"   t |tjk||fdd dd dS )Nc                 S   s
   t | S r<   )r   r   r  r-   r-   r.   rC  6  rD  zt_gen._logpdf.<locals>.<lambda>c                 S   sV   t |d d t |d  dt|tj  |d d td| d |     S r  )r[   r  r>   r   r   r  r-   r-   r.   rC  7  s
     r  rx  r~  r-   r-   r.   r   3  s     zt_gen._logpdfc                 C   s   t ||S r<   r[   Zstdtrr~  r-   r-   r.   rZ   >  s    z
t_gen._cdfc                 C   s   t || S r<   r  r~  r-   r-   r.   r\   A  s    z	t_gen._sfc                 C   s   t ||S r<   r[   Zstdtritr  r-   r-   r.   r_   D  s    z
t_gen._ppfc                 C   s   t || S r<   r  r  r-   r-   r.   r`   G  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   re   rD   c                 S   s   t t j| jS r<   r>   broadcast_torS   r  r{  r-   r-   r.   rC  S  rD  zt_gen._stats.<locals>.<lambda>c                 S   s   | | d  S r   r-   r  r-   r-   r.   rC  T  rD  c                 S   s   t d| jS rJ   r>   r  r  r  r-   r-   r.   rC  U  rD  r  r   c                 S   s   t t j| jS r<   r  r  r-   r-   r.   rC  ]  rD  c                 S   s   d| d  S )Nr  r%  r-   r  r-   r-   r.   rC  ^  rD  c                 S   s   t d| jS r  r  r  r-   r-   r.   rC  _  rD  )r>   Zisposinfr&  rS   r   r   r   )	r6   r{  Zinfinite_dfr   r  
choicelistr   r   r   r-   r-   r.   r   J  s,    
zt_gen._statsc                 C   sZ   |t jkrt S |d }|d d }|t|t|  t t |t|d  S )NrD   r   rm   )	r>   rS   r   r   r[   r\  r   r   r   )r6   r{  ZhalfZhalf1r-   r-   r.   r   d  s    
zt_gen._entropy)NN)ra   rb   rc   rd   rU   r   rY   r   rZ   r\   r_   r`   r   r   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 r  r-   r  r-   r-   r.   rO     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^  rR   r  r-   r-   r.   rU     s    znct_gen._shape_infoNc                 C   s8   t j|||d}tj|||d}|t| t| S )Nr  r  )r   r   r|  r>   r   )r6   r{  r^  r   r   rN   r  r-   r-   r.   r     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 )Nrf   r|   r   rD   r  rm   r   )
r>   r   r[   r  r}   r   r  r   r  clip)r6   rX   r{  r^  rN   r  r  r%  trm1r  ZvalFtrm2r-   r-   r.   rY     s(    *
& znct_gen._pdfc                 C   s   t t|||ddS Nr   r   )r>   r  r   Z_nct_cdfr6   rX   r{  r^  r-   r-   r.   rZ     s    znct_gen._cdfc                 C   s   t |||S r<   )r   Z_nct_ppf)r6   r^   r{  r^  r-   r-   r.   r_     s    znct_gen._ppfc                 C   s   t t|||ddS r  )r>   r  r   Z_nct_sfr  r-   r-   r.   r\     s    znct_gen._sfc                 C   s   t |||S r<   )r   Z_nct_isfr  r-   r-   r.   r`     s    znct_gen._isfr2  c                 C   sX   t ||}t ||}d|kr,t ||nd }d|krHt ||d nd }||||fS )Nr3  r6  r  )r   Z	_nct_meanZ_nct_varianceZ_nct_skewnessZ_nct_kurtosis_excess)r6   r{  r^  r9  r   r   r   r   r-   r-   r.   r     s
    znct_gen._stats)NN)r2  )ra   rb   rc   rd   rO   rU   r   rY   rZ   r_   r\   r`   r   r-   r-   r-   r.   r  p  s   
r  nctc                       sf   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
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  rR   rT   r-   r-   r.   rU     s    zpareto_gen._shape_infoc                 C   s   ||| d   S rJ   r-   r  r-   r-   r.   rY     s    zpareto_gen._pdfc                 C   s   d||   S rJ   r-   r  r-   r-   r.   rZ     s    zpareto_gen._cdfc                 C   s   t d| d| S )Nr   rQ  r	  r  r-   r-   r.   r_     s    zpareto_gen._ppfc                 C   s
   ||  S r<   r-   r  r-   r-   r.   r\     s    zpareto_gen._sfr2  c           
      C   s  d\}}}}d|krT|dk}t ||}t jt |t jd}t ||||d   d|kr|dk}t ||}t jt |t jd}t ||||d  |d d   d	|kr|d
k}t ||}t jt |t jd}d|d  t |d  |d t |  }	t |||	 d|kr|dk}t ||}t jt |t jd}dt ddddg| t ddddg| }	t |||	 ||||fS )N)NNNNr  r   r  rf   r  rD   r|   r3  r  r$  r6  r   r  r  r   g      r  re   )	r>   extractr  r  rS   Zplacer   r   r  )
r6   ri   r9  r   r   r   r   maskZbtr,  r-   r-   r.   r     s4    "
,
zpareto_gen._statsc                 C   s   dd|  t | S r  r   ri  r-   r-   r.   r     s    zpareto_gen._entropyc                    s  t | ||}|\}}|d k	rHt| |p4dk rHtddtjdjd fdd||  krvd krn nfddfd	d
  fddfdd}|dd}|d |d  }	}
||	|
s|	dks|
tjk r|	d }	|
d9 }
qt|	|
gd}|jrx|j	}t| }p>||}|| tk snt| }t
|d}|||fS t jf|S n|d krt| }n|}|pt| }pʈ||}|||fS )Nr   paretor   r  c                    s   t t  | |   S r<   )r>   r  r   )r&   location)r   ndatar-   r.   	get_shape  s    z!pareto_gen.fit.<locals>.get_shapec                    s    |  | S r<   r-   )r  r&   )r  r-   r.   	dL_dScale  s    z!pareto_gen.fit.<locals>.dL_dScalec                    s   | d t d |   S rJ   r>   r  )r  r  r  r-   r.   dL_dLocation!  s    z$pareto_gen.fit.<locals>.dL_dLocationc                    s0   t |  }p| |} ||||  S r<   )r>   r  )r&   r  r  )r  r  r   fshaper  r-   r.   fun_to_solve&  s    z$pareto_gen.fit.<locals>.fun_to_solvec                    s   t  | t  |kS r<   r=   r@   r  r-   r.   rC   -  s    z.pareto_gen.fit.<locals>.interval_contains_rootr&   rD   r  )r  r>   r  r   rS   r  r1   r#   	convergedr  	nextafterr3   r5   )r6   r   r7   r,   
parametersr   r   rC   r  rA   rB   r  r&   r%   r  r
  )r  r  r   r   r  r  r  r.   r5     sH    



zpareto_gen.fit)r2  )ra   rb   rc   rd   rU   rY   rZ   r_   r\   r   r   r;   r	   r   r5   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 )	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 r+  rR   rT   r-   r-   r.   rU   v  s    zlomax_gen._shape_infoc                 C   s   |d d| |d   S r   r-   r.  r-   r-   r.   rY   y  s    zlomax_gen._pdfc                 C   s   t ||d t|  S rJ   r  r.  r-   r-   r.   r   }  s    zlomax_gen._logpdfc                 C   s   t | t |  S r<   r/  r.  r-   r-   r.   rZ     s    zlomax_gen._cdfc                 C   s   t | t| S r<   )r>   r}   r[   r  r.  r-   r-   r.   r\     s    zlomax_gen._sfc                 C   s   | t | S r<   r-  r.  r-   r-   r.   r     s    zlomax_gen._logsfc                 C   s   t t |  | S r<   r/  r1  r-   r-   r.   r_     s    zlomax_gen._ppfc                 C   s$   t j|ddd\}}}}||||fS )NrQ  r  )r%   r9  )r  r  r/  r-   r-   r.   r     s    zlomax_gen._statsc                 C   s   dd|  t | S r  r   ri  r-   r-   r.   r     s    zlomax_gen._entropyN)ra   rb   rc   rd   rU   rY   r   rZ   r\   r   r_   r   r   r-   r-   r-   r.   r  ^  s   r  lomaxc                       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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 )Nre   rf   g>r|   rD   )r>   r  copyr#  )r6   rX   r  r%   r&   Znorm2pearson_transitionansr  invmaskr   r   r.  transxr-   r-   r.   _preprocess  s    zpearson3_gen._preprocessc                 C   s
   t |S r<   r2  )r6   r  r-   r-   r.   rO     s    zpearson3_gen._argcheckc                 C   s   t ddtj tjfdgS )Nr  Fr   rR   rT   r-   r-   r.   rU     s    zpearson3_gen._shape_infoc                 C   s$   d}d}|}d|d  }||||fS )Nre   rf   r  rD   r-   )r6   r  r  r  r3  r6  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   re   )r>   r}   r   rI  r  )r6   rX   r  r  r-   r-   r.   rY     s    

zpearson3_gen._pdfc           
      C   sT   |  ||\}}}}}}}}	tt|| ||< tt|t|| ||< |S r<   )r  r>   r   r   r  r  rL  )
r6   rX   r  r  r  r  r  r   r   r  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 r  )	r  r   r>   r  r  r  r  rs   r  )r6   rX   r  r  r  r  r  r  r   Z	invmask1aZ	invmask1bZ	invmask2aZ	invmask2br-   r-   r.   rZ     s    
zpearson3_gen._cdfNc                 C   sv   t ||}| dg|\}}}}}}}	}
| }|j| }||||< ||	|| |
 ||< |dkrr|d }|S )Nr   r-   )r>   r  r  r  r   r   ri  )r6   r  r   r   r  r  r  r  r   r   r.  ZnsmallZnbigr-   r-   r.   r   &  s    
zpearson3_gen._rvsc           
      C   sh   |  ||\}}}}}}}}	t|| ||< || }d||dk   ||dk < t||| |	 ||< |S r*  )r  r   r[   r  )
r6   r^   r  r  r  r  r  r   r   r.  r-   r-   r.   r_   4  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|f||S d S )Nr(   ZMMzhFit `method='MM'` is not available for the Pearson3 distribution. Please try the default `method='MLE'`.)r1   r'  r3   r4   r5   ru  r
  r-   r.   r5   =  s    
zpearson3_gen.fit)NN)ra   rb   rc   rd   r  rO   rU   r   rY   r   rZ   r   r_   r;   r   r   r5   r  r-   r-   r
  r.   r	    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 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   rR   rT   r-   r-   r.   rU   n  s    zpowerlaw_gen._shape_infoc                 C   s   |||d   S r   r-   r   r-   r-   r.   rY   q  s    zpowerlaw_gen._pdfc                 C   s   t |t|d | S rJ   )r>   r   r[   r   r   r-   r-   r.   r   u  s    zpowerlaw_gen._logpdfc                 C   s   ||d  S r   r-   r   r-   r-   r.   rZ   x  s    zpowerlaw_gen._cdfc                 C   s   |t | S r<   r   r   r-   r-   r.   r   {  s    zpowerlaw_gen._logcdfc                 C   s   t |d| S r   r	  r   r-   r-   r.   r_   ~  s    zpowerlaw_gen._ppfc              
   C   sr   ||d  ||d  |d d  d|d |d   t |d |  dt ddd	dg| ||d  |d
   fS )Nrf   r|   rD   g       r$  r  r   re  r  r   )r>   r   r  r   r-   r-   r.   r     s
    
$*zpowerlaw_gen._statsc                 C   s   dd|  t | S r  r   r   r-   r-   r.   r     s    zpowerlaw_gen._entropyc                    s"   t t| |||dk|dkB @ S r  )r3   r  r   r   r
  r-   r.   r     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f||S ttdkrFt jf||S t| ||\}}| fg}| |i d }|d k	r	 |kst
ddd|d k	r || kst
ddd|d k	r|dkrtd| krd}t|dd	 d
d |d k	r&|d k	r&||||fS |d k	rt	 tj }	pT|	|}
||
|	|f}t | tj}p||}||||f}||k r|
|	|fS |||fS |d k	r|}p||}|||fS fdd}dd dd   fdd fddfdd}d k	rhdkrh| S d k	rdkr| S | }| |}| }| |}||kr|d dkr|S ||kr|d dkr|S t jf||S d S )Nr  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 r<   )r  r>   r  r   )r   r%   r&   r  r-   r-   r.   r    s    z#powerlaw_gen.fit.<locals>.get_shapec                 S   s   |   | S r<   )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 r<   )	r>   r  r  rS   r  Zfinfor  Ztinyr?   r%   r&   r  )r   r   r  r  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 r  )r  )r   r  r&   r-   r-   r.   r    s    z#powerlaw_gen.fit.<locals>.dL_dScalec                 S   s   |d t d||    S rJ   r  )r   r  r%   r-   r-   r.   r    s    z&powerlaw_gen.fit.<locals>.dL_dLocationc                    s2   t | t j }p$| |} || S r<   r>   r  rS   r  )r  r   r   r  r  r-   r.   dL_dLocation_star  s    z+powerlaw_gen.fit.<locals>.dL_dLocation_starc                    s>   t | t j }p$| |}|| ||  S r<   r  r  )r  r  r   r   r  r  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   rD   c                    s   t  | t  |kS r<   r=   r@   r  r-   r.   rC   4  s    zTpowerlaw_gen.fit.<locals>.fit_loc_scale_w_shape_gt_1.<locals>.interval_contains_rootr   rf   r  )r>   r  r  rS   r   r#   r  )	rB   r.  rC   rA   r  r  r%   r&   r  )r  r   r   r  r  r  r-   r.   fit_loc_scale_w_shape_gt_1(  s$    



z4powerlaw_gen.fit.<locals>.fit_loc_scale_w_shape_gt_1)r*   r3   r5   r  r>   uniquer  r	  Z_reduce_funcr  r   r  r   ptpr  rS   Znnlf)r6   r   r7   r,   r   r   Zpenalized_nllf_argsZpenalized_nllfrG   Zloc_lt1Z	shape_lt1Zll_lt1Zloc_gt1Z	shape_gt1Zll_gt1r&   r  r  r  Zfit_shape_lt1Zfit_shape_gt1r
  )r  r  r  r   r   r  r  r  r.   r5     st    ( 






$zpowerlaw_gen.fit)ra   rb   rc   rd   rU   rY   r   rZ   r   r_   r   r   r   r;   r   r   r5   r  r-   r-   r
  r.   r  M  s    
r  r  c                   @   s6   e Zd ZdZej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 )Nr,  Fr   r   r3  rR   )r6   r@  r  r-   r-   r.   rU   }  s    zpowerlognorm_gen._shape_infoc                 C   s@   |||  t t||  ttt| | |d d  S r   )r   r>   r   r  r   r6   rX   r,  r3  r-   r-   r.   rY     s     zpowerlognorm_gen._pdfc                 C   s"   dt tt| | |d  S r   )r  r   r>   r   r  r-   r-   r.   rZ     s    zpowerlognorm_gen._cdfc                 C   s"   t | ttd| d|  S r   )r>   r}   r   r  )r6   r^   r,  r3  r-   r-   r.   r_     s    zpowerlognorm_gen._ppfN)ra   rb   rc   rd   r   r   r   rU   rY   rZ   r_   r-   r-   r-   r.   r  c  s   r  powerlognormc                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )powernorm_gena  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, and :math:`\Phi` is the normal cdf,
    and :math:`x >= 0`, :math:`c > 0`.

    `powernorm` 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 r+  rR   rT   r-   r-   r.   rU     s    zpowernorm_gen._shape_infoc                 C   s   |t | t| |d   S r   r   r   r.  r-   r-   r.   rY     s    zpowernorm_gen._pdfc                 C   s$   t |t| |d t|   S rJ   )r>   r   r   r   r.  r-   r-   r.   r     s    zpowernorm_gen._logpdfc                 C   s   dt | |d   S r   r   r.  r-   r-   r.   rZ     s    zpowernorm_gen._cdfc                 C   s   t td| d|  S r   )r   r  r1  r-   r-   r.   r_     s    zpowernorm_gen._ppfNr  r-   r-   r-   r.   r    s   r  	powernormc                   @   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 )	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 r+  rR   rT   r-   r-   r.   rU     s    zrdist_gen._shape_infoc                 C   s   t | ||S r<   r#  r.  r-   r-   r.   rY     s    zrdist_gen._pdfc                 C   s*   t d t|d d |d |d  S r  )r>   r   r   r   r.  r-   r-   r.   r     s    zrdist_gen._logpdfc                 C   s   t |d d |d |d S r   )r   rZ   r.  r-   r-   r.   rZ     s    zrdist_gen._cdfc                 C   s   dt ||d |d  d S r  )r   r_   r1  r-   r-   r.   r_     s    zrdist_gen._ppfNc                 C   s   d| |d |d | d S r  r   r  r-   r-   r.   r     s    zrdist_gen._rvsc                 C   s8   d|d  t |d d |d  }|t d|d  S )Nr   rD   rf   r|   rm   r_  )r6   rN   r,  	numeratorr-   r-   r.   r     s    $zrdist_gen._munp)NN)ra   rb   rc   rd   rU   rY   r   rZ   r_   r   r   r-   r-   r-   r.   r     s   !
r   rQ  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 r<   r-   rT   r-   r-   r.   rU     s    zrayleigh_gen._shape_infoNc                 C   s   t jd||dS )NrD   r  r  r   r-   r-   r.   r     s    zrayleigh_gen._rvsc                 C   s   t | |S r<   r#  r6   r}  r-   r-   r.   rY     s    zrayleigh_gen._pdfc                 C   s   t |d| |  S rD  r   r$  r-   r-   r.   r     s    zrayleigh_gen._logpdfc                 C   s   t d|d   S r  r  r$  r-   r-   r.   rZ     s    zrayleigh_gen._cdfc                 C   s   t dt|  S Nr   )r>   r   r[   r  ry   r-   r-   r.   r_   "  s    zrayleigh_gen._ppfc                 C   s   t | |S r<   rN  r$  r-   r-   r.   r\   %  s    zrayleigh_gen._sfc                 C   s   d| | S )Nr  r-   r$  r-   r-   r.   r   (  s    zrayleigh_gen._logsfc                 C   s   t dt | S r%  )r>   r   r   ry   r-   r-   r.   r`   +  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   rD   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   rm   rD   r
  rT   r-   r-   r.   r   5  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 f||S t|  ||\ }} fdd} fdd}|f fdd	}|d k	rt | d	krtd
dtjdn|||fS |d}	|	d kr| 	 d	 }	|d kr|n|}
t
t tj }t|
|}tj|
||fd}|jst|j|j}|p||}||fS )Nr  Fc                    s"   t  |  d dt   d S r  )r>   r  r  )r%   r  r-   r.   	scale_mleG  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_mleL  s
    z!rayleigh_gen.fit.<locals>.loc_mlec                    s$    |  }|  |d d|     S r  )r  )r%   r&   r,  r  r-   r.   loc_mle_scale_fixedU  s    z-rayleigh_gen.fit.<locals>.loc_mle_scale_fixedr   rayleighr   r  r%   r  )r*   r3   r5   r  r>   r  r   rS   r1   r	  r  r  rH   r   r#   r  rF   flagr  )r6   r   r7   r,   r   r   r&  r'  r(  Zloc0r9   rB   rA   r  r%   r&   r
  r  r.   r5   8  s2    
 
	


zrayleigh_gen.fit)NN)ra   rb   rc   rd   r   r   r   rU   r   rY   r   rZ   r_   r\   r   r`   r   r   r;   r   r5   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
    >>> 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 r  r-   r   r-   r-   r.   rO     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   rR   r   r-   r-   r.   rU     s    zreciprocal_gen._shape_infoc                    s    t  j|t|t|fdS Nr  r3   r	  r>   r  r  r  r
  r-   r.   r	    s    zreciprocal_gen._fitstartc                 C   s   ||fS r<   r-   r   r-   r-   r.   ro     s    zreciprocal_gen._get_supportc                 C   s   d|t |d |   S r   r   r   r-   r-   r.   rY     s    zreciprocal_gen._pdfc                 C   s$   t | t t |d |  S r   r   r   r-   r-   r.   r     s    zreciprocal_gen._logpdfc                 C   s&   t |t | t |d |  S r   r   r   r-   r-   r.   rZ     s    zreciprocal_gen._cdfc                 C   s   |t |d | | S r   r	  r=  r-   r-   r.   r_     s    zreciprocal_gen._ppfc                 C   s6   dt |d |  | t|d |t|d |  S r   r+  r(  r-   r-   r.   r     s    zreciprocal_gen._munpc                 C   s*   dt ||  t t |d |  S rl   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|f|d|i|S )Nr   r   )r*   r3   r5   )r6   r   r7   r,   r   r
  r-   r.   r5     s    zreciprocal_gen.fit)ra   rb   rc   rd   rO   rU   r	  ro   rY   r   rZ   r_   r   r   Zfit_noter   r   r5   r  r-   r-   r
  r.   r+  v  s   2
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 r  r-   r6   ri   r-   r-   r.   rO     s    zrice_gen._argcheckc                 C   s   t dddtjfdgS )Nri   Fr   rQ   rR   rT   r-   r-   r.   rU     s    zrice_gen._shape_infoNc                 C   s4   |t d |jd| d }t || jddS )NrD   )rD   r  r   rY  )r>   r   r   r  )r6   ri   r   r   r  r-   r-   r.   r     s    zrice_gen._rvsc                 C   s   t t|dt|S r   )r[   Zchndtrr>   squarer  r-   r-   r.   rZ     s    zrice_gen._cdfc              	   C   s   t t|dt |S r   )r>   r   r[   Zchndtrixr2  r  r-   r-   r.   r_     s    zrice_gen._ppfc                 C   s.   |t ||  ||  d  t||  S r   )r>   r}   r[   i0er  r-   r-   r.   rY     s    zrice_gen._pdfc                 C   sH   |d }d| }|| d }d| t |  t| t|d| S ry  )r>   r}   r[   r  r  )r6   rN   ri   Znd2Zn1r  r-   r-   r.   r     s    zrice_gen._munp)NN)ra   rb   rc   rd   rO   rU   r   rZ   r_   rY   r   r-   r-   r-   r.   r0    s   
	r0  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 r  rR   rT   r-   r-   r.   rU   2  s    zrecipinvgauss_gen._shape_infoc                 C   s   t | ||S r<   r#  r  r-   r-   r.   rY   5  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|   rD   rm   r   )rX   r   r-   r-   r.   rC  <  s    z+recipinvgauss_gen._logpdf.<locals>.<lambda>rX  rx  r  r-   r-   r.   r   :  s    zrecipinvgauss_gen._logpdfc                 C   sP   d| | }d| | }dt | }t| | t d| t| |   S Nrf   r|   r>   r   r   r}   r6   rX   r   r  r  Zisqxr-   r-   r.   rZ   @  s    zrecipinvgauss_gen._cdfc                 C   sN   d| | }d| | }dt | }t|| t d| t| |   S r6  r7  r8  r-   r-   r.   r\   F  s    zrecipinvgauss_gen._sfNc                 C   s   d|j |d|d S r  r  r  r-   r-   r.   r   L  s    zrecipinvgauss_gen._rvs)NN)
ra   rb   rc   rd   rU   rY   r   rZ   r\   r   r-   r-   r-   r.   r5    s   r5  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 r<   r-   rT   r-   r-   r.   rU   r  s    zsemicircular_gen._shape_infoc                 C   s   dt j t d||   S ry  r  rx   r-   r-   r.   rY   u  s    zsemicircular_gen._pdfc                 C   s$   t dt j dt| |   S r  r  rx   r-   r-   r.   r   x  s    zsemicircular_gen._logpdfc                 C   s.   ddt j |t d||   t |   S )Nrm   rf   r   )r>   r   r   r   rx   r-   r-   r.   rZ   {  s    zsemicircular_gen._cdfc                 C   s   t |dS Nr  )r"  r_   ry   r-   r-   r.   r_   ~  s    zsemicircular_gen._ppfNc                 C   s2   t |j|d}t t j|j|d }|| S r  )r>   r   r  r   r   )r6   r   r   r}  rh   r-   r-   r.   r     s    zsemicircular_gen._rvsc                 C   s   dS )N)r   r  r   rQ  r-   rT   r-   r-   r.   r     s    zsemicircular_gen._statsc                 C   s   dS )NgzCϑ?r-   rT   r-   r-   r.   r     s    zsemicircular_gen._entropy)NN)ra   rb   rc   rd   rU   rY   r   rZ   r_   r   r   r   r-   r-   r-   r.   r:  S  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 rJ   )r>   r  r   r-   r-   r.   rO     s    zskewcauchy_gen._argcheckc                 C   s   t ddddgS )Nrh   F)rQ  rf   r   r   rT   r-   r-   r.   rU     s    zskewcauchy_gen._shape_infoc                 C   s,   dt j|d |t | d d  d   S r   )r>   r   r?   r   r-   r-   r.   rY     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   rD   )r>   r&  r   rm  r   r-   r-   r.   rZ     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?  )rZ   r>   r&  ro  r   )r6   rX   rh   r  r-   r-   r.   r_     s
    **zskewcauchy_gen._ppfr  c                 C   s   t jt jt jt jfS r<   rp  )r6   rh   r9  r-   r-   r.   r     s    zskewcauchy_gen._statsc                 C   s*   t |dddg\}}}d||| d fS )Nrq  rr  rs  re   rD   rt  )r6   r   ru  rv  rw  r-   r-   r.   r	    s    zskewcauchy_gen._fitstartN)r  )ra   rb   rc   rd   rO   rU   rY   rZ   r_   r   r	  r-   r-   r-   r.   r=    s   !
r=  
skewcauchyc                       s   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dZdddZedd Zdd Zeedd fddZ  ZS ) skew_norm_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 r<   r2  r   r-   r-   r.   rO     s    zskew_norm_gen._argcheckc                 C   s   t ddtj tjfdgS )Nrh   Fr   rR   rT   r-   r-   r.   rU     s    zskew_norm_gen._shape_infoc                 C   s    t |dk||fdd dd dS )Nr   c                 S   s   t | S r<   r   rX   rh   r-   r-   r.   rC    rD  z$skew_norm_gen._pdf.<locals>.<lambda>c                 S   s   dt |  t||   S r   r  rB  r-   r-   r.   rC    rD  rF  r6  r   r-   r-   r.   rY     s      zskew_norm_gen._pdfc                    sV   t |dd|}t||j}|dk |dk@ }t || || ||< t|ddS )Nr   r   gư>)r   Z_skewnorm_cdfr>   r  r  r3   rZ   r  )r6   rX   rh   rs   Zi_small_cdfr
  r-   r.   rZ     s
    zskew_norm_gen._cdfc                 C   s   t |dd|S r  )r   Z_skewnorm_ppfr   r-   r-   r.   r_      s    zskew_norm_gen._ppfc                 C   s   |  | | S r<   rE  r   r-   r-   r.   r\      s    zskew_norm_gen._sfc                 C   s   t |dd|S r  )r   Z_skewnorm_isfr   r-   r-   r.   r`      s    zskew_norm_gen._isfNc                 C   s`   |j |d}|j |d}|td|d   }|| |td|d    }t|dk|| S )Nr  r   rD   r   )normalr>   r   r&  )r6   rh   r   r   Zu0r  r>  r!  r-   r-   r.   r      s
    zskew_norm_gen._rvsr  c                 C   s   d d d d g}t dt j | t d|d   }d|krB||d< d|krZd|d  |d< d|krdt j d |t d|d   d  |d< d	|krdt jd  |d d|d  d   |d< |S )
NrD   r   r  r   r  r3  r   r  r6  r  )r6   rh   r9  rK  constr-   r-   r.   r      s    &,*zskew_norm_gen._statsc                 C   s   t dgt ddgt dddgt dddd	gt d
ddddgt ddddddgt dddddddgt ddddddd d!gt d"d#d$d%d&d'd(d)dg	t d*d+d,d-d.d/d0d1d2d3g
d4
}|S )5Nr   r  re  r  ii   i?   ii  iin  ii(  iSi6Q  ii  iOi iBi/ iio ii iԷi iYei{Hx ii i!i!iׅi쇀iiViX'iliis_'il   </1 ldy( l   J8D l.~ l   -Rx iWi[i0)
r   r  rS  r  r5  r     r        r   )r6   Zskewnorm_odd_momentsr-   r-   r.   _skewnorm_odd_moments,   s>    
  
   
    z#skew_norm_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   rI  zKskewnorm noncentral moments not implemented for odd orders greater than 19.rD   )r'  r>   r   rJ  r!   r[   r  r    )r6   orderrh   r.  r-   r-   r.   r   B   s    	zskew_norm_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              	      s*  t | |||\}}}}|dd }dd t| d}t |krt|dkrt|d krt|stt j|f||S |dkrd\}	}
}n,t|r|d nd }	|	d	d }
|	d
d }|d kr6|	d kr6t
 | | t fddddgdj}t
jdd. t
t
|d d|d  t
  }	W 5 Q R X n(|d k	rD|n|	}	|	t
d|	d   }|d kr|d krt
|}t
|dd|d  t
j   }n|d k	r|}|d kr|
d krt
|}||| t
dt
j   }
n|d k	r|}
|dkr
|	|
|fS t j||	f|
|d|S d S )Nr(   r0   c                 S   s@   dt j d | t dt j  d dd| d  t j  d   S )Nr   rD   r  r   r  r  r>  r-   r-   r.   skew_dk   s    "z!skew_norm_gen.fit.<locals>.skew_dr   r  r  r   r%   r&   c                    s   |   S r<   r-   rL  r3  rM  r-   r.   rC     rD  z#skew_norm_gen.fit.<locals>.<lambda>re  r  r   r   rD   r  )r  r1   r2   r  r  r  r3   r5   r  r*   r>   r  r#   r  r   r   r   r?   r  r   r   )r6   r   r7   r,   r  r   r   r(   Zs_maxrh   r%   r&   r>  r  r  r
  rN  r.   r5   V   sF     
 4
"




zskew_norm_gen.fit)NN)r  )ra   rb   rc   rd   rO   rU   rY   rZ   r_   r\   r`   r   r   r   rJ  r   r   r   r5   r  r-   r-   r
  r.   rA    s   	



rA  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-   r6   r,  r>  r-   r-   r.   rO      s    ztrapezoid_gen._argcheckc                 C   s$   t dddd}t dddd}||gS )Nr,  Fr   rf   TTr>  r>  r?  r-   r-   r.   rU      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 )NrD   r   c                 S   s   ||  | S r<   r-   rX   r,  r>  r  r-   r-   r.   rC     rD  z$trapezoid_gen._pdf.<locals>.<lambda>c                 S   s   |S r<   r-   rT  r-   r-   r.   rC     rD  c                 S   s   |d|   d|  S rJ   r-   rT  r-   r-   r.   rC     rD  r   )r6   rX   r,  r>  r  r-   r-   r.   rY      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-   rX   r,  r>  r-   r-   r.   rC     rD  z$trapezoid_gen._cdf.<locals>.<lambda>c                 S   s   |d| |   || d  S r  r-   rV  r-   r-   r.   rC     rD  c                 S   s$   dd|  d || d  d|   S r   r-   rV  r-   r-   r.   rC     s   
rU  rM  r-   r-   r.   rZ      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{  )rZ   r>   r   select)r6   r^   r,  r>  ZqcZqdr  r  r-   r-   r.   r_      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   re   rf   c                 S   s   dS r   r-   rL  r-   r-   r.   rC     rD  z%trapezoid_gen._munp.<locals>.<lambda>c                    s    t  d t |  | d  S r  )r>   r0  r   rL  rO  r-   r.   rC     rD  c                    s    d S r   r-   rL  rO  r-   r.   rC     rD  r|   rD   rU  )r6   rN   r,  r>  Zab_termZdc_termr'  r-   rO  r.   r      s    

(ztrapezoid_gen._munpc                 C   s2   dd| |  d| |  t dd| |   S rl   r   rQ  r-   r-   r.   r   !  s    ztrapezoid_gen._entropyN)ra   rb   rc   rd   rO   rU   rY   rZ   r_   r   r   r-   r-   r-   r.   rP     s   !
rP  	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  )
triangularr  r-   r-   r.   r   )!  s    ztriang_gen._rvsc                 C   s   |dk|dk@ S r  r-   ri  r-   r-   r.   rO   ,!  s    ztriang_gen._argcheckc                 C   s   t ddddgS )Nr,  FrR  rS  r>  rT   r-   r-   r.   rU   /!  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-   r5  r-   r-   r.   rC  <!  rD  z!triang_gen._pdf.<locals>.<lambda>c                 S   s   d|  | S r   r-   r5  r-   r-   r.   rC  =!  rD  c                 S   s   dd|   d|  S r  r-   r5  r-   r-   r.   rC  >!  rD  c                 S   s   d|  S r   r-   r5  r-   r-   r.   rC  ?!  rD  rU  r6   rX   r,  r}  r-   r-   r.   rY   2!  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-   r5  r-   r-   r.   rC  H!  rD  z!triang_gen._cdf.<locals>.<lambda>c                 S   s   | |  | S r<   r-   r5  r-   r-   r.   rC  I!  rD  c                 S   s   | |  d|   | |d  S r  r-   r5  r-   r-   r.   rC  J!  rD  c                 S   s   | |  S r<   r-   r5  r-   r-   r.   rC  K!  rD  rU  r\  r-   r-   r.   rZ   C!  s    	ztriang_gen._cdfc              
   C   s2   t ||k t || dt d| d|   S rJ   )r>   r&  r   r1  r-   r-   r.   r_   O!  s    ztriang_gen._ppfc              	   C   sb   |d d d| ||  d t dd| d  |d  |d  dt d| ||  d  dfS )	Nrf   r$     rD   r   rS  r  g333333)r>   r   r  ri  r-   r-   r.   r   R!  s
    
@ztriang_gen._statsc                 C   s   dt d S r  r   ri  r-   r-   r.   r   X!  s    ztriang_gen._entropy)NN)ra   rb   rc   rd   r   rO   rU   rY   rZ   r_   r   r   r-   r-   r-   r.   rZ  !  s   
rZ  triangc                   @   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 )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  rR   rT   r-   r-   r.   rU   u!  s    ztruncexpon_gen._shape_infoc                 C   s
   | j |fS r<   rn  r1  r-   r-   r.   ro   x!  s    ztruncexpon_gen._get_supportc                 C   s   t | t|   S r<   r  r  r-   r-   r.   rY   {!  s    ztruncexpon_gen._pdfc                 C   s   | t t|   S r<   rC  r  r-   r-   r.   r   !  s    ztruncexpon_gen._logpdfc                 C   s   t | t |  S r<   r  r  r-   r-   r.   rZ   !  s    ztruncexpon_gen._cdfc                 C   s   t |t |   S r<   )r[   r  r0  r  r-   r-   r.   r_   !  s    ztruncexpon_gen._ppfc                 C   s   |dkr.d|d t |   t|   S |dkrpddd|| d|  d  t |    t|   S | ||S d S r  )r>   r}   r[   r0  r  )r6   rN   ri   r-   r-   r.   r   !  s
    &:ztruncexpon_gen._munpc                 C   s0   t |}t |d d||d   d|   S r  )r>   r}   r   )r6   ri   ZeBr-   r-   r.   r   !  s    
ztruncexpon_gen._entropyN)ra   rb   rc   rd   rU   ro   rY   r   rZ   r_   r   r   r-   r-   r-   r.   r_  _!  s   r_  
truncexponc                 C   s   t j| |gddS )Nr   rY  )r[   r  Zlog_pZlog_qr-   r-   r.   _log_sum!  s    rb  c                 C   s   t j| |tjd  gddS )Ny              ?r   rY  )r[   r  r>   r   ra  r-   r-   r.   	_log_diff!  s    rc  c                    s   t | t | } }t | |\} }|dk}| dk}||B  }dd   fdd}dd }t j| t jt jd}| | jr | | || ||< | | jr|| | || ||< | | jr|| | || ||< t |S )	z3Log of Gaussian probability mass within an intervalr   c                 S   s   t t|t| S r<   )rc  r[   r   rh   ri   r-   r-   r.   mass_case_left!  s    z'_log_gauss_mass.<locals>.mass_case_leftc                    s    | |  S r<   r-   rd  re  r-   r.   mass_case_right!  s    z(_log_gauss_mass.<locals>.mass_case_rightc                 S   s   t t |  t |  S r<   )r[   r  r   rd  r-   r-   r.   mass_case_central!  s    z*_log_gauss_mass.<locals>.mass_case_central)r  r  )r>   r  r  r   r   Z
complex128r   real)rh   ri   	case_left
case_rightZcase_centralrg  rh  r  r-   rf  r.   _log_gauss_mass!  s     



rl  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dZ  ZS ) truncnorm_gena^  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 clipped at ``a``,
    ``b`` standard deviations to the left, right (respectively) from ``loc``.
    If ``myclip_a`` and ``myclip_b`` are clip values in the sample space (as
    opposed to the number of standard deviations) then they can be converted
    to the required form according to::

        a, b = (myclip_a - loc) / scale, (myclip_b - loc) / scale

    %(example)s

    c                 C   s   ||k S r<   r-   r   r-   r-   r.   rO   !  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 )Nrh   FrQ   ri   )FTrR   r   r-   r-   r.   rU   !  s    ztruncnorm_gen._shape_infoc                    s    t  j|t|t|fdS r,  r-  r  r
  r-   r.   r	  !  s    ztruncnorm_gen._fitstartc                 C   s   ||fS r<   r-   r   r-   r-   r.   ro   !  s    ztruncnorm_gen._get_supportc                 C   s   t | |||S r<   r#  r   r-   r-   r.   rY   !  s    ztruncnorm_gen._pdfc                 C   s   t |t|| S r<   )r   rl  r   r-   r-   r.   r   !  s    ztruncnorm_gen._logpdfc                 C   s   t | |||S r<   rM  r   r-   r-   r.   rZ   !  s    ztruncnorm_gen._cdfc              
   C   sj   t |||\}}}t||t|| }|dk}t |rft t | || || ||  ||< |S Ng)r>   r  rl  r  r  r}   r   )r6   rX   rh   ri   r  r  r-   r-   r.   r   !  s    
,ztruncnorm_gen._logcdfc                 C   s   t | |||S r<   rN  r   r-   r-   r.   r\   "  s    ztruncnorm_gen._sfc              
   C   sj   t |||\}}}t||t|| }|dk}t |rft t | || || ||  ||< |S rn  )r>   r  rl  r  r  r}   r   )r6   rX   rh   ri   r  r  r-   r-   r.   r   "  s    
,ztruncnorm_gen._logsfc                 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 r<   )rb  r[   r   r>   r   rl  	ndtri_expr^   rh   ri   Z	log_Phi_xr-   r-   r.   ppf_left"  s    
z$truncnorm_gen._ppf.<locals>.ppf_leftc                 S   s0   t t| t|  t|| }t| S r<   )rb  r[   r   r>   r  rl  ro  rp  r-   r-   r.   	ppf_right"  s    z%truncnorm_gen._ppf.<locals>.ppf_rightr>   r  
empty_liker   )r6   r^   rh   ri   rj  rk  rq  rr  r  q_leftq_rightr-   r-   r.   r_   "  s    
ztruncnorm_gen._ppfc                 C   s   t |||\}}}|dk }| }dd }dd }t |}|| }	|| }
|	jrj||	|| || ||< |
jr||
|| || ||< |S )Nr   c                 S   s0   t t|t| t|| }tt|S r<   )rc  r[   r   r>   r   rl  ro  ri  rp  r-   r-   r.   isf_left1"  s    
z$truncnorm_gen._isf.<locals>.isf_leftc                 S   s6   t t| t|  t|| }tt| S r<   )rc  r[   r   r>   r  rl  ro  ri  rp  r-   r-   r.   	isf_right6"  s    z%truncnorm_gen._isf.<locals>.isf_rightrs  )r6   r^   rh   ri   rj  rk  rw  rx  r  ru  rv  r-   r-   r.   r`   *"  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    ||g||\}}|| g}ddg}td| d D ]H t||||gg fdddd}t| d |d   }|| q6|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 rJ   r-   rX   r^  r6  r-   r.   rC  V"  rD  z:truncnorm_gen._munp.<locals>.n_th_moment.<locals>.<lambda>rX  r   re  )rY   r  r   r>   r  r'  )	rN   rh   ri   pApBprobsr9  r,  mkrT   rz  r.   n_th_momentH"  s    

 z(truncnorm_gen._munp.<locals>.n_th_momentr   Zotypes)r   r>   r  float64r   )r6   rN   rh   ri   r  r-   rT   r.   r   G"  s
     ztruncnorm_gen._munpr2  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 r<   r-   ry  r-   r-   r.   rC  g"  rD  zGtruncnorm_gen._stats.<locals>._truncnorm_stats_scalar.<locals>.<lambda>r   rX  r   c                 S   s   | | S r<   r-   ry  r-   r-   r.   rC  j"  rD  c                 S   s   | |d  S r   r-   ry  r-   r-   r.   rC  o"  rD  rD   c                 S   s   | |d  S r;  r-   ry  r-   r-   r.   rC  r"  rD  r  r`  r  rT  )r   r>   r  r  )rh   ri   r{  r|  r9  r  r   r}  r,  r  r   Zm3Zm4Zmu3r   Zmu4r   r-   r-   r.   _truncnorm_stats_scalarb"  s0    
(z5truncnorm_gen._stats.<locals>._truncnorm_stats_scalar)r9  )Zexcluded)r  r>   r  r  )r6   rh   ri   r9  r{  r|  r  Z_truncnorm_statsr-   r-   r.   r   _"  s    ztruncnorm_gen._stats)r2  )ra   rb   rc   rd   rO   rU   r	  ro   rY   r   rZ   r   r\   r   r_   r`   r   r   r  r-   r-   r
  r.   rm  !  s   rm  	truncnorm)rj   rv   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d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 )Nri   Fre   r   r,  rf   rR   )r6   r   r@  r-   r-   r.   rU   "  s    ztruncpareto_gen._shape_infoc                 C   s   |dk|dk@ S r  r-   r6   ri   r,  r-   r-   r.   rO   "  s    ztruncpareto_gen._argcheckc                 C   s
   | j |fS r<   rn  r  r-   r-   r.   ro   "  s    ztruncpareto_gen._get_supportc                 C   s    |||d    d||    S rJ   r-   r6   rX   ri   r,  r-   r-   r.   rY   "  s    ztruncpareto_gen._pdfc                 C   s.   t |t ||    |d t |  S rJ   r  r  r-   r-   r.   r   "  s    ztruncpareto_gen._logpdfc                 C   s   d||   d||    S rJ   r-   r  r-   r-   r.   rZ   "  s    ztruncpareto_gen._cdfc                 C   s$   t ||   t ||    S r<   rO  r  r-   r-   r.   r   "  s    ztruncpareto_gen._logcdfc                 C   s    t dd||   |  d| S Nr   re  r	  r6   r^   ri   r,  r-   r-   r.   r_   "  s    ztruncpareto_gen._ppfc                 C   s"   ||  ||   d||    S rJ   r-   r  r-   r-   r.   r\   "  s    ztruncpareto_gen._sfc                 C   s,   t ||  ||   t ||    S r<   r  r  r-   r-   r.   r   "  s    ztruncpareto_gen._logsfc                 C   s&   t ||  d||   |  d| S r  r	  r  r-   r-   r.   r`   "  s    ztruncpareto_gen._isfc                 C   s@   t |d||    |d t ||| d  d|     S rJ   r   r  r-   r-   r.   r   "  s    $ztruncpareto_gen._entropyc                 C   sP   ||kr$|t | d||    S |||  || ||   || d  S d S rJ   r   )r6   rN   ri   r,  r-   r-   r.   r   "  s    ztruncpareto_gen._munpc                 C   s,   t |\}}}t|| | }||||fS r<   )r  r5   r  )r6   r   ri   r%   r&   r,  r-   r-   r.   r	  "  s    ztruncpareto_gen._fitstartN)ra   rb   rc   rd   rU   rO   ro   rY   r   rZ   r   r_   r\   r   r`   r   r   r	  r-   r-   r-   r.   r  "  s   )r  truncparetoc                   @   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 r<   r2  r6   lamr-   r-   r.   rO   "  s    ztukeylambda_gen._argcheckc                 C   s   t ddtj tjfdgS )Nr  Fr   rR   rT   r-   r-   r.   rU   "  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 )Nrf   r   r   re   )r>   r   r[   tklmbdar&  r  )r6   rX   r  ZFxr  r-   r-   r.   rY   #  s    "ztukeylambda_gen._pdfc                 C   s   t ||S r<   )r[   r  )r6   rX   r  r-   r-   r.   rZ   #  s    ztukeylambda_gen._cdfc                 C   s   t ||t | | S r<   )r[   r8  r7  )r6   r^   r  r-   r-   r.   r_   
#  s    ztukeylambda_gen._ppfc                 C   s   dt |dt|fS r  )_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 rJ   r+  )r  r  r-   r.   integ#  s    z'tukeylambda_gen._entropy.<locals>.integr   r   )r   r  )r6   r  r  r-   r  r.   r   #  s    ztukeylambda_gen._entropyN)ra   rb   rc   rd   rO   rU   rY   rZ   r_   r   r   r-   r-   r-   r.   r  "  s   r  tukeylambdac                   @   s   e Zd Zdd ZdS )FitUniformFixedScaleDataErrorc                 C   s   d||f f| _ d S )NzInvalid values in `data`.  Maximum likelihood estimation with the uniform distribution and fixed scale requires that data.ptp() <= fscale, but data.ptp() = %r and fscale = %r.r  )r6   r  r   r-   r-   r.   r   #  s    z&FitUniformFixedScaleDataError.__init__N)ra   rb   rc   r   r-   r-   r-   r.   r  #  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 r<   r-   rT   r-   r-   r.   rU   /#  s    zuniform_gen._shape_infoNc                 C   s   | dd|S )Nre   rf   )r  r   r-   r-   r.   r   2#  s    zuniform_gen._rvsc                 C   s   d||k S r   r-   rx   r-   r-   r.   rY   5#  s    zuniform_gen._pdfc                 C   s   |S r<   r-   rx   r-   r-   r.   rZ   8#  s    zuniform_gen._cdfc                 C   s   |S r<   r-   ry   r-   r-   r.   r_   ;#  s    zuniform_gen._ppfc                 C   s   dS )N)rm   gUUUUUU?r   g333333r-   rT   r-   r-   r.   r   >#  s    zuniform_gen._statsc                 C   s   dS r  r-   rT   r-   r-   r.   r   A#  s    zuniform_gen._entropyc           	      O   s  t |dkrtd|dd}|dd}t| |dk	rL|dk	rLtdt|}t| sltd|dkr|dkr|	 }|
 }q|}| | }|	 |k rtd||| d	n4|
 }||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   rm   )r  r+   r*   r/   r   r>   r   r   r   r  r  r  r   r  r  )	r6   r   r7   r,   r   r   r%   r&   r  r-   r-   r.   r5   D#  s0    K

zuniform_gen.fit)NN)ra   rb   rc   rd   rU   r   rY   rZ   r_   r   r   r;   r5   r-   r-   r-   r.   r  ##  s   
r  r  c                       s|   e Zd Z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  ZS )vonmises_gena  A Von Mises continuous random variable.

    %(before_notes)s

    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 > 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.

    `vonmises` and `vonmises_line` take ``kappa`` as a shape parameter.

    %(after_notes)s

    %(example)s

    c                 C   s   t dddtjfdgS rJ  rR   rT   r-   r-   r.   rU   #  s    zvonmises_gen._shape_infoNc                 C   s   |j d||dS )Nre   r  )vonmises)r6   rK  r   r   r-   r-   r.   r   #  s    zvonmises_gen._rvsc                    s,   t  j||}t|tj dtj tj S r   )r3   r   r>   modr   )r6   r7   r,   r   r
  r-   r.   r   $  s    zvonmises_gen.rvsc                 C   s(   t |t| dt j t|  S r   )r>   r}   r[   cosm1r   r3  rL  r-   r-   r.   rY   $  s    zvonmises_gen._pdfc                 C   s.   |t | tdtj  tt | S r   )r[   r  r>   r   r   r3  rL  r-   r-   r.   r   $  s    zvonmises_gen._logpdfc                 C   s   t ||S r<   )r   Zvon_mises_cdfrL  r-   r-   r.   rZ   $  s    zvonmises_gen._cdfc                 C   s   dS r  r-   rS  r-   r-   r.   _stats_skip$  s    zvonmises_gen._stats_skipc                 C   s8   | t | t | tdtj t |  | S r   )r[   Zi1er3  r>   r   r   rS  r-   r-   r.   r   $  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                    sL   t j t j }	}
|d kr ||	 }|d kr0||
 }t j|||||||f|S r<   )r>   r   r3   r  )r6   r   r7   r%   r&   ZlbZubZconditionalr,   rI  rH  r
  r-   r.   r  $$  s       zvonmises_gen.expect)NN)Nr-   r   r   NNF)ra   rb   rc   rd   rU   r   r	   r   r   rY   r   rZ   r  r   r   r  r  r-   r-   r
  r.   r  #  s   

  r  r  vonmises_linec                   @   sp   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S )r  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 r<   r-   rT   r-   r-   r.   rU   P$  s    zwald_gen._shape_infoNc                 C   s   |j dd|dS r  r  r   r-   r-   r.   r   S$  s    zwald_gen._rvsc                 C   s   t |dS r   )r  rY   rx   r-   r-   r.   rY   V$  s    zwald_gen._pdfc                 C   s   t |dS r   )r  rZ   rx   r-   r-   r.   rZ   Z$  s    zwald_gen._cdfc                 C   s   t |dS r   )r  r\   rx   r-   r-   r.   r\   ]$  s    zwald_gen._sfc                 C   s   t |dS r   )r  r_   rx   r-   r-   r.   r_   `$  s    zwald_gen._ppfc                 C   s   t |dS r   )r  r`   rx   r-   r-   r.   r`   c$  s    zwald_gen._isfc                 C   s   t |dS r   )r  r   rx   r-   r-   r.   r   f$  s    zwald_gen._logpdfc                 C   s   t |dS r   )r  r   rx   r-   r-   r.   r   i$  s    zwald_gen._logcdfc                 C   s   t |dS r   )r  r   rx   r-   r-   r.   r   l$  s    zwald_gen._logsfc                 C   s   dS )N)rf   rf   r$  r-  r-   rT   r-   r-   r.   r   o$  s    zwald_gen._stats)NN)ra   rb   rc   rd   r   r   r   rU   r   rY   rZ   r\   r_   r`   r   r   r   r   r-   r-   r-   r.   r  9$  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 )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-   ri  r-   r-   r.   rO   $  s    zwrapcauchy_gen._argcheckc                 C   s   t ddddgS )Nr,  F)r   r   r   r>  rT   r-   r-   r.   rU   $  s    zwrapcauchy_gen._shape_infoc                 C   s4   d||  dt j d||  d| t |    S r  r  r.  r-   r-   r.   rY   $  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   r>   r   rm  ro  rX   crr-   r-   r.   r  $  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.   rG  $  s    zwrapcauchy_gen._cdf.<locals>.f2r   r  )r   r>   r   )r6   rX   r,  r  rG  r  r-   r-   r.   rZ   $  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 )Nrf   rD   r   rm   )r>   rm  ro  r   r&  )r6   r^   r,  r'  ZrcqZrcmqr-   r-   r.   r_   $  s    ,zwrapcauchy_gen._ppfc                 C   s   t dt j d||   S r  r   ri  r-   r-   r.   r   $  s    zwrapcauchy_gen._entropyc                 C   s    dt |t |dt j  fS r  )r>   r  r  r   r  r-   r-   r.   r	  $  s    zwrapcauchy_gen._fitstartN)ra   rb   rc   rd   rO   rU   rY   rZ   r_   r   r	  r-   r-   r-   r.   r  v$  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   rR   rT   r-   r-   r.   rU   $  s    zgennorm_gen._shape_infoc                 C   s   t | ||S r<   r#  r6   rX   r   r-   r-   r.   rY   $  s    zgennorm_gen._pdfc                 C   s(   t d| td|  t||  S rl   )r>   r   r[   r  r  r  r-   r-   r.   r   $  s    zgennorm_gen._logpdfc                 C   s2   dt | }d| |td| t||   S rl   )r>   r?   r[   r  r  r6   rX   r   r,  r-   r-   r.   rZ   $  s    zgennorm_gen._cdfc                 C   s:   t |d }|td| d| d| |  d|   S )Nrm   rf   r|   )r>   r?   r[   r  r  r-   r-   r.   r_   $  s    zgennorm_gen._ppfc                 C   s   |  | |S r<   rE  r  r-   r-   r.   r\   $  s    zgennorm_gen._sfc                 C   s   |  || S r<   rG  r  r-   r-   r.   r`   $  s    zgennorm_gen._isfc                 C   sN   t d| d| d| g\}}}dt|| dt|| d|  d fS )Nrf   r$  r  re   r|   )r[   r  r>   r}   )r6   r   Zc1c3Zc5r-   r-   r.   r   $  s    "zgennorm_gen._statsc                 C   s$   d| t d|  td|  S r  r  r6   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  rm   )r  r>   r   randomr  )r6   r   r   r   r  r^  r  r-   r-   r.   r   %  s    
zgennorm_gen._rvs)NN)ra   rb   rc   rd   rU   rY   r   rZ   r_   r\   r`   r   r   r   r-   r-   r-   r.   r  $  s   *r  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 r  rR   rT   r-   r-   r.   rU   4%  s    zhalfgennorm_gen._shape_infoc                 C   s   t | ||S r<   r#  r  r-   r-   r.   rY   7%  s    zhalfgennorm_gen._pdfc                 C   s    t |td|  ||  S r   r  r  r-   r-   r.   r   =%  s    zhalfgennorm_gen._logpdfc                 C   s   t d| || S r   r  r  r-   r-   r.   rZ   @%  s    zhalfgennorm_gen._cdfc                 C   s   t d| |d|  S r   r  r  r-   r-   r.   r_   C%  s    zhalfgennorm_gen._ppfc                 C   s   t d| || S r   r  r  r-   r-   r.   r\   F%  s    zhalfgennorm_gen._sfc                 C   s   t d| |d|  S r   rj  r  r-   r-   r.   r`   I%  s    zhalfgennorm_gen._isfc                 C   s    d| t | td|  S r   r  r  r-   r-   r.   r   L%  s    zhalfgennorm_gen._entropyN)ra   rb   rc   rd   rU   rY   r   rZ   r_   r\   r`   r   r-   r-   r-   r.   r  %  s   #r  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.

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

    %(after_notes)s

    .. versionadded:: 0.19.0

    %(example)s
    c                 C   s   |dk|dk@ S )z@
        Shape parameter bounds are m > 1 and beta > 0.
        r   r   r-   )r6   r   r  r-   r-   r.   rO   w%  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   r  r   rR   )r6   ZibetaZimr-   r-   r.   rU   }%  s    zcrystalball_gen._shape_infoc                    s   t  j|ddS )N)r   r  r  r  r  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
                                            --
        rf   r   rD   r|   c                 S   s   t | d  d S r   r  rX   r   r  r-   r-   r.   rhs%  s    z!crystalball_gen._pdf.<locals>.rhsc                 S   s6   || | t |d  d  || | |  |   S r{   r  r  r-   r-   r.   lhs%  s    z!crystalball_gen._pdf.<locals>.lhsr  r>   r}   r~   r   r   r6   rX   r   r  r  r  r  r-   r-   r.   rY   %  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.
        rf   r   rD   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  )r>   r}   r~   r   r   r   r  r-   r-   r.   r   %  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
        rf   r   rD   r|   c                 S   s:   || t |d  d  |d  tt| t|    S NrD   r|   r   r>   r}   r~   r   r  r-   r-   r.   r  %  s    "z!crystalball_gen._cdf.<locals>.rhsc                 S   sB   || | t |d  d  || | |  | d   |d  S r  r  r  r-   r-   r.   r  %  s
    z!crystalball_gen._cdf.<locals>.lhsr  r  r  r-   r-   r.   rZ   %  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 )
Nrf   r   rD   r|   c                 S   sv   t |d  d }|| | |d  }d|tt|   }|| | |d || |   | |  | dd|    S r  r  r  r   r  Zeb2Cr  r-   r-   r.   ppf_less%  s    
,z&crystalball_gen._ppf.<locals>.ppf_lessc                 S   s^   t |d  d }|| | |d  }d|tt|   }tt| dt | | |   S r  )r>   r}   r~   r   r   r  r-   r-   r.   ppf_greater%  s    z)crystalball_gen._ppf.<locals>.ppf_greaterr  r  )r6   r  r   r  r  Zpbetar  r  r-   r-   r.   r_   %  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.
        rf   r   rD   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
            rD   r|   r   rf   re  )	r>   r}   r[   r  r  r  r  r  Zbinom)rN   r   r  r  Br  r  r6  r-   r-   r.   r  %  s      &,z*crystalball_gen._munp.<locals>.n_th_momentr  )r>   r}   r~   r   r   r  r  rS   )r6   rN   r   r  r  r  r-   r-   r.   r   %  s    $
zcrystalball_gen._munp)ra   rb   rc   rd   rO   rU   r	  rY   r   rZ   r_   r   r  r-   r-   r
  r.   r  S%  s   #r  crystalballzA Crystalball Function)rj   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  rD   r  )r  r-   r-   r.   
_argus_phi%  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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.

    %(after_notes)s

    References
    ----------
    .. [1] "ARGUS distribution",
           https://en.wikipedia.org/wiki/ARGUS_distribution

    .. versionadded:: 0.19.0

    %(example)s
    c                 C   s   t dddtjfdgS )Nr  Fr   r   rR   rT   r-   r-   r.   rU   !&  s    zargus_gen._shape_infoc              
   C   s   t jddl d||  }dt | t t t| }|t | dt | |   |d | d  W  5 Q R  S Q R X d S )Nr   r   rf   r  rm   rD   )r>   r   r   r   r  r  )r6   rX   r  r^  r  r-   r-   r.   r   $&  s     zargus_gen._logpdfc                 C   s   t | ||S r<   r#  r6   rX   r  r-   r-   r.   rY   +&  s    zargus_gen._pdfc                 C   s   d|  || S r   r*  r  r-   r-   r.   rZ   .&  s    zargus_gen._cdfc                 C   s"   t |td|d   t | S r   )r  r>   r   r  r-   r-   r.   r\   1&  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   )r  r   r  r  r  c                 3   s(   | ] } | sj | ntd V  qd S r<   r  r  r  r-   r.   r  A&  s   z!argus_gen._rvs.<locals>.<genexpr>r   r-   )r>   r   r   r  r   r  r&  r  r  r   r  r  r  r  r\  r  )	r6   r  r   r   r  r  r  r  r}  r-   r  r.   r   4&  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   rm   rD   r  gUUUUUU?r   g?r  )r  r>   r  r&  r  r  r  r   r  r   r}   ri  r\  )r6   r  r  r   r  r  rX   r  r|  r>  r6  r  r  r  r  r  r   ZechirW  r-   r-   r.   r  L&  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	| ||   ||< ||  }dd	d
d	dd	dd	dg	}t 
|||| < |||d  d d fS )Nr  r   r   rD   r   g?r  g_1g־r   gWBagp|RH?gE'卡?g?)r>   r   r  r  r   r   r[   r  rt  r   r  )r6   r  r  r  r   r  r,  Zcoefr-   r-   r.   r   &  s    ,
(
zargus_gen._stats)NN)NN)ra   rb   rc   rd   rU   r   rY   rZ   r\   r   r  r   r-   r-   r-   r.   r  %  s   $

er  arguszAn Argus Function)rj   r  rh   ri   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_histograma  
    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                   s^  || _ || _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k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|| 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.
        rD   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.Nre  zjBin widths are not constant. Assuming `density=True`.Specify `density` explicitly to silence this warning.r  Tre   rh   ri   )
_histogram_densityr  r   r>   r   _hpdf_hbins_hbin_widthsZallcloser   rs  rt  r  r  Zcumsum_hcdfZhstackrh   ri   r3   r   )r6   	histogramr  r7   kwargsZ	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
        r0  )Zside)r  r>   Zsearchsortedr  rx   r-   r-   r.   rY   R'  s    zrv_histogram._pdfc                 C   s   t || j| jS )z3
        CDF calculated from the histogram
        )r>   interpr  r  rx   r-   r-   r.   rZ   X'  s    zrv_histogram._cdfc                 C   s   t || j| jS )zC
        Percentile function calculated from the histogram
        )r>   r  r  r  rx   r-   r-   r.   r_   ^'  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   Nre  )r  r>   r  r  )r6   rN   Z	integralsr-   r-   r.   r   d'  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   re  re   )r   r  r>   r   r  r  )r6   r  r-   r-   r.   r   i'  s    zrv_histogram._entropyc                    s"   t   }| j|d< | j|d< |S )zF
        Set the histogram as additional constructor argument
        r  r  )r3   _updated_ctor_paramr  r  )r6   dctr
  r-   r.   r  q'  s    


z rv_histogram._updated_ctor_param)ra   rb   rc   rd   r   r   r   rY   rZ   r_   r   r   r  r  r-   r-   r
  r.   r  &  s   Z0r  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 r*  r-   )r6   r6  r{  r-   r-   r.   rO   '  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 )Nr6  Fr   r   r{  r   rR   )r6   r  r  r-   r-   r.   rU   '  s    z!studentized_range_gen._shape_infoc                    s   t t| j|ddS )N)rD   r   r  )r3   r  r	  r  r
  r-   r.   r	  '  s    zstudentized_range_gen._fitstartc                    s@   d|   \  fdd}t|dd}t||||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   ra  -q=ZepsabsZepsrelrangesopts)r   _studentized_range_pdf_logconstr>   r  r  r  r  r  r
   r  rS   dictr   nquad)	r  r6  r{  	log_constargusr_datar  r  r  rI  rH  cython_symbolr-   r.   _single_moment'  s    z3studentized_range_gen._munp.<locals>._single_momentr  r   )ro   r>   
frompyfuncr  )r6   r  r6  r{  r  ufuncr-   r  r.   r   '  s
    zstudentized_range_gen._munpc                 C   s(   dd }t |dd}t ||||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_asymptoticra  r  r  r  )r   r  r>   r  r  r  r  r  rS   r
   r  r  r   r  
r^   r6  r{  r  r  r  r  r  r  r  r-   r-   r.   _single_pdf(  s    z/studentized_range_gen._pdf.<locals>._single_pdfr  r   )r>   r  r  )r6   rX   r6  r{  r  r  r-   r-   r.   rY   (  s    zstudentized_range_gen._pdfc                 C   s2   dd }t |dd}t t ||||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 )	Nr  Z_studentized_range_cdfr   Z!_studentized_range_cdf_asymptoticra  r  r  r  )r   Z_studentized_range_cdf_logconstr>   r  r  r  r  r  rS   r
   r  r  r   r  r  r-   r-   r.   _single_cdf&(  s    z/studentized_range_gen._cdf.<locals>._single_cdfr  r   r   )r>   r  r  r  )r6   rX   r6  r{  r  r  r-   r-   r.   rZ   $(  s    zstudentized_range_gen._cdf)ra   rb   rc   rd   rO   rU   r	  r   rY   rZ   r  r-   r-   r
  r.   r  {'  s   nr  studentized_range)rj   rh   ri   )N(A  r   collections.abcr   	functoolsr   r   r  Znumpyr>   Znumpy.polynomialr   Zscipy._lib.doccerr   r   r	   Zscipy._lib._ccallbackr
   Zscipyr   r   Zscipy.specialspecialr[   Zscipy.special._ufuncsZ_ufuncsrV   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"   Zscipy.stats._boostr  r   Zscipy.optimizer#   Zscipy.stats._warnings_errorsr$   Zscipy.statsr/   r;   rH   rI   rg   rk   ru   rw   rz   r   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   r  r)  r*  r;  r<  rb  rc  rf  rg  rj  rk  rx  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)  r0  r1  r?  r@  rD  rE  r[  rf  rg  r  rq  rv  rw  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"  r3  r4  r7  r8  r>  r?  rA  rB  rC  rI  rT  r  ra  rf  rg  ri  rj  rk  ru  rw  rx  r|  r~  r  r  r  r  r  r  r  Z_gibrat_method_namesr  Z	deprecategetattrr:   setattrr  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+  r.  r/  r0  r4  r5  r9  r:  r<  r=  r@  rA  rO  rP  rX  rY  rd   rZ  r^  r_  r`  rb  rc  rl  rm  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  rS   r  listglobalsr
  itemspairsZ_distn_namesZ_distn_gen_names__all__r-   r-   r-   r.   <module>   sr  $ <@8
o
6(-	 @C7{PK3
DC59
;
mN
B5M)[: k
G8
x5 
/ $6T2 P
*
L
+53(
9Jv  9 
C22
H
[
.een
G
4 6                 ;>  8\NWZiM 6 4  ,(:y_?5<A IjI:) 3]2
 8X:=W@  G 7 H

