
    Џkh2                       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Z	d dl
m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c mZ d d
lmZ d dlm c 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/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ ddlAmBZB d dlCmDZD d dlEmFZF d dlGmHZH d ZId ZJddZK G d de/      ZL eLddd      ZM G d de/      ZN eNd ddd       ZO G d! d"e/      ZP ePdd#$      ZQ e	j                  d%e	j                  z        ZT e	j                  eT      ZVd& ZWd' ZXd( ZYd) ZZd* Z[d+ Z\d, Z]d- Z^ G d. d/e/      Z_ e_d01      Z` G d2 d3e/      Za eadd4$      Zb G d5 d6e/      Zc ece	j                   d7z  e	j                  d7z  d8      Zd G d9 d:e/      Ze eeddd;      Zf G d< d=eg      Zh G d> d?eF      Zid@ ZjdA Zk G dB dCe/      Zl eldddD      Zm G dE dFe/      Zn enddG$      Zo G dH dIe/      Zp epdddJ      Zq G dK dLe/      Zr erddM$      Zs G dN dOe/      Zt etddP$      Zu G dQ dRer      Zv evddS$      Zw G dT dUe/      Zx exdV1      Zy G dW dXe/      Zz ezddY$      Z{ G dZ d[e/      Z| e|dd\$      Z} G d] d^e/      Z~ e~e	j                   e	j                  d_      Z G d` dae/      Z edb1      Z G dc dde/      Z ed de$      Z G df dge/      Z edh1      Z G di dje/      Z eddk$      Z G dl dme/      Z edn1      Zdo Z G dp dqe/      Z eddr$      Z G ds dte/      Z eddu$      Z G dv dwe/      Z eddx$      Z G dy dze/      Z edd{$      Z G d| d}e/      Z edd~$      Z G d de/      Z edd$      Z G d de/      Z edd$      Z G d de/      Z ed1      Zde_         G d de/      Z edd      Z G d de/      Z ed1      Z G d de/      Z edd$      Z G d de/      Z edd$      Z G d de/      Z ed1      Zd Z G d de/      Z edd$      Z G d de      Z edd$      Z G d de/      Z edd$      Z G d de/      Z edd$      Z G d de/      Z ed1      Z G d de/      Z edd$      Zd Z G d de/      Z ed1      Z G d de/      Z ed1      Z G d de/      Z edd$      Z G d de/      Z edd$      Z G d de/      Z edd$      Z G d de/      Z ed1      Z G d de/      Z eddd      Z G d de/      Z eddĬ$      Z G dń de/      Z eddǬ$      Z G dȄ de/      Z eddʬ$      Z G d˄ de/      Z edͬ1      Z G d΄ de/      Z ed dЬ$      Z G dф de/      Z edӬ1      Z G dԄ de/      Z eddd֬      Z G dׄ de/      Z ed٬1      Z G dڄ de/      Z edܬ1      Z G d݄ de/      Z ed߬1      Z G d de/      Z ed1      Zd Z G d de/      Z edd$      Z G d de/      Z edd鬌      Z G d de/      Z ed1      Z G d de/      Z ed1      Z G d de/      Z edd$      Zd Z G d de/      Z edd$      Z G d de/      Z edd$      Z G d de/      Z edd$      Z G d de/      Z edd$      Z G d  de/      Z ed1      Z G d de/      Z edd$      Z G d de/      Z ed1      Z G d	 d
e/      Z edd$      Zd Z G d de/      Z edd$      Z G d de/      Z edd$      Z G d de/      Z ed1      Z G d de/      Z ed1      Z G d de/      Z edd$      Z G d de/      Z edd$      Z  G d d e/      Z ed!1      Z G d" d#e/      Z eddd$      Z G d% d&e/      Z edd'$      Z G d( d)e/      Z ed*1      Z G d+ d,e/      Z	 e	d-dd.      Z
 G d/ d0e/      Z edd1$      Z G d2 d3e/      Z ed41      Z ed51      Zde_        de_         G d6 d7e/      Z edd8$      Z G d9 d:e/      Z ed;1      Zd<e_         G d= d>e/      Z edd?$      Z G d@ dAe/      Z ed-ddB      Z G dC dDe/      Z edE1      Z G dF dGe/      Z edH1      Z G dI dJe/      Z edddK      Z G dL dMe/      Z edddN      Z G dO dPe/      Z  e ddQ$      Z!dRe!_        dS Z"dT Z#dU Z$ G dV dWe/      Z% e%dXdY      Z&de&_         G dZ d[e/      Z' e'dd\$      Z(d]e(_         G d^ d_e/      Z) e)d`1      Z* G da dbeh      Z+ G dc dde/      Z, e,ddde      Z- G df dge/      Z. e.dh1      Z/ e.e	j                   e	j                  di      Z0 G dj dkeī      Z1 e1ddl$      Z2 G dm dne/      Z3 e3dd%e	j                  z  do      Z4 G dp dqe/      Z5 e5dr1      Z6 G ds dte/      Z7 e7d du$      Z8 G dv dwe/      Z9 e9dxdyz      Z:d{ Z; G d| d}e/      Z< e<d~ddd      Z= G d de/      Z> G d de/      Z? e?dd e	j                        ZA G d de/      ZB eBdd$      ZC eD eE       j                         j                               ZH e,eHe/      \  ZIZJeIeJz   dgz   ZKy(      N)Iterable)wrapscached_property
Polynomial)BSpline)extend_notes_in_docstringreplace_notes_in_docstringinherit_docstring_from)LowLevelCallable)optimize)	integrate_lazyselect   )_stats)tukeylambda_variancetukeylambda_kurtosis)	_vectorize_rvs_over_shapesget_distribution_names	_kurtosis_isintegralrv_continuous_skew_get_fixed_fit_value_check_shape
_ShapeInfo)kolmognkolmognpkolmogni)_XMIN_LOGXMIN_EULER_ZETA3_SQRT_PI_SQRT_2_OVER_PI_LOG_PI_LOG_SQRT_2_OVER_PI)CensoredData)root_scalar)FitErrorc                     | j                  dd       | j                  dd       | j                  dd       | j                  dd       | rt        d|  d      y)a  
    Remove the optimizer-related keyword arguments 'loc', 'scale' and
    'optimizer' from `kwds`.  Then check that `kwds` is empty, and
    raise `TypeError("Unknown arguments: %s." % kwds)` if it is not.

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

    `kwds` is modified in-place.
    locNscale	optimizermethodzUnknown arguments: .)pop	TypeError)kwdss    Z/var/www/teggl/fontify/venv/lib/python3.12/site-packages/scipy/stats/_continuous_distns.py_remove_optimizer_parametersr6   (   sY     	HHUDHHWdHH[$HHXt-dV1566     c                 .     t                fd       }|S )Nc                    |j                  dd      j                         }t        |t              }|dk(  s|r/|j	                         dkD  rt        t        |       |   |g|i |S |r|j                  } | |g|i |S )Nr0   mlemmr   )	getlower
isinstancer)   num_censoredsupertypefit_uncensored)selfdataargsr4   r0   censoredfuns         r5   wrapperz _call_super_mom.<locals>.wrapper?   s    (E*002dL1T>h4+<+<+>+BdT.tCdCdCC ''tT1D1D11r7   )r   )rH   rI   s   ` r5   _call_super_momrJ   ;   s"     3Z2 2 Nr7   c                      |xs |dz
  }||z
  } fd} |||      s6|dz  }||z
  }d}t        j                  |      rt        |       |||      s6|S )Nr   c                 r    t        j                   |             t        j                   |            k7  S Nnpsign)lbrackrbrackrH   s     r5   interval_contains_rootz1_get_left_bracket.<locals>.interval_contains_rootW   s(    wws6{#rwws6{';;;r7      zVThe solver could not find a bracket containing a root to an MLE first order condition.)rO   isinfFitSolverError)rH   rR   rQ   diffrS   msgs   `     r5   _get_left_bracketrY   P   sn    !vzFF?D< %VV4	$788F %% %VV4 Mr7   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
	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).

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

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

    >>> n = 1e+03
    >>> x = np.linspace(ksone.ppf(0.01, n),
    ...                 ksone.ppf(0.99, n), 100)
    >>> ax.plot(x, ksone.pdf(x, n),
    ...         'r-', lw=5, alpha=0.6, label='ksone 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 = ksone(n)
    >>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')
    >>> ax.legend(loc='best', frameon=False)
    >>> plt.show()

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

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

    c                 >    |dk\  |t        j                  |      k(  z  S Nr   rO   roundrD   ns     r5   	_argcheckzksone_gen._argcheck       Q1+,,r7   c                 @    t        dddt        j                  fd      gS Nra   Tr   TFr   rO   infrD   s    r5   _shape_infozksone_gen._shape_info       3q"&&k=ABBr7   c                 0    t        j                  ||       S rM   )scu	_smirnovprD   xra   s      r5   _pdfzksone_gen._pdf   s    a###r7   c                 .    t        j                  ||      S rM   )rm   	_smirnovcro   s      r5   _cdfzksone_gen._cdf   s    }}Q""r7   c                 .    t        j                  ||      S rM   )scsmirnovro   s      r5   _sfzksone_gen._sf   s    zz!Qr7   c                 .    t        j                  ||      S rM   )rm   
_smirnovcirD   qra   s      r5   _ppfzksone_gen._ppf   s    ~~a##r7   c                 .    t        j                  ||      S rM   )rv   smirnovir{   s      r5   _isfzksone_gen._isf       {{1a  r7   N)__name__
__module____qualname____doc__rb   rj   rq   rt   rx   r}   r    r7   r5   r[   r[   g   s-    BF-C$# $!r7   r[                 ?ksone)abnamec                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)	kstwo_genad  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).

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

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

    >>> n = 10
    >>> x = np.linspace(kstwo.ppf(0.01, n),
    ...                 kstwo.ppf(0.99, n), 100)
    >>> ax.plot(x, kstwo.pdf(x, n),
    ...         'r-', lw=5, alpha=0.6, label='kstwo 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 = kstwo(n)
    >>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')
    >>> ax.legend(loc='best', frameon=False)
    >>> plt.show()

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

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

    c                 >    |dk\  |t        j                  |      k(  z  S r]   r^   r`   s     r5   rb   zkstwo_gen._argcheck  rc   r7   c                 @    t        dddt        j                  fd      gS re   rg   ri   s    r5   rj   zkstwo_gen._shape_info
  rk   r7   c                 b    dt        |t              s|z  dfS t        j                  |      z  dfS N      ?r   )r>   r   rO   
asanyarrayr`   s     r5   _get_supportzkstwo_gen._get_support  s;    jH5QL 	2==;KL 	r7   c                     t        ||      S rM   )r   ro   s      r5   rq   zkstwo_gen._pdf  s    1~r7   c                     t        ||      S rM   r   ro   s      r5   rt   zkstwo_gen._cdf  s    q!}r7   c                     t        ||d      S NFcdfr   ro   s      r5   rx   zkstwo_gen._sf  s    q!''r7   c                     t        ||d      S )NTr   r    r{   s      r5   r}   zkstwo_gen._ppf  s    1$''r7   c                     t        ||d      S r   r   r{   s      r5   r   zkstwo_gen._isf  s    1%((r7   N)r   r   r   r   rb   rj   r   rq   rt   rx   r}   r   r   r7   r5   r   r      s2    AD-C(()r7   r   kstwo)momtyper   r   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	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                     g S rM   r   ri   s    r5   rj   zkstwobign_gen._shape_infoJ      	r7   c                 .    t        j                  |       S rM   )rm   _kolmogprD   rp   s     r5   rq   zkstwobign_gen._pdfM  s    Qr7   c                 ,    t        j                  |      S rM   )rm   _kolmogcr   s     r5   rt   zkstwobign_gen._cdfP  s    ||Ar7   c                 ,    t        j                  |      S rM   )rv   
kolmogorovr   s     r5   rx   zkstwobign_gen._sfS  s    }}Qr7   c                 ,    t        j                  |      S rM   )rm   	_kolmogcirD   r|   s     r5   r}   zkstwobign_gen._ppfV  s    }}Qr7   c                 ,    t        j                  |      S rM   )rv   kolmogir   s     r5   r   zkstwobign_gen._isfY  s    zz!}r7   N)
r   r   r   r   rj   rq   rt   rx   r}   r   r   r7   r5   r   r   %  s&    #H   r7   r   	kstwobign)r   r   rT   c                 H    t        j                  | dz   dz        t        z  S NrT          @)rO   exp_norm_pdf_Crp   s    r5   	_norm_pdfr   i  s     661a4%){**r7   c                 "    | dz   dz  t         z
  S r   )_norm_pdf_logCr   s    r5   _norm_logpdfr   m  s    qD53;''r7   c                 ,    t        j                  |       S rM   )rv   ndtrr   s    r5   	_norm_cdfr   q  s    771:r7   c                 ,    t        j                  |       S rM   )rv   log_ndtrr   s    r5   _norm_logcdfr   u  s    ;;q>r7   c                 ,    t        j                  |       S rM   )rv   ndtrir|   s    r5   	_norm_ppfr   y  s    88A;r7   c                     t        |        S rM   r   r   s    r5   _norm_sfr   }  s    aR=r7   c                     t        |        S rM   r   r   s    r5   _norm_logsfr     s    r7   c                     t        |        S rM   r   r   s    r5   	_norm_isfr     s    aL=r7   c                       e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Ze eed      d               Zd Zy)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                     g S rM   r   ri   s    r5   rj   znorm_gen._shape_info  r   r7   Nc                 $    |j                  |      S rM   )standard_normalrD   sizerandom_states      r5   _rvsznorm_gen._rvs  s    ++D11r7   c                     t        |      S rM   r   r   s     r5   rq   znorm_gen._pdf  s    |r7   c                     t        |      S rM   r   r   s     r5   _logpdfznorm_gen._logpdf      Ar7   c                     t        |      S rM   r   r   s     r5   rt   znorm_gen._cdf      |r7   c                     t        |      S rM   r   r   s     r5   _logcdfznorm_gen._logcdf  r   r7   c                     t        |      S rM   r   r   s     r5   rx   znorm_gen._sf  s    {r7   c                     t        |      S rM   )r   r   s     r5   _logsfznorm_gen._logsf  s    1~r7   c                     t        |      S rM   r   r   s     r5   r}   znorm_gen._ppf  r   r7   c                     t        |      S rM   r   r   s     r5   r   znorm_gen._isf  r   r7   c                      y)N)r   r   r   r   r   ri   s    r5   r   znorm_gen._stats      !r7   c                 Z    dt        j                  dt         j                  z        dz   z  S Nr   rT   r   rO   logpiri   s    r5   _entropyznorm_gen._entropy  s"    BFF1RUU7OA%&&r7   a}          For the normal distribution, method of moments and maximum likelihood
        estimation give identical fits, and explicit formulas for the estimates
        are available.
        This function uses these explicit formulas for the maximum likelihood
        estimation of the normal distribution parameters, so the
        `optimizer` and `method` arguments are ignored.

notesc                    |j                  dd       }|j                  dd       }t        |       ||t        d      t        j                  |      }t        j
                  |      j                         st        d      ||j                         }n|}|-t        j                  ||z
  dz  j                               }||fS |}||fS )Nflocfscale3All parameters fixed. There is nothing to optimize.$The data contains non-finite values.rT   )	r2   r6   
ValueErrorrO   asarrayisfiniteallmeansqrt)rD   rE   r4   r   r   r-   r.   s          r5   rB   znorm_gen.fit  s     xx%(D)$T* 2  ) * * zz${{4 $$&CDD<))+CC>GGdSj1_2245E Ez EEzr7   c                 b    |dk(  ry|dz  dk(  r!t        j                  t        |      dz
        S y)z
        @returns Moments of standard normal distribution for integer n >= 0

        See eq. 16 of https://arxiv.org/abs/1209.4340v2
        r   r   rT   r   r   )rv   
factorial2intr`   s     r5   _munpznorm_gen._munp  s3     6q5A:==Q!,,r7   NN)r   r   r   r   rj   r   rq   r   rt   r   rx   r   r}   r   r   r   rJ   r
   r   rB   r  r   r7   r5   r   r     sr    ,2"'  6? @@ <r7   r   norm)r   c                   L    e Zd ZdZej
                  Zd Zd Zd Z	d Z
d Zd Zy)		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                 @    t        dddt        j                  fd      gS Nr   Fr   FFrg   ri   s    r5   rj   zalpha_gen._shape_info      3266{NCDDr7   c                 N    d|dz  z  t        |      z  t        |d|z  z
        z  S Nr   rT   )r   r   rD   rp   r   s      r5   rq   zalpha_gen._pdf!  s+    AqDz)A,&y3q5'999r7   c                     dt        j                  |      z  t        |d|z  z
        z   t        j                  t        |            z
  S )Nr   )rO   r   r   r   r  s      r5   r   zalpha_gen._logpdf%  s8    "&&)|l1SU733bffYq\6JJJr7   c                 <    t        |d|z  z
        t        |      z  S Nr   r   r  s      r5   rt   zalpha_gen._cdf(  s    3q5!IaL00r7   c           
      b    dt        j                  |t        |t        |      z        z
        z  S r  )rO   r   r   r   rD   r|   r   s      r5   r}   zalpha_gen._ppf+  s(    2::a)AilN";;<<<r7   c                 T    t         j                  gdz  t         j                  gdz  z   S NrT   rO   rh   nanrD   r   s     r5   r   zalpha_gen._stats.  s!    xzRVVHQJ&&r7   N)r   r   r   r   r   _open_support_mask_support_maskrj   rq   r   rt   r}   r   r   r7   r5   r  r    s4    > "44ME:K1='r7   r  alphac                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)

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                     g S rM   r   ri   s    r5   rj   zanglit_gen._shape_infoI  r   r7   c                 2    t        j                  d|z        S r  )rO   cosr   s     r5   rq   zanglit_gen._pdfL  s    vvac{r7   c                 Z    t        j                  |t         j                  dz  z         dz  S N   r   rO   sinr   r   s     r5   rt   zanglit_gen._cdfP  s"    vvaai #%%r7   c                 Z    t        j                  |t         j                  dz  z         dz  S r"  )rO   r   r   r   s     r5   rx   zanglit_gen._sfS  s"    vva"%%!)m$++r7   c                 z    t        j                  t        j                  |            t         j                  dz  z
  S Nr#  )rO   arcsinr   r   r   s     r5   r}   zanglit_gen._ppfV  s&    yy$RUU1W,,r7   c                     dt         j                  t         j                  z  dz  dz
  ddt         j                  dz  dz
  z  t         j                  t         j                  z  dz
  dz  z  fS )	Nr      r   r  r#  `      rT   rO   r   ri   s    r5   r   zanglit_gen._statsY  sR    BEE"%%KN3&RB-?ruuQQR@R-RRRr7   c                 2    dt        j                  d      z
  S Nr   rT   rO   r   ri   s    r5   r   zanglit_gen._entropy\      {r7   N)r   r   r   r   rj   rq   rt   rx   r}   r   r   r   r7   r5   r  r  5  s+    &&,-Sr7   r  r#  anglitc                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	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                     g S rM   r   ri   s    r5   rj   zarcsine_gen._shape_infow  r   r7   c                     t        j                  d      5  dt         j                  z  t        j                  |d|z
  z        z  cd d d        S # 1 sw Y   y xY w)Nignoredivider   r   )rO   errstater   r   r   s     r5   rq   zarcsine_gen._pdfz  sD    [[) 	.ruu9RWWQ!W--	. 	. 	.s   /AAc                 z    dt         j                  z  t        j                  t        j                  |            z  S Nr   )rO   r   r)  r   r   s     r5   rt   zarcsine_gen._cdf  s&    255y2771:...r7   c                 Z    t        j                  t         j                  dz  |z        dz  S r=  r$  r   s     r5   r}   zarcsine_gen._ppf  s"    vvbeeCik"C''r7   c                     d}d}d}d}||||fS )Nr   g      ?r         r   rD   mumu2g1g2s        r5   r   zarcsine_gen._stats  s$    3Br7   c                      y)Ngοr   ri   s    r5   r   zarcsine_gen._entropy  s    &r7   N
r   r   r   r   rj   rq   rt   r}   r   r   r   r7   r5   r5  r5  c  s%    &.
/('r7   r5  arcsinec                       e Zd ZdZd Zy)FitDataErrorz=Raised when input data is inconsistent with fixed parameters.c                 (    d|d|d|df| _         y )Nz>Invalid values in `data`.  Maximum likelihood estimation with z requires that z < (x - loc)/scale  < z for each x in `data`.rF   )rD   distrr=   uppers       r5   __init__zFitDataError.__init__  s/    $iui @""'*@B
	r7   Nr   r   r   r   rO  r   r7   r5   rJ  rJ    s
    G
r7   rJ  c                       e Zd ZdZd Zy)rV   zN
    Raised when a solver fails to converge while fitting a distribution.
    c                 B    d}||j                  dd      z  }|f| _        y )Nz1Solver for the MLE equations failed to converge: 
 )replacerF   )rD   mesgemsgs      r5   rO  zFitSolverError.__init__  s%    BT2&&G	r7   NrP  r   r7   r5   rV   rV     s    
r7   rV   c                 t    t        j                  | |z         }||| t        j                  |       z   z  z
  }|S rM   rv   psi)r   r   ra   s1psiabfuncs         r5   _beta_mle_ar^    s8     FF1q5MEeVbffQi'((DKr7   c                     | \  }}t        j                  ||z         }||| t        j                  |      z   z  z
  ||| t        j                  |      z   z  z
  g}|S rM   rY  )thetara   r[  s2r   r   r\  r]  s           r5   _beta_mle_abrb    sb     DAqFF1q5MEufrvvay())ufrvvay())+DKr7   c                        e Zd ZdZd ZddZd Zd Zd Zd Z	d Z
d	 Zd
 Z fdZe eed       fd              Zd Z x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.

    This distribution uses routines from the Boost Math C++ library for
    the computation of the ``pdf``, ``cdf``, ``ppf``, ``sf`` and ``isf``
    methods. [1]_

    %(after_notes)s

    References
    ----------
    .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.

    %(example)s

    c                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS Nr   Fr   r	  r   rg   rD   iaibs      r5   rj   zbeta_gen._shape_info  ;    UQK@UQK@Bxr7   c                 (    |j                  |||      S rM   beta)rD   r   r   r   r   s        r5   r   zbeta_gen._rvs  s      At,,r7   c                     t        j                  d      5  t        j                  |||      cd d d        S # 1 sw Y   y xY wNr8  over)rO   r;  rm   	_beta_pdfrD   rp   r   r   s       r5   rq   zbeta_gen._pdf  s5     [[h' 	*==Aq)	* 	* 	*	   8Ac                     t        j                  |dz
  |       t        j                  |dz
  |      z   }|t        j                  ||      z  }|S r  )rv   xlog1pyxlogybetaln)rD   rp   r   r   lPxs        r5   r   zbeta_gen._logpdf  sE    jjS1"%S!(<<ryyA
r7   c                 0    t        j                  |||      S rM   )rv   betaincrs  s       r5   rt   zbeta_gen._cdf  s    zz!Q""r7   c                 0    t        j                  |||      S rM   )rv   betainccrs  s       r5   rx   zbeta_gen._sf  s    {{1a##r7   c                 0    t        j                  |||      S rM   )rv   betainccinvrs  s       r5   r   zbeta_gen._isf  s    ~~aA&&r7   c                 0    t        j                  |||      S rM   )rm   	_beta_ppfrD   r|   r   r   s       r5   r}   zbeta_gen._ppf   s    }}Q1%%r7   c                 *   ||z   }||z  }||z  |dz  |dz   z  z  }d||z
  z  t        j                  |dz         z  |dz   t        j                  ||z        z  z  }d||z
  dz  |dz   z  ||z  |dz   z  z
  z  }||z  |dz   z  |dz   z  }||z  }	||||	fS )NrT   r         rO   r   )
rD   r   r   a_plus_b
_beta_mean_beta_variance_beta_skewness_beta_kurtosis_excess_n_beta_kurtosis_excess_d_beta_kurtosis_excesss
             r5   r   zbeta_gen._stats  s    q5xZ
1!x!| <=A;A)>>$qLBGGAEN:<"#AzX\'B'(1u1'=(> #?"#a%8a<"8HqL"I 7:Q Q!	# 	#r7   c                     t        |t              r|j                         }t        |      t	        |      fd}t        j                  |d      \  }}t        | !  |||f      S )Nc                 J   | \  }}d||z
  z  t        j                  ||z   dz         z  ||z   dz   z  t        j                  ||z        z  }|dz  |dz  d|z  dz
  z  z
  |dz  |dz   z  z   d|z  |z  |dz   z  z
  }|||z  ||z   dz   z  ||z   dz   z  z  }|dz  }|z
  |z
  gS )NrT   r   r  r  r  )rp   r   r   skkurD  rE  s        r5   r]  z beta_gen._fitstart.<locals>.func  s    DAqAaCQ++q1uqy9BGGAaCLHBA1ac!e$q!tQqSz1AaCE1Q3K?B!A#qs1u+qs1u%%B!GBrE2b5>!r7   )r   r   rL  )	r>   r)   	_uncensorr   r   r   fsolver@   	_fitstart)rD   rE   r]  r   r   rD  rE  	__class__s        @@r5   r  zbeta_gen._fitstart  s_    dL)>>#D4[t_	" tZ01w QF 33r7   z        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           	         |j                  dd       }|j                  dd       }||t        |   |g|i |S |j                  dd        |j                  dd        t	        |g d      }t	        |g d      }t        |       ||t        d      t        j                  |      j                         st        d      t        j                  |      |z
  |z  }t        j                  |dk        st        j                  |dk\        rt        d	|||z   
      |j                         }||||}	d|z
  }d|z
  }n|}	|	|z  d|z
  z  }
t        j                  t         |
|	t#        |      t        j$                  |      j'                         fd      \  }}}}|dk7  rt)        |      |d   }
||	|
}	}
nt        j$                  |      j'                         }t+        j,                  |       j'                         }|d|z
  z  |j/                  d      z  dz
  }||z  }
d|z
  |z  }	t        j                  t0        |
|	gt#        |      ||fd      \  }}}}|dk7  rt)        |      |\  }
}	|
|	||fS )Nr   r   f0fafix_a)f1fbfix_br   r   r   r   rm  r=   rN  T)rF   full_output)rV  )ddof)r<   r@   rB   r2   r   r6   r   rO   r   r   ravelanyrJ  r   r   r  r^  lenr   sumrV   rv   log1pvarrb  )rD   rE   rF   r4   r   r   r  r  xbarr   r   r`  infoierrV  r[  ra  facr  s                     r5   rB   zbeta_gen.fit$  s    xx%(D)<6>7;t3d3d33 	4 !$(=>!$(=>$T*>bn ) * * {{4 $$&CDD %/66$!)tqy 1vTGGyy{>R^ ~ 4x4x DAH%A &.__QTBFF4L$4$4$67 &"E4d
 ax$$//aA~ !1 !!#B4%$$&B !d(#dhhAh&66:Cs
ATS A &.__q!f$iR( &"E4d
 ax$$//DAq!T6!!r7   c                     d }d }d }d }|dk\  r|dk\  r	 |||      S |dk  r||z
  dk\  r| ||      k\  r	 |||      S |dk  r||z
  dk\  r| ||      k\  r	 |||      S  |||      S )Nc                     t        j                  | |      | dz
  t        j                  |       z  z
  |dz
  t        j                  |      z  z
  | |z   dz
  t        j                  | |z         z  z   S r0  )rv   rx  rZ  r   r   s     r5   regularz"beta_gen._entropy.<locals>.regular  sf    IIaOq1uq	&99UbffQi'(+,q519q1u*EF Gr7   c                    | |z   }dt        j                  dt         j                  z        t        j                  |       z   t        j                  |      z   dt        j                  |      z  z
  dz   z  }d|z  d|dz  z  z   |dz  z   d|d	z  z  z
  }d
| z  d| dz  z  z
  | dz  z
  | d	z  z   }d
|z  d|dz  z  z
  |dz  z
  |d	z  z   }|||z   |z   dz  z   S )Nr   rT   r  r   n                         i
   x   r   )r   r   sum_ablog_termt1t2t3s          r5   asymptotic_ab_largez.beta_gen._entropy.<locals>.asymptotic_ab_large  s    UFqw"&&)+bffQi7!BFF6N:JJQNH Vbo-<q~MBQAtG#ag-47BQAtG#ag-47BrBw|s222r7   c                    | |z   }t        j                  |       | dz
  t        j                  |       z  z
  }dd|z  z  dd|z  z  z   |dz  dz  z
  |dz  dz  z
  |dz  dz  z   |d	z  d
z  z   |dz  d
z  z
  d|z  z   dd|z  z  z
  |dz  dz  z   |dz  dz  z   |dz  dz  z
  |d	z  d
z  z
  |dz  dz  z   }|t        j                  | |z        z  t        j
                  |      z   dt        j
                  |      z  z
  }||z   |z   S )Nr   rT      r  r  r  r                 r  <   ~   )rv   gammalnrZ  rO   r  r   )r   r   r  r  r  r  s         r5   asymptotic_b_largez-beta_gen._entropy.<locals>.asymptotic_b_large  sM   UFA!a%266!9!44BQqS	Ar!tH$q$wrz1AtGCK?!T'#+MT'#+ !4,./h79:BvIG$,q.!#)4<#346<dl2oF $,s"# &,T\#%56  bhhqsm+bffQi7!BFF6N:JJH7X%%r7   c                     | dk(  ryt        j                  |       }t        |      }t        | d|z  z        dz   }|dd|z   z  z  S )Nr   i  r  rT      )rO   log10r  )vjdigitsds       r5   threshold_largez*beta_gen._entropy.<locals>.threshold_large  sL    CxAVFAf$%)AR!a%[= r7   g    RAg    (RAg    .Ar   )rD   r   r   r  r  r  r  s          r5   r   zbeta_gen._entropy  s    	G	3
	&	! ;1;&q!,,%ZAESLQ/!2D-D%a++%ZAESLQ/!2D-D%a++1a= r7   r  )r   r   r   r   rj   r   rq   r   rt   rx   r   r}   r   r  rJ   r	   r   rB   r   __classcell__r  s   @r5   rd  rd    sj    >
-*
#$'&# 4" } 5+ ,
c", c"J+!r7   rd  rm  c                   Z    e Zd ZdZej
                  Zd ZddZd Z	d Z
d Zd Zd	 Zd
 Zy)betaprime_gena  A beta prime continuous random variable.

    %(before_notes)s

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

    .. math::

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

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

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

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

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

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

    %(after_notes)s

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

    %(example)s

    c                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS rf  rg   rg  s      r5   rj   zbetaprime_gen._shape_info  rj  r7   Nc                 l    t         j                  |||      }t         j                  |||      }||z  S Nr   r   )gammarvs)rD   r   r   r   r   u1u2s          r5   r   zbetaprime_gen._rvs  s3    YYqt,Y?YYqt,Y?Bwr7   c                 N    t        j                  | j                  |||            S rM   rO   r   r   rs  s       r5   rq   zbetaprime_gen._pdf      vvdll1a+,,r7   c                     t        j                  |dz
  |      t        j                  ||z   |      z
  t        j                  ||      z
  S r  )rv   rw  rv  rx  rs  s       r5   r   zbetaprime_gen._logpdf   s:    xxC#bjjQ&::RYYq!_LLr7   c                 B    t        j                  |dkD  |||fd d       S )Nr   c                 <    t         j                  dd| z   z  ||      S r]   rm  rx   x_a_b_s      r5   <lambda>z$betaprime_gen._cdf.<locals>.<lambda>  s    txxQVb"= r7   c                 <    t         j                  | d| z   z  ||      S r]   rm  rt   r  s      r5   r  z$betaprime_gen._cdf.<locals>.<lambda>  s    tyyq2vB? r7   xpxapply_wherers  s       r5   rt   zbetaprime_gen._cdf  s,     EAq!9=?A 	Ar7   c                 B    t        j                  |dkD  |||fd d       S )Nr   c                 <    t         j                  dd| z   z  ||      S r]   r  r  s      r5   r  z#betaprime_gen._sf.<locals>.<lambda>  s    tyya"fr2> r7   c                 <    t         j                  | d| z   z  ||      S r]   r  r  s      r5   r  z#betaprime_gen._sf.<locals>.<lambda>  s    txxa"fr2> r7   r  rs  s       r5   rx   zbetaprime_gen._sf  s*    EAq!9>>@ 	@r7   c                    t        j                  |||      \  }}}t        j                  j	                  |||      }t        j
                  d      5  |d|z
  z  }d d d        |dkD  }t        j                  |      r+|r'dt        j                  j                  |||      z  dz
  }S dt        j                  j                  ||   ||   ||         z  dz
  |<   |S # 1 sw Y   xY w)Nr8  r9  r   gH.?)rO   broadcast_arraysstatsrm  r}   r;  isscalarr   )rD   pr   r   routrnear1s          r5   r}   zbetaprime_gen._ppf  s    %%aA.1a JJOOAq!$[[) 	q1u+C	V;;q>

1a0014 
 EJJOOAfIqy!F)LLqPCK
	 	s   	CC'c                 b    t        j                  |kD  ||ffdt        j                        S )Nc                     t        j                  t        dt              dz         D cg c]  }| |z   dz
  ||z
  z   c}d      S c c}w )Nr   r   axis)rO   prodranger  )r   r   ira   s      r5   r  z%betaprime_gen._munp.<locals>.<lambda>+  s@    q#a&(9K!LA1Q3q51Q3-!LSTU !Ls   A	
fill_valuer  r  rO   rh   )rD   ra   r   r   s    `  r5   r  zbetaprime_gen._munp(  s+    EAq6Uvv 	r7   r  )r   r   r   r   r   r  r  rj   r   rq   r   rt   rx   r}   r  r   r7   r5   r  r    s@    .^ "44M

-MA@$r7   r  	betaprimec                   6    e Zd ZdZd Zd Zd Zd Zd	dZd Z	y)
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                 @    t        dddt        j                  fd      gS NcFr   r	  rg   ri   s    r5   rj   zbradford_gen._shape_infoH  r
  r7   c                 D    |||z  dz   z  t        j                  |      z  S r  rv   r  rD   rp   r  s      r5   rq   zbradford_gen._pdfK  s!    AaC#I!,,r7   c                 ^    t        j                  ||z        t        j                  |      z  S rM   r  r	  s      r5   rt   zbradford_gen._cdfO  s!    xx!}rxx{**r7   c                 ^    t        j                  |t        j                  |      z        |z  S rM   rv   expm1r  rD   r|   r  s      r5   r}   zbradford_gen._ppfR  s"    xxBHHQK(1,,r7   c                 j   t        j                  d|z         }||z
  ||z  z  }|dz   |z  d|z  z
  d|z  |z  |z  z  }d }d }d|v r{t        j                  d      d|z  |z  d|z  |z  |dz   z  z
  d|z  |z  ||dz   z  dz   z  z   z  }|t        j                  |||dz
  z  d|z  z   z        d|z  |dz
  z  d|z  z   z  z  }d	|v rj|dz  |dz
  z  |d|z  d
z
  z  dz   z  d|z  |z  |z  |dz
  z  |dz
  z  z   d|z  |z  |z  d|z  dz
  z  z   d|dz  z  z   }|d|z  ||dz
  z  d|z  z   dz  z  z  }||||fS )Nr   r   rT   sr  	   r  r  kr+     r#     )rO   r   r   )rD   r  momentsr  rB  rC  rD  rE  s           r5   r   zbradford_gen._statsU  s   FF3q5McAaC[#qyQ1Qq)'>RT!VAaCE1Q3K/!Aq!A#wqy0AABB"''!Q!WQqS[/*AaC1IacM::B'>Q$!*a1Rjm,RT!VAXqs^QqS-AAA#a%'1Q3r6"#%'1W-B!A#q!A#wqs{Q&&&B3Br7   c                 n    t        j                  d|z         }|dz  t        j                  ||z        z
  S Nr   r   r1  )rD   r  r  s      r5   r   zbradford_gen._entropyd  s.    FF1Q3Kurvvac{""r7   NmvrG  r   r7   r5   r  r  2  s&    *E-+-#r7   r  bradfordc                   R    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)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                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS Nr  Fr   r	  r  rg   rD   icids      r5   rj   zburr_gen._shape_info  rj  r7   c                 n    t        j                  |dk(  |||fd d       }|j                  dk(  r|d   S |S )Nr   c                 6    ||z  | ||z  dz
  z  z  d| |z  z   z  S r]   r   r  c_d_s      r5   r  zburr_gen._pdf.<locals>.<lambda>  s(    rBw"r"uQw-8ABJG r7   c                 @    ||z  | | dz
  z  z  d| | z  z   |dz   z  z  S Nr   r   r   r$  s      r5   r  zburr_gen._pdf.<locals>.<lambda>  s6    R22#)+< ="#bbSk/rCx!@!B r7   r   r  r  ndimrD   rp   r  r  outputs        r5   rq   zburr_gen._pdf  sE    FQ1IGCD
 $[[A-vbz969r7   c                 n    t        j                  |dk(  |||fd d       }|j                  dk(  r|d   S |S )Nr   c                     t        j                  |      t        j                  |      z   t        j                  ||z  dz
  |       z   |dz   t        j                  | |z        z  z
  S r]   )rO   r   rv   rw  r  r$  s      r5   r  z"burr_gen._logpdf.<locals>.<lambda>  sQ    r
RVVBZ 7"((2b519b:Q Q#%a4288BH+="=!> r7   c                     t        j                  |      t        j                  |      z   t        j                  | dz
  |       z   t        j                  |dz   | | z        z
  S r]   rO   r   rv   rw  rv  r$  s      r5   r  z"burr_gen._logpdf.<locals>.<lambda>  sQ    r
RVVBZ 7"$((B37B"7!8"$**RT29"=!> r7   r   r)  r+  s        r5   r   zburr_gen._logpdf  sF    FQ1I??	@ $[[A-vbz969r7   c                     d|| z  z   | z  S r]   r   rD   rp   r  r  s       r5   rt   zburr_gen._cdf  s    AGr""r7   c                 <    t        j                  || z        | z  S rM   r  r2  s       r5   r   zburr_gen._logcdf  s    xxQB QB''r7   c                 N    t        j                  | j                  |||            S rM   rO   r   r   r2  s       r5   rx   zburr_gen._sf      vvdkk!Q*++r7   c                 D    t        j                  d|| z  z   | z         S r]   rO   r  r2  s       r5   r   zburr_gen._logsf  s%    xx1qA2w;1"--..r7   c                 $    |d|z  z  dz
  d|z  z  S N      r   r   rD   r|   r  r  s       r5   r}   zburr_gen._ppf  s    DFa46**r7   c                 l    t        j                  d|z  |       }t        j                  |      d|z  z  S Nr;  rv   rv  r  )rD   r|   r  r  _qs        r5   r   zburr_gen._isf  s/    ZZq1"%xx|q))r7   c                    t        j                  dd      j                  dd      |z  }t        j                  ||z   d|z
        |z  \  }}}}t        j
                  |dkD  |t         j                        }||dz  z
  }	t        j
                  |dkD  |	t         j                        }
t        j                  |dkD  ||||	fd t         j                  	      }t        j                  |d
kD  |||||	fd t         j                  	      }t        j                  |      dk(  r>|j                         |
j                         |j                         |j                         fS ||
||fS )Nr      r#  r   rT   r         @c                 \    |d|z  | z  z
  d| dz  z  z   t        j                  |dz        z  S )Nr  rT   r  )e1e2e3mu2_if_cs       r5   r  z!burr_gen._stats.<locals>.<lambda>  s5    2"R<!BE'+A-/WWh]-C+D r7   r        @c                 T    |d|z  | z  z
  d|z  | dz  z  z   d| dz  z  z
  |dz  z  dz
  S )Nr#  r  rT   r  r   )rE  rF  rG  e4rH  s        r5   r  z!burr_gen._stats.<locals>.<lambda>  sB    qtBw,2b!e+aAg51DI r7   r   )rO   arangereshaperv   rm  wherer  r  r  r*  item)rD   r  r  ncrE  rF  rG  rK  rB  rH  rC  rD  rE  s                r5   r   zburr_gen._stats  s-   YYq!_$$Qq)A-Rb1A5BBXXa#gr266*A:hhq3w"&&1__Gb"b(+Evv	
 __Gb"b"h/Kvv	
 771:?779chhj"'')RWWY>>3Br7   c                     d }t        j                  |      t        j                  |      t        j                  |      }}}t        j                  ||kD  ||k(  z  ||k(  z  |||f|t         j                        S )Nc                 P    d| z  |z  }|t        j                  d|z
  ||z         z  S r  rv   rm  ra   r  r  rP  s       r5   __munpzburr_gen._munp.<locals>.__munp  -    a!BrwwsRxR000r7   r  )rO   r   r  r  r  )rD   ra   r  r  _burr_gen__munps        r5   r  zburr_gen._munp  sj    	1 **Q-A

1a1A!q&1Q!V< !1ay&RVVE 	Er7   N)r   r   r   r   rj   rq   r   rt   r   rx   r   r}   r   r   r  r   r7   r5   r  r  l  s@    +`
::#(,/+**Er7   r  burrc                   L    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)
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                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS r  rg   r  s      r5   rj   zburr12_gen._shape_info  rj  r7   c                 N    t        j                  | j                  |||            S rM   r  r2  s       r5   rq   zburr12_gen._pdf  r  r7   c                     t        j                  |      t        j                  |      z   t        j                  |dz
  |      z   t        j                  | dz
  ||z        z   S r]   r0  r2  s       r5   r   zburr12_gen._logpdf  sL    vvay266!9$rxxAq'99BJJr!tQPQT<RRRr7   c                 P    t        j                  | j                  |||             S rM   rv   r  r   r2  s       r5   rt   zburr12_gen._cdf"  !    Q1-...r7   c                 B    t        j                  d||z  z   | z         S r]   r  r2  s       r5   r   zburr12_gen._logcdf%  s#    xx!ad(qb))**r7   c                 N    t        j                  | j                  |||            S rM   r5  r2  s       r5   rx   zburr12_gen._sf(  r6  r7   c                 6    t        j                  | ||z        S rM   rv   rv  r2  s       r5   r   zburr12_gen._logsf+  s    zz1"ad##r7   c                 l    t        j                  d|z  t        j                  |       z        d|z  z  S Nr  r   r  r<  s       r5   r}   zburr12_gen._ppf.  s/     xx1rxx|+,qs33r7   c                 j    t        j                  d|z  t        j                  |      z        d|z  z  S rf  )rv   r  rO   r   )rD   r  r  r  s       r5   r   zburr12_gen._isf4  s+    xx1rvvay()AaC00r7   c                 h    d }t        j                  ||z  |kD  |||f|t        j                        S )Nc                 P    d| z  |z  }|t        j                  d|z   ||z
        z  S r  rS  rT  s       r5   moment_if_existsz*burr12_gen._munp.<locals>.moment_if_exists8  rV  r7   r  r  r  rO   r  )rD   ra   r  r  rj  s        r5   r  zburr12_gen._munp7  s6    	1 q1uqy1a)5E*,&&2 	2r7   N)r   r   r   r   rj   rq   r   rt   r   rx   r   r}   r   r  r   r7   r5   rZ  rZ    s;    +X
-S/+,$412r7   rZ  burr12c                   X    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)fisk_gena  A Fisk continuous random variable.

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

    %(before_notes)s

    See Also
    --------
    burr

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

    .. math::

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

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

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

    .. math::

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

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

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

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

    %(after_notes)s

    %(example)s

    c                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zfisk_gen._shape_infon  r
  r7   c                 0    t         j                  ||d      S r  )rX  rq   r	  s      r5   rq   zfisk_gen._pdfq  s    yyAs##r7   c                 0    t         j                  ||d      S r  )rX  rt   r	  s      r5   rt   zfisk_gen._cdfu      yyAs##r7   c                 0    t         j                  ||d      S r  )rX  rx   r	  s      r5   rx   zfisk_gen._sfx  s    xx1c""r7   c                 0    t         j                  ||d      S r  )rX  r   r	  s      r5   r   zfisk_gen._logpdf{  s    ||Aq#&&r7   c                 0    t         j                  ||d      S r  )rX  r   r	  s      r5   r   zfisk_gen._logcdf  s    ||Aq#&&r7   c                 0    t         j                  ||d      S r  )rX  r   r	  s      r5   r   zfisk_gen._logsf  s    {{1a%%r7   c                 0    t         j                  ||d      S r  )rX  r}   r	  s      r5   r}   zfisk_gen._ppf  rr  r7   c                 0    t         j                  ||d      S r  )rX  r   r  s      r5   r   zfisk_gen._isf  rr  r7   c                 0    t         j                  ||d      S r  )rX  r  rD   ra   r  s      r5   r  zfisk_gen._munp  s    zz!Q$$r7   c                 .    t         j                  |d      S r  )rX  r   rD   r  s     r5   r   zfisk_gen._stats  s    {{1c""r7   c                 2    dt        j                  |      z
  S r  r1  r|  s     r5   r   zfisk_gen._entropy      266!9}r7   N)r   r   r   r   rj   rq   rt   rx   r   r   r   r}   r   r  r   r   r   r7   r5   rn  rn  C  sE    )TE$$#''&$$%#r7   rn  fiskc                   N    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZddZy)
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`.

    This distribution uses routines from the Boost Math C++ library for
    the computation of the ``ppf` and ``isf`` methods. [1]_

    %(after_notes)s

    References
    ----------
    .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.

    %(example)s

    c                     g S rM   r   ri   s    r5   rj   zcauchy_gen._shape_info  r   r7   c                     t        j                  d      5  dt         j                  z  d||z  z   z  cd d d        S # 1 sw Y   y xY w)Nr8  rp  r   )rO   r;  r   r   s     r5   rq   zcauchy_gen._pdf  s;    [[h' 	'ruu9c!A#g&	' 	' 	's	   =Ac                 f    t        j                  |      }t        j                  |dk  |d d       S )Nr   c                 B    t          t        j                  | dz        z
  S r  )r'   rO   r  absxs    r5   r  z$cauchy_gen._logpdf.<locals>.<lambda>  s    'BHHT1W$55 r7   c                 z    t          dt        j                  |       z  t        j                  d| z  dz        z   z
  S NrT   r   )r'   rO   r   r  r  s    r5   r  z$cauchy_gen._logpdf.<locals>.<lambda>  s/    7(atnrxx4!7L&LM r7   )rO   absr  r  )rD   rp   r  s      r5   r   zcauchy_gen._logpdf  s5     vvay 1Hd5NP 	Pr7   c                 R    t        j                  d|       t         j                  z  S r]   rO   arctan2r   r   s     r5   rt   zcauchy_gen._cdf  s    zz!aR &&r7   c                 0    t        j                  |dd      S Nr   r   )rm   _cauchy_ppfr   s     r5   r}   zcauchy_gen._ppf      q!Q''r7   c                 P    t        j                  d|      t         j                  z  S r]   r  r   s     r5   rx   zcauchy_gen._sf  s    zz!Q%%r7   c                 0    t        j                  |dd      S r  )rm   _cauchy_isfr   s     r5   r   zcauchy_gen._isf  r  r7   c                 ~    t         j                  t         j                  t         j                  t         j                  fS rM   rO   r  ri   s    r5   r   zcauchy_gen._stats  !    vvrvvrvvrvv--r7   c                 N    t        j                  dt         j                  z        S r(  r   ri   s    r5   r   zcauchy_gen._entropy      vvagr7   Nc                     t        |t              r|j                         }t        j                  |g d      \  }}}|||z
  dz  fS N   2   K   rT   r>   r)   r  rO   
percentilerD   rE   rF   p25p50p75s         r5   r  zcauchy_gen._fitstart  A    dL)>>#DdL9S#S3YM!!r7   rM   )r   r   r   r   rj   rq   r   rt   r}   rx   r   r   r   r  r   r7   r5   r  r    s:    4'
P'(&(."r7   r  cauchyc                   N    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zy)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                 @    t        dddt        j                  fd      gS NdfFr   r	  rg   ri   s    r5   rj   zchi_gen._shape_info      4BFF^DEEr7   Nc                 X    t        j                  t        j                  |||            S r  )rO   r   chi2r  rD   r  r   r   s       r5   r   zchi_gen._rvs	  s     wwtxxLxIJJr7   c                 L    t        j                  | j                  ||            S rM   r  rD   rp   r  s      r5   rq   zchi_gen._pdf  s     vvdll1b)**r7   c                     t        j                  d      dt        j                  d      z  |z  z
  t        j                  d|z        z
  }|t        j                  |dz
  |      z   d|dz  z  z
  S )NrT   r   r   )rO   r   rv   r  rw  )rD   rp   r  ls       r5   r   zchi_gen._logpdf  s]    FF1I266!9R'"**RU*;;288BGQ''"QT'11r7   c                 @    t        j                  d|z  d|dz  z        S Nr   rT   rv   gammaincr  s      r5   rt   zchi_gen._cdf  s    {{2b5"QT'**r7   c                 @    t        j                  d|z  d|dz  z        S r  rv   	gammainccr  s      r5   rx   zchi_gen._sf  s    ||BrE2ad7++r7   c                 `    t        j                  dt        j                  d|z  |      z        S NrT   r   rO   r   rv   gammaincinvrD   r|   r  s      r5   r}   zchi_gen._ppf  s%    wwq2q1122r7   c                 `    t        j                  dt        j                  d|z  |      z        S r  rO   r   rv   gammainccinvr  s      r5   r   zchi_gen._isf  s%    wwqB2233r7   c                 z   t        j                  d      t        j                  d|z  d      z  }|||z  z
  }d|dz  z  |dd|z  z
  z  z   t        j                  t        j
                  |d            z  }d|z  d|z
  z  d|dz  z  z
  d|dz  z  d|z  dz
  z  z   }|t        j                  |d	z        z  }||||fS )
NrT   r   rC  r         ?r   r  r#  r   )rO   r   rv   pochr   powerrD   r  rB  rC  rD  rE  s         r5   r   zchi_gen._stats"  s    WWQZ"''#(C002b5jCi"a"f+%rzz"((32D'EErT3r6]1RU7"Qr1uW"Q%77
bjjc""3Br7   c                 D    d }d }t        j                  |dk  |||      S )Nc                     t        j                  d| z        d| t        j                  d      z
  | dz
  t        j                  d| z        z  z
  z  z   S r   )rv   r  rO   r   digammar  s    r5   regular_formulaz)chi_gen._entropy.<locals>.regular_formula-  sM    JJrBw'R"&&)^rAvC"H9M.MMNO Pr7   c                     dt        j                  t         j                        dz  z   | dz  dz  z
  | dz  dz  z
  d| dz  z  z
  | dz  d	z  z   S )
Nr   rT   r  r  r  gll?   r   r  s    r5   asymptotic_formulaz,chi_gen._entropy.<locals>.asymptotic_formula1  sY    "&&-/)RVQJ6"b&!CBFm$')2vrk2 3r7   i,  r  )rD   r  r  r  s       r5   r   zchi_gen._entropy+  s)    	P	3 rCx_>PQQr7   r  r   r   r   r   rj   r   rq   r   rt   rx   r}   r   r   r   r   r7   r5   r  r    s<    <FK+2+,34
Rr7   r  chic                   N    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zy)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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zchi2_gen._shape_info]  r  r7   Nc                 &    |j                  ||      S rM   )	chisquarer  s       r5   r   zchi2_gen._rvs`  s    %%b$//r7   c                 L    t        j                  | j                  ||            S rM   r  r  s      r5   rq   zchi2_gen._pdfc  s    vvdll1b)**r7   c                     t        j                  |dz  dz
  |      |dz  z
  t        j                  |dz        z
  t        j                  d      |z  dz  z
  S )Nr   r   rT   )rv   rw  r  rO   r   r  s      r5   r   zchi2_gen._logpdfg  sM    xx2a#ad*RZZ2->>"&&)B,PRARRRr7   c                 .    t        j                  ||      S rM   )rv   chdtrr  s      r5   rt   zchi2_gen._cdfj      xxAr7   c                 .    t        j                  ||      S rM   )rv   chdtrcr  s      r5   rx   zchi2_gen._sfm      yyQr7   c                 .    t        j                  ||      S rM   )rv   chdtrirD   r  r  s      r5   r   zchi2_gen._isfp  r  r7   c                 :    dt        j                  |dz  |      z  S r  rv   r  r  s      r5   r}   zchi2_gen._ppfs  s    1a(((r7   c                 \    |}d|z  }dt        j                  d|z        z  }d|z  }||||fS )NrT   r         (@r  r  s         r5   r   zchi2_gen._statsv  s=    drwws2v"W3Br7   c                 N    d|z  }d }d }t        j                  |dk  |||      S )Nr   c                     | t        j                  d      z   t        j                  |       z   d| z
  t        j                  |       z  z   S r  )rO   r   rv   r  rZ  )half_dfs    r5   r  z*chi2_gen._entropy.<locals>.regular_formula  s>    bffQi'"**W*==[BFF7O34 5r7   c                     t        j                  d      ddt        j                  dt         j                  z        z   z  z   }d| z  }|d|d|d|dz  z   z  z   z  z   z  dt        j                  |       z  z   |z   S )NrT   r   r   gUUUUUUUUUUUUտgllg      @r   )r  r  hs      r5   r  z-chi2_gen._entropy.<locals>.asymptotic_formula  s     q	CRVVAbeeG_!455AGAta51S5=(9!9::;w'(*+, -r7   }   r  )rD   r  r  r  r  s        r5   r   zchi2_gen._entropy}  s8    (	5		- w}g.0BD 	Dr7   r  )r   r   r   r   rj   r   rq   r   rt   rx   r   r}   r   r   r   r7   r5   r  r  ;  s=     BF0+S  )Dr7   r  r  c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)
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                     g S rM   r   ri   s    r5   rj   zcosine_gen._shape_info  r   r7   c                 Z    dt         j                  z  dt        j                  |      z   z  S Nr   r   rO   r   r   r   s     r5   rq   zcosine_gen._pdf  s!    RUU{AbffQiK((r7   c                     t        j                  |      }t        j                  |dk7  |d t         j                         S )Nr  c                 z    t        j                  |       t        j                  dt         j                  z        z
  S r  )rO   r  r   r   r  s    r5   r  z$cosine_gen._logpdf.<locals>.<lambda>  s#    !rvvag)F r7   r  )rO   r   r  r  rh   r	  s      r5   r   zcosine_gen._logpdf  s4    FF1IqBwF+-66'3 	3r7   c                 ,    t        j                  |      S rM   rm   _cosine_cdfr   s     r5   rt   zcosine_gen._cdf  s    q!!r7   c                 .    t        j                  |       S rM   r  r   s     r5   rx   zcosine_gen._sf  s    r""r7   c                 ,    t        j                  |      S rM   rm   _cosine_invcdfrD   r  s     r5   r}   zcosine_gen._ppf  s    !!!$$r7   c                 .    t        j                  |       S rM   r  r   s     r5   r   zcosine_gen._isf  s    ""1%%%r7   c                     t         j                  t         j                  z  dz  dz
  }dt         j                  dz  dz
  z  dt         j                  t         j                  z  dz
  dz  z  z  }d	|d	|fS )
NrC  r   r  r#  Z         @r  rT   r   r.  )rD   r  r  s      r5   r   zcosine_gen._stats  sa    UURUU]S C'BEE1HrM"cRUURUU]Q->,B&BCAsA~r7   c                 T    t        j                  dt         j                  z        dz
  S )Nr#  r   r   ri   s    r5   r   zcosine_gen._entropy  s    vvags""r7   Nr   r   r   r   rj   rq   r   rt   rx   r}   r   r   r   r   r7   r5   r  r    s4    ()3"#%&
#r7   r  cosinec                   N    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zy)
dgamma_gena  A double gamma continuous random variable.

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

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

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

    %(example)s

    c                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zdgamma_gen._shape_info  r
  r7   Nc                     |j                  |      }t        j                  |||      }|t        j                  |dk\  dd      z  S Nr   r  r   r   r  )uniformr  r  rO   rN  )rD   r   r   r   ugms         r5   r   zdgamma_gen._rvs  sE      d +YYqt,Y?BHHQ#Xq"---r7   c                     t        |      }ddt        j                  |      z  z  ||dz
  z  z  t        j                  |       z  S r  )r  rv   r  rO   r   rD   rp   r   axs       r5   rq   zdgamma_gen._pdf  s>    VAbhhqkM"2#;.<<r7   c                     t        |      }t        j                  |dz
  |      |z
  t        j                  d      z
  t        j
                  |      z
  S r  )r  rv   rw  rO   r   r  r  s       r5   r   zdgamma_gen._logpdf  s?    VxxC$r)BFF1I5

1EEr7   c           	          t        j                  |dkD  ddt        j                  ||      z  z   dt        j                  ||       z        S Nr   r   )rO   rN  rv   r  r  r  s      r5   rt   zdgamma_gen._cdf  sF    xxAc"++a"333BLLQB//1 	1r7   c           
          t        j                  |dkD  dt        j                  ||      z  ddt        j                  ||       z  z         S r  )rO   rN  rv   r  r  r  s      r5   rx   zdgamma_gen._sf  sF    xxABLLA..c"++a!"4446 	6r7   c                 l    t         j                  j                  |      t        j                  d      z
  S Nr   )r  r  r   rO   r   r  s     r5   r   zdgamma_gen._entropy  s$    {{##A&44r7   c           	          t        j                  |dkD  t        j                  |d|z  dz
        t        j                  |d|z               S r   rO   rN  rv   r  r  r  s      r5   r}   zdgamma_gen._ppf  sD    xxCq!A#'2AaC002 	2r7   c           	          t        j                  |dkD  t        j                  |d|z  dz
         t        j                  |d|z              S r   r  r  s      r5   r   zdgamma_gen._isf  sD    xxC1Q37331Q3/1 	1r7   c                 <    ||dz   z  }d|d|dz   |dz   z  |z  dz
  fS )Nr   r   r   rC  r   )rD   r   rC  s      r5   r   zdgamma_gen._stats  s4    3iCququoc1#555r7   r  )r   r   r   r   rj   r   rq   r   rt   rx   r   r}   r   r   r   r7   r5   r	  r	    s;    >E.
=
F1
6
52
1
6r7   r	  dgammac                       e Zd ZdZej
                  Zej                  Zej                  Z
ej                  Zej                  Zej                  Zd Zd Zd Zd ZddZd Zd	 Zd
 Z	d Zd Zd Zd Zy)dpareto_lognorm_gena  A double Pareto lognormal continuous random variable.

    %(before_notes)s

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

    .. math::

        f(x, \mu, \sigma, \alpha, \beta) =
        \frac{\alpha \beta}{(\alpha + \beta) x}
        \phi\left( \frac{\log x - \mu}{\sigma} \right)
        \left( R(y_1) + R(y_2) \right)

    where :math:`R(t) = \frac{1 - \Phi(t)}{\phi(t)}`,
    :math:`\phi` and :math:`\Phi` are the normal PDF and CDF, respectively,
    :math:`y_1 = \alpha \sigma - \frac{\log x - \mu}{\sigma}`,
    and :math:`y_2 = \beta \sigma + \frac{\log x - \mu}{\sigma}`
    for real numbers :math:`x` and :math:`\mu`, :math:`\sigma > 0`,
    :math:`\alpha > 0`, and :math:`\beta > 0` [1]_.

    `dpareto_lognorm` takes
    ``u`` as a shape parameter for :math:`\mu`,
    ``s`` as a shape parameter for :math:`\sigma`,
    ``a`` as a shape parameter for :math:`\alpha`, and
    ``b`` as a shape parameter for :math:`\beta`.

    A random variable :math:`X` distributed according to the PDF above
    can be represented as :math:`X = U \frac{V_1}{V_2}` where :math:`U`,
    :math:`V_1`, and :math:`V_2` are independent, :math:`U` is lognormally
    distributed such that :math:`\log U \sim N(\mu, \sigma^2)`, and
    :math:`V_1` and :math:`V_2` follow Pareto distributions with parameters
    :math:`\alpha` and :math:`\beta`, respectively [2]_.

    %(after_notes)s

    References
    ----------
    .. [1] Hajargasht, Gholamreza, and William E. Griffiths. "Pareto-lognormal
           distributions: Inequality, poverty, and estimation from grouped income
           data." Economic Modelling 33 (2013): 593-604.
    .. [2] Reed, William J., and Murray Jorgensen. "The double Pareto-lognormal
           distribution - a new parametric model for size distributions."
           Communications in Statistics - Theory and Methods 33.8 (2004): 1733-1753.

    %(example)s

    c                 H    | j                  |      | j                  |      z  S rM   )_Phic_phirD   zs     r5   _Rzdpareto_lognorm_gen._RY  s    zz!}tyy|++r7   c                 H    | j                  |      | j                  |      z
  S rM   )_logPhic_logphir$  s     r5   _logRzdpareto_lognorm_gen._logR\  s    }}Q$,,q/11r7   c           	         t        ddt        j                   t        j                  fd      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   r   rg   ri   s    r5   rj   zdpareto_lognorm_gen._shape_info_  sm    3'8.I3266{NC3266{NC3266{NCE 	Er7   c                 $    |dkD  |dkD  z  |dkD  z  S Nr   r   )rD   r  r  r   r   s        r5   rb   zdpareto_lognorm_gen._argchecke  s    A!a% AE**r7   Nc                     |j                  |||      }|j                  |      }|j                  |      }	t        j                  |||z  z   |	|z  z
        S Nr  )normalstandard_exponentialrO   r   )
rD   r  r  r   r   r   r   ZE1E2s
             r5   r   zdpareto_lognorm_gen._rvsh  sa     140..D.9..D.9vva"q&j26)**r7   c                 f   t        j                  dd      5  t        j                  |      |}}||z
  |z  }||z  |z
  }	||z  |z   }
t        j                  t        j                  |      t        j                  |      z   t        j                  ||z         z
  |z
        }|| j	                  |      z  }|t        j
                  | j                  |	      | j                  |
            z  }d d d        t         j                   |dk(  t        j                  |      z  <   |d   S # 1 sw Y   ;xY w)Nr8  invalidr:  r   r   )	rO   r;  r   r   r)  	logaddexpr*  rh   rU   )rD   rp   r  r  r   r   log_ymr%  x1x2r  s               r5   r   zdpareto_lognorm_gen._logpdfq  s    [[(; 	@vvay!1EaAQBQB**RVVAY2RVVAE]BUJKC4<<?"C2<<

2

2??C	@ (*vvgQ!Vrxx{"#2w	@ 	@s   CD''D0c           	         t        j                  dd      5  t        j                  |      |}}||z
  |z  }||z  |z
  }	||z  |z   }
| j                  |      }| j	                  |      }t        j                  |      | j                  |	      z   }t        j                  |      | j                  |
      z   }t        j                  ||||d      \  }}}}}t        j                  ||g|| gdd      \  }}|||z   t        j                  ||z         z
  g}t        j                  t        j                  ||| |z  gd            }d d d        t         j                   |dk(  <   |d   S # 1 sw Y   %xY w)	Nr8  r6  r   r   T)r   r  return_sign)r   r  r   )rO   r;  r   _logPhir)  r*  r  rv   	logsumexpr   rh   )rD   rp   r  r  r   r   r9  r:  r%  r;  r<  r  r  r  t4onet5rP   tempr  s                       r5   r   zdpareto_lognorm_gen._logcdf}  sZ   [[(; 	Mvvay!1EaAQBQBaBaB&&)djjn,B&&)djjn,B"$"5"5b"b"a"HBBC b"X#t1RVWHBR"&&Q-/0D**R\\$3T	2BKLC	M  vvgAF2w#	M 	Ms   D1E--E6c           	      R    t        j                  | j                  |||||            S rM   )rm   	_log1mexpr   rD   rp   r  r  r   r   s         r5   r   zdpareto_lognorm_gen._logsf  s"    }}T\\!Q1a899r7   c           	      R    t        j                  | j                  |||||            S rM   r  rG  s         r5   rq   zdpareto_lognorm_gen._pdf  "    vvdll1aAq122r7   c           	      R    t        j                  | j                  |||||            S rM   rO   r   r   rG  s         r5   rt   zdpareto_lognorm_gen._cdf  rI  r7   c           	      R    t        j                  | j                  |||||            S rM   r5  rG  s         r5   rx   zdpareto_lognorm_gen._sf  s"    vvdkk!Q1a011r7   c                     |t        |      }}||z  ||z
  ||z   z  z  t        j                  ||z  |dz  |dz  z  dz  z         z  }t        j                  |      }t        j                  |||k  <   |S r  )floatrO   r   r   r  )	rD   ra   r  r  r   r   r:  r  r  s	            r5   r  zdpareto_lognorm_gen._munp  su    %(11u!a%AE*+bffQUQ!Va1f_q=P5P.QQjjoffAF
r7   r  )r   r   r   r   r  r   r)  r   r?  r   r(  rq   r#  rt   _Phirx   r"  r&  r*  rj   rb   r   r  r   r7   r5   r   r      s}    0b llGllG{{H99D99DHHE,2E++
(:
332r7   r   dpareto_lognormc                   T    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zy)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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zdweibull_gen._shape_info  r
  r7   Nc                     |j                  |      }t        j                  |||      }|t        j                  |dk\  dd      z  S r  )r  weibull_minr  rO   rN  )rD   r  r   r   r  ws         r5   r   zdweibull_gen._rvs  sE      d +OOAD|ODBHHQ#Xq"-..r7   c                 l    t        |      }|dz  ||dz
  z  z  t        j                  ||z         z  }|S Nr   r   )r  rO   r   )rD   rp   r  r  Pxs        r5   rq   zdweibull_gen._pdf  s9    VWrAcE{"RVVRUF^3	r7   c                     t        |      }t        j                  |      t        j                  d      z
  t        j                  |dz
  |      z   ||z  z
  S rX  )r  rO   r   rv   rw  )rD   rp   r  r  s       r5   r   zdweibull_gen._logpdf  sC    Vvvay266#;&!c'2)>>QFFr7   c                     dt        j                  t        |      |z         z  }t        j                  |dkD  d|z
  |      S Nr   r   r   )rO   r   r  rN  )rD   rp   r  Cx1s       r5   rt   zdweibull_gen._cdf  s:    BFFCFAI:&&xxAq3w,,r7   c                     dt        j                  |dk  |d|z
        z  }t        j                  t        j                  |       d|z        }t        j                  |dkD  ||       S Nr   r   r   )rO   rN  r  r   )rD   r|   r  r  s       r5   r}   zdweibull_gen._ppf  sX    288AHaa00hhs|S1W-xxCsd++r7   c                     dt         j                  j                  t        j                  |      |      z  }t        j
                  |dkD  |d|z
        S r\  )r  rU  rx   rO   r  rN  )rD   rp   r  half_weibull_min_sfs       r5   rx   zdweibull_gen._sf  sF    !E$5$5$9$9"&&)Q$GGxxA2A8K4KLLr7   c                     dt        j                  |dk  |d|z
        z  }t        j                  j	                  ||      }t        j                  |dkD  | |      S r_  )rO   rN  r  rU  r   )rD   r|   r  double_qweibull_min_isfs        r5   r   zdweibull_gen._isf  sS    c1b1f55++001=xxC/!1?CCr7   c                 P    d|dz  z
  t        j                  dd|z  |z  z         z  S )Nr   rT   r   rv   r  rz  s      r5   r  zdweibull_gen._munp  s+    QUrxxcAgk(9:::r7   c                      yN)r   Nr   Nr   r|  s     r5   r   zdweibull_gen._stats      r7   c                 p    t         j                  j                  |      t        j                  d      z
  }|S r  )r  rU  r   rO   r   )rD   r  r  s      r5   r   zdweibull_gen._entropy  s*    &&q)BFF3K7r7   r  )r   r   r   r   rj   r   rq   r   rt   r}   rx   r   r  r   r   r   r7   r5   rR  rR    sB    *E/
G-,
MD
; r7   rR  dweibullc                   ~    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Ze eed      d               Zy)	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                     g S rM   r   ri   s    r5   rj   zexpon_gen._shape_info  r   r7   Nc                 $    |j                  |      S rM   )r1  r   s      r5   r   zexpon_gen._rvs  s    0066r7   c                 .    t        j                  |       S rM   rO   r   r   s     r5   rq   zexpon_gen._pdf  s    vvqbzr7   c                     | S rM   r   r   s     r5   r   zexpon_gen._logpdf  	    r	r7   c                 0    t        j                  |        S rM   rv   r  r   s     r5   rt   zexpon_gen._cdf      !}r7   c                 0    t        j                  |        S rM   r  r   s     r5   r}   zexpon_gen._ppf   rv  r7   c                 .    t        j                  |       S rM   rq  r   s     r5   rx   zexpon_gen._sf#  s    vvqbzr7   c                     | S rM   r   r   s     r5   r   zexpon_gen._logsf&  rs  r7   c                 .    t        j                  |       S rM   r1  r   s     r5   r   zexpon_gen._isf)      q	zr7   c                      y)N)r   r   r         @r   ri   s    r5   r   zexpon_gen._stats,  r   r7   c                      yr  r   ri   s    r5   r   zexpon_gen._entropy/      r7   z        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                    t        |      dkD  rt        d      |j                  dd       }|j                  dd       }t        |       ||t	        d      t        j                  |      }t        j                  |      j                         st	        d      |j                         }||}n#|}||k  rt        d|t
        j                        ||j                         |z
  }n|}t        |      t        |      fS )	Nr   Too many arguments.r   r   r   r   exponr  )r  r3   r2   r6   r   rO   r   r   r   minrJ  rh   r   rN  )	rD   rE   rF   r4   r   r   data_minr-   r.   s	            r5   rB   zexpon_gen.fit2  s     t9q=122xx%(D)$T* 2 ) * * zz${{4 $$&CDD88:<CC#~"7$bffEE>IIK#%EE Sz5<''r7   r  )r   r   r   r   rj   r   rq   r   rt   r}   rx   r   r   r   r   rJ   r
   r   rB   r   r7   r5   rm  rm    sf    47"  6 &( &(r7   rm  r  c                   <    e Zd ZdZd Zd
dZd Zd Zd Zd Z	d	 Z
y)exponnorm_gena  An exponentially modified Normal continuous random variable.

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

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

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

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

    .. versionadded:: 0.16.0

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

    %(example)s

    c                 @    t        dddt        j                  fd      gS )NKFr   r	  rg   ri   s    r5   rj   zexponnorm_gen._shape_info  r
  r7   Nc                 V    |j                  |      |z  }|j                  |      }||z   S rM   )r1  r   )rD   r  r   r   expvalgvals         r5   r   zexponnorm_gen._rvs  s1    22481<++D1}r7   c                 L    t        j                  | j                  ||            S rM   r  )rD   rp   r  s      r5   rq   zexponnorm_gen._pdf      vvdll1a())r7   c                 p    d|z  }|d|z  |z
  z  }|t        ||z
        z   t        j                  |      z
  S Nr   r   r   rO   r   )rD   rp   r  invKexpargs        r5   r   zexponnorm_gen._logpdf  s>    Qwta(QX..::r7   c                     d|z  }|d|z  |z
  z  }|t        ||z
        z   }t        |      t        j                  |      z
  S r  r   r   rO   r   rD   rp   r  r  r  logprods         r5   rt   zexponnorm_gen._cdf  sG    Qwta(<D11|bffWo--r7   c                     d|z  }|d|z  |z
  z  }|t        ||z
        z   }t        |       t        j                  |      z   S r  r  r  s         r5   rx   zexponnorm_gen._sf  sI    Qwta(<D11!}rvvg..r7   c                 Z    ||z  }d|z   }d|dz  z  |dz  z  }d|z  |z  |dz  z  }||||fS )Nr   rT   r  r@  r}  r  r   )rD   r  K2opK2skwkrts         r5   r   zexponnorm_gen._stats  sO    URx!Q$h%BhmdRj($S  r7   r  )r   r   r   r   rj   r   rq   r   rt   rx   r   r   r7   r5   r  r  e  s,    (RE
*;
./!r7   r  	exponnormc                 T    t        j                  t        j                  ||             S )a'  
    Compute (1 + x)**y - 1.

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

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

        t = _pow1pm1(x, y)

    then

        x = _pow1pm1(t, 1/y)
    )rO   r  rv   rv  rp   ys     r5   _pow1pm1r    s      88BJJq!$%%r7   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
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                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS Nr   Fr   r	  r  rg   rD   rh  r   s      r5   rj   zexponweib_gen._shape_info  rj  r7   c                 N    t        j                  | j                  |||            S rM   r  rD   rp   r   r  s       r5   rq   zexponweib_gen._pdf        vvdll1a+,,r7   c                    ||z   }t        j                  |       }t        j                  |      t        j                  |      z   t        j                  |dz
  |      z   |z   t        j                  |dz
  |      z   }|S r  )rv   r  rO   r   rw  )rD   rp   r   r  negxcexm1clogps          r5   r   zexponweib_gen._logpdf  so    A% q	BFF1I%S%(@@S!,-r7   c                 @    t        j                  ||z          }||z  S rM   ru  )rD   rp   r   r  r  s        r5   rt   zexponweib_gen._cdf	  s!    1a4% axr7   c                 n    t        j                  |d|z  z          t        j                  d|z        z  S r  )rv   r  rO   r   )rD   r|   r   r  s       r5   r}   zexponweib_gen._ppf	  s0    1s1u:+&&CE):::r7   c                 L    t        t        j                  ||z          |       S rM   )r  rO   r   r  s       r5   rx   zexponweib_gen._sf
	  s"    "&&!Q$-+++r7   c                 X    t        j                  t        | d|z                d|z  z  S r]   )rO   r   r  )rD   r  r   r  s       r5   r   zexponweib_gen._isf	  s-    1"ac**++qs33r7   Nr   r   r   r   rj   rq   r   rt   r}   rx   r   r   r7   r5   r  r    s+    'P
-
;,4r7   r  	exponweibc                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
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                 @    t        dddt        j                  fd      gS Nr   Fr   r	  rg   ri   s    r5   rj   zexponpow_gen._shape_info0	  r
  r7   c                 L    t        j                  | j                  ||            S rM   r  rD   rp   r   s      r5   rq   zexponpow_gen._pdf3	      vvdll1a())r7   c                     ||z  }dt        j                  |      z   t        j                  |dz
  |      z   |z   t        j                  |      z
  }|S Nr   r   )rO   r   rv   rw  r   )rD   rp   r   xbfs        r5   r   zexponpow_gen._logpdf7	  sG    Tq	MBHHQWa0025r
Br7   c                 \    t        j                  t        j                  ||z                S rM   ru  r  s      r5   rt   zexponpow_gen._cdf<	  s"    "((1a4.)))r7   c                 Z    t        j                  t        j                  ||z               S rM   rO   r   rv   r  r  s      r5   rx   zexponpow_gen._sf?	  s    vvrxx1~o&&r7   c                 `    t        j                  t        j                  |             d|z  z  S r  rv   r  rO   r   r  s      r5   r   zexponpow_gen._isfB	  s$    "&&)$1--r7   c                 p    t        t        j                  t        j                  |              d|z        S r  powrv   r  rD   r|   r   s      r5   r}   zexponpow_gen._ppfE	  s(    288RXXqb\M*CE22r7   N)r   r   r   r   rj   rq   r   rt   rx   r   r}   r   r7   r5   r  r  	  s+    6E*
*'.3r7   r  exponpowc                   `    e Zd ZdZej
                  Zd ZddZd Z	d Z
d Zd Zd	 Zd
 Zd Zy)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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zfatiguelife_gen._shape_infoi	  r
  r7   Nc                     |j                  |      }d|z  |z  }||z  }dd|z  z   d|z  t        j                  d|z         z  z   }|S )Nr   r   rT   r   )r   rO   r   )rD   r  r   r   r%  rp   r<  ts           r5   r   zfatiguelife_gen._rvsl	  sT    ((.E!GqS!B$J1RWWQV_,,r7   c                 L    t        j                  | j                  ||            S rM   r  r	  s      r5   rq   zfatiguelife_gen._pdfs	  s     vvdll1a())r7   c                    t        j                  |dz         |dz
  dz  d|z  |dz  z  z  z
  t        j                  d|z        z
  dt        j                  dt         j                  z        dt        j                  |      z  z   z  z
  S )Nr   rT   r   r   r  r   r	  s      r5   r   zfatiguelife_gen._logpdfx	  ss    qsqsQh#a%1*55qsCRVVAbeeG_q{234 	5r7   c                 |    t        d|z  t        j                  |      dt        j                  |      z  z
  z        S r  )r   rO   r   r	  s      r5   rt   zfatiguelife_gen._cdf|	  s/    qBGGAJRWWQZ$?@AAr7   c                 f    |t        |      z  }d|t        j                  |dz  dz         z   dz  z  S N      ?rT   r#  r   rO   r   rD   r|   r  tmps       r5   r}   zfatiguelife_gen._ppf	  s6    )A,sRWWS!VaZ001444r7   c                 |    t        d|z  t        j                  |      dt        j                  |      z  z
  z        S r  )r   rO   r   r	  s      r5   rx   zfatiguelife_gen._sf	  s/    a2771:BGGAJ#>?@@r7   c                 h    | t        |      z  }d|t        j                  |dz  dz         z   dz  z  S r  r  r  s       r5   r   zfatiguelife_gen._isf	  s8    b9Q<sRWWS!VaZ001444r7   c                     ||z  }|dz  dz   }d|z  dz   }||z  dz  }d|z  d|z  dz   z  t        j                  |d      z  }d	|z  d
|z  dz   z  |dz  z  }||||fS )Nr   r   r  rI  r#     r}  r  r  ]   g      D@rO   r  )rD   r  c2rB  denrC  rD  rE  s           r5   r   zfatiguelife_gen._stats	  s     qS#X^BhnfslUbeck"RXXc3%77Vr"ut|$sCx/3Br7   r  )r   r   r   r   r   r  r  rj   r   rq   r   rt   r}   rx   r   r   r   r7   r5   r  r  L	  sD    4 "44ME*
5B5A5r7   r  fatiguelifec                   <    e Zd ZdZd Zd Zd
dZd Zd Zd Z	d	 Z
y)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                     |dk\  S r-  r   r|  s     r5   rb   zfoldcauchy_gen._argcheck	      Avr7   c                 @    t        dddt        j                  fd      gS Nr  Fr   rf   rg   ri   s    r5   rj   zfoldcauchy_gen._shape_info	      3266{MBCCr7   Nc                 D    t        t        j                  |||            S )Nr-   r   r   )r  r  r  rD   r  r   r   s       r5   r   zfoldcauchy_gen._rvs	  s&    6::!$+7  9 : 	:r7   c                 d    dt         j                  z  dd||z
  dz  z   z  dd||z   dz  z   z  z   z  S Nr   r   rT   r.  r	  s      r5   rq   zfoldcauchy_gen._pdf	  s<    255y#q!A#z*S!QqS1H*-==>>r7   c                     dt         j                  z  t        j                  ||z
        t        j                  ||z         z   z  S r  rO   r   arctanr	  s      r5   rt   zfoldcauchy_gen._cdf	  s2    255y"))AaC.299QqS>9::r7   c                     t        j                  d||z
        t        j                  d||z         z   t         j                  z  S r]   r  r	  s      r5   rx   zfoldcauchy_gen._sf	  s6    
 

1a!e$rzz!QU';;RUUBBr7   c                 ~    t         j                  t         j                  t         j                  t         j                  fS rM   r  r|  s     r5   r   zfoldcauchy_gen._stats	  r  r7   r  r   r   r   r   rb   rj   r   rq   rt   rx   r   r   r7   r5   r  r  	  s,    &D:?;C.r7   r  
foldcauchyc                   H    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zy)f_gena  An F continuous random variable.

    For the noncentral F distribution, see `ncf`.

    %(before_notes)s

    See Also
    --------
    ncf

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

    The probability density function for `f` is:

    .. math::

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

    for :math:`x > 0`.

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

    %(after_notes)s

    %(example)s

    c                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS )NdfnFr   r	  dfdrg   )rD   idfnidfds      r5   rj   zf_gen._shape_info	  s<    %BFF^D%BFF^Dd|r7   Nc                 (    |j                  |||      S rM   )r  )rD   r  r  r   r   s        r5   r   z
f_gen._rvs	  s    ~~c3--r7   c                 N    t        j                  | j                  |||            S rM   r  rD   rp   r  r  s       r5   rq   z
f_gen._pdf	  s      vvdll1c3/00r7   c                 F   d|z  }d|z  }|dz  t        j                  |      z  |dz  t        j                  |      z  z   t        j                  |dz  dz
  |      z   ||z   dz  t        j                  |||z  z         z  t        j                  |dz  |dz        z   z
  }|S Nr   rT   r   )rO   r   rv   rw  rx  )rD   rp   r  r  ra   r:  ry  s          r5   r   zf_gen._logpdf
  s    #I#IsRVVAY1rvvay0288AaC!GQ3GGaC7bffQ1Wo-		!A#qs0CCE
r7   c                 0    t        j                  |||      S rM   )rv   fdtrr  s       r5   rt   z
f_gen._cdf	
  s    wwsC##r7   c                 0    t        j                  |||      S rM   )rv   fdtrcr  s       r5   rx   z	f_gen._sf
      xxS!$$r7   c                 0    t        j                  |||      S rM   )rv   fdtri)rD   r|   r  r  s       r5   r}   z
f_gen._ppf
  r  r7   c                    d|z  d|z  }}|dz
  |dz
  |dz
  |dz
  f\  }}}}t        j                  |dkD  ||fd t        j                        }	t        j                  |d	kD  ||||fd
 t        j                        }
t        j                  |dkD  ||||fd t        j                        }|t        j
                  d      z  }t        j                  |dkD  |||fd t        j                        }|dz  }|	|
||fS )Nr   r   rI  r}         @rT   c                     | |z  S rM   r   )v2v2_2s     r5   r  zf_gen._stats.<locals>.<lambda>
  s
    R$Y r7   r  r#  c                 6    d|z  |z  | |z   z  | |dz  z  |z  z  S r  r   )v1r	  r
  v2_4s       r5   r  zf_gen._stats.<locals>.<lambda>
  s-    FRK29%dAg)<= r7   r  c                 V    d| z  |z   |z  t        j                  || | |z   z  z        z  S r  r  )r  r
  r  v2_6s       r5   r  zf_gen._stats.<locals>.<lambda>#
  s3    Vd]d"RWWTR295E-F%GG r7   r-  c                     d| | z  |z  z   |z  S )Nr-  r   )rD  r  v2_8s      r5   r  zf_gen._stats.<locals>.<lambda>*
  s    AR$$6$#> r7   r  )r  r  rO   rh   r  r   )rD   r  r  r  r	  r
  r  r  r  rB  rC  rD  rE  s                r5   r   zf_gen._stats
  s   c28B!#b"r'27BG!CdD$__FRJ&vv
 ooFRT4(>vv	 __FRtT*Hvv	
 	bggbk__FRt$>vv 	g3Br7   c                 L   d|z  }d|z  }d||z   z  }t        j                  |      t        j                  |      z
  t        j                  ||      z   d|z
  t        j                  |      z  z   d|z   t        j                  |      z  z
  |t        j                  |      z  z   S r  )rO   r   rv   rx  rZ  )rD   r  r  half_dfnhalf_dfdhalf_sums         r5   r   zf_gen._entropy0
  s     99#)$sbffSk)BIIh,IIX!11256\x 5!!#+bffX.>#>? 	@r7   r  )r   r   r   r   rj   r   rq   r   rt   rx   r}   r   r   r   r7   r5   r  r  	  s6    #H
.1$%%<
@r7   r  r  c                   <    e Zd ZdZd Zd Zd
dZd Zd Zd Z	d	 Z
y)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                     |dk\  S r-  r   r|  s     r5   rb   zfoldnorm_gen._argcheck^
  r  r7   c                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zfoldnorm_gen._shape_infoa
  r  r7   Nc                 <    t        |j                  |      |z         S rM   r  r   r  s       r5   r   zfoldnorm_gen._rvsd
  s    <//59::r7   c                 <    t        ||z         t        ||z
        z   S rM   r   r	  s      r5   rq   zfoldnorm_gen._pdfg
  s    Q)AaC.00r7   c                     t        j                  d      }dt        j                  ||z
  |z        t        j                  ||z   |z        z   z  S r  )rO   r   rv   erf)rD   rp   r  sqrt_twos       r5   rt   zfoldnorm_gen._cdfk
  sC    771:bffa!eX-.Q8H1IIJJr7   c                 <    t        ||z
        t        ||z         z   S rM   r   r	  s      r5   rx   zfoldnorm_gen._sfo
  s    A!a%00r7   c                    ||z  }t        j                  d|z        t        j                  dt         j                  z        z  }d|z  |t	        j
                  |t        j                  d      z        z  z   }|dz   ||z  z
  }d||z  |z  ||z  z
  |z
  z  }|t        j                  |d      z  }||dz   z  dz   d|z  |z  z   }|d|d	z
  z  d	|dz  z  z
  |dz  z  z  }||dz  z  d	z
  }||||fS )
N      r   rT   r   r  r}  r  r  rC  )rO   r   r   r   rv   r  r  )rD   r  r  expfacrB  rC  rD  rE  s           r5   r   zfoldnorm_gen._statsr
  s	    qSR2772bee8#44YRVVAbggajL1111fr"un2b58be#f,-
bhhsC  27^a"V)B,.
rR"W~RU
*b!e33#s(]R3Br7   r  r  r   r7   r5   r  r  H
  s,    *D;1K1r7   r  foldnormc                   x     e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Z eed       fd       Z xZS )weibull_min_gena  Weibull minimum continuous random variable.

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

    %(before_notes)s

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

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

    .. math::

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

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

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

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

    %(after_notes)s

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

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

    %(example)s

    c                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zweibull_min_gen._shape_info
  r
  r7   c                 h    |t        ||dz
        z  t        j                  t        ||             z  S r]   r  rO   r   r	  s      r5   rq   zweibull_min_gen._pdf
  s,    Q!}RVVSAYJ///r7   c                 z    t        j                  |      t        j                  |dz
  |      z   t	        ||      z
  S r]   rO   r   rv   rw  r  r	  s      r5   r   zweibull_min_gen._logpdf
  s/    vvay288AE1--Aq	99r7   c                 D    t        j                  t        ||              S rM   rv   r  r  r	  s      r5   rt   zweibull_min_gen._cdf
  s    #a)$$$r7   c                 J    t        t        j                  |        d|z        S r  r  r  s      r5   r}   zweibull_min_gen._ppf
  s    BHHaRL=#a%((r7   c                 L    t        j                  | j                  ||            S rM   r5  r	  s      r5   rx   zweibull_min_gen._sf
      vvdkk!Q'((r7   c                     t        ||       S rM   r  r	  s      r5   r   zweibull_min_gen._logsf
  s    Aq	zr7   c                 :    t        j                  |       d|z  z  S r]   r1  r  s      r5   r   zweibull_min_gen._isf
  s    
ac""r7   c                 >    t        j                  d|dz  |z  z         S r  rf  rz  s      r5   r  zweibull_min_gen._munp
  s    xxAcE!G$$r7   c                 V    t          |z  t        j                  |      z
  t         z   dz   S r]   r#   rO   r   r|  s     r5   r   zweibull_min_gen._entropy
  %    w{RVVAY&/!33r7   a          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           	      4   t        |t              r7|j                         dk(  r|j                         }nt	        |   |g|i |S |j                  dd      rt	        |   |g|i |S t        | |||      \  }}}}|j                  dd      j                         }d t        j                  |      d} |      }	|	k  r|dk7  r||st	        |   |g|i |S |dk(  rd	\  }
}}n6t        |      r|d   nd }
|j                  d
d       }|j                  dd       }|!|
t        fdd|gd      j                  }
n||}
|h|ft        j                   |      }t        j"                  |t%        j&                  dd|
z  z         t%        j&                  dd|
z  z         dz  z
  z        }n||}|9|7t        j(                  |      }||t%        j&                  dd|
z  z         z  z
  }n||}|dk(  r|
||fS t	        |   ||
f||d|S )Nr   superfitFr0   r:   c                     t        j                  dd| z  z         }t        j                  dd| z  z         }t        j                  dd| z  z         }d|dz  z  d|z  |z  z
  |z   }||dz  z
  dz  }||z  S )Nr   rT   r  r  rf  )r  gamma1gamma2gamma3numr  s         r5   skewz!weibull_min_gen.fit.<locals>.skew
  s|    XXa!e_FXXa!e_FXXa!e_Ffai-!F(6/1F:CFAI%-Cs7Nr7   g     @r;   NNNr-   r.   c                      |       z
  S rM   r   )r  r  r?  s    r5   r  z%weibull_min_gen.fit.<locals>.<lambda>  s    d1gk r7   g{Gz?bisect)bracketr0   r   rT   r-   r.   )r>   r)   r?   r  r@   rB   r2   _check_fit_input_parametersr<   r=   r  r?  r  r*   rootrO   r  r   rv   r  r   )rD   rE   rF   r4   fcr   r   r0   max_cs_minr  r-   r.   r  r:  r  r?  r  s                  @@r5   rB   zweibull_min_gen.fit
  s<    dL)  "a'~~'w{47$7$7788J&7;t3d3d33 "=T4=A4"Ib$(E*002	 JJtUu94BJt7;t3d3d33 T>,MAsEt9Q$A((5$'CHHWd+E:!) 1D%=#+--1T ^A>emtAGGA!AaC%288AacE?A3E!EFGEE<CKAeBHHQ1W---CCT>c5=  7;tQECuEEEr7   )r   r   r   r   rj   rq   r   rt   r}   rx   r   r   r  r   r	   r   rB   r  r  s   @r5   r&  r&  
  s`    +XE0:%))#%4 } 5 JFJFr7   r&  rU  c                   j     e Zd ZdZd Zd Z fdZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Z x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                 $    |dk\  ||kD  z  |dkD  z  S Nr   r   rD   r  r   r   s       r5   rb   ztruncweibull_min_gen._argcheckZ  s    RAE"a"f--r7   c                     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   rf   r   rg   )rD   r   rh  ri  s       r5   rj   z truncweibull_min_gen._shape_info]  sV    UQK@UQK?UQK@B|r7   c                 &    t         |   |d      S )N)r   r   r   rL  r@   r  rD   rE   r  s     r5   r  ztruncweibull_min_gen._fitstartc  s    w I 66r7   c                 
    ||fS rM   r   rN  s       r5   r   z!truncweibull_min_gen._get_supportg      !tr7   c                     t        j                  t        ||             t        j                  t        ||             z
  }|t        ||dz
        z  t        j                  t        ||             z  |z  S r]   rO   r   r  )rD   rp   r  r   r   denums         r5   rq   ztruncweibull_min_gen._pdfj  s]    Q
#bffc!QiZ&88C1Q3K"&&#a)"44==r7   c           	      (   t        j                  t        j                  t        ||             t        j                  t        ||             z
        }t        j                  |      t	        j
                  |dz
  |      z   t        ||      z
  |z
  S r]   )rO   r   r   r  rv   rw  )rD   rp   r  r   r   logdenums         r5   r   ztruncweibull_min_gen._logpdfn  si    66"&&#a),rvvs1ayj/AABvvay288AE1--Aq	9HDDr7   c                    t        j                  t        ||             t        j                  t        ||             z
  }t        j                  t        ||             t        j                  t        ||             z
  }||z  S rM   rV  rD   rp   r  r   r   r>  rW  s          r5   rt   ztruncweibull_min_gen._cdfr  d    vvs1ayj!BFFC1I:$66Q
#bffc!QiZ&88U{r7   c           	      \   t        j                  t        j                  t        ||             t        j                  t        ||             z
        }t        j                  t        j                  t        ||             t        j                  t        ||             z
        }||z
  S rM   rO   r   r   r  rD   rp   r  r   r   lognumrY  s          r5   r   ztruncweibull_min_gen._logcdfw  w    Aq	z*RVVSAYJ-??@66"&&#a),rvvs1ayj/AAB  r7   c                    t        j                  t        ||             t        j                  t        ||             z
  }t        j                  t        ||             t        j                  t        ||             z
  }||z  S rM   rV  r[  s          r5   rx   ztruncweibull_min_gen._sf|  r\  r7   c           	      \   t        j                  t        j                  t        ||             t        j                  t        ||             z
        }t        j                  t        j                  t        ||             t        j                  t        ||             z
        }||z
  S rM   r^  r_  s          r5   r   ztruncweibull_min_gen._logsf  ra  r7   c                     t        t        j                  d|z
  t        j                  t        ||             z  |t        j                  t        ||             z  z          d|z        S r]   r  rO   r   r   rD   r|   r  r   r   s        r5   r   ztruncweibull_min_gen._isf  Y    VVQUbffc!QiZ001rvvs1ayj7I3IIJJAaC 	r7   c                     t        t        j                  d|z
  t        j                  t        ||             z  |t        j                  t        ||             z  z          d|z        S r]   re  rf  s        r5   r}   ztruncweibull_min_gen._ppf  rg  r7   c           	      `   t        j                  ||z  dz         t        j                  ||z  dz   t        ||            t        j                  ||z  dz   t        ||            z
  z  }t	        j
                  t        ||             t	        j
                  t        ||             z
  }||z  S r  )rv   r  r  r  rO   r   )rD   ra   r  r   r   	gamma_funrW  s          r5   r  ztruncweibull_min_gen._munp  s    HHQqS2X&KK!b#a),r{{1Q38SAY/OO	 Q
#bffc!QiZ&885  r7   )r   r   r   r   rb   rj   r  r   rq   r   rt   r   rx   r   r   r}   r  r  r  s   @r5   rK  rK  -  sK    +X.7>E
!

!


!r7   rK  truncweibull_minr  c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zweibull_max_gen._shape_info  r
  r7   c                 l    |t        | |dz
        z  t        j                  t        | |             z  S r]   r)  r	  s      r5   rq   zweibull_max_gen._pdf  s0    aR1~bffc1"aj[111r7   c                 ~    t        j                  |      t        j                  |dz
  |       z   t	        | |      z
  S r]   r+  r	  s      r5   r   zweibull_max_gen._logpdf  s3    vvay288AaC!,,sA2qz99r7   c                 D    t        j                  t        | |             S rM   rV  r	  s      r5   rt   zweibull_max_gen._cdf  s    vvsA2qzk""r7   c                     t        | |       S rM   r2  r	  s      r5   r   zweibull_max_gen._logcdf  s    QB
{r7   c                 F    t        j                  t        | |              S rM   r-  r	  s      r5   rx   zweibull_max_gen._sf  s    #qb!*%%%r7   c                 J    t        t        j                  |       d|z         S r  )r  rO   r   r  s      r5   r}   zweibull_max_gen._ppf  s     RVVAYJA&&&r7   c                 v    t        j                  d|dz  |z  z         }t        |      dz  rd}||z  S d}||z  S )Nr   rT   r  r   )rv   r  r  )rD   ra   r  valsgns        r5   r  zweibull_max_gen._munp  sI    hhs1S57{#q6A:C Sy CSyr7   c                 V    t          |z  t        j                  |      z
  t         z   dz   S r]   r6  r|  s     r5   r   zweibull_max_gen._entropy  r7  r7   N)r   r   r   r   rj   rq   r   rt   r   rx   r}   r  r   r   r7   r5   rm  rm    s6    #HE2:#&'4r7   rm  weibull_max)r   r   c                   L    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)genlogistic_gena  A generalized logistic continuous random variable.

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

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

    %(example)s

    c                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zgenlogistic_gen._shape_info  r
  r7   c                 L    t        j                  | j                  ||            S rM   r  r	  s      r5   rq   zgenlogistic_gen._pdf
  r  r7   c                     |dz
   |dk  z  dz
  }t        j                  |      }t        j                  |      ||z  z   |dz   t        j                  t        j
                  |             z  z
  S Nr   r   )rO   r  r   rv   r  r   )rD   rp   r  multr  s        r5   r   zgenlogistic_gen._logpdf  sb     Qx1q5!A%vvayvvay49$!rxxu/F'FFFr7   c                 @    dt        j                  |       z   | z  }|S r]   rq  )rD   rp   r  Cxs       r5   rt   zgenlogistic_gen._cdf  s!    r
lqb!	r7   c                 \    | t        j                  t        j                  |             z  S rM   )rO   r  r   r	  s      r5   r   zgenlogistic_gen._logcdf  s"    rBHHRVVQBZ(((r7   c                 \    t        j                  t        j                  |d|z               S r>  )rO   r   rv   powm1r  s      r5   r}   zgenlogistic_gen._ppf  s#    rxx46*+++r7   c                 N    t        j                  | j                  ||             S rM   rv   r  r   r	  s      r5   rx   zgenlogistic_gen._sf       a+,,,r7   c                 ,    | j                  d|z
  |      S r]   r}   r  s      r5   r   zgenlogistic_gen._isf#  s    yyQ""r7   c                    t         t        j                  |      z   }t        j                  t        j                  z  dz  t        j
                  d|      z   }dt        j
                  d|      z  dt        z  z   }|t        j                  |d      z  }t        j                  dz  dz  dt        j
                  d|      z  z   }||d	z  z  }||||fS )
Nr}  rT   r  r  r  r#        .@r  r   )r#   rv   rZ  rO   r   zetar$   r  rD   r  rB  rC  rD  rE  s         r5   r   zgenlogistic_gen._stats&  s    bffQieeBEEk#o1-1&(
bhhsC  UUAXd]Qrwwq!}_,
c3h3Br7   c                 <    t        j                  |dk  |d d       S )Ng    ^Ac                 t    t        j                  |        t        j                  | dz         z   t        z   dz   S r]   )rO   r   rv   rZ  r#   r  s    r5   r  z*genlogistic_gen._entropy.<locals>.<lambda>2  s+    rvvayj266!a%=069A= r7   c                 &    dd| z  z  t         z   dz   S r0  r#   r  s    r5   r  z*genlogistic_gen._entropy.<locals>.<lambda>8  s    a1q5kF*Q. r7   r  r|  s     r5   r   zgenlogistic_gen._entropy/  s$    GQ= /0 	0r7   N)r   r   r   r   rj   rq   r   rt   r   r}   rx   r   r   r   r   r7   r5   r{  r{    s<    @E*G),-#	0r7   r{  genlogisticc                   `    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZddZd Zd Zy)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                 ,    t        j                  |      S rM   rO   r   r|  s     r5   rb   zgenpareto_gen._argcheckb      {{1~r7   c                 ^    t        ddt        j                   t        j                  fd      gS Nr  Fr	  rg   ri   s    r5   rj   zgenpareto_gen._shape_infoe  %    3'8.IJJr7   c                     t        j                  |      }t        j                  | j                  |      d   j	                         }t        j                  |dk  |d t         j                        }||fS )Nr   c                     d| z  S r>  r   r  s    r5   r  z,genpareto_gen._get_support.<locals>.<lambda>k  s
    a r7   r  )rO   r   r  r   copyr  r  rh   rN  s       r5   r   zgenpareto_gen._get_supporth  s\    JJqM*1-224OOAE1&7')vv/!tr7   c                 L    t        j                  | j                  ||            S rM   r  r	  s      r5   rq   zgenpareto_gen._pdfo  r  r7   c                 N    t        j                  ||k(  |dk7  z  ||fd |       S )Nr   c                 B    t        j                  |dz   || z         |z  S r  rd  rp   r  s     r5   r  z'genpareto_gen._logpdf.<locals>.<lambda>u  s!    RZZB!-D,Dq,H r7   r  r  r	  s      r5   r   zgenpareto_gen._logpdfs  s0    Q162QFH+,". 	.r7   c                 4    t        j                  | |        S rM   )rv   inv_boxcox1pr	  s      r5   rt   zgenpareto_gen._cdfx  s    QB'''r7   c                 2    t        j                  | |       S rM   )rv   
inv_boxcoxr	  s      r5   rx   zgenpareto_gen._sf{  s    }}aR!$$r7   c                 N    t        j                  ||k(  |dk7  z  ||fd |       S )Nr   c                 :    t        j                  || z         |z  S rM   r  r  s     r5   r  z&genpareto_gen._logsf.<locals>.<lambda>  s    RXXac]NQ,> r7   r  r  r	  s      r5   r   zgenpareto_gen._logsf~  s0    Q162QF>+,". 	.r7   c                 4    t        j                  | |        S rM   )rv   boxcox1pr  s      r5   r}   zgenpareto_gen._ppf  s    QB###r7   c                 2    t        j                  ||        S rM   )rv   boxcoxr  s      r5   r   zgenpareto_gen._isf  s    		!aR   r7   c                    d\  }}}}d|v r+t        j                  |dk  |d t        j                        }d|v r+t        j                  |dk  |d t        j                        }d	|v r+t        j                  |d
k  |d t        j                        }d|v r+t        j                  |dk  |d t        j                        }||||fS )NNNNNr:  r   c                     dd| z
  z  S r]   r   xis    r5   r  z&genpareto_gen._stats.<locals>.<lambda>  s    1B< r7   r  r  r   c                 *    dd| z
  dz  z  dd| z  z
  z  S r0  r   r  s    r5   r  z&genpareto_gen._stats.<locals>.<lambda>  s    1B{?a!b&j+I r7   r  gUUUUUU?c                 \    dd| z   z  t        j                  dd| z  z
        z  dd| z  z
  z  S )NrT   r   r  r  r  s    r5   r  z&genpareto_gen._stats.<locals>.<lambda>  s1    1B<"''!ad(*;;q1R4xH r7   r  r  c                 `    ddd| z  z
  z  d| dz  z  | z   dz   z  dd| z  z
  z  dd| z  z
  z  dz
  S )Nr  r   rT   r#  r   r  s    r5   r  z&genpareto_gen._stats.<locals>.<lambda>  sP    1AbD>Qr1uWr\A-=>!B$h(+,qt85789 r7   r  r  rO   rh   r  )rD   r  r  r:  r  r  r  s          r5   r   zgenpareto_gen._stats  s    +
1a'>Aq 7+-663A '>C I+-663A '>CH66#A
 '>C966	#A !Qzr7   c           	      r    fd}t        j                  |dk7  ||t        j                  dz               S )Nc                    d}t        j                  ddz         }t        |t        j                  |            D ]  \  }}||d|z  z  d| |z  z
  z  z   } t        j
                  | z  dk  |d| z  z  z  t         j                        S )Nr   r   r   r  r   r;  )rO   rL  ziprv   combrN  rh   )r  rv  r  kicnkra   s        r5   rU  z#genpareto_gen._munp.<locals>.__munp  s    C		!QU#Aq"''!Q-0 >CC2"*,a"f==>88AEAIsdQh1_'<bffEEr7   r   r   r  )r  r  rv   r  )rD   ra   r  _genpareto_gen__munps    `  r5   r  zgenpareto_gen._munp  s0    	F qAvq&RXXa!e_MMr7   c                     d|z   S r  r   r|  s     r5   r   zgenpareto_gen._entropy      Avr7   Nr  )r   r   r   r   rb   rj   r   rq   r   rt   rx   r   r}   r   r   r  r   r   r7   r5   r  r  >  sK    "FK*.
(%.
$!8Nr7   r  	genparetoc                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
genexpon_gena!  A generalized exponential continuous random variable.

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

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

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

    %(example)s

    c                     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  rg   )rD   rh  ri  r   s       r5   rj   zgenexpon_gen._shape_info  sV    UQK@UQK@UQK@B|r7   c           	          ||t        j                  | |z         z  z   t        j                  | |z
  |z  |t        j                  | |z         z  |z  z         z  S rM   rv   r  rO   r   rD   rp   r   r   r  s        r5   rq   zgenexpon_gen._pdf  sh     A!A''!Aq01BHHaRTN?0CA0E1F *G G 	Gr7   c                     t        j                  ||t        j                  | |z         z  z         | |z
  |z  z   |t        j                  | |z         z  |z  z   S rM   rO   r   rv   r  r  s        r5   r   zgenexpon_gen._logpdf  sY    vvaBHHaRTN?++,1ax7BHHaRTN?8KA8MMMr7   c                 ~    t        j                  | |z
  |z  |t        j                  | |z         z  |z  z          S rM   ru  r  s        r5   rt   zgenexpon_gen._cdf  s=    1"Q$A!A$7$99:::r7   c                     ||z   }||t        j                  |       z  z
  |z  }|t        j                  | |z  t        j                  |       z        j
                  z   |z  S rM   )rO   r  rv   lambertwr   realrD   r  r   r   r  r  r  s          r5   r}   zgenexpon_gen._ppf  s\    E288QB<"BKK1rvvqbz 12777::r7   c                 |    t        j                  | |z
  |z  |t        j                  | |z         z  |z  z         S rM   r  r  s        r5   rx   zgenexpon_gen._sf  s:    vvr!tQhRXXqbd^O!4Q!6677r7   c                     ||z   }||t        j                  |      z  z
  |z  }|t        j                  | |z  t        j                  |       z        j
                  z   |z  S rM   )rO   r   rv   r  r   r  r  s          r5   r   zgenexpon_gen._isf  sY    E266!9_aBKK1rvvqbz 12777::r7   Nr  r   r7   r5   r  r    s,    >GN;;
8;r7   r  genexponc                   v     e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Z fdZd Zd Z x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                 ,    t        j                  |      S rM   r  r|  s     r5   rb   zgenextreme_gen._argcheck   r  r7   c                 ^    t        ddt        j                   t        j                  fd      gS r  rg   ri   s    r5   rj   zgenextreme_gen._shape_info#  r  r7   c                    t        j                  |dkD  dt        j                  |t              z  t         j                        }t        j                  |dk  dt        j
                  |t               z  t         j                         }||fS Nr   r   )rO   rN  maximumr!   rh   minimum)rD   r  _b_as       r5   r   zgenextreme_gen._get_support&  sc    XXa!eS2::a#77@XXa!eS2::a%#88266'B2vr7   c                 N    t        j                  ||k(  |dk7  z  ||fd |       S )Nr   c                 :    t        j                  | | z        |z  S rM   r  r  s     r5   r  z+genextreme_gen._loglogcdf.<locals>.<lambda>/  s    1"Q$) r7   r  r  r	  s      r5   
_loglogcdfzgenextreme_gen._loglogcdf+  s1    !VQ!Q)r 	r7   c                 L    t        j                  | j                  ||            S rM   r  r	  s      r5   rq   zgenextreme_gen._pdf2  s     vvdll1a())r7   c                    t        j                  ||k(  |dk7  z  ||ft        j                  d      }t	        j
                  |       }| j                  ||      }t        j                  |      }t        j                  ||dk(  |t        j                   k(  z  d       t        j                  |dk(  |t        j                   k(  z   |||fd t        j                         }t        j                  ||dk(  |dk(  z  d       |S )Nr   r   r  r   c                     |  |z   |z
  S rM   r   )pex2lpex2lex2s      r5   r  z(genextreme_gen._logpdf.<locals>.<lambda>D  s    teemd&: r7   )r  r  operatormulrv   r  r  rO   r   putmaskrh   )rD   rp   r  cxlogex2logpex2r  logpdfs           r5   r   zgenextreme_gen._logpdf8  s    __a1fa01a&%\\c;2#//!Q'vvg


7Q!VbffW5s;Qw2"&&=)*7F#:w	 
 	

6AFqAv.4r7   c                 N    t        j                  | j                  ||             S rM   )rO   r   r  r	  s      r5   r   zgenextreme_gen._logcdfI  s    tq!,---r7   c                 L    t        j                  | j                  ||            S rM   rK  r	  s      r5   rt   zgenextreme_gen._cdfL  r  r7   c                 N    t        j                  | j                  ||             S rM   r  r	  s      r5   rx   zgenextreme_gen._sfO  r  r7   c                     t        j                  t        j                  |              }t        j                  ||k(  |dk7  z  ||fd |      S )Nr   c                 <    t        j                  | | z         |z  S rM   ru  r  s     r5   r  z%genextreme_gen._ppf.<locals>.<lambda>V      "((A26**Q. r7   r  )rO   r   r  r  rD   r|   r  rp   s       r5   r}   zgenextreme_gen._ppfR  sJ    VVRVVAYJ!VQ!Q. 	r7   c                     t        j                  t        j                  |               }t	        j
                  ||k(  |dk7  z  ||fd |      S )Nr   c                 <    t        j                  | | z         |z  S rM   ru  r  s     r5   r  z%genextreme_gen._isf.<locals>.<lambda>]  r  r7   r  )rO   r   rv   r  r  r  r  s       r5   r   zgenextreme_gen._isfY  sL    VVRXXqb\M""!VQ!Q. 	r7   c                    fd} |d      } |d      } |d      } |d      }t        j                  t              dk  t         j                  z  dz  dz  ||dz  z
        }d	 }t	        j
                  t              dk\  |t         j                  dz  dz  
      }	d}
d }t	        j
                  t              |
k\  |t         
      }t        j                  dk  t         j                  |       }t        j                  dk  t         j                  |dz  |	z        }d }dt        j                  d      z  t        z  t         j                  dz  z  }||||f}t	        j
                  t              |
dz  kD  g|||
      }d }|||||f}t	        j
                  t              |
dz  kD  g||d
      }||||fS )Nc                 :    t        j                  | z  dz         S r]   rf  )ra   r  s    r5   gz genextreme_gen._stats.<locals>.ga  s    88AEAI&&r7   r   rT   r  r#  gHz>r   r}  c                     t        j                  t        j                  d| z  dz         dt        j                  | dz         z  z
        | dz  z  S )Nr   r   rT   rv   r  r  r  s    r5   gam2k_fz&genextreme_gen._stats.<locals>.gam2k_fh  sB    88BJJs1uSy1!BJJq3w4G2GGHCOOr7   r  +=c                 ^    t        j                  t        j                  | dz               | z  S r]   r  r  s    r5   gamk_fz%genextreme_gen._stats.<locals>.gamk_fl  s#    88BJJq1u-.q00r7   r;  r"  c                 d    d }t        j                  | dk\  | g||t        j                        S )Nc                 X    t        j                  |       | |d|z  z   |z  z   z  |dz  z  S NrT   r  rN   )r  rD  rE  g3g2mg12s        r5   
sk1_eval_fz;genextreme_gen._stats.<locals>.sk1_eval.<locals>.sk1_eval_fx  s2    wwqzB3"qx-);#;<VS[HHr7   r  r  rk  )r  rF   r  s      r5   sk1_evalz'genextreme_gen._stats.<locals>.sk1_evalw  s2    I??1:zDz#-"&&B Br7   r  r  g(\?c                 \    d }t        j                  | dk\  ||t        j                        S )Nc                 B    |d|z  d||z   z  | z  z   | z  z   |dz  z  dz
  S )Nr  r  rT   r   )rD  rE  r  g4r   s        r5   
ku1_eval_fz;genextreme_gen._stats.<locals>.ku1_eval.<locals>.ku1_eval_f  s6    beafob&88"<<faiG!KKr7   g      пr  rk  )r  rF   r  s      r5   ku1_evalz'genextreme_gen._stats.<locals>.ku1_eval  s%    L??1:tZBFFSSr7   gq=
ףp?333333@)
rO   rN  r  r   r  r  r#   r  r   r$   )rD   r  r  rD  rE  r  r  r   r  gam2kepsr  gamkr:  r  r  sk_fillrF   r  r  r  s    `                   r5   r   zgenextreme_gen._stats`  s   	'qTqTqTqT#a&4-!BEE'C);RCZH	PA$7ruuczRU~V	1s1v}aVGL HHQXrvvu- HHQXrvvr3wu}5	B RWWQZ-&ruuax/BF#__SVc4i/!d%';	T
 BB'__SVc4i/!d%(< !R|r7   c                     t        |t              r|j                         }t        |      }|dk  rd}nd}t        |   ||f      S )Nr   r   r"  rL  r>   r)   r  r   r@   r  )rD   rE   r  r   r  s       r5   r  zgenextreme_gen._fitstart  sJ    dL)>>#D$Kq5AAw QD 11r7   c                 6   t        j                  d|dz         }d||z  z  t        j                  t        j                  ||      d|z  z  t        j
                  ||z  dz         z  d      z  }t        j                  ||z  dkD  |t         j                        S )Nr   r   r   r  r  )rO   rL  r  rv   r  r  rN  rh   )rD   ra   r  r  valss        r5   r  zgenextreme_gen._munp  s    IIa11a4x"&&GGAqMR!G#bhhqsQw&77  xx!b$//r7   c                      t         d|z
  z  dz   S r]   r  r|  s     r5   r   zgenextreme_gen._entropy  s    q1u~!!r7   )r   r   r   r   rb   rj   r   r  rq   r   r   rt   rx   r}   r   r   r  r  r   r  r  s   @r5   r  r    sV    %LK
*".*-,\	20"r7   r  
genextremec                 J    d} fd} dkD  r7t        j                         dz   } dk  rDt        j                  ||d      }|S  dkD  rt        j                   d	z        d
z   }n	d  |z
  z  }t        j                  ||dd      \  }}}}|dk7  rt        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                 4    t        j                  |       z
  S rM   )rv   r  r  s    r5   r]  z_digammainv.<locals>.func  s    zz!}q  r7   g      r   r  绽|=)tolr  g-@g뭁,?r   dy=T)xtolr  r   z _digammainv: fsolve failed, y = r   )rO   r   r   newtonr  RuntimeError)r  _emr]  x0valuer  r  rV  s   `       r5   _digammainvr    s    $ &C! 	6zVVAY_r6 OOD"%8EL	
RVVAeG_w&QBH%__T2E9=?E4d
ax=aUCDD8Or7   c                        e Zd ZdZd ZddZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Z fdZ eed       fd       Z x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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zgamma_gen._shape_info  r
  r7   c                 &    |j                  ||      S rM   standard_gamma)rD   r   r   r   s       r5   r   zgamma_gen._rvs  s    **1d33r7   c                 L    t        j                  | j                  ||            S rM   r  r  s      r5   rq   zgamma_gen._pdf  r  r7   c                 f    t        j                  |dz
  |      |z
  t        j                  |      z
  S r  )rv   rw  r  r  s      r5   r   zgamma_gen._logpdf  s)    xx#q!A%

155r7   c                 .    t        j                  ||      S rM   r  r  s      r5   rt   zgamma_gen._cdf  r   r7   c                 .    t        j                  ||      S rM   r  r  s      r5   rx   zgamma_gen._sf  s    ||Aq!!r7   c                 .    t        j                  ||      S rM   r  r  s      r5   r}   zgamma_gen._ppf  s    ~~a##r7   c                 .    t        j                  ||      S rM   rv   r  r  s      r5   r   zgamma_gen._isf  s    q!$$r7   c                 @    ||dt        j                  |      z  d|z  fS )Nr   r}  r  r  s     r5   r   zgamma_gen._stats  s!    !S^SU**r7   c                 .    t        j                  ||      S rM   rv   r  rD   ra   r   s      r5   r  zgamma_gen._munp  s    wwq!}r7   c                 D    d }d }t        j                  |dk  |||      S )Nc                 j    t        j                  |       d| z
  z  | z   t        j                  |       z   S r]   rv   rZ  r  r   s    r5   r  z+gamma_gen._entropy.<locals>.regular_formula#  s+    66!9!$q(2::a=88r7   c                     ddt        j                  dt         j                  z        z   t        j                  |       z   z  dd| z  z  z
  | dz  dz  z
  | dz  d	z  z
  | d
z  dz  z   S )Nr   r   rT   r   r  r  r  r  r  r  r  r   r3  s    r5   r  z.gamma_gen._entropy.<locals>.asymptotic_formula&  sq    
 2qw/"&&);<q!a%yH#vrk"%&VRK034c63,? @r7      r  )rD   r   r  r  s       r5   r   zgamma_gen._entropy!  s)    	9	@ q3w?<NOOr7   c                     t        |t              r|j                         }t        |      }dd|dz  z   z  }t        |   ||f      S )Nr#  :0yE>rT   rL  r  )rD   rE   r  r   r  s       r5   r  zgamma_gen._fitstart0  sM     dL)>>#D4[Aw QD 11r7   a<          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                    |j                  dd       }|j                  dd      }t        |t              s|&|j                         dk7  rt	        |   |g|i |S |j                  dd        t        |g d      }|j                  dd       }t        |       |||t        d      t        j                  |      }t        j                  |      j                         st        d      |j                         dk(  rt        j                  |      }t        j                  |      }	t        j                  ||z
  d	z        }
|||}}}||
||
d
|	z  z  }||t        j                   |	|z        }|
||	||z
  z  }|
||	|d
z  z  }|||z
  |z  }||||z  z
  }|||z
  |z  }|||fS t        j"                  ||k        rt%        d|t        j&                        |dk7  r||z
  }|j                         }|||}nt        j(                  |      t        j(                  |      j                         z
  d	z
  t        j                   d	z
  d
z  dz  z         z   dz  z  }|dz  }|dz  }t+        j,                  fd||d      }||z  }nFt        j(                  |      j                         t        j(                  |      z
  }t/        |      }|}|||fS )Nr   r0   r:   r;   r  r   r   r   r  rT   r  r  r   r  r  g333333?gffffff?c                 `    t        j                  |       t        j                  |       z
  z
  S rM   )rO   r   rv   r  )r   r  s    r5   r  zgamma_gen.fit.<locals>.<lambda>  s!    bffQi"**Q-.G!.K r7   )disp)r<   r>   r)   r=   r@   rB   r2   r   r6   r   rO   r   r   r   r   r  r   r  rJ  rh   r   r   brentqr  )rD   rE   rF   r4   r   r0   r  r   m1m2m3r   r-   r.   r  aestxar  r  r  r  s                      @r5   rB   zgamma_gen.fit<  s    xx%(E*t\*4!7 7;t3d3d33 	!$(=>(D)$T*>d.63E  ) * * zz${{4 $$&CDD <<>T!BB$))*BfEsAyS[U]a"f{u}QyU]b3hyS[%1*%y#X&{1u9n}cQc5= 
 66$$,wd"&&AA19 $;Dyy{ >~ FF4L266$<#4#4#66!bggqsQhAo662a4@5\5\OO$K$&4
 1HE
 t!!#bffVn4AAAE$~r7   r  )r   r   r   r   rj   r   rq   r   rt   rx   r}   r   r   r  r   r  r	   r   rB   r  r  s   @r5   r   r     si    'PE4*6!"$%+P
2 } 5 eer7   r   r  c                   R     e Zd ZdZd Zd Z fdZ eed       fd       Z	 x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                     t        j                  t        j                  |      |k(        }|s"d|d}t        j                  |t
        d       |dkD  S )NzRThe shape parameter of the erlang distribution has been given a non-integer value r1   r  
stacklevelr   )rO   r   floorwarningswarnRuntimeWarning)rD   r   allintmessages       r5   rb   zerlang_gen._argcheck  sM    q()==>EDGMM'>a@1ur7   c                 @    t        dddt        j                  fd      gS )Nr   Tr   rf   rg   ri   s    r5   rj   zerlang_gen._shape_info  rk   r7   c                     t        |t              r|j                         }t        ddt	        |      dz  z   z        }t
        t        |   ||f      S )NrI  r7  rT   rL  )r>   r)   r  r  r   r@   r   r  )rD   rE   r   r  s      r5   r  zerlang_gen._fitstart  sP     dL)>>#DteDk1n,-.Y/A4/@@r7   a          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                 *    t        |   |g|i |S rM   )r@   rB   rD   rE   rF   r4   r  s       r5   rB   zerlang_gen.fit  s     w{4/$/$//r7   )r   r   r   r   rb   rj   r  r	   r   rB   r  r  s   @r5   rB  rB    s9    &CA } 5/ 0000r7   rB  erlangc                   T    e Zd ZdZd Zd Zd Zd Zd ZddZ	d	 Z
d
 Zd Zd Zd Zy)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                     |dkD  |dk7  z  S r-  r   )rD   r   r  s      r5   rb   zgengamma_gen._argcheck      A!q&!!r7   c                     t        dddt        j                  fd      }t        ddt        j                   t        j                  fd      }||gS r  rg   r  s      r5   rj   zgengamma_gen._shape_info  B    UQK@UbffWbff$5~FBxr7   c                 N    t        j                  | j                  |||            S rM   r  r  s       r5   rq   zgengamma_gen._pdf      vvdll1a+,,r7   c                 p    t        j                  |dk7  |dkD  z  ||ffdt        j                         S )Nr   c                     t        j                  t        |            t        j                  |z  dz
  |       z   | |z  z
  t        j
                        z
  S r]   )rO   r   r  rv   rw  r  )rp   r  r   s     r5   r  z&gengamma_gen._logpdf.<locals>.<lambda>  sB    "&&Q.288AaC!GQ+??!Q$FTUV r7   r  r   r  s     ` r5   r   zgengamma_gen._logpdf  s6    !VAAWw  	 r7   c                     ||z  }t        j                  ||      }t        j                  ||      }t        j                  |dkD  ||      S r-  rv   r  r  rO   rN  rD   rp   r   r  xcval1val2s          r5   rt   zgengamma_gen._cdf  B    T{{1b!||Ar"xxAtT**r7   Nc                 8    |j                  ||      }|d|z  z  S )Nr  r   r#  )rD   r   r  r   r   r  s         r5   r   zgengamma_gen._rvs  s%    '''52a4yr7   c                     ||z  }t        j                  ||      }t        j                  ||      }t        j                  |dkD  ||      S r-  r\  r]  s          r5   rx   zgengamma_gen._sf#  ra  r7   c                     t        j                  ||      }t        j                  ||      }t        j                  |dkD  ||      d|z  z  S r  rv   r  r  rO   rN  rD   r|   r   r  r_  r`  s         r5   r}   zgengamma_gen._ppf)  B    ~~a#q!$xxAtT*SU33r7   c                     t        j                  ||      }t        j                  ||      }t        j                  |dkD  ||      d|z  z  S r  re  rf  s         r5   r   zgengamma_gen._isf.  rg  r7   c                 :    t        j                  ||dz  |z        S r  r.  )rD   ra   r   r  s       r5   r  zgengamma_gen._munp3  s    wwq!C%'""r7   c                 H    d }d }t        j                  |dk\  ||f||      S )Nc                     t        j                  |       }| d|z
  z  ||z  z   }t        j                  |       t        j                  t        |            z
  }||z   }|S r]   )rv   rZ  r  rO   r   r  )r   r  rv  ABr  s         r5   r  z&gengamma_gen._entropy.<locals>.regular8  sQ    &&)CQWa'A

1s1v.AAAHr7   c                 :   t         j                         t        j                  |       dz  z
  t        j                  t        j                  |            z
  | dz  dz  z   | dz  dz  z
  t        j                  |       | dz  dz  z
  | dz  dz  z
  | dz  d	z  z   |z  z   S )
NrT   r;  r  r  r  r  r  r  r  )r  r   rO   r   r  )r   r  s     r5   
asymptoticz)gengamma_gen._entropy.<locals>.asymptotic?  s    MMObffQik1ffRVVAY'(+,c61*5893{CvvayAsFA:-C;q#vslJAMN Or7      r  )rD   r   r  r  ro  s        r5   r   zgengamma_gen._entropy7  s,    		O qCx!QWEEr7   r  )r   r   r   r   rb   rj   rq   r   rt   r   rx   r}   r   r  r   r   r7   r5   rR  rR    s?    >"
- ++4
4
#Fr7   rR  gengammac                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zgenhalflogistic_gen._shape_infoa  r
  r7   c                 $    | j                   d|z  fS r  r3  r|  s     r5   r   z genhalflogistic_gen._get_supportd  s    vvs1u}r7   c                 x    d|z  }t        j                  d||z  z
        }||dz
  z  }||z  }d|z  d|z   dz  z  S r  rO   r   )rD   rp   r  limitr  tmp0tmp2s          r5   rq   zgenhalflogistic_gen._pdfg  sP     Ajj1Q3U1W~Cxv4!##r7   c                 b    d|z  }t        j                  d||z  z
        }||z  }d|z
  d|z   z  S r(  rw  )rD   rp   r  rx  r  rz  s         r5   rt   zgenhalflogistic_gen._cdfp  s=    Ajj1Q3U|DQtV$$r7   c                 0    d|z  dd|z
  d|z   z  |z  z
  z  S r(  r   r  s      r5   r}   zgenhalflogistic_gen._ppfv  s'    1ua#a%#a%1,,--r7   c                 D    dd|z  dz   t        j                  d      z  z
  S r  r1  r|  s     r5   r   zgenhalflogistic_gen._entropyy  s"    AaCE266!9$$$r7   N)
r   r   r   r   rj   r   rq   rt   r}   r   r   r7   r5   rs  rs  K  s&    *E$%.%r7   rs  genhalflogisticc                   p     e Zd ZdZd Zd Z fdZd Zd Zd e	d               Z
d	 Zd
 ZddZd Z xZS )genhyperbolic_genu  A generalized hyperbolic continuous random variable.

    %(before_notes)s

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

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

    .. math::

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

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

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

    %(after_notes)s

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

    .. math::

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

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

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

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

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

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

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

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

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

    %(example)s

    c                     t        j                  t        j                  |      |k  |dk\        t        j                  t        j                  |      |k  |dk        z  S r-  )rO   logical_andr  )rD   r  r   r   s       r5   rb   zgenhyperbolic_gen._argcheck  sH    rvvay1}a1f5..aQ78 	9r7   c                     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	  r   r   rf   r   rg   )rD   iprh  ri  s       r5   rj   zgenhyperbolic_gen._shape_info  sd    UbffWbff$5~FUQK?UbffWbff$5~FB|r7   c                 &    t         |   |d      S )N)r   r   r   rL  rQ  rR  s     r5   r  zgenhyperbolic_gen._fitstart  s     w K 88r7   c                 D    t         j                  d        } |||||      S )Nc                 2    t        j                  | |||      S rM   )r   genhyperbolic_logpdfrp   r  r   r   s       r5   _logpdf_singlez1genhyperbolic_gen._logpdf.<locals>._logpdf_single  s    ..q!Q::r7   rO   	vectorize)rD   rp   r  r   r   r  s         r5   r   zgenhyperbolic_gen._logpdf  s-     
	; 
	; aAq))r7   c                 D    t         j                  d        } |||||      S )Nc                 2    t        j                  | |||      S rM   )r   genhyperbolic_pdfr  s       r5   _pdf_singlez+genhyperbolic_gen._pdf.<locals>._pdf_single  s    ++Aq!Q77r7   r  )rD   rp   r  r   r   r  s         r5   rq   zgenhyperbolic_gen._pdf  s-     
	8 
	8 1aA&&r7   c                 N    t        j                  | t         j                  g      S )NotypesrO   r  float64)r]  s    r5   r  zgenhyperbolic_gen.<lambda>  s    ",,tRZZL9 r7   c                    t        j                  |||gt              j                  j	                  t        j
                        }t        j                  t        d|      }t        j                  ||z   ||z
  z        }||z  t        j                  |dz   |      z  t        j                  ||      z  }d}	d}
| |cxk  r|k  r?n n<t        j                  || ||	|
      d   t        j                  ||||	|
      d   z   }nt        j                  || ||	|
      d   }t        j                  |      rd}t        j                   |t"        d       t%        d	t'        d
|            S )z
        Integrate the pdf of the genhyberbolic distribution from x0 to x1.
        This is a private function used by _cdf() and _sf() only; either x0
        will be -inf or x1 will be inf.
        _genhyperbolic_pdfr   r  r   )epsrelepsabszdInfinite values encountered in scipy.special.kve. Values replaced by NaN to avoid incorrect results.r  rD  r   r   )rO   arrayrN  ctypesdata_asc_void_pr   from_cythonr   r   rv   kvr   quadisnanrG  rH  rI  maxr  )r  r;  r  r   r   	user_datallcr  r   r  r  intgrlrX   s                r5   _integrate_pdfz genhyperbolic_gen._integrate_pdf  sJ    HHaAY.55==fooN	**63G+46GGQUQUO$sRUU1q5!_$ruuQ{2>r>  nnS"d,26CCDF!sD".4VEEFHHF
 ^^CR+1&BBCEF88FHCMM#~!<3C())r7   c                 J    | j                  t        j                   ||||      S rM   r  rO   rh   rD   rp   r  r   r   s        r5   rt   zgenhyperbolic_gen._cdf   s!    ""BFF7Aq!Q77r7   c                 H    | j                  |t        j                  |||      S rM   r  r  s        r5   rx   zgenhyperbolic_gen._sf#  s    ""1bffaA66r7   c                 R   t        j                  |d      t        j                  |d      z
  }t        j                  |d      }t        j                  |d      }t        j                  |||||      }	t        j                  ||      }
||	z  t        j
                  |	      |
z  z   S )NrT   r   r"  )r  r   r.   r   r   r  )rO   float_powergeninvgaussr  r  r   )rD   r  r   r   r   r   r  r  r  gignormsts              r5   r   zgenhyperbolic_gen._rvs&  s    
 ^^Aq!BNN1a$88^^B$^^B&oo%   t,?3w...r7   c                    t        j                  |||      \  }}}t        j                  |d      t        j                  |d      z
  }t        j                  |d      }t        j                  dd      t        j                  |d      z  }t        j                  ddd      }|j	                  |j
                  d|j                  z  z         }t        j                  ||z   |      \  }}}	}
fd	|||	|
fD        \  }}}}||z  |z  }||z  t        j                  |d      t        j                  |d      z  |t        j                  |d      z
  z  z   }t        j                  |d
      t        j                  |d
      z  |d
|z  |z  t        j                  d      z  z
  dt        j                  |d
      z  z   z  d
|z  t        j                  |d      z  |t        j                  |d      z
  z  z   }|t        j                  |d      z  }t        j                  |d      t        j                  |d      z  |d|	z  |z  t        j                  d      z  z
  d|z  t        j                  |d      z  t        j                  d      z  z   d
t        j                  |d      z  z
  z  t        j                  |d      t        j                  |d
      z  d|z  d|z  |z  t        j                  d      z  z
  dt        j                  |d
      z  z   z  z   d
t        j                  |d      z  |z  z   }|t        j                  |d      z  d
z
  }||||fS )NrT   r   r   r  r   r#  rB  )r   c              3   (   K   | ]	  }|z    y wrM   r   ).0r   b0s     r5   	<genexpr>z+genhyperbolic_gen._stats.<locals>.<genexpr>G  s     ;Q!b&;s   r  r  r@  r  r  r  )	rO   r  r  linspacerM  shaper*  rv   r  )rD   r  r   r   r  r  integersb1b2b3b4r1r2r3r4r:  r  m3er  m4er  r  s                        @r5   r   zgenhyperbolic_gen._stats;  s    %%aA.1a^^Aq!BNN1a$88^^B$^^Aq!BNN2s$;;;;q!Q'##HNNTAFF]$BCUU1x<4BB;2r2r*:;BBFRKGbnnQ*R^^B-BB"..Q'') ) 	

 NN1a 2>>"a#88!b&2+r2 666A&&'( EBNN2q))"..Q'')) 	 "..G,,NN1a 2>>"a#88!b&2+r3 777VbnnR++bnnR.EEFA&&'( NN1a 2>>"a#88Vb2glR^^B%<<<A&&'(	( r1%%*+ 	 "..B''!+!Qzr7   r  )r   r   r   r   rb   rj   r  r   rq   staticmethodr  rt   rx   r   r   r  r  s   @r5   r  r    sT    Wr99
*' :*  :*@87/*'r7   r  genhyperbolicc                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zgompertz_gen._shape_info~  r
  r7   c                 L    t        j                  | j                  ||            S rM   r  r	  s      r5   rq   zgompertz_gen._pdf  r  r7   c                 d    t        j                  |      |z   |t        j                  |      z  z
  S rM   r  r	  s      r5   r   zgompertz_gen._logpdf  s%    vvay1}q288A;..r7   c                 \    t        j                  | t        j                  |      z         S rM   ru  r	  s      r5   rt   zgompertz_gen._cdf  s#    !bhhqk)***r7   c                 `    t        j                  d|z  t        j                  |       z        S r>  r  r  s      r5   r}   zgompertz_gen._ppf  s$    xxq288QB</00r7   c                 Z    t        j                  | t        j                  |      z        S rM   r  r	  s      r5   rx   zgompertz_gen._sf  s     vvqb288A;&''r7   c                 Z    t        j                  t        j                  |       |z        S rM   r  rD   r  r  s      r5   r   zgompertz_gen._isf  s    xx
1%%r7   c                 x    dt        j                  |      z
  t        j                  j	                  |      |z  z
  S r  )rO   r   rv   _ufuncs_scaled_exp1r|  s     r5   r   zgompertz_gen._entropy  s-    RVVAY!8!8!;A!===r7   Nr   r   r   r   rj   rq   r   rt   r}   rx   r   r   r   r7   r5   r  r  h  s0    *E*/+1(&>r7   r  gompertzc                     t        j                  |       } t        j                  |      }|j                         }t        j                  ||z
        }t        j                  | |      S )N)weights)rO   r   r  r   average)rp   
logweightsmaxlogwr  s       r5   _average_with_log_weightsr    sM    


1AJ'JnnGffZ')*G::a))r7   c                   r    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Ze ee      d               Zy)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}))

    for real :math:`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                     g S rM   r   ri   s    r5   rj   zgumbel_r_gen._shape_info  r   r7   c                 J    t        j                  | j                  |            S rM   r  r   s     r5   rq   zgumbel_r_gen._pdf      vvdll1o&&r7   c                 6    | t        j                  |       z
  S rM   rq  r   s     r5   r   zgumbel_r_gen._logpdf  s    rBFFA2Jr7   c                 V    t        j                  t        j                  |              S rM   rq  r   s     r5   rt   zgumbel_r_gen._cdf  s    vvrvvqbzk""r7   c                 0    t        j                  |        S rM   rq  r   s     r5   r   zgumbel_r_gen._logcdf  s    r
{r7   c                 V    t        j                  t        j                  |              S rM   r1  r   s     r5   r}   zgumbel_r_gen._ppf  s    q	z"""r7   c                 X    t        j                  t        j                  |               S rM   r  r   s     r5   rx   zgumbel_r_gen._sf  s     "&&!*%%%r7   c                 X    t        j                  t        j                  |               S rM   rO   r   r  r   s     r5   r   zgumbel_r_gen._isf  s     !}%%%r7   c                     t         t        j                  t        j                  z  dz  dt        j                  d      z  t        j                  dz  z  t        z  dfS )Nr}  r  r  r  r  r#   rO   r   r   r$   ri   s    r5   r   zgumbel_r_gen._stats  s?    ruuRUU{32771:beeQh(>(GOOr7   c                     t         dz   S r  r  ri   s    r5   r   zgumbel_r_gen._entropy  s    {r7   c                    t        | ||      \  }}fd}||} ||      |fS |	|fdnfd|j                  dd      }|dz  |dz  }
}	fd} ||	|
      sE|	dkD  s|
t        j                  k  r-|	dz  }	|
dz  }
 ||	|
      s|	dkD  r|
t        j                  k  r-t	        j
                  |	|
fd	d	
      }|j                  }||n ||      |fS )Nc                 |    |  t        j                   | z        t        j                  t	                    z
  z  S rM   )rv   r@  rO   r   r  )r.   rE   s    r5   get_loc_from_scalez,gumbel_r_gen.fit.<locals>.get_loc_from_scale  s1    6R\\4%%-8266#d);LLMMr7   c                     z
  t        j                  z
  | z        z  z   }t              | z   z  }|j                         |z
  S rM   )rO   r   r  r  )r.   term1term2rE   r-   s      r5   r]  zgumbel_r_gen.fit.<locals>.func  sK     4Z2663:2F+GG$NEIu5E 99;..r7   c                 V     | z  }t        |      }j                         |z
  | z
  S )N)r  )r  r   )r.   sdatawavgrE   s      r5   r]  zgumbel_r_gen.fit.<locals>.func  s0    !EEME4TeLD99;-55r7   r.   r   rT   c                 r    t        j                   |             t        j                   |            k7  S rM   rN   )rQ   rR   r]  s     r5   rS   z0gumbel_r_gen.fit.<locals>.interval_contains_root  s-    V-V-. /r7   r   r  )rC  rtolr  )rE  r<   rO   rh   r   r*   rF  )rD   rE   rF   r4   r   r   r  r.   brack_startrQ   rR   rS   resr]  r-   s    `           @@r5   rB   zgumbel_r_gen.fit  s    9t9=tEdF	N  E$U+C\ EzU /6 ((7A.K(1_kAoFF
/ .ff=
frvvo!! .ff=
frvvo &&tff5E,1?CHHE*$0B50ICEzr7   N)r   r   r   r   rj   rq   r   rt   r   r}   rx   r   r   r   rJ   r   r   rB   r   r7   r5   r  r    s]    6'##&&P M*@ + @r7   r  gumbel_rc                   r    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Ze ee      d               Zy)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)

    for real :math:`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                     g S rM   r   ri   s    r5   rj   zgumbel_l_gen._shape_infoD  r   r7   c                 J    t        j                  | j                  |            S rM   r  r   s     r5   rq   zgumbel_l_gen._pdfG  r  r7   c                 2    |t        j                  |      z
  S rM   rq  r   s     r5   r   zgumbel_l_gen._logpdfK  r~  r7   c                 V    t        j                  t        j                  |              S rM   r  r   s     r5   rt   zgumbel_l_gen._cdfN  s    "&&)$$$r7   c                 V    t        j                  t        j                  |              S rM   rO   r   rv   r  r   s     r5   r}   zgumbel_l_gen._ppfQ  s    vvrxx|m$$r7   c                 .    t        j                  |       S rM   rq  r   s     r5   r   zgumbel_l_gen._logsfT  r{  r7   c                 T    t        j                  t        j                  |             S rM   rq  r   s     r5   rx   zgumbel_l_gen._sfW      vvrvvayj!!r7   c                 T    t        j                  t        j                  |             S rM   r1  r   s     r5   r   zgumbel_l_gen._isfZ  r   r7   c                     t          t        j                  t        j                  z  dz  dt        j                  d      z  t        j                  dz  z  t        z  dfS )Nr}  r  r  r  r  ri   s    r5   r   zgumbel_l_gen._stats]  sF    wbeeC2771:~beeQh&/8 	8r7   c                     t         dz   S r  r  ri   s    r5   r   zgumbel_l_gen._entropya  s    {r7   c                     |j                  d      	|d    |d<   t        j                  t        j                  |       g|i |\  }}| |fS )Nr   )r<   r  rB   rO   r   )rD   rE   rF   r4   loc_rscale_rs         r5   rB   zgumbel_l_gen.fitd  sV     88F' L=DL",,

4(8'8H4H4Hwvwr7   N)r   r   r   r   rj   rq   r   rt   r}   r   rx   r   r   r   rJ   r   r   rB   r   r7   r5   r  r  '  sZ    8'%%""8 M* + r7   r  gumbel_lc                   x     e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Ze ee       fd              Z xZS )halfcauchy_gena  A Half-Cauchy continuous random variable.

    %(before_notes)s

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

    .. math::

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

    for :math:`x \ge 0`.

    %(after_notes)s

    %(example)s

    c                     g S rM   r   ri   s    r5   rj   zhalfcauchy_gen._shape_info  r   r7   c                 :    dt         j                  z  d||z  z   z  S rX  r.  r   s     r5   rq   zhalfcauchy_gen._pdf  s    255y#ac'""r7   c                     t        j                  dt         j                  z        t        j                  ||z        z
  S r=  rO   r   r   rv   r  r   s     r5   r   zhalfcauchy_gen._logpdf  s*    vvc"%%i 288AaC=00r7   c                 T    dt         j                  z  t        j                  |      z  S r=  r  r   s     r5   rt   zhalfcauchy_gen._cdf  s    255y1%%r7   c                 T    t        j                  t         j                  dz  |z        S r  rO   tanr   r   s     r5   r}   zhalfcauchy_gen._ppf  s    vvbeeAgai  r7   c                 V    dt         j                  z  t        j                  d|      z  S Nr   r   )rO   r   r  r   s     r5   rx   zhalfcauchy_gen._sf  s     255y2::a+++r7   c                 Z    dt        j                  t         j                  |z  dz        z  S r  r  r   s     r5   r   zhalfcauchy_gen._isf  s"    266"%%'!)$$$r7   c                 ~    t         j                  t         j                  t         j                  t         j                  fS rM   r  ri   s    r5   r   zhalfcauchy_gen._stats  r  r7   c                 N    t        j                  dt         j                  z        S r  r   ri   s    r5   r   zhalfcauchy_gen._entropy  r  r7   c                    |j                  dd      rt        
|   |g|i |S t        | |||      \  }}}t	        j
                  |      }|$||k  rt        d|t        j                        |}n|}d }||}	||	fS  |||      }	||	fS )Nr9  F
halfcauchyr  c                     || z
  }|j                   t        j                  |      fd}t        j                  d      j                  dz  }t        ||t        j                  |      f      }|j                  S )Nc                 P    | dz  z   }dt        j                  |z        z  z
  S r  rO   r  )r.   denominatorra   shifted_data_squareds     r5   fun_to_solvez<halfcauchy_gen.fit.<locals>.find_scale.<locals>.fun_to_solve  s1    #Qh)==266"6{"BCCaGGr7   r   r   rC  )r   rO   squarefinfotinyr*   r  rF  )r-   rE   shifted_datar  smallr  ra   r  s         @@r5   
find_scalez&halfcauchy_gen.fit.<locals>.find_scale  sg    #:L		A#%99\#: H HHSM&&+ElUBFF<<P4QRC88Or7   r2   r@   rB   rE  rO   r  rJ  rh   )rD   rE   rF   r4   r   r   r  r-   r&  r.   r  s             r5   rB   zhalfcauchy_gen.fit  s     88J&7;t3d3d338t9=tEdF 66$<$"<t266JJC C	 E Ez sD)EEzr7   )r   r   r   r   rj   rq   r   rt   r}   rx   r   r   r   rJ   r   r   rB   r  r  s   @r5   r
  r
  x  sV    &#1&!,%. M*% + %r7   r
  r  c                   x     e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Ze ee       fd              Z xZS )halflogistic_gena  A half-logistic continuous random variable.

    %(before_notes)s

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

    .. math::

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

    for :math:`x \ge 0`.

    %(after_notes)s

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

    %(example)s

    c                     g S rM   r   ri   s    r5   rj   zhalflogistic_gen._shape_info  r   r7   c                 J    t        j                  | j                  |            S rM   r  r   s     r5   rq   zhalflogistic_gen._pdf  s     vvdll1o&&r7   c                     t        j                  d      |z
  dt        j                  t        j                  |             z  z
  S r   )rO   r   rv   r  r   r   s     r5   r   zhalflogistic_gen._logpdf  s1    vvay1}rBHHRVVQBZ$8888r7   c                 2    t        j                  |dz        S r=  )rO   tanhr   s     r5   rt   zhalflogistic_gen._cdf  s    wwqu~r7   c                 2    dt        j                  |      z  S r  rO   arctanhr   s     r5   r}   zhalflogistic_gen._ppf  s    Ar7   c                 4    dt        j                  |       z  S r  rv   expitr   s     r5   rx   zhalflogistic_gen._sf   s    288QB<r7   c                 <    t        j                  |dk  |d d       S )Nr   c                 4    t        j                  d| z         S r  rv   logitr   s    r5   r  z'halflogistic_gen._isf.<locals>.<lambda>  s    "((37*;); r7   c                 8    dt        j                  d| z
        z  S r  r0  r   s    r5   r  z'halflogistic_gen._isf.<locals>.<lambda>  s    2::a!e+<)< r7   r  r   s     r5   r   zhalflogistic_gen._isf  s!    q3w;<> 	>r7   c                 |   |dk(  ry|dk(  rdt        j                  d      z  S |dk(  r$t         j                  t         j                  z  dz  S |dk(  r	dt        z  S |dk(  rdt         j                  dz  z  d	z  S ddt	        d
d|z
        z
  z  t        j                  |dz         z  t        j                  |d      z  S )Nr   r   rT   rC  r  r  r#  r  r  r   )rO   r   r   r$   r  rv   r  r  r`   s     r5   r  zhalflogistic_gen._munp  s    66RVVAY;655;s?"6V8O6RUUAX:$$!CQqSM/"288AaC=0A>>r7   c                 2    dt        j                  d      z
  S r  r1  ri   s    r5   r   zhalflogistic_gen._entropy  r2  r7   c                    |j                  dd      rt        
|   |g|i |S t        | |||      \  }}}d }t	        j
                  |      }|$||k  rt        d|t        j                        |}n|}||n |||      }	||	fS )Nr9  Fc                    | j                   d   }t        j                  | d      }t        j                  d|dz         |dz   z  }d|z
  }d|z   }|d|z  |z  t        j                  ||z        z  z
  }d|z  |z  }||z
  }dt        j
                  |dd  |dd  z        z  }	dt        j
                  |dd  |dd  dz  z        z  }
|	t        j                  |	dz  d|z  |
z  z         z   d|z  z  }d}d}|j                         }||kD  rN|t        j                  | |z        z  }|d|z  |j                         z  z
  }t        ||z
  |z        }|}||kD  rN|S )	Nr   r  r   r   rT   r-  r#  r7  )r  rO   sortrL  r   r  r   r   rv   r4  r  )rE   r-   n_observationssorted_datar  r|   pp1r  rm  rm  Cr.   r  relative_residualshifted_meansum_term	scale_news                    r5   r&  z(halflogistic_gen.fit.<locals>.find_scale!  s    "ZZ]N''$Q/K		!^a/0.12DEAAAa%Ca#sQw77E7S=D%+KBFF59{12677ABFF48k!"oq&8899A"''!Q$^);a)?"?@@.(*E D !&++-L $d*&;,u2D)EE(1^+;hlln+LL	$'):E(A$B!!	 $d*
 Lr7   halflogisticr  r'  )rD   rE   rF   r4   r   r   r&  r  r-   r.   r  s             r5   rB   zhalflogistic_gen.fit  s     88J&7;t3d3d338t9=tEdF	D 66$<$">RVVLLC C !,*T32GEzr7   )r   r   r   r   rj   rq   r   rt   r}   rx   r   r  r   rJ   r   r   rB   r  r  s   @r5   r)  r)    sV    2'
9 >
? M*6 + 6r7   r)  rG  c                        e Zd ZdZd ZddZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Ze ee       fd              Z xZS )halfnorm_genaF  A half-normal continuous random variable.

    %(before_notes)s

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

    .. math::

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

    for :math:`x >= 0`.

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

    %(after_notes)s

    %(example)s

    c                     g S rM   r   ri   s    r5   rj   zhalfnorm_gen._shape_infol  r   r7   c                 8    t        |j                  |            S r/  r  r   s      r5   r   zhalfnorm_gen._rvso  s    <//T/:;;r7   c                     t        j                  dt         j                  z        t        j                  | |z  dz        z  S r=  rO   r   r   r   r   s     r5   rq   zhalfnorm_gen._pdfr  s1    wws255y!"&&!Ac"222r7   c                 f    dt        j                  dt         j                  z        z  ||z  dz  z
  S Nr   r   r   r   s     r5   r   zhalfnorm_gen._logpdfv  s+    RVVCI&&1S00r7   c                 X    t        j                  |t        j                  d      z        S r  rv   r  rO   r   r   s     r5   rt   zhalfnorm_gen._cdfy  s    vva"''!*n%%r7   c                 $    t        d|z   dz        S r  r   r   s     r5   r}   zhalfnorm_gen._ppf|  s    !A#s##r7   c                     dt        |      z  S r  r   r   s     r5   rx   zhalfnorm_gen._sf  s    8A;r7   c                     t        |dz        S r  r   r   s     r5   r   zhalfnorm_gen._isf  s    1~r7   c                 P   t        j                  dt         j                  z        ddt         j                  z  z
  t        j                  d      dt         j                  z
  z  t         j                  dz
  dz  z  dt         j                  dz
  z  t         j                  dz
  dz  z  fS )Nr   r   rT   r#  r  r-  r  rO   r   r   ri   s    r5   r   zhalfnorm_gen._stats  sx    BEE	"#bee)
AbeeG$beeAg^32557RUU1WqL(* 	*r7   c                 Z    dt        j                  t         j                  dz        z  dz   S rO  r   ri   s    r5   r   zhalfnorm_gen._entropy  s#    266"%%)$$S((r7   c                 :   |j                  dd      rt        	|   |g|i |S t        | |||      \  }}}t	        j
                  |      }|$||k  rt        d|t        j                        |}n|}||}||fS t        j                  |d|      dz  }||fS )Nr9  Fhalfnormr  rT   )ordercenterr   )
r2   r@   rB   rE  rO   r  rJ  rh   r  moment)
rD   rE   rF   r4   r   r   r  r-   r.   r  s
            r5   rB   zhalfnorm_gen.fit  s     88J&7;t3d3d338t9=tEdF 66$<$":THHCCE Ez LLQs;S@EEzr7   r  )r   r   r   r   rj   r   rq   r   rt   r}   rx   r   r   r   rJ   r   r   rB   r  r  s   @r5   rI  rI  V  s[    *<31&$*) M* + r7   rI  rY  c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)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                     g S rM   r   ri   s    r5   rj   zhypsecant_gen._shape_info  r   r7   c                 T    dt         j                  t        j                  |      z  z  S r  )rO   r   coshr   s     r5   rq   zhypsecant_gen._pdf  s    BEE"''!*$%%r7   c                 z    dt         j                  z  t        j                  t        j                  |            z  S r=  rO   r   r  r   r   s     r5   rt   zhypsecant_gen._cdf  s&    255y266!9---r7   c                 z    t        j                  t        j                  t         j                  |z  dz              S r=  rO   r   r  r   r   s     r5   r}   zhypsecant_gen._ppf  s&    vvbffRUU1WS[)**r7   c                 |    dt         j                  z  t        j                  t        j                  |             z  S r=  rc  r   s     r5   rx   zhypsecant_gen._sf  s(    255y2661":...r7   c                 |    t        j                  t        j                  t         j                  |z  dz               S r=  re  r   s     r5   r   zhypsecant_gen._isf  s)    rvvbeeAgck*+++r7   c                 R    dt         j                  t         j                  z  dz  ddfS )Nr   r#  rT   r.  ri   s    r5   r   zhypsecant_gen._stats  s!    "%%+a-A%%r7   c                 N    t        j                  dt         j                  z        S r  r   ri   s    r5   r   zhypsecant_gen._entropy  r  r7   N)r   r   r   r   rj   rq   rt   r}   rx   r   r   r   r   r7   r5   r^  r^    s/    &&.+/,&r7   r^  	hypsecantc                   (    e Zd ZdZd Zd Zd Zd Zy)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                 0    |dkD  |dkD  z  ||k(  z  |dkD  z  S )Nr   r  r   )rD   r   r   r  r%  s        r5   rb   zgausshyper_gen._argcheck  s'    A!a% AF+q2v66r7   c                    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 )	Nr   Fr   r	  r   r  r%  r  rg   )rD   rh  ri  r   izs        r5   rj   zgausshyper_gen._shape_info  sx    UQK@UQK@UbffWbff$5~FURL.ABBr7   c                     t        j                  ||      t        j                  ||||z   |       z  }d|z  ||dz
  z  z  d|z
  |dz
  z  z  d||z  z   |z  z  S r  rv   rm  hyp2f1)rD   rp   r   r   r  r%  normalization_constants          r5   rq   zgausshyper_gen._pdf	  sm    !#A1aQ1K!K))ABK726QW:MM19q.! 	"r7   c                     t        j                  ||z   |      t        j                  ||      z  }t        j                  |||z   ||z   |z   |       }t        j                  ||||z   |       }||z  |z  S rM   rq  )	rD   ra   r   r   r  r%  r  r>  r  s	            r5   r  zgausshyper_gen._munp  sn    ggac1o1-ii1Q3!Ar*ii1acA2&3w}r7   N)r   r   r   r   rb   rj   rq   r  r   r7   r5   rl  rl    s    @7 "
r7   rl  
gausshyperc                   `    e Zd ZdZej
                  Zd Zd Zd Z	d Z
d Zd Zd Zdd	Zd
 Zy)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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zinvgamma_gen._shape_info8  r
  r7   c                 L    t        j                  | j                  ||            S rM   r  r  s      r5   rq   zinvgamma_gen._pdf;  r  r7   c                 r    |dz    t        j                  |      z  t        j                  |      z
  d|z  z
  S r  rO   r   rv   r  r  s      r5   r   zinvgamma_gen._logpdf?  s1    1vq	!BJJqM1CE99r7   c                 4    t        j                  |d|z        S r  r  r  s      r5   rt   zinvgamma_gen._cdfB  s    ||AsQw''r7   c                 4    dt        j                  ||      z  S r  r+  r  s      r5   r}   zinvgamma_gen._ppfE  s    R__Q***r7   c                 4    t        j                  |d|z        S r  r  r  s      r5   rx   zinvgamma_gen._sfH  s    {{1cAg&&r7   c                 4    dt        j                  ||      z  S r  r  r  s      r5   r   zinvgamma_gen._isfK  s    R^^Aq)))r7   c                    t        j                  |dkD  |d t        j                        }t        j                  |dkD  |d t        j                        }d\  }}d|v r+t        j                  |dkD  |d	 t        j                        }d
|v r+t        j                  |dkD  |d t        j                        }||||fS )Nr   c                     d| dz
  z  S r  r   r   s    r5   r  z%invgamma_gen._stats.<locals>.<lambda>P  s    rQV} r7   r  rT   c                 $    d| dz
  dz  z  | dz
  z  S )Nr   rT   r   r   r   s    r5   r  z%invgamma_gen._stats.<locals>.<lambda>S  s    rQVaK'71r6'B r7   r  r  r  c                 D    dt        j                  | dz
        z  | dz
  z  S )NrI  r   rC  r  r   s    r5   r  z%invgamma_gen._stats.<locals>.<lambda>Y  s     2B+?1r6+J r7   r  r#  c                 0    dd| z  dz
  z  | dz
  z  | dz
  z  S )Nr}  r  g      &@rC  rI  r   r   s    r5   r  z%invgamma_gen._stats.<locals>.<lambda>]  s&    2a#+>!b&+IQQSV+T r7   r  )rD   r   r  r<  r=  rD  rE  s          r5   r   zinvgamma_gen._statsN  s    __QUA4(*0 __QUAB(*0 B'>Q!J,.FF4B '>Q!T,.FF4B 2r2~r7   c                 H    d }d }t        j                  |dk\  |||      }|S )Nc                 n    | | dz   t        j                  |       z  z
  t        j                  |       z   }|S r  r2  r   r  s     r5   r  z&invgamma_gen._entropy.<locals>.regularc  s/    QWq	))BJJqM9AHr7   c                     ddt        j                  |       z  z
  t        j                  d      z   t        j                  t         j                        z   dz  d| dz  z  z   | dz  dz  z   | dz  d	z  z
  | d
z  dz  z
  }|S )Nr   r  rT   UUUUUU?r;  r  r  r  r  r  r  r   r  s     r5   ro  z)invgamma_gen._entropy.<locals>.asymptoticg  s     aq	k/BFF1I-ruu=q@q#v: !3r	*,-sF2I6893s
CAHr7   rp  r  )rD   r   r  ro  r  s        r5   r   zinvgamma_gen._entropyb  s+    		 OOAHaW=r7   Nmvsk)r   r   r   r   r   r  r  rj   rq   r   rt   r}   rx   r   r   r   r   r7   r5   rw  rw    sB    : "44ME*:(+'*(r7   rw  invgammac                        e Zd ZdZej
                  Zd ZddZd Z	d Z
d Zd Zd Zd	 Z fd
Z fdZd Z ee       fd       Zd Z xZS )invgauss_genaU  An inverse Gaussian continuous random variable.

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

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

    .. math::

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

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

    This distribution uses routines from the Boost Math C++ library for
    the computation of the ``ppf`` and ``isf`` methods. [1]_

    References
    ----------
    .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.

    %(example)s

    c                 @    t        dddt        j                  fd      gS NrB  Fr   r	  rg   ri   s    r5   rj   zinvgauss_gen._shape_info  r  r7   c                 *    |j                  |d|      S Nr   r  waldrD   rB  r   r   s       r5   r   zinvgauss_gen._rvs  s      St 44r7   c                     dt        j                  dt         j                  z  |dz  z        z  t        j                  dd|z  z  ||z  dz
  dz  z        z  S )Nr   rT   rC  r;  r   rM  rD   rp   rB  s      r5   rq   zinvgauss_gen._pdf  sO     2771RUU71c6>**266$!*adQh]2J+KKKr7   c                     dt        j                  dt         j                  z        z  dt        j                  |      z  z
  ||z  dz
  dz  d|z  z  z
  S )Nr"  rT   r  r   r   r  s      r5   r   zinvgauss_gen._logpdf  sH    BFF1RUU7O#c"&&)m3qtax!mQqS6IIIr7   c                     dt        j                  |      z  }t        |||z  dz
  z        }d|z  t        | ||z  dz   z        z   }|t        j                  t        j                  ||z
              z   S r0  )rO   r   r   r  r   rD   rp   rB  r  r   r   s         r5   r   zinvgauss_gen._logcdf  sl    "''!*n"q)*F\3$!B$("344288BFF1q5M***r7   c                     dt        j                  |      z  }t        |||z  dz
  z        }d|z  t        | ||z  dz   z        z   }|t        j                  t        j
                  ||z
               z   S r0  )rO   r   r   r   r  r   r  s         r5   r   zinvgauss_gen._logsf  sn    "''!*nqtax()F\3$!B$("344288RVVAE]N+++r7   c                 L    t        j                  | j                  ||            S rM   r5  r  s      r5   rx   zinvgauss_gen._sf  s    vvdkk!R())r7   c                 L    t        j                  | j                  ||            S rM   rK  r  s      r5   rt   zinvgauss_gen._cdf      vvdll1b)**r7   c                    t        j                  ddd      5  t        j                  ||      \  }}t        j                  t	        j
                  ||d            }|dkD  }t	        j                  d||   z
  ||   d      ||<   t        j                  |      }t        | %  ||   ||         ||<   d d d        |S # 1 sw Y   S xY wNr8  )r:  rq  r7  r   r   )
rO   r;  r  r   rm   _invgauss_ppf_invgauss_isfr  r@   r}   )rD   rp   rB  ppfi_wti_nanr  s         r5   r}   zinvgauss_gen._ppf  s    [[xJ 	;''2.EAr**S..q"a89Cs7D))!AdG)RXqACIHHSMEah5	:CJ	; 
	; 
s   BB>>Cc                 p   t        j                  ddd      5  t        j                  ||      \  }}t        j                  ||d      }|dkD  }t        j
                  d||   z
  ||   d      ||<   t        j                  |      }t        | !  ||   ||         ||<   d d d        |S # 1 sw Y   S xY wr  )	rO   r;  r  rm   r  r  r  r@   r   )rD   rp   rB  isfr  r  r  s         r5   r   zinvgauss_gen._isf  s    [[xJ 	;''2.EAr##Ar1-Cs7D))!AdG)RXqACIHHSMEah5	:CJ	; 
	; 
s   BB++B5c                 F    ||dz  dt        j                  |      z  d|z  fS )NrC  r  r  r  )rD   rB  s     r5   r   zinvgauss_gen._stats  s%    2s7AbggbkM2b500r7   c                    |j                  dd      }t        |t              s#t        | t              s|j	                         dk(  rt        	|   |g|i |S t        | |||      \  }}}}	 ||t        	|   |g|i |S t        j                  ||z
  dk        rt        ddt        j                        ||z
  }t        j                  |      }|*t        |      t        j                  |dz  |dz  z
        z  }||z  }|||fS )Nr0   r:   r;   r   invgaussr  r  )r<   r>   r)   wald_genr=   r@   rB   rE  rO   r  rJ  rh   r   r  r  )
rD   rE   rF   r4   r0   fshape_sr   r   fshape_nr  s
            r5   rB   zinvgauss_gen.fit  s   (E*t\*jx.H<<>T)7;t3d3d33'B4CG(O$hf	 <8/7;t3d3d33VVD4K!O$z"&&AA$;Dwwt}H~TbffTRZ(b.-H&IJ&(Hv%%r7   c                     dt        j                  dt         j                  z        z   dt        j                  |      z  z   }d|z  }t        j                  j                  |      |z  }d|z  d|z  z
  S )zV
        Ref.: https://moser-isi.ethz.ch/docs/papers/smos-2012-10.pdf (eq. 9)
        r   rT   r  r   r  )rO   r   r   rv   r  r  )rD   rB  r   r  r   s        r5   r   zinvgauss_gen._entropy  sg     BEE	""Q^3 bDJJ##A&q(Qwq  r7   r  )r   r   r   r   r   r  r  rj   r   rq   r   r   r   rx   rt   r}   r   r   r   rB   r   r  r  s   @r5   r  r  u  so    (R "44MF5L
J+,*+1 M*& +&B!r7   r  r  c                   N    e Zd ZdZd Zd Zd Zd Zd Zd Z	dd	Z
d
 Zd Zd Zy)geninvgauss_genab  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                     ||k(  |dkD  z  S r-  r   rD   r  r   s      r5   rb   zgeninvgauss_gen._argcheck4  s    Q1q5!!r7   c                     t        ddt        j                   t        j                  fd      }t        dddt        j                  fd      }||gS )Nr  Fr	  r   r   rg   )rD   r  ri  s      r5   rj   zgeninvgauss_gen._shape_info7  B    UbffWbff$5~FUQK@Bxr7   c                     d }t        j                  |t         j                  g      } ||||      }t        j                  |      j	                         rd}t        j                  |t        d       |S )Nc                 0    t        j                  | ||      S rM   )r   geninvgauss_logpdfrp   r  r   s      r5   logpdf_singlez.geninvgauss_gen._logpdf.<locals>.logpdf_single@  s    ,,Q155r7   r  zjInfinite values encountered in scipy.special.kve(p, b). Values replaced by NaN to avoid incorrect results.r  rD  )rO   r  r  r  r  rG  rH  rI  )rD   rp   r  r   r  r%  rX   s          r5   r   zgeninvgauss_gen._logpdf<  s\    	6 ]BJJ<H!Q"88A;??HCMM#~!<r7   c                 N    t        j                  | j                  |||            S rM   r  rD   rp   r  r   s       r5   rq   zgeninvgauss_gen._pdfL  r  r7   c                     | j                  ||      \  }fd}t        j                  |t        j                  g      } ||||      S )Nc                     t        j                  ||gt              j                  j	                  t        j
                        }t        j                  t        d|      }t        j                  ||       d   S )N_geninvgauss_pdfr   )rO   r  rN  r  r  r  r   r  r   r   r  )rp   r  r   r  r  r  s        r5   _cdf_singlez)geninvgauss_gen._cdf.<locals>._cdf_singleS  s^    !Q/66>>vOI"..v7I/8:C >>#r1-a00r7   r  )r   rO   r  r  )rD   rp   r  r   r  r  r  s         @r5   rt   zgeninvgauss_gen._cdfP  sE    ""1a(B	1 ll;

|D1a##r7   c                 `    t        j                  |dkD  |||fd t        j                         S )Nr   c                 V    |dz
  t        j                  |       z  || d| z  z   z  dz  z
  S r0  r1  r  s      r5   r  z.geninvgauss_gen._logquasipdf.<locals>.<lambda>a  s,    Arvvay/@1a!A#g;q=/P r7   r  r   r  s       r5   _logquasipdfzgeninvgauss_gen._logquasipdf^  s-    q1uq!QiP+-66'3 	3r7   Nc                 X  	
 t        j                  |      r+t        j                  |      r| j                  ||||      }nR|j                  dk(  rA|j                  dk(  r2| j                  |j	                         |j	                         ||      }nt        j
                  ||      \  }}t        |j                  |      \  }	t        t        j                  |            }t        j                  |      }t        j                  ||gdgdgdgg      

j                  srt        	
fdt        t        |       d      D              }| j                  
d   
d   ||      j!                  |      ||<   
j#                          
j                  sr|dk(  r|j	                         }|S )Nr   multi_indexreadonlyflagsop_flagsc              3   \   K   | ]#  }|   sj                   |   n
t        d        % y wrM   r  slicer  r  bcits     r5   r  z'geninvgauss_gen._rvs.<locals>.<genexpr>  1      ; ! 79eR^^A.tL ;   ),r   r   )rO   r  _rvs_scalarr   rO  r  r   r  r  r  emptynditerfinishedtupler  r  rM  iternext)rD   r  r   r   r   r  shp
numsamplesidxr  r  s            @@r5   r   zgeninvgauss_gen._rvsd  si    ;;q>bkk!n""1a|<CVVq[QVVq[""1668QVVXt\JC &&q!,DAq #177D1GC RWWS\*J ((4.CAq6"/&0\J<$@BB kk  ;%*CI:q%9; ;++BqE2a5*,8::A'#, C kk  2:((*C
r7   c           	         3 d}|sd}dk  r d} j                        }d}dk\  sdkD  rd}n0t        ddt        j                  dz
        z  dz        k\  rd}nd}t	        t        j
                  |            }	t        j                  |	      }
t        j                  |
      }d}|rrqddz   z  z  |z
  }d|z  dz
  z  z  dz
  }||dz  dz  z
  }d|dz  z  d	z  ||z  dz  z
  |z   }t        j                  | t        j                  d
|dz  z        z  dz        }t        j                  d|z  dz         }|t        j                  |dz  t        j                  dz  z         z  |dz  z
  }| t        j                  |dz        z  |dz  z
  } j                  |      3 j                  |      3z
  } j                  |      3z
  }||z
  t        j                  d|z        z  }||z
  t        j                  d|z        z  }d}3 fd}|}nt        j                  d j                  |      z        }dz   t        j                  dz   dz  dz  z         z   z  }d}|t        j                  d j                  |      z        z  }d} fd}||k\  rt        d      |dk  rt        d      d}||
k  rr|
|z
  }||j                  |      z  }|j                  |      } |||z
  | z  z   } | |z  |z   }!dt        j                  |      z   ||!      k  }"t        j                   |"      }#|#dkD  r|!|"   ||||#z    ||#z  }|dk(  r||
z  dk\  rd||
z   d}$t#        |$      |dz  }||
k  rndz
  z  }%t        j$                  |%dz  f      }&t        j                   j                  |            }'|'|%z  }(|%dz  k  rOt        j                         })dkD  r|)dz  z  |%z  z
  z  z  }*n$|)t        j                  ddz  z        z  }*nd\  })}*|&dz
  z  }+d|+z  t        j                  |& z  dz        z  z  },|(|*z   |,z   }-||
k  r|
|z
  }t        j                  |      t        j                  |      }!}.|j                  |      }|-|j                  |      z  } | |(k  }/t        j&                  |/      | |(|*z   k  z  }0t        j&                  |/|0z        }1|%| |/   z  |(z  |!|/<   |'|.|/<   dkD  r|%z  | |0   |(z
  z  |)z  z   dz  z  |!|0<   n7t        j                  | |0   |(z
  t        j                        z        z  |!|0<   |)|!|0   dz
  z  z  |.|0<   t        j                  |& z  dz        | |1   |(z
  |*z
  z  d|+z  z  z
  }2dz  t        j                  |2      z  |!|1<   |+t        j                  |!|1    z  dz        z  |.|1<   t        j                  ||.z         j                  |!      k  }"t!        |"      }#|#dkD  r|!|"   ||||#z    ||#z  }||
k  rt        j(                  ||	      }!|rd|!z  }!|!S )NFr   r   Tr   rT   r  r     ir  c                 0    j                  |       z
  S rM   r  )rp   r   lmr  rD   s    r5   logqpdfz,geninvgauss_gen._rvs_scalar.<locals>.logqpdf  s    ,,Q15::r7   c                 *    j                  |       S rM   r  )rp   r   r  rD   s    r5   r  z,geninvgauss_gen._rvs_scalar.<locals>.logqpdf  s    ,,Q155r7   zvmin must be smaller than vmax.zumax must be positive.r  iP  z2Not a single random variate could be generated in zH attempts. Sampling does not appear to work for the provided parameters.)r   r   )_moder  rO   r   r  
atleast_1dr  zerosarccosr   r   r  r   r   r  r   r  r  r  logical_notrM  )4rD   r  r   r  r   
invert_resr:  
ratio_unif
mode_shiftsize1dNrp   	simulateda2a1p1q1phir[  root1root2d1d2vminvmaxumaxr  r  xplusr  r  r  r  r  accept
num_acceptrX   r  xsk1A1k2A2k3A3rl  r  cond1cond2cond3r%  r  s4   ```                                                @r5   r  zgeninvgauss_gen._rvs_scalar  s    
Jq5AJJJq! 
6QUJ#c1rwwq1u~-122J J r}}Z01GGFOHHQK	1q5\A%)Ua!e_q(1,"a%!)^QY^b2gk1A5iibggcBEk&: :Q >?ggb2gk**RVVC!Gbeeai$78826AbffS1Wo-Q6 &&q!Q/&&ua3b8&&ua3b8 	RVVC"H%55	RVVC"H%55;  vvc$"3"3Aq!"<<=a%277AEA:1+<#==q@rvvcD,=,=eQ,J&JKK6 t| !BCCqy !9::Aa-	M<//Q/77 ((a(0D4K1,,!eaiBFF1I+5VVF^
><?KAiZ!79+IN1!!"1 &??C 's++Q' a-, a!eBQU$B))!Q23BbBAEzVVQBZq5AzBE12Q6BbffQAX..BBa!eBR"&&"q1--1BR"A a-	M!bhhqk3 ((a(0,,!,44Ru-b2g>uu}5!E(]R/E
%q5"$a%1U8b=A*=*B"Ba!e!LCJ!"RVVQuX]bffQi,G%H!HCJE
QU 33%FFB37Q;'!qx"}r/A*Ba"f*MM!VbffQi/E
E
{Q': ;;%&&Q-4+<+<S!Q+GG [
><?KAiZ!79+I7 a-: jjF#c'C
r7   c                     |dk  r*|t        j                  |dz
  dz  |dz  z         dz   |z
  z  S t        j                  d|z
  dz  |dz  z         d|z
  z
  |z  S r0  r  r  s      r5   r  zgeninvgauss_gen._mode4  sf    q5Q
QT 12Q6:;;GGQUQJA-.!a%8A==r7   c                    t        j                  ||z   |      }t        j                  ||      }t        j                  |      t        j                  |      z  }|j	                         red}t        j                  |t        d       t        j                  |t        j                  t        j                        }||    ||    z  || <   |S ||z  }|S )NzInfinite values encountered in the moment calculation involving scipy.special.kve. Values replaced by NaN to avoid incorrect results.r  rD  dtype)rv   kverO   rU   r  rG  rH  rI  	full_liker  r  )	rD   ra   r  r   r>  denominf_valsrX   r:  s	            r5   r  zgeninvgauss_gen._munp;  s    ffQUAq!88C=288E?2<<>.C MM#~!<S"&&

;Ay>E8),<<AxiL  eAr7   r  )r   r   r   r   rb   rj   r   rq   rt   r  r   r  r  r  r   r7   r5   r  r    s=    #H"
 -$35nWr>r7   r  r  c                   f     e Zd ZdZej
                  Zd Zd Z fdZ	d Z
d Zd Zd
dZd	 Z x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                 >    |dkD  t        j                  |      |k  z  S r-  )rO   absoluterD   r   r   s      r5   rb   znorminvgauss_gen._argcheck  s    A"++a.1,--r7   c                     t        dddt        j                  fd      }t        ddt        j                   t        j                  fd      }||gS rf  rg   rg  s      r5   rj   znorminvgauss_gen._shape_info  rV  r7   c                 &    t         |   |d      S )N)r   r   rL  rQ  rR  s     r5   r  znorminvgauss_gen._fitstart  s     w H 55r7   c                    t        j                  |dz  |dz  z
        }|t         j                  z  }t        j                  d|      }|t	        j
                  ||z        z  t        j                  ||z  ||z  z
  |z         z  |z  S r  )rO   r   r   hypotrv   k1er   )rD   rp   r   r   r  fac1sqs          r5   rq   znorminvgauss_gen._pdf  ss    1q!t$255yXXa^bffQVn$rvvacAbDj5.@'AABFFr7   c           
         t        j                  |      r6t        j                  | j                  |t         j
                  ||f      d   S t        j                  |      }t        j                  |      }g }t        |||      D ]K  \  }}}|j                  t        j                  | j                  |t         j
                  ||f      d          M t        j                  |      S )NrL  r   )
rO   r  r   r  rq   rh   r  r  appendr  )rD   rp   r   r   resultr  a0r  s           r5   rx   znorminvgauss_gen._sf  s    ;;q>>>$))QaVDQGGa Aa AF #Aq! @RinnTYYBFF35r(<<=? @@ 88F##r7   c                       fd}t        j                  |      r
 ||||      S g }t        |||      D ]  \  }}}|j                   ||||             ! t        j                  |      S )Nc                 t   
fd}
j                  ||      } |||||       }|dk(  r|S |dkD  r1d}|}||z   } |||||       dkD  rJd|z  }||z   } |||||       dkD  rn0d}|}||z
  } |||||       dk  rd|z  }||z
  } |||||       dk  rt        j                  |||||| f
j                        }	|	S )Nc                 0    j                  | ||      |z
  S rM   rx   )rp   r   r   r|   rD   s       r5   eqz6norminvgauss_gen._isf.<locals>._isf_scalar.<locals>.eq  s    xx1a(1,,r7   r   r   rT   )rF   r  )r   r   r;  r  )r|   r   r   r!  xmemdeltaleftrightr  rD   s             r5   _isf_scalarz*norminvgauss_gen._isf.<locals>._isf_scalar  s   - 1aBB1aBQw	AvU
1a(1,eGEJE 1a(1,
 Ezq!Q'!+eGE:D q!Q'!+ __RuAq!9*.))5FMr7   )rO   r  r  r  r  )	rD   r|   r   r   r'  r  q0r  r  s	   `        r5   r   znorminvgauss_gen._isf  sk    	B ;;q>q!Q''F #Aq! 7Rk"b"56788F##r7   c                     t        j                  |dz  |dz  z
        }t        j                  d|z  ||      }||z  t        j                  |      t        j                  ||      z  z   S )NrT   r   )rB  r   r   r  )rO   r   r  r  r  )rD   r   r   r   r   r  igs          r5   r   znorminvgauss_gen._rvs  so     1q!t$\\QuW4l\K2vdhhD<H '/ 'J J J 	Jr7   c                     t        j                  |dz  |dz  z
        }||z  }|dz  |dz  z  }d|z  |t        j                  |      z  z  }ddd|dz  z  |dz  z  z   z  |z  }||||fS )NrT   r  rC  r   r#  r  )rD   r   r   r  r   varianceskewnesskurtosiss           r5   r   znorminvgauss_gen._stats  s    1q!t$5ya4%(?7a"''%.01!a!Q$hAo-.6Xx11r7   r  )r   r   r   r   r   r  r  rb   rj   r  rq   rx   r   r   r   r  r  s   @r5   r  r  N  sA    4j "44M.
6
G$($TJ2r7   r  norminvgaussc                   l     e Zd ZdZej
                  Zd Zd Zd Z	d Z
d Zd Zd Zd	 Zd fd
	Z x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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zinvweibull_gen._shape_info  r
  r7   c                     t        j                  || dz
        }t        j                  ||       }t        j                  |       }||z  |z  S r  rO   r  r   )rD   rp   r  xc1xc2s        r5   rq   zinvweibull_gen._pdf  sF    hhq1"s(#hhq1"offcTl3w}r7   c                 \    t        j                  ||       }t        j                  |       S rM   r4  )rD   rp   r  r5  s       r5   rt   zinvweibull_gen._cdf  s#    hhq1"ovvsd|r7   c                 8    t        j                  || z          S rM   )rO   r  r	  s      r5   rx   zinvweibull_gen._sf  s    !aR%   r7   c                 \    t        j                  t        j                  |       d|z        S r>  )rO   r  r   r  s      r5   r}   zinvweibull_gen._ppf  s!    xx
DF++r7   c                 <    t        j                  |        d|z  z  S Nr  r8  r  s      r5   r   zinvweibull_gen._isf  s    1"A&&r7   c                 8    t        j                  d||z  z
        S r]   rf  rz  s      r5   r  zinvweibull_gen._munp  s    xxAE	""r7   c                 T    dt         z   t         |z  z   t        j                  |      z
  S r]   r6  r|  s     r5   r   zinvweibull_gen._entropy  s"    x&1*$rvvay00r7   c                 2    |dn|}t         |   ||      S )N)r   rL  rQ  )rD   rE   rF   r  s      r5   r  zinvweibull_gen._fitstart!  s#    v4w D 11r7   rM   )r   r   r   r   r   r  r  rj   rq   rt   rx   r}   r   r  r   r  r  r  s   @r5   r1  r1    sH    : "44ME!,'#12 2r7   r1  
invweibullc                   <    e Zd ZdZd Zd Zd
dZd Zd Zd Z	d	 Z
y)jf_skew_t_gena  Jones and Faddy skew-t distribution.

    %(before_notes)s

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

    .. math::

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

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

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

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

    %(after_notes)s

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

    %(example)s

    c                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS rf  rg   rg  s      r5   rj   zjf_skew_t_gen._shape_infoO  rj  r7   c                 0   d||z   dz
  z  t        j                  ||      z  t        j                  ||z         z  }d|t        j                  ||z   |dz  z         z  z   |dz   z  }d|t        j                  ||z   |dz  z         z  z
  |dz   z  }||z  |z  S NrT   r   r   )rv   rm  rO   r   )rD   rp   r   r   r  r  r  s          r5   rq   zjf_skew_t_gen._pdfT  s    !a%!)rwwq!},rwwq1u~=!bgga!ea1fn---1s7;!bgga!ea1fn---1s7;Bw{r7   Nc                     |j                  |||      }d|z  dz
  t        j                  ||z         z  }dt        j                  |d|z
  z        z  }||z  S r  )rm  rO   r   )rD   r   r   r   r   r  r  d3s           r5   r   zjf_skew_t_gen._rvsZ  sX    q!T*"fqjBGGAEN*q2v''Bwr7   c                 ~    d|t        j                  ||z   |dz  z         z  z   dz  }t        j                  |||      S Nr   rT   r   )rO   r   rv   r{  rD   rp   r   r   r  s        r5   rt   zjf_skew_t_gen._cdf`  s>    RWWQUQ!V^,,,3zz!Q""r7   c                 ~    d|t        j                  ||z   |dz  z         z  z   dz  }t        j                  |||      S rH  )rO   r   rv   r}  rI  s        r5   rx   zjf_skew_t_gen._sfd  s>    RWWQUQ!V^,,,3{{1a##r7   c                     t         j                  |||      }d|z  dz
  t        j                  ||z         z  }dt        j                  |d|z
  z        z  }||z  S r  )rm  r  rO   r   )rD   r|   r   r   r  r  rF  s          r5   r}   zjf_skew_t_gen._ppfh  sV    XXaA"fqjBGGAEN*q2v''Bwr7   c                     d }|d|z  kD  |d|z  kD  z  |dk\  z  }t        j                  ||||ft        j                  |t        j                  g      t        j
                        S )zReturns the n-th moment(s) where all the following hold:

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

        The result is np.nan in all other cases.
        c                 n   ||z   d| z  z  }d| z  t        j                  ||      z  }t        j                  | dz         }t        j                  |dz  dkD  dd      }t        j                  |d| z  z   |z
  |d| z  z
  |z         }t        j
                  | |      |z  |z  }||z  |j                         z  S )zgComputes E[T^(n_k)] where T is skew-t distributed with
            parameters a_k and b_k.
            r   rT   r   r   r  )rv   rm  rO   rL  rN  r  r  )	n_ka_kb_kr>  r  indicesrw  r  	sum_termss	            r5   
nth_momentz'jf_skew_t_gen._munp.<locals>.nth_momentw  s     9#),CHrwwsC00Eiia(G((7Q;?B2CcCi'13s?W3LMAW-3a7I;00r7   r   r   r  r  r  r  rO   r  r  r  )rD   ra   r   r   rS  nth_moment_valids         r5   r  zjf_skew_t_gen._munpn  se    	1 aKAaK8AFC1ILLRZZL9vv	
 	
r7   r  )r   r   r   r   rj   rq   r   rt   rx   r}   r  r   r7   r5   rA  rA  *  s+    #H
#$
r7   rA  	jf_skew_tc                   R    e Zd ZdZej
                  Zd Zd Zd Z	d Z
d Zd Zd Zy	)
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                     |dkD  ||k(  z  S r-  r   r  s      r5   rb   zjohnsonsb_gen._argcheck  rT  r7   c                     t        ddt        j                   t        j                  fd      }t        dddt        j                  fd      }||gS Nr   Fr	  r   r   rg   rg  s      r5   rj   zjohnsonsb_gen._shape_info  r  r7   c                 l    t        ||t        j                  |      z  z         }|dz  |d|z
  z  z  |z  S r(  )r   rv   r8  )rD   rp   r   r   trms        r5   rq   zjohnsonsb_gen._pdf  s8    AbhhqkM)*ua1gs""r7   c                 J    t        ||t        j                  |      z  z         S rM   )r   rv   r8  rs  s       r5   rt   zjohnsonsb_gen._cdf  s    Qrxx{]*++r7   c                 P    t        j                  d|z  t        |      |z
  z        S r  )rv   r4  r   r  s       r5   r}   zjohnsonsb_gen._ppf  #    xxa9Q<!#3455r7   c                 J    t        ||t        j                  |      z  z         S rM   )r   rv   r8  rs  s       r5   rx   zjohnsonsb_gen._sf  s    AbhhqkM)**r7   c                 P    t        j                  d|z  t        |      |z
  z        S r  )rv   r4  r   r  s       r5   r   zjohnsonsb_gen._isf  r`  r7   N)r   r   r   r   r   r  r  rb   rj   rq   rt   r}   rx   r   r   r7   r5   rX  rX    s7    6 "44M"
#
,6+6r7   rX  	johnsonsbc                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
dd	Zy
)johnsonsu_gena-  A Johnson SU continuous random variable.

    %(before_notes)s

    See Also
    --------
    johnsonsb

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

    .. math::

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

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

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

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

    %(after_notes)s

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

    %(example)s

    c                     |dkD  ||k(  z  S r-  r   r  s      r5   rb   zjohnsonsu_gen._argcheck  rT  r7   c                     t        ddt        j                   t        j                  fd      }t        dddt        j                  fd      }||gS r[  rg   rg  s      r5   rj   zjohnsonsu_gen._shape_info  r  r7   c                     ||z  }t        ||t        j                  |      z  z         }|dz  t        j                  |dz         z  |z  S r  )r   rO   arcsinhr   )rD   rp   r   r   r<  r]  s         r5   rq   zjohnsonsu_gen._pdf  sI     qSA

1--.uRWWRV_$S((r7   c                 J    t        ||t        j                  |      z  z         S rM   )r   rO   ri  rs  s       r5   rt   zjohnsonsu_gen._cdf  s    QA..//r7   c                 J    t        j                  t        |      |z
  |z        S rM   )rO   sinhr   r  s       r5   r}   zjohnsonsu_gen._ppf      ww	!q(A-..r7   c                 J    t        ||t        j                  |      z  z         S rM   )r   rO   ri  rs  s       r5   rx   zjohnsonsu_gen._sf  s    A

1--..r7   c                 J    t        j                  t        |      |z
  |z        S rM   )rO   rl  r   rs  s       r5   r   zjohnsonsu_gen._isf  rm  r7   c                    d\  }}}}|dz  }t        j                  |      }	||z  }
d|v r|	dz   t        j                  |
      z  }d|v r7dt        j                  |      z  |	t        j
                  d|
z        z  dz   z  }d|v r|	dz  t        j                  |      dz  z  }d	t        j                  |
      z  }|	|	dz   z  t        j                  d	|
z        z  }t        j                  d      d|	t        j
                  d|
z        z  z   d
z  z  }| ||z   z  |z  }d|v rd	d|	z  z   }d|	dz  z  |	dz   z  t        j
                  d|
z        z  }|	dz  t        j
                  d|
z        z  }dd	|	dz  z  z   d|	d	z  z  z   |	dz  z   }dd|	t        j
                  d|
z        z  z   dz  z  }||z   ||z  z   |z  d	z
  }||||fS )Nr  r  r:  r   r  rT   r   r  r  r  r  r  r#  r  )rO   r   rl  rv   r  ra  r   )rD   r   r   r  rB  rC  rD  rE  bn2expbn2a_br  r  r  r  rA  s                   r5   r   zjohnsonsu_gen._stats  s    1CRf!e'>#+,B'>bhhsm#VBGGAcEN%:Q%>?C'>bhhsmS00B2773<B6A:&37BGGAJ!frwwqu~&="=!EEER5(B'>QvXB619
+bggaen<BRWWQsU^+Ba	k!AfaiK/&!);Bq6"''!C%.00144Er'BrE/U*Q.B3Br7   Nr  )r   r   r   r   rb   rj   rq   rt   r}   rx   r   r   r   r7   r5   re  re    s0    "F"
)0///r7   re  	johnsonsuc                   V    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZddZddZy)
landau_gena4  A Landau continuous random variable.

    %(before_notes)s

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

    .. math::

        f(x) = \frac{1}{\pi}\int_0^\infty \exp(-t \log t - xt)\sin(\pi t) dt

    for a real number :math:`x`.

    %(after_notes)s

    Often (e.g. [2]_), the Landau distribution is parameterized in terms of a
    location parameter :math:`\mu` and scale parameter :math:`c`, the latter of
    which *also* introduces a location shift. If ``mu`` and ``c`` are used to
    represent these parameters, this corresponds with SciPy's parameterization
    with ``loc = mu + 2*c / np.pi * np.log(c)`` and ``scale = c``.

    This distribution uses routines from the Boost Math C++ library for
    the computation of the ``pdf``, ``cdf``, ``ppf``, ``sf`` and ``isf``
    methods. [1]_

    References
    ----------
    .. [1] Landau, L. (1944). "On the energy loss of fast particles by
           ionization". J. Phys. (USSR). 8: 201.
    .. [2] "Landau Distribution", Wikipedia,
           https://en.wikipedia.org/wiki/Landau_distribution
    .. [3] Chambers, J. M., Mallows, C. L., & Stuck, B. (1976).
           "A method for simulating stable random variables."
           Journal of the American Statistical Association, 71(354), 340-344.
    .. [4] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
    .. [5] Yoshimura, T. "Numerical Evaluation and High Precision Approximation
           Formula for Landau Distribution".
           :doi:`10.36227/techrxiv.171822215.53612870/v2`

    %(example)s

    c                     g S rM   r   ri   s    r5   rj   zlandau_gen._shape_infoX  r   r7   c                      y)NgX(@r   ri   s    r5   r   zlandau_gen._entropy[  s    "r7   c                 0    t        j                  |dd      S r  )rm   _landau_pdfr   s     r5   rq   zlandau_gen._pdf_  r  r7   c                 0    t        j                  |dd      S r  )rm   _landau_cdfr   s     r5   rt   zlandau_gen._cdfb  r  r7   c                 0    t        j                  |dd      S r  )rm   
_landau_sfr   s     r5   rx   zlandau_gen._sfe  s    ~~aA&&r7   c                 0    t        j                  |dd      S r  )rm   _landau_ppfr   s     r5   r}   zlandau_gen._ppfh  r  r7   c                 0    t        j                  |dd      S r  )rm   _landau_isfr   s     r5   r   zlandau_gen._isfk  r  r7   c                 ~    t         j                  t         j                  t         j                  t         j                  fS rM   r  ri   s    r5   r   zlandau_gen._statsn  r  r7   c                 0    |dkD  rt         j                  S dS r  r  r`   s     r5   r  zlandau_gen._munpq  s    Qrvv%A%r7   Nc                     t        |t              r|j                         }t        j                  |g d      \  }}}|||z
  dz  fS r  r  r  s         r5   r  zlandau_gen._fitstartt  r  r7   c                    t         j                  dz  }|j                  t         j                   dz  t         j                  dz  |      }|j                  |      }dt         j                  z  ||z   t        j                  |      z  t        j
                  ||z  t        j                  |      z  ||z   z        z
  z  }|S )NrT   r  )rO   r   r  r1  r  r   r   )rD   r   r   pi_2UWSs          r5   r   zlandau_gen._rvs{  s    uuqy  "%%!RUUQYT B--4-8I$(bffQi/664!8bffQi#7D1H"EFG Hr7   rM   r  )r   r   r   r   rj   r   rq   rt   rx   r}   r   r   r  r  r   r   r7   r5   rv  rv  ,  s?    *V#(('((.&"r7   rv  landauc                   r    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Ze eed      d               Zy)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                     g S rM   r   ri   s    r5   rj   zlaplace_gen._shape_info  r   r7   Nc                 *    |j                  dd|      S )Nr   r   r  )laplacer   s      r5   r   zlaplace_gen._rvs  s    ##Aqt#44r7   c                 F    dt        j                  t        |             z  S r  )rO   r   r  r   s     r5   rq   zlaplace_gen._pdf  s    2663q6'?""r7   c           	          t        j                  d      5  t        j                  |dkD  ddt        j                  |       z  z
  dt        j                  |      z        cd d d        S # 1 sw Y   y xY w)Nr8  rp  r   r   r   )rO   r;  rN  r   r   s     r5   rt   zlaplace_gen._cdf  sZ    [[h' 	H88AE3RVVQBZ#7RVVAYG	H 	H 	Hs   A
A++A4c                 &    | j                  |       S rM   rt   r   s     r5   rx   zlaplace_gen._sf  s    yy!}r7   c                     t        j                  |dkD  t        j                  dd|z
  z         t        j                  d|z              S r   rO   rN  r   r   s     r5   r}   zlaplace_gen._ppf  s8    xxC"&&AaC/!1266!A#;??r7   c                 &    | j                  |       S rM   r  r   s     r5   r   zlaplace_gen._isf  s    		!}r7   c                      y)N)r   rT   r   r  r   ri   s    r5   r   zlaplace_gen._stats  s    r7   c                 2    t        j                  d      dz   S r  r1  ri   s    r5   r   zlaplace_gen._entropy  s    vvay{r7   z        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                     t        | |||      \  }}}|t        j                  |      }|7t        j                  t        j                  ||z
              t        |      z  }||fS rM   )rE  rO   medianr  r  r  )rD   rE   rF   r4   r   r   s         r5   rB   zlaplace_gen.fit  sf     9t9=tEdF <99T?D>ffRVVD4K01SY>FV|r7   r  )r   r   r   r   rj   r   rq   rt   rx   r}   r   r   r   rJ   r
   r   rB   r   r7   r5   r  r    sa    &5#H@  6F G	G 
r7   r  r  c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)laplace_asymmetric_genu  An asymmetric Laplace continuous random variable.

    %(before_notes)s

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

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

    .. math::

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

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

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

    %(after_notes)s

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

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

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

    %(example)s

    c                 @    t        dddt        j                  fd      gS )NkappaFr   r	  rg   ri   s    r5   rj   z"laplace_asymmetric_gen._shape_info  s    7EArvv;GHHr7   c                 L    t        j                  | j                  ||            S rM   r  rD   rp   r  s      r5   rq   zlaplace_asymmetric_gen._pdf  s    vvdll1e,--r7   c                     d|z  }|t        j                  |dk\  | |      z  }|t        j                  ||z         z  }|S r  r  )rD   rp   r  kapinvry  s        r5   r   zlaplace_asymmetric_gen._logpdf  sD    5"((16E6622rvveFl##
r7   c                     d|z  }||z   }t        j                  |dk\  dt        j                  | |z        ||z  z  z
  t        j                  ||z        ||z  z        S r  rO   rN  r   rD   rp   r  r  
kappkapinvs        r5   rt   zlaplace_asymmetric_gen._cdf  sf    56\
xxQBFFA2e8,fZ.?@@qx(%
*:;= 	=r7   c           	          d|z  }||z   }t        j                  |dk\  t        j                  | |z        ||z  z  dt        j                  ||z        ||z  z  z
        S r  r  r  s        r5   rx   zlaplace_asymmetric_gen._sf  sh    56\
xxQr%x(&*;<BFF1V8,eJ.>??A 	Ar7   c                     d|z  }||z   }t        j                  |||z  k\  t        j                  d|z
  |z  |z         |z  t        j                  ||z  |z        |z        S r]   r  rD   r|   r  r  r  s        r5   r}   zlaplace_asymmetric_gen._ppf  sm    56\
xxU:--Q
 25 899&@q|E1258: 	:r7   c                     d|z  }||z   }t        j                  |||z  k  t        j                  ||z  |z         |z  t        j                  d|z
  |z  |z        |z        S r]   r  r  s        r5   r   zlaplace_asymmetric_gen._isf   so    56\
xxVJ..*U 233F:Az1%78>@ 	@r7   c                 `   d|z  }||z
  }||z  ||z  z   }ddt        j                  |d      z
  z  t        j                  dt        j                  |d      z   d      z  }ddt        j                  |d      z   z  t        j                  dt        j                  |d      z   d      z  }||||fS )	Nr   r   r  r#  r  r}  r-  rT   r  )rD   r  r  mnr  rD  rE  s          r5   r   zlaplace_asymmetric_gen._stats'  s    5e^VmeEk)!BHHUA&&'288E13E1Es(KK!BHHUA&&'288E13E1Eq(II3Br7   c                 >    dt        j                  |d|z  z         z   S r]   r1  rD   r  s     r5   r   zlaplace_asymmetric_gen._entropy/  s    266%%-(((r7   Nr  r   r7   r5   r  r    s8    *VI.=A:@)r7   r  laplace_asymmetricc                    t        |t              st        j                  |      }|j	                  dd       }|j	                  dd       }| j
                  r$t        | j
                  j                  d            nd}g }g }| j
                  r| j
                  j                  dd      j                         }	t        |	      D ]T  \  }
}dt        |
      z   }|d|z   d|z   g}t        ||      }|j                  |       |j                  |       |P|||<   V dd	d
dddh|}t        |      j                  |      }|rt        d| d      t        |      |kD  rt        d      d ||h|vrt!        d      t        |t              r|j#                         n|}t        j$                  |      j'                         st)        d      |g|||S )Nr   r   ,r    r  fix_r-   r.   r/   r0   zUnknown keyword arguments: r1   zToo many positional arguments.r   r   )r>   r)   rO   r   r<   shapesr  splitrU  	enumeratestrr   r  set
differencer3   r  r  r   r   r   )distrE   rF   r4   r   r   
num_shapesfshape_keysfshapesr  r  r  keynamesrv  
known_keysunknown_keys
uncensoreds                     r5   rE  rE  6  s   dL)zz$88FD!DXXh%F04T[[&&s+,JKG
 {{$$S#.446f% 	 DAqA,C#'6A:.E&tU3Cs#NN3S		  +x(2%02Jt9''
3L5l^1EFF
4y:899D&+7++  ' ( 	( &0l%C!J;;z"&&(?@@)7)D)&))r7   c                   R    e Zd ZdZej
                  Zd Zd Zd Z	d Z
d Zd Zd Zy	)
levy_genag  A Levy continuous random variable.

    %(before_notes)s

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

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

    .. math::

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

    for :math:`x > 0`.

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

    %(after_notes)s

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

    Calculate the first four moments:

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

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

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

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

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

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

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

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

    Generate random numbers:

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

    And compare the histogram:

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

    c                     g S rM   r   ri   s    r5   rj   zlevy_gen._shape_info  r   r7   c                     dt        j                  dt         j                  z  |z        z  |z  t        j                  dd|z  z        z  S Nr   rT   r  rM  r   s     r5   rq   zlevy_gen._pdf  s=    2771RUU719%%)BFF2qs8,<<<r7   c                 X    t        j                  t        j                  d|z              S r  )rv   erfcrO   r   r   s     r5   rt   zlevy_gen._cdf  s    wwrwwsQw'((r7   c                 X    t        j                  t        j                  d|z              S r  rQ  r   s     r5   rx   zlevy_gen._sf  s    vvbggcAg&''r7   c                 .    t        |dz        }d||z  z  S NrT   r   r   rD   r|   rv  s      r5   r}   zlevy_gen._ppf  s    !ncCi  r7   c                 >    ddt        j                  |      dz  z  z  S r0  )rv   erfinvr   s     r5   r   zlevy_gen._isf  s    !BIIaL!O#$$r7   c                 ~    t         j                  t         j                  t         j                  t         j                  fS rM   r  ri   s    r5   r   zlevy_gen._stats  r  r7   Nr   r   r   r   r   r  r  rj   rq   rt   rx   r}   r   r   r   r7   r5   r  r  g  s9    GP "44M=)(!
%.r7   r  levyc                   R    e Zd ZdZej
                  Zd Zd Zd Z	d Z
d Zd Zd Zy	)

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                     g S rM   r   ri   s    r5   rj   zlevy_l_gen._shape_info  r   r7   c                     t        |      }dt        j                  dt        j                  z  |z        z  |z  t        j                  dd|z  z        z  S r  )r  rO   r   r   r   rD   rp   r  s      r5   rq   zlevy_l_gen._pdf  sF    V255$$R'r1R4y(999r7   c                 f    t        |      }dt        dt        j                  |      z        z  dz
  S r  )r  r   rO   r   r  s      r5   rt   zlevy_l_gen._cdf!  s,    V9Q_--11r7   c                 `    t        |      }dt        dt        j                  |      z        z  S r  )r  r   rO   r   r  s      r5   rx   zlevy_l_gen._sf%  s'    V8AO,,,r7   c                 4    t        |dz   dz        }d||z  z  S )Nr   rT   r;  r   r  s      r5   r}   zlevy_l_gen._ppf)  s#    SA&sSy!!r7   c                 *    dt        |dz        dz  z  S )Nr  rT   r   r   s     r5   r   zlevy_l_gen._isf-  s    )AaC.!###r7   c                 ~    t         j                  t         j                  t         j                  t         j                  fS rM   r  ri   s    r5   r   zlevy_l_gen._stats0  r  r7   Nr  r   r7   r5   r  r    s9    FN "44M:
2-"$.r7   r  levy_lc                        e Zd ZdZd ZddZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Ze ee       fd              Z x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                     g S rM   r   ri   s    r5   rj   zlogistic_gen._shape_infoO  r   r7   c                 &    |j                  |      S r/  )logisticr   s      r5   r   zlogistic_gen._rvsR  s    $$$$//r7   c                 J    t        j                  | j                  |            S rM   r  r   s     r5   rq   zlogistic_gen._pdfU  r  r7   c                     t        j                  |       }|dt        j                  t        j                  |            z  z
  S r=  )rO   r  rv   r  r   )rD   rp   r  s      r5   r   zlogistic_gen._logpdfY  s2    VVAYJ2++++r7   c                 ,    t        j                  |      S rM   r3  r   s     r5   rt   zlogistic_gen._cdf]      xx{r7   c                 ,    t        j                  |      S rM   rv   	log_expitr   s     r5   r   zlogistic_gen._logcdf`  s    ||Ar7   c                 ,    t        j                  |      S rM   r7  r   s     r5   r}   zlogistic_gen._ppfc  r  r7   c                 .    t        j                  |       S rM   r3  r   s     r5   rx   zlogistic_gen._sff  s    xx|r7   c                 .    t        j                  |       S rM   r  r   s     r5   r   zlogistic_gen._logsfi  s    ||QBr7   c                 .    t        j                  |       S rM   r7  r   s     r5   r   zlogistic_gen._isfl  s    |r7   c                 R    dt         j                  t         j                  z  dz  ddfS )Nr   rC  g333333?r.  ri   s    r5   r   zlogistic_gen._statso  s!    "%%+c/1g--r7   c                      yr=  r   ri   s    r5   r   zlogistic_gen._entropyr  s    r7   c                   
 |j                  dd      rt        |   g|i |S t        | ||      \  }}t	              | j                        \  }}|j                  d|      |j                  d|      }}|ffd	
|ffd	
fd}|+|)t        j                  
|f      }	|	j                  d   }|}nT|+|)t        j                  |f      }	|	j                  d   }|}n't        j                  |||f      }	|	j                  \  }}t        |      }|	j                  r||fS t        |   g|i |S )	Nr9  Fr-   r.   c                 p    | z
  |z  }t        j                  t        j                  |            dz  z
  S r  )rO   r  rv   r4  )r-   r.   r  rE   ra   s      r5   dl_dlocz!logistic_gen.fit.<locals>.dl_dloc  s1    u$A66"((1+&1,,r7   c                 v    |z
  | z  }t        j                  |t        j                  |dz        z        z
  S r  )rO   r  r.  )r.   r-   r  rE   ra   s      r5   	dl_dscalez#logistic_gen.fit.<locals>.dl_dscale  s5    u$A66!BGGAaCL.)A--r7   c                 2    | \  }} ||       ||      fS rM   r   )paramsr-   r.   r  r  s      r5   r]  zlogistic_gen.fit.<locals>.func  s%    JC3&	%(===r7   r   )r2   r@   rB   rE  r  r  r<   r   rF  rp   r  success)rD   rE   rF   r4   r   r   r-   r.   r]  r  r  r  ra   r  s    `        @@@r5   rB   zlogistic_gen.fitv  sS    88J&7;t3d3d338t9=tEdFI ^^D)
UXXeS)488GU+CU  & 	- "& 	.	> $,--#0C%%(CE&.--	E84CEE!HEC--sEl3CJC E
 #e 	7W[555	7r7   r  )r   r   r   r   rj   r   rq   r   rt   r   r}   rx   r   r   r   r   rJ   r   r   rB   r  r  s   @r5   r  r  7  se    .0', . M*07 + 07r7   r  r  c                   N    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zy)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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zloggamma_gen._shape_info  r
  r7   Nc                     t        j                  |j                  |dz   |            t        j                  |j                  |            |z  z   S )Nr   r  )rO   r   r  r  r  s       r5   r   zloggamma_gen._rvs  sM     |))!a%d);<&&--4-89!;< 	=r7   c                     t        j                  ||z  t        j                  |      z
  t        j                  |      z
        S rM   rO   r   rv   r  r	  s      r5   rq   zloggamma_gen._pdf  s.    vvac"&&)mBJJqM122r7   c                 d    ||z  t        j                  |      z
  t        j                  |      z
  S rM   r  r	  s      r5   r   zloggamma_gen._logpdf  s%    sRVVAYA..r7   c                 H    t        j                  |t        k  ||fd d       S )Nc                 d    t        j                  || z  t        j                  |dz         z
        S r]   r  r  s     r5   r  z#loggamma_gen._cdf.<locals>.<lambda>  s$    !bjj1o 56 r7   c                 T    t        j                  |t        j                  |             S rM   )rv   r  rO   r   r  s     r5   r  z#loggamma_gen._cdf.<locals>.<lambda>  s    Qq	2 r7   r  r  r"   r	  s      r5   rt   zloggamma_gen._cdf  s(     L1a&624 	4r7   c                 v    t        j                  ||      }t        j                  |t        k  |||fd d       S )Nc                 d    t        j                  |      t        j                  |dz         z   |z  S r]   r{  r  r|   r  s      r5   r  z#loggamma_gen._ppf.<locals>.<lambda>  s$    RVVAYAaC8!; r7   c                 ,    t        j                  |       S rM   r1  r  s      r5   r  z#loggamma_gen._ppf.<locals>.<lambda>      BFF1I r7   )rv   r  r  r  r!   rD   r|   r  r  s       r5   r}   zloggamma_gen._ppf  s:     NN1a I1ay;%' 	'r7   c                 H    t        j                  |t        k  ||fd d       S )Nc                 f    t        j                  || z  t        j                  |dz         z
         S r]   )rO   r  rv   r  r  s     r5   r  z"loggamma_gen._sf.<locals>.<lambda>   s'    "((1Q3AaC#899 r7   c                 T    t        j                  |t        j                  |             S rM   )rv   r  rO   r   r  s     r5   r  z"loggamma_gen._sf.<locals>.<lambda>  s    a3 r7   r  r	  s      r5   rx   zloggamma_gen._sf  s&    L1a&935 	5r7   c                 v    t        j                  ||      }t        j                  |t        k  |||fd d       S )Nc                 f    t        j                  |       t        j                  |dz         z   |z  S r]   )rO   r  rv   r  r  s      r5   r  z#loggamma_gen._isf.<locals>.<lambda>	  s&    RXXqb\BJJqsO;Q> r7   c                 ,    t        j                  |       S rM   r1  r  s      r5   r  z#loggamma_gen._isf.<locals>.<lambda>
  r  r7   )rv   r  r  r  r!   r	  s       r5   r   zloggamma_gen._isf  s:     OOAq!I1ay>%' 	'r7   c                     t        j                  |      }t        j                  d|      }t        j                  d|      t        j                  |d      z  }t        j                  d|      ||z  z  }||||fS )Nr   rT   r  r  )rv   r  	polygammarO   r  )rD   r  r   r  r-  excess_kurtosiss         r5   r   zloggamma_gen._stats  si     zz!}ll1a <<1%c(::,,q!,C8S(O33r7   c                 D    d }d }t        j                  |dk\  |||      S )Nc                 h    t        j                  |       | t        j                  |       z  z
  | z   }|S rM   )rv   r  r  )r  r  s     r5   r  z&loggamma_gen._entropy.<locals>.regular  s+    

1BJJqM 11A5AHr7   c                     dt        j                  |       z  | dz  dz  z   | dz  dz  z
  | dz  dz  z   }t        j                         |z   }|S )Nr"  r;  r  r  r  r     )rO   r   r  r   )r  termr  s      r5   ro  z)loggamma_gen._entropy.<locals>.asymptotic  sO    q	>AsF1H,q#vby81c6#:ED$&AHr7   -   r  )rD   r  r  ro  s       r5   r   zloggamma_gen._entropy  s'    		 qBw:w??r7   r  r   r   r   r   rj   r   rq   r   rt   r}   rx   r   r   r   r   r7   r5   r  r    s;    0E=3/4('5'4@r7   r  loggammac                   r     e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Ze ee       fd
              Z xZS )loglaplace_genaT  A log-Laplace continuous random variable.

    %(before_notes)s

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

    .. math::

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

    for :math:`c > 0`.

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

    %(after_notes)s

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

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

    %(example)s

    c                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zloglaplace_gen._shape_infoG  r
  r7   c                 X    |dz  }t        j                  |dk  ||       }|||dz
  z  z  S r  rO   rN  )rD   rp   r  cd2s       r5   rq   zloglaplace_gen._pdfJ  s7     eHHQUAr"1qs8|r7   c                 V    t        j                  |dk  d||z  z  dd|| z  z  z
        S Nr   r   r  r	  s      r5   rt   zloglaplace_gen._cdfQ  s/    xxAs1a4x3qA2w;77r7   c                 V    t        j                  |dk  dd||z  z  z
  d|| z  z        S r"  r  r	  s      r5   rx   zloglaplace_gen._sfT  s/    xxAq3q!t8|SaR[99r7   c                 `    t        j                  |dk  d|z  d|z  z  dd|z
  z  d|z  z        S Nr   r   r   rT   r;  r  r  s      r5   r}   zloglaplace_gen._ppfW  s7    xxC#a%3q5!1As1uIa3HIIr7   c                 `    t        j                  |dkD  dd|z
  z  d|z  z  d|z  d|z  z        S r%  r  r  s      r5   r   zloglaplace_gen._isfZ  s6    xxC#sQw-3q5!9AaC46?KKr7   c                     t        j                  d      5  |dz  |dz  }}t        j                  ||k  |||z
  z  t         j                        cd d d        S # 1 sw Y   y xY w)Nr8  r9  rT   )rO   r;  rN  rh   )rD   ra   r  r  n2s        r5   r  zloglaplace_gen._munp]  sT    [[) 	=T1a4B88BGR27^RVV<	= 	= 	=s   8AA"c                 8    t        j                  d|z        dz   S rX  r1  r|  s     r5   r   zloglaplace_gen._entropyb  s    vvc!e}s""r7   c                    t        | |||      \  }}}}|t        t        |       |   |g|i |S t	        j
                  ||k        rt        d|t        j                        |dk7  r||z
  }t        j                  t	        j                  |      |t	        j                  |      nd |d|z  nd d      \  }}|}	|t	        j                  |      n|}
|d|z  n|}||	|
fS )N
loglaplacer  r   r   r:   )r   r   r0   )rE  r@   rA   rB   rO   r  rJ  rh   r  r   r   )rD   rE   rF   r4   rG  r   r   r   r   r-   r.   r  r  s               r5   rB   zloglaplace_gen.fite  s     "=T4=A4"Ib$ <dT.tCdCdCC 66$$,|4rvvFF 19$;D {{266$<282Dv$*,.!B$d"'  )1 #^q	ZAER#u}r7   )r   r   r   r   rj   rq   rt   rx   r}   r   r  r   rJ   r   r   rB   r  r  s   @r5   r  r  &  sU    @E8:JL=
# M* + r7   r  r+  c                 ^    t        j                  | dk7  | |fd t        j                         S )Nr   c                     t        j                  |       dz   d|dz  z  z  t        j                  || z  t        j                  dt         j                  z        z        z
  S r  )rO   r   r   r   rp   r  s     r5   r  z!_lognorm_logpdf.<locals>.<lambda>  sL    rvvay!|mq1a4x0q1urwwq255y'99:; r7   r  r   r.  s     r5   _lognorm_logpdfr/    s.    ??	QA	<FF7	 r7   c                        e Zd ZdZej
                  Zd ZddZd Z	d Z
d Zd Zd Zd	 Zd
 Zd Zd Zd Ze eed       fd              Z xZS )lognorm_gena  A lognormal continuous random variable.

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

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

    %(example)s

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

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

    c                 @    t        dddt        j                  fd      gS )Nr  Fr   r	  rg   ri   s    r5   rj   zlognorm_gen._shape_info  r
  r7   c                 P    t        j                  ||j                  |      z        S rM   rO   r   r   )rD   r  r   r   s       r5   r   zlognorm_gen._rvs  s!    vva,66t<<==r7   c                 L    t        j                  | j                  ||            S rM   r  rD   rp   r  s      r5   rq   zlognorm_gen._pdf  r  r7   c                     t        ||      S rM   r/  r6  s      r5   r   zlognorm_gen._logpdf  s    q!$$r7   c                 D    t        t        j                  |      |z        S rM   r   rO   r   r6  s      r5   rt   zlognorm_gen._cdf  s    Q''r7   c                 D    t        t        j                  |      |z        S rM   r  r6  s      r5   r   zlognorm_gen._logcdf  s    BFF1IM**r7   c                 D    t        j                  |t        |      z        S rM   rO   r   r   rD   r|   r  s      r5   r}   zlognorm_gen._ppf      vva)A,&''r7   c                 D    t        t        j                  |      |z        S rM   r   rO   r   r6  s      r5   rx   zlognorm_gen._sf  s    q	A&&r7   c                 D    t        t        j                  |      |z        S rM   )r   rO   r   r6  s      r5   r   zlognorm_gen._logsf  s    266!9q=))r7   c                 D    t        j                  |t        |      z        S rM   rO   r   r   r>  s      r5   r   zlognorm_gen._isf  r?  r7   c                     t        j                  ||z        }t        j                  |      }||dz
  z  }t        j                  |dz
        d|z   z  }t        j                  g d|      }||||fS Nr   rT   )r   rT   r  r   r  )rO   r   r   polyval)rD   r  r  rB  rC  rD  rE  s          r5   r   zlognorm_gen._stats  sf    FF1Q3KWWQZ1gWWQqS\1Q3ZZ*A.3Br7   c                     ddt        j                  dt         j                  z        z   dt        j                  |      z  z   z  S Nr   r   rT   r   )rD   r  s     r5   r   zlognorm_gen._entropy  s3    a"&&255/)Aq	M9::r7   aF          When `method='MLE'` and
        the location parameter is fixed by using the `floc` argument,
        this function uses explicit formulas for the maximum likelihood
        estimation of the log-normal shape and scale parameters, so the
        `optimizer`, `loc` and `scale` keyword arguments are ignored.
        If the location is free, a likelihood maximum is found by
        setting its partial derivative wrt to location to 0, and
        solving by substituting the analytical expressions of shape
        and scale (or provided parameters).
        See, e.g., equation 3.1 in
        A. Clifford Cohen & Betty Jones Whitten (1980)
        Estimation in the Three-Parameter Lognormal Distribution,
        Journal of the American Statistical Association, 75:370, 399-404
        https://doi.org/10.2307/2287466
        

r   c                     |j                  dd      rt           g|i |S t         ||      }|\  }t	        j
                        }fdfd} fd}|&t	        j                  |      }	||	z
  }
 ||
      } ||
      }d|	z  }|dk\  r||z
  }
 ||
      }|dz  }|dk\  rt	        j                  |
      rt	        j                  |      st           g|i |S t	        j                  t	        j                  |
t        j                         |
dz
        } ||      }d|
|z
  z  }t	        j                  |      rt	        j                  |      rt	        j                  |      t	        j                  |      k(  rh|
|z
  } ||      }|dz  }t	        j                  |      rAt	        j                  |      r,t	        j                  |      t	        j                  |      k(  rht	        j                  |      rt	        j                  |      st           g|i |S t        |||
f	      }|j                  st           g|i |S  ||j                        }||kD  r|j                  n||	z
  }n#||k\  rt        d
dt        j                        |} |      \  }} j!                  |      r|dkD  st           g|i |S |||fS )Nr9  Fc                    t        j                  | z
        }xs# t        j                  j                               }xsA t        j                  t        j                  t        j                  |      z
  dz              }||fS r  )rO   r   r   r   r   )r-   lndatar.   r  rE   r   fshapes       r5   get_shape_scalez(lognorm_gen.fit.<locals>.get_shape_scale  sq     ~s
+3bffV[[]3EKbggbggvu/E.I&JKE%<r7   c                      |       \  }}| z
  }t        j                  dt        j                  ||z        |dz  z  z   |z        S r0  rO   r  r   )r-   r  r.   shiftedrE   rN  s       r5   dL_dLocz lognorm_gen.fit.<locals>.dL_dLoc  sI    *3/LE5SjG661rvvgem4UAX==wFGGr7   c                 F     |       \  }}j                  || |f       S rM   )nnlf)r-   r  r.   rE   rN  rD   s      r5   llzlognorm_gen.fit.<locals>.ll  s,    *3/LE5IIuc514888r7   rT   gưr   r   lognormr   r  r   )r2   r@   rB   rE  rO   r  spacingr   r  	nextafterrh   rP   r*   	convergedrF  rJ  rb   )rD   rE   rF   r4   
parametersr   r  rR  rU  rW  rR   dL_dLoc_rbrack	ll_rbrackr$  rQ   dL_dLoc_lbrackr  ll_rootr-   r  r.   r   rM  rN  r  s   ``                   @@@r5   rB   zlognorm_gen.fit  s   $ 88J&7;t3d3d330tT4H
%/"fdF66$<	 	H	9
 < jj*G'F %V_N6
IKE E)!E)!(
 !E)
 ;;v&bkk..I w{47$7$77
 ZZVbffW =vaxHF$V_N&)E;;v&2;;~+Fww~."''.2II%!(
	 ;;v&2;;~+Fww~."''.2II ;;v&bkk..Iw{47$7$77 g/?@C==w{47$7$77
 lG%	1#((x7GC x"9BbffEEC&s+uu%%!)7;t3d3d33c5  r7   r  )r   r   r   r   r   r  r  rj   r   rq   r   rt   r   r}   rx   r   r   r   r   rJ   r	   rB   r  r  s   @r5   r1  r1    s}    *V "44ME>*%(+('*(; } 5  Z!! "Z!r7   r1  rV  c                   f    e Zd ZdZej
                  Zd ZddZd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zy)
gibrat_gena[  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)

    for :math:`x >= 0`.

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

    %(after_notes)s

    %(example)s

    c                     g S rM   r   ri   s    r5   rj   zgibrat_gen._shape_infor  r   r7   Nc                 J    t        j                  |j                  |            S rM   r4  r   s      r5   r   zgibrat_gen._rvsu  s    vvl224899r7   c                 J    t        j                  | j                  |            S rM   r  r   s     r5   rq   zgibrat_gen._pdfx  r  r7   c                     t        |d      S r  r8  r   s     r5   r   zgibrat_gen._logpdf|  s    q#&&r7   c                 >    t        t        j                  |            S rM   r:  r   s     r5   rt   zgibrat_gen._cdf  s    ##r7   c                 >    t        j                  t        |            S rM   r=  r   s     r5   r}   zgibrat_gen._ppf      vvil##r7   c                 >    t        t        j                  |            S rM   rA  r   s     r5   rx   zgibrat_gen._sf  s    q	""r7   c                 >    t        j                  t        |            S rM   rD  r   s     r5   r   zgibrat_gen._isf  rg  r7   c                     t         j                  }t        j                  |      }||dz
  z  }t        j                  |dz
        d|z   z  }t        j                  g d|      }||||fS rF  )rO   er   rG  )rD   r  rB  rC  rD  rE  s         r5   r   zgibrat_gen._stats  s^    DDWWQZ1q5kWWQU^q1u%ZZ*A.3Br7   c                 Z    dt        j                  dt         j                  z        z  dz   S r  r   ri   s    r5   r   zgibrat_gen._entropy  s#    RVVAI&&,,r7   r  )r   r   r   r   r   r  r  rj   r   rq   r   rt   r}   rx   r   r   r   r   r7   r5   r`  r`  Z  sF    * "44M:''$$#$-r7   r`  gibratc                   N    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zy)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                     g S rM   r   ri   s    r5   rj   zmaxwell_gen._shape_info  r   r7   Nc                 2    t         j                  d||      S )NrC  r  r  r  r   s      r5   r   zmaxwell_gen._rvs  s    wwsLwAAr7   c                 T    t         |z  |z  t        j                  | |z  dz        z  S r=  )r&   rO   r   r   s     r5   rq   zmaxwell_gen._pdf  s*    q "2661"Q$s(#333r7   c                     t        j                  d      5  t        dt        j                  |      z  z   d|z  |z  z
  cd d d        S # 1 sw Y   y xY w)Nr8  r9  rT   r   )rO   r;  r(   r   r   s     r5   r   zmaxwell_gen._logpdf  sD    [[) 	?&266!94s1uQw>	? 	? 	?s   (A		Ac                 :    t        j                  d||z  dz        S Nr  r   r  r   s     r5   rt   zmaxwell_gen._cdf  s    {{3!C((r7   c                 Z    t        j                  dt        j                  d|      z        S r  r  r   s     r5   r}   zmaxwell_gen._ppf  s!    wwqQ//00r7   c                 :    t        j                  d||z  dz        S rv  r  r   s     r5   rx   zmaxwell_gen._sf  s    ||C1S))r7   c                 Z    t        j                  dt        j                  d|      z        S r  r  r   s     r5   r   zmaxwell_gen._isf  s!    wwqa0011r7   c                    dt         j                  z  dz
  }dt        j                  dt         j                  z        z  ddt         j                  z  z
  t        j                  d      ddt         j                  z  z
  z  |dz  z  dt         j                  z  t         j                  z  d	t         j                  z  z   d
z
  |dz  z  fS )Nr  r-  rT   r       r  r  r     i  rO   r   r   rD   rv  s     r5   r   zmaxwell_gen._stats  s    gai"''#bee)$$!BEE'	
Br"%%xK(c1RUU2553ruu9,s2c3h>@ 	@r7   c                 h    t         dt        j                  dt        j                  z        z  z   dz
  S r  )r#   rO   r   r   ri   s    r5   r   zmaxwell_gen._entropy  s'    BFF1RUU7O++C//r7   r  r  r   r7   r5   ro  ro    s;    4B4?
)1*2@0r7   ro  maxwellc                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	
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                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS )Nr  Fr   r	  r  rg   )rD   iki_ss      r5   rj   zmielke_gen._shape_info   <    UQK@ea[.ACyr7   c                 B    |||dz
  z  z  d||z  z   d|dz  |z  z   z  z  S r  r   rD   rp   r  r  s       r5   rq   zmielke_gen._pdf  s2    QsU|s1a4x3quQw;777r7   c                     t        j                  d      5  t        j                  |      t        j                  |      |dz
  z  z   t        j                  ||z        d||z  z   z  z
  cd d d        S # 1 sw Y   y xY w)Nr8  r9  r   )rO   r;  r   r  r  s       r5   r   zmielke_gen._logpdf  sf    [[) 	L66!9rvvay!a%00288AqD>1qs73KK	L 	L 	Ls   AA44A=c                 0    ||z  d||z  z   |dz  |z  z  z  S r  r   r  s       r5   rt   zmielke_gen._cdf  s&    !ts1a4x1S57+++r7   c                 P    t        ||dz  |z        }t        |d|z
  z  d|z        S r  r2  )rD   r|   r  r  qsks        r5   r}   zmielke_gen._ppf  s.    !QsU1Wo3C=#a%((r7   c                 b    d }t        j                  ||k  |||f|t        j                        S )Nc                     t        j                  || z   |z        t        j                  d| |z  z
        z  t        j                  ||z        z  S r]   rf  )ra   r  r  s      r5   rS  z$mielke_gen._munp.<locals>.nth_moment  s?    88QqS!G$RXXa!e_4RXXac]BBr7   r  r   )rD   ra   r  r  rS  s        r5   r  zmielke_gen._munp  s-    	C q1uq!QiOOr7   N)
r   r   r   r   rj   rq   r   rt   r}   r  r   r7   r5   r  r    s(     B
8L
,)Pr7   r  mielkec                   R    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)
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                 v    t        j                  ||      d   j                  }t        j                  |d      S )Nr   Tr  )rO   r  r  full)rD   r  r  r  s       r5   rb   zkappa4_gen._argcheckx  s0    ##Aq)!,22wwu..r7   c                     t        ddt        j                   t        j                  fd      }t        ddt        j                   t        j                  fd      }||gS )Nr  Fr	  r  rg   )rD   ihr  s      r5   rj   zkappa4_gen._shape_info|  sI    UbffWbff$5~FUbffWbff$5~FBxr7   c           
      
   t        j                  |dkD  |dkD        t        j                  |dkD  |dk(        t        j                  |dkD  |dk        t        j                  |dk  |dkD        t        j                  |dk  |dk(        t        j                  |dk  |dk        g}d }d }d }d }t        |||||||g||gt         j                        }d }d }t        |||||||g||gt         j                        }	||	fS )	Nr   c                 <    dt        j                  | |       z
  |z  S r  )rO   r  r  r  s     r5   r  z#kappa4_gen._get_support.<locals>.f0  s    "..QB//22r7   c                 ,    t        j                  |       S rM   r1  r  s     r5   r  z#kappa4_gen._get_support.<locals>.f1  s    66!9r7   c                 ~    t        j                  t        j                  |             }t         j                   |d d  |S rM   rO   r  r  rh   r  r  r   s      r5   f3z#kappa4_gen._get_support.<locals>.f3  s,    !%AFF7AaDHr7   c                     d|z  S r  r   r  s     r5   f5z#kappa4_gen._get_support.<locals>.f5      q5Lr7   defaultc                     d|z  S r  r   r  s     r5   r  z#kappa4_gen._get_support.<locals>.f0  r  r7   c                 |    t        j                  t        j                  |             }t         j                  |d d  |S rM   r  r  s      r5   r  z#kappa4_gen._get_support.<locals>.f1  s*    !%A66AaDHr7   rO   r  r   r  )
rD   r  r  condlistr  r  r  r  r  r  s
             r5   r   zkappa4_gen._get_support  s   NN1q5!a%0NN1q5!q&1NN1q5!a%0NN161q51NN16162NN161q513	3		
	 b"b"b1Q!#)
		
 b"b"b1Q!#) 2vr7   c                 N    t        j                  | j                  |||            S rM   r  rD   rp   r  r  s       r5   rq   zkappa4_gen._pdf  r  r7   c                 >   t        j                  |dk7  |dk7        t        j                  |dk(  |dk7        t        j                  |dk7  |dk(        t        j                  |dk(  |dk(        g}d }d }d }d }t        |||||g|||gt         j                        S )Nr   c                     t        j                  d|z  dz
  | | z        t        j                  d|z  dz
  | d|| z  z
  d|z  z  z        z   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 = ...
            r   rd  rp   r  r  s      r5   r  zkappa4_gen._logpdf.<locals>.f0  sZ    
 JJs1us{QBqD1JJs1us{QBac	SU/C,CDE Fr7   c                 `    t        j                  d|z  dz
  | | z        d|| z  z
  d|z  z  z
  S )z~pdf = (1.0 - k*x)**(1.0/k - 1.0)*np.exp(-(
                      1.0 - k*x)**(1.0/k))
               logpdf = ...
            r   rd  r  s      r5   r  zkappa4_gen._logpdf.<locals>.f1  s9    
 ::c!eckA2a40C!A#IQ3GGGr7   c                 r    |  t        j                  d|z  dz
  | t        j                  |        z        z   S )z]pdf = np.exp(-x)*(1.0 - h*np.exp(-x))**(1.0/h - 1.0)
               logpdf = ...
            r   )rv   rv  rO   r   r  s      r5   f2zkappa4_gen._logpdf.<locals>.f2  s4     2

3q53;2661":>>>r7   c                 6    |  t        j                  |        z
  S )zDpdf = np.exp(-x-np.exp(-x))
               logpdf = ...
            rq  r  s      r5   r  zkappa4_gen._logpdf.<locals>.f3  s     2r
?"r7   r  r  	rD   rp   r  r  r  r  r  r  r  s	            r5   r   zkappa4_gen._logpdf  s    NN16162NN16162NN16162NN161624
	F	H	?	# 8B+q!9#%66+ 	+r7   c                 N    t        j                  | j                  |||            S rM   rK  r  s       r5   rt   zkappa4_gen._cdf  rX  r7   c                 >   t        j                  |dk7  |dk7        t        j                  |dk(  |dk7        t        j                  |dk7  |dk(        t        j                  |dk(  |dk(        g}d }d }d }d }t        |||||g|||gt         j                        S )Nr   c                 X    d|z  t        j                  | d|| z  z
  d|z  z  z        z  S )zVcdf = (1.0 - h*(1.0 - k*x)**(1.0/k))**(1.0/h)
               logcdf = ...
            r   r  r  s      r5   r  zkappa4_gen._logcdf.<locals>.f0  s4     E288QBac	SU';$;<<<r7   c                      d|| z  z
  d|z  z   S )zLcdf = np.exp(-(1.0 - k*x)**(1.0/k))
               logcdf = ...
            r   r   r  s      r5   r  zkappa4_gen._logcdf.<locals>.f1  s     1Q3Y#a%(((r7   c                 h    d|z  t        j                  | t        j                  |        z        z  S )zLcdf = (1.0 - h*np.exp(-x))**(1.0/h)
               logcdf = ...
            r   )rv   r  rO   r   r  s      r5   r  zkappa4_gen._logcdf.<locals>.f2  s,     E288QBrvvqbzM222r7   c                 0    t        j                  |         S )zBcdf = np.exp(-np.exp(-x))
               logcdf = ...
            rq  r  s      r5   r  zkappa4_gen._logcdf.<locals>.f3  s     FFA2J;r7   r  r  r  s	            r5   r   zkappa4_gen._logcdf  s    NN16162NN16162NN16162NN161624
	=	)	3	 8B+q!9#%66+ 	+r7   c                 >   t        j                  |dk7  |dk7        t        j                  |dk(  |dk7        t        j                  |dk7  |dk(        t        j                  |dk(  |dk(        g}d }d }d }d }t        |||||g|||gt         j                        S )Nr   c                 0    d|z  dd| |z  z
  |z  |z  z
  z  S r  r   r|   r  r  s      r5   r  zkappa4_gen._ppf.<locals>.f0  s(    q5##A,!1A 5566r7   c                 F    d|z  dt        j                  |        |z  z
  z  S r  r1  r  s      r5   r  zkappa4_gen._ppf.<locals>.f1  s$    q5#"&&)a/00r7   c                 b    t        j                  | |z          t        j                  |      z   S )z,ppf = -np.log((1.0 - (q**h))/h)
            r  r  s      r5   r  zkappa4_gen._ppf.<locals>.f2  s)     HHq!tW%%q	11r7   c                 V    t        j                  t        j                  |               S rM   r1  r  s      r5   r  zkappa4_gen._ppf.<locals>.f3  s    FFBFF1I:&&&r7   r  r  )	rD   r|   r  r  r  r  r  r  r  s	            r5   r}   zkappa4_gen._ppf  s    NN16162NN16162NN16162NN161624
	7	1	2
	' 8B+q!9#%66+ 	+r7   c                 v    t        j                  |dk  |dk\        |dk  g}d }d }t        |||g||gd      S )Nr   c                 8    d| z  |z  j                  t              S r>  astyper  r  s     r5   r  z&kappa4_gen._get_stats_info.<locals>.f0  s    F1H$$S))r7   c                 2    d|z  j                  t              S r>  r  r  s     r5   r  z&kappa4_gen._get_stats_info.<locals>.f1  s    F??3''r7   rB  r  )rO   r  r   )rD   r  r  r  r  r  s         r5   _get_stats_infozkappa4_gen._get_stats_info  sK    NN1q5!q&)E

	*	( 8b"X1vqAAr7   c                     | j                  ||      }t        dd      D cg c],  }t        j                  ||k        rd nt        j                  . }}|d d  S c c}w Nr   rB  )r  r  rO   r  r  )rD   r  r  maxrr  outputss         r5   r   zkappa4_gen._stats"  sU    ##Aq)AFq!MA266!d(+47MMqz Ns   1Ac                     | j                  |d   |d         }||k\  rt        j                  S t        j                  | j
                  dd|f|z         d   S Nr   r   rL  )r  rO   r  r   r  _mom_integ1)rD   r:  rF   r  s       r5   _mom1_sczkappa4_gen._mom1_sc'  sR    ##DGT!W5966M~~d..1A49EaHHr7   N)r   r   r   r   rb   rj   r   rq   r   rt   r   r}   r  r   r  r   r7   r5   r  r    sE    Wp/
'R-
$+L-!+F+2B
Ir7   r  kappa4c                   L     e Zd ZdZd Zd Zd Z fdZd Zd Z	d Z
d	 Z xZS )

kappa3_gena*  Kappa 3 parameter distribution.

    %(before_notes)s

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

    .. math::

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

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

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

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

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

    %(after_notes)s

    %(example)s

    c                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zkappa3_gen._shape_infoR  r
  r7   c                 *    ||||z  z   d|z  dz
  z  z  S r:  r   r  s      r5   rq   zkappa3_gen._pdfU  s"    !ad(d1fQh'''r7   c                 $    ||||z  z   d|z  z  z  S r>  r   r  s      r5   rt   zkappa3_gen._cdfY  s    !ad(d1f%%%r7   c           	         t        j                  ||      \  }}t        |   ||      }d}||k  }t	        j
                  t	        j                  d||   z  ||   ||   ||    z  z               }||kD  }||   |   ||<   |||<   |S )Ng{Gz?r;  )rO   r  r@   rx   rv   r  rv  )	rD   rp   r   sfcutoffr  sf2i2r  s	           r5   rx   zkappa3_gen._sf\  s    ""1a(1W[A
 Kxx

4!A$;!qtadU{0BCDD6\Q%)B1	r7   c                 &    ||| z  dz
  z  d|z  z  S r  r   r  s      r5   r}   zkappa3_gen._ppfl  s    1qb53;3q5))r7   c                 r    t        j                  | |       }t        j                  |      }||z  d|z  z  S r  r?  )rD   r|   r   lgr  s        r5   r   zkappa3_gen._isfo  s6    ZZQBE	S1W%%r7   c                     t        dd      D cg c],  }t        j                  ||k        rd nt        j                  . }}|d d  S c c}w r  )r  rO   r  r  )rD   r   r  r  s       r5   r   zkappa3_gen._statst  sB    >CAqkJ266!a%=4bff4JJqz Ks   1Ac                     t        j                  ||d   k\        rt         j                  S t        j                  | j
                  dd|f|z         d   S r  )rO   r  r  r   r  r  )rD   r:  rF   s      r5   r  zkappa3_gen._mom1_scx  sE    66!tAw,66M~~d..1A49EaHHr7   )r   r   r   r   rj   rq   rt   rx   r}   r   r   r  r  r  s   @r5   r  r  1  s3    @E(& *&
Ir7   r  kappa3c                   B    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zy)	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                     g S rM   r   ri   s    r5   rj   zmoyal_gen._shape_info  r   r7   Nc                 `    t         j                  dd||      }t        j                  |       S )Nr   rT   )r   r.   r   r   )r  r  rO   r   )rD   r   r   r  s       r5   r   zmoyal_gen._rvs  s.    YYAD$0  2r
{r7   c                     t        j                  d|t        j                  |       z   z        t        j                  dt         j                  z        z  S Nr"  rT   )rO   r   r   r   r   s     r5   rq   zmoyal_gen._pdf  s:    vvda"&&!*n-.2551AAAr7   c                     t        j                  t        j                  d|z        t        j                  d      z        S r  )rv   r  rO   r   r   r   s     r5   rt   zmoyal_gen._cdf  s+    wwrvvdQh'"''!*455r7   c                     t        j                  t        j                  d|z        t        j                  d      z        S r  )rv   r  rO   r   r   r   s     r5   rx   zmoyal_gen._sf  s+    vvbffTAX&344r7   c                 `    t        j                  dt        j                  |      dz  z         S r  )rO   r   rv   erfcinvr   s     r5   r}   zmoyal_gen._ppf  s&    q2::a=!++,,,r7   c                    t        j                  d      t         j                  z   }t         j                  dz  dz  }dt        j                  d      z  t        j                  d      z  t         j                  dz  z  }d}||||fS )NrT      r  rI  )rO   r   euler_gammar   r   rv   r  rA  s        r5   r   zmoyal_gen._stats  sg    VVAY'eeQhl"''!*_rwwqz)BEE1H43Br7   c                    |dk(  r&t        j                  d      t         j                  z   S |dk(  r@t         j                  dz  dz  t        j                  d      t         j                  z   dz  z   S |dk(  rdt         j                  dz  z  t        j                  d      t         j                  z   z  }t        j                  d      t         j                  z   dz  }dt	        j
                  d      z  }||z   |z   S |dk(  rd	t	        j
                  d      z  t        j                  d      t         j                  z   z  }dt         j                  dz  z  t        j                  d      t         j                  z   dz  z  }t        j                  d      t         j                  z   d
z  }dt         j                  d
z  z  d
z  }||z   |z   |z   S | j                  |      S )Nr   rT   r   rC  r  r  r  rI  8   r#  r  )rO   r   r  r   rv   r  r  )rD   ra   tmp1rz  tmp3tmp4s         r5   r  zmoyal_gen._munp  sn   866!9r~~--#X55!8a<266!9r~~#="AAA#X>RVVAYr~~%=>DFF1Ibnn,q0D
?D$;%%#XBGGAJ&"&&)bnn*DEDruuax<266!9r~~#="AADFF1I.2Druuax<!#D$;%,, ==##r7   r  )r   r   r   r   rj   r   rq   rt   rx   r}   r   r  r   r7   r5   r  r    s1    )T
B65-$r7   r  moyalc                   \    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZddZddZy)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                     |dkD  S r-  r   )rD   nus     r5   rb   znakagami_gen._argcheck   r  r7   c                 @    t        dddt        j                  fd      gS )Nr  Fr   r	  rg   ri   s    r5   rj   znakagami_gen._shape_info  r  r7   c                 L    t        j                  | j                  ||            S rM   r  rD   rp   r  s      r5   rq   znakagami_gen._pdf  r  r7   c                     t        j                  d      t        j                  ||      z   t        j                  |      z
  t        j                  d|z  dz
  |      z   ||dz  z  z
  S r  )rO   r   rv   rw  r  r  s      r5   r   znakagami_gen._logpdf	  s\     q	BHHR,,rzz"~=21%&(*1a40 	1r7   c                 :    t        j                  |||z  |z        S rM   r  r  s      r5   rt   znakagami_gen._cdf  s    {{2r!tAv&&r7   c                 `    t        j                  d|z  t        j                  ||      z        S r  r  )rD   r|   r  s      r5   r}   znakagami_gen._ppf  s%    wws2vbnnR3344r7   c                 :    t        j                  |||z  |z        S rM   r  r  s      r5   rx   znakagami_gen._sf  s    ||B1Q''r7   c                 `    t        j                  d|z  t        j                  ||      z        S r]   r  )rD   r  r  s      r5   r   znakagami_gen._isf  s%    wwqtboob!4455r7   c                 (   t        j                  |d      t        j                  |      z  }d||z  z
  }|dd|z  |z  z
  z  dz  |z  t        j                  |d      z  }d|dz  z  |z  d|z  d	z
  |d	z  z  z   d	|z  z
  dz   }|||dz  z  z  }||||fS )
Nr   r   r   r#  r   r  r-  rT   )rv   r  rO   r   r  )rD   r  rB  rC  rD  rE  s         r5   r   znakagami_gen._stats  s    WWRbggbk)"R%i1qtCx< 3&+bhhsC.@@AXb[AbDFBE>)!B$.2
bck3Br7   c                    t        j                  |      }t        j                  |      }t        j                  |      }||dz
  t        j
                  |      z  z
  }dt        j                  |      z  t        j                  d      z
  }||z   |z   }t        j                  j                         }|dkD  }||   |z   dd||   z  z  z
  ||<   |j                  |      d   S )Nr   r"  rT   g     j@r   r  r   )rO   r  r  rv   r  r  r   r  r  r   rM  )	rD   r  r  rl  rm  rB  r  norm_entropyr  s	            r5   r   znakagami_gen._entropy#  s    ]]2JJrN"s(bjjn,,266":q	)EAIzz**, Htl"Q2a5\1!yy##r7   Nc                 T    t        j                  |j                  ||      |z        S r/  )rO   r   r$  )rD   r  r   r   s       r5   r   znakagami_gen._rvs4  s&    ww|222D2ABFGGr7   c                    t        |t              r|j                         }|d| j                  z  }t	        j
                  |      }t	        j                  t	        j                  ||z
  dz        t        |      z        }|||fz   S )N)r   rT   )	r>   r)   r  numargsrO   r  r   r  r  )rD   rE   rF   r-   r.   s        r5   r  znakagami_gen._fitstart8  sq    dL)>>#D<DLL(D ffTls
Q/#d);<sEl""r7   r  rM   )r   r   r   r   rb   rj   rq   r   rt   r}   rx   r   r   r   r   r  r   r7   r5   r  r    sE    >F+1'5(6$"H	#r7   r  nakagamic                 J   |dz  dz
  }t        j                  |       t        j                  |      }}t        j                  |dz  | |z        d||z
  dz  z  z
  }t        j                  |||z        dz  }t        j                  |dkD  ||fd t         j                         S )Nr   r   r   rT   r   c                 2    | t        j                  |      z   S rM   r1  )r  r  s     r5   r  z_ncx2_log_pdf.<locals>.<lambda>T  s    Q] r7   r  )rO   r   rv   rw  iver  r  rh   )rp   r  rP  df2r  nsr  corrs           r5   _ncx2_log_pdfr		  H  s     S&3,CWWQZB
((3s7AbD
!Cb1$4
4C66#r"u#D??q	d"FF7	 r7   c                   N    e Zd ZdZd Zd ZddZd Zd Zd Z	d	 Z
d
 Zd Zd Zy)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.

    This distribution uses routines from the Boost Math C++ library for
    the computation of the ``pdf``, ``cdf``, ``ppf``, ``sf`` and ``isf``
    methods. [1]_

    %(after_notes)s

    References
    ----------
    .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.

    %(example)s

    c                 D    |dkD  t        j                  |      z  |dk\  z  S r-  r  rD   r  rP  s      r5   rb   zncx2_gen._argcheck|  s"    Q"++b/)R1W55r7   c                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS )Nr  Fr   r	  rP  rf   rg   rD   idfincs      r5   rj   zncx2_gen._shape_info  s<    uq"&&k>Buq"&&k=ASzr7   Nc                 (    |j                  |||      S rM   )noncentral_chisquare)rD   r  rP  r   r   s        r5   r   zncx2_gen._rvs  s    00R>>r7   c                 H    t        j                  |dk7  |||ft        d       S )Nr   c                 .    t         j                  | |      S rM   )r  r   rp   r  _s      r5   r  z"ncx2_gen._logpdf.<locals>.<lambda>  s    Q0C r7   )r  r  r		  rD   rp   r  rP  s       r5   r   zncx2_gen._logpdf  s(    rQwB]CE 	Er7   c                     t        j                  d      5  t        j                  |dk7  |||ft        j
                  d       cd d d        S # 1 sw Y   y xY w)Nr8  rp  r   c                 .    t         j                  | |      S rM   )r  rq   r	  s      r5   r  zncx2_gen._pdf.<locals>.<lambda>      DIIa4D r7   )rO   r;  r  r  rm   	_ncx2_pdfr	  s       r5   rq   zncx2_gen._pdf  K    [[h' 	F??27QBK#DF	F 	F 	F   -AAc                     t        j                  d      5  t        j                  |dk7  |||ft        j
                  d       cd d d        S # 1 sw Y   y xY w)Nr8  rp  r   c                 .    t         j                  | |      S rM   )r  rt   r	  s      r5   r  zncx2_gen._cdf.<locals>.<lambda>  r	  r7   )rO   r;  r  r  rm   	_ncx2_cdfr	  s       r5   rt   zncx2_gen._cdf  r	  r	  c                     t        j                  d      5  t        j                  |dk7  |||ft        j
                  d       cd d d        S # 1 sw Y   y xY w)Nr8  rp  r   c                 .    t         j                  | |      S rM   )r  r}   r	  s      r5   r  zncx2_gen._ppf.<locals>.<lambda>  r	  r7   )rO   r;  r  r  rm   	_ncx2_ppfrD   r|   r  rP  s       r5   r}   zncx2_gen._ppf  r	  r	  c                     t        j                  d      5  t        j                  |dk7  |||ft        j
                  d       cd d d        S # 1 sw Y   y xY w)Nr8  rp  r   c                 .    t         j                  | |      S rM   )r  rx   r	  s      r5   r  zncx2_gen._sf.<locals>.<lambda>  s    DHHQO r7   )rO   r;  r  r  rm   _ncx2_sfr	  s       r5   rx   zncx2_gen._sf  sK    [[h' 	E??27QBK#CE	E 	E 	Er	  c                     t        j                  d      5  t        j                  |dk7  |||ft        j
                  d       cd d d        S # 1 sw Y   y xY w)Nr8  rp  r   c                 .    t         j                  | |      S rM   )r  r   r	  s      r5   r  zncx2_gen._isf.<locals>.<lambda>  r	  r7   )rO   r;  r  r  rm   	_ncx2_isfr	  s       r5   r   zncx2_gen._isf  r	  r	  c                     ||z   }d }d |||d      z  }t        j                  d       |||d      z  t        j                   |||d      dz        z  }d |||d      z   |||d      dz  z  }||||fS )Nc                     | ||z  z   S rM   r   )r  r  r  s      r5   	k_plus_clz"ncx2_gen._stats.<locals>.k_plus_cl  s    qs7Nr7   r   r  r  r  rI  rT   r  )rD   r  rP  
_ncx2_meanr.	  _ncx2_variance_ncx2_skewness_ncx2_kurtosis_excesss           r5   r   zncx2_gen._stats  s    "W
		"b# 66''#,2r1)=='')BC"8!";<=!%	"b#(>!>!*2r3!7!:"; !	
 	
r7   r  )r   r   r   r   rb   rj   r   r   rq   rt   r}   rx   r   r   r   r7   r5   r	  r	  X  s@    "F6
?EF
F
F
E
F

r7   r	  ncx2c                   J    e Zd ZdZd Zd ZddZd Zd Zd Z	d	 Z
d
 ZddZy)ncf_gena2  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 ``dfn``, ``dfd`` and ``nc`` as shape parameters. If ``nc=0``,
    the distribution becomes equivalent to the Fisher distribution.

    This distribution uses routines from the Boost Math C++ library for
    the computation of the ``pdf``, ``cdf``, ``ppf``, ``stats``, ``sf`` and
    ``isf`` methods. [1]_

    %(after_notes)s

    References
    ----------
    .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.

    %(example)s

    c                 $    |dkD  |dkD  z  |dk\  z  S r-  r   )rD   r  r  rP  s       r5   rb   zncf_gen._argcheck  s    aC!G$a00r7   c                     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  rP  rf   rg   )rD   idf1idf2r	  s       r5   rj   zncf_gen._shape_info  sW    %BFF^D%BFF^Duq"&&k=AdC  r7   Nc                 *    |j                  ||||      S rM   )noncentral_f)rD   r  r  rP  r   r   s         r5   r   zncf_gen._rvs  s    ((c2t<<r7   c                 2    t        j                  ||||      S rM   )rm   _ncf_pdfrD   rp   r  r  rP  s        r5   rq   zncf_gen._pdf  s    ||AsC,,r7   c                 2    t        j                  ||||      S rM   )rv   ncfdtrr>	  s        r5   rt   zncf_gen._cdf  s    yyc2q))r7   c                     t        j                  d      5  t        j                  ||||      cd d d        S # 1 sw Y   y xY wro  )rO   r;  rv   ncfdtri)rD   r|   r  r  rP  s        r5   r}   zncf_gen._ppf  s5    [[h' 	/::c3A.	/ 	/ 	/	   9Ac                 2    t        j                  ||||      S rM   )rm   _ncf_sfr>	  s        r5   rx   zncf_gen._sf  s    {{1c3++r7   c                     t        j                  d      5  t        j                  ||||      cd d d        S # 1 sw Y   y xY wro  )rO   r;  rm   _ncf_isfr>	  s        r5   r   zncf_gen._isf  s5    [[h' 	1<<3R0	1 	1 	1rC	  c                     t        j                  |||      }t        j                  |||      }d|v rt        j                  |||      nd }d|v rt        j                  |||      dz
  nd }||||fS )Nr  r  r  )rm   	_ncf_mean_ncf_variance_ncf_skewness_ncf_kurtosis_excess)	rD   r  r  rP  r  rB  rC  rD  rE  s	            r5   r   zncf_gen._stats  s    ]]3R(S"-03wSsC,D!$ %%b59 	 3Br7   r  r  r   r   r   r   rb   rj   r   rq   rt   r}   rx   r   r   r   r7   r5   r5	  r5	    s5    /`1!=-*/,1r7   r5	  ncfc                   N    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zy)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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zt_gen._shape_info:  r  r7   Nc                 (    |j                  ||      S r/  )
standard_tr  s       r5   r   z
t_gen._rvs=  s    &&r&55r7   c                 b     t        j                  |t        j                  k(  ||fd  fd      S )Nc                 ,    t         j                  |       S rM   )r  rq   rp   r  s     r5   r  zt_gen._pdf.<locals>.<lambda>C  s    $))A, r7   c                 N    t        j                  j                  | |            S rM   r  )rp   r  rD   s     r5   r  zt_gen._pdf.<locals>.<lambda>D  s    "&&a!45 r7   r   r  s   `  r5   rq   z
t_gen._pdf@  s+    "&&L1b'&57 	7r7   c                 d    d }d }t        j                  |t        j                  k(  ||f||      S )Nc                    t        j                  t        j                  d|z  d            dt        j                  |      t        j                  t         j                        z   z  z
  |dz   dz  t        j
                  | | z  |z        z  z
  S rI  )rO   r   rv   r  r   r  rV	  s     r5   t_logpdfzt_gen._logpdf.<locals>.t_logpdfH  sn    FF27738S12RVVBZ"&&-789Avqj!a%(!334 5r7   c                 ,    t         j                  |       S rM   )r  r   rV	  s     r5   norm_logpdfz"t_gen._logpdf.<locals>.norm_logpdfM  s    <<?"r7   r   )rD   rp   r  rZ	  r\	  s        r5   r   zt_gen._logpdfF  s/    	5
	# rRVV|aWk8LLr7   c                 .    t        j                  ||      S rM   rv   stdtrr  s      r5   rt   z
t_gen._cdfR  r  r7   c                 0    t        j                  ||       S rM   r^	  r  s      r5   rx   z	t_gen._sfU  s    xxQBr7   c                 .    t        j                  ||      S rM   rv   stdtritr  s      r5   r}   z
t_gen._ppfX  s    zz"a  r7   c                 0    t        j                  ||       S rM   rb	  r  s      r5   r   z
t_gen._isf[  s    

2q!!!r7   c                    t        j                  |      }t        j                  |dkD  dt         j                        }|dkD  |dk  z  |dkD  t        j                  |      z  |f}d d d f}t        |||ft         j                        }t        j                  |dkD  dt         j                        }|dkD  |dk  z  |dkD  t        j                  |      z  |f}d	 d
 d f}t        |||ft         j                        }||||fS )Nr   r   rT   c                 ^    t        j                  t         j                  | j                        S rM   rO   broadcast_torh   r  r  s    r5   r  zt_gen._stats.<locals>.<lambda>g      !B r7   c                     | | dz
  z  S r=  r   r  s    r5   r  zt_gen._stats.<locals>.<lambda>h  s    r#v r7   c                 B    t        j                  d| j                        S r]   rO   rh	  r  r  s    r5   r  zt_gen._stats.<locals>.<lambda>i      BHH!= r7   r  r#  c                 ^    t        j                  t         j                  | j                        S rM   rg	  r  s    r5   r  zt_gen._stats.<locals>.<lambda>q  ri	  r7   c                     d| dz
  z  S )Nr}  rI  r   r  s    r5   r  zt_gen._stats.<locals>.<lambda>r  s    3 r7   c                 B    t        j                  d| j                        S r-  rl	  r  s    r5   r  zt_gen._stats.<locals>.<lambda>s  rm	  r7   )rO   isposinfrN  rh   r   r   r  )	rD   r  infinite_dfrB  r  
choicelistrC  rD  rE  s	            r5   r   zt_gen._stats^  s   kk"oXXb1fc266*!Va(!Vr{{2.! C.=?
 (Jrvv>XXb1fc266*!Va(!Vr{{2.! C/=?
 :ubff=3Br7   c                     |t         j                  k(  rt        j                         S d }d }t	        j
                  |dk\  |||      S )Nc                     | dz  }| dz   dz  }|t        j                  |      t        j                  |      z
  z  t        j                  t        j                  |       t        j
                  |d      z        z   S rD  )rv   r  rO   r   r   rm  )r  halfhalf1s      r5   r  zt_gen._entropy.<locals>.regular|  se    a4D!VQJE2::e,rzz$/??@ffRWWR[s);;<= >r7   c                     t         j                         d| z  z   | dz  dz  z   | dz  dz  z
  | dz  dz  z
  d| d	z  z  z   | d
z  dz  z   }|S )Nr   r  r#  r  r  r  r-  g333333?r  r  )r  r   )r  r  s     r5   ro  z"t_gen._entropy.<locals>.asymptotic  sg     1R4'2s7A+5S!CGQ;!%r3w035s7A+>AHr7   d   )rO   rh   r  r   r  r  )rD   r  r  ro  s       r5   r   zt_gen._entropyx  s>    <==?"	>	 rSy"j'BBr7   r  r  r   r7   r5   rP	  rP	    s<    <F67
M !"4Cr7   rP	  r  c                   J    e Zd ZdZd Zd ZddZd Zd Zd Z	d	 Z
d
 ZddZy)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.

    This distribution uses routines from the Boost Math C++ library for
    the computation of the ``pdf``, ``cdf``, ``ppf``, ``sf`` and ``isf``
    methods. [1]_

    %(after_notes)s

    References
    ----------
    .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.

    %(example)s

    c                     |dkD  ||k(  z  S r-  r   r	  s      r5   rb   znct_gen._argcheck  s    Q28$$r7   c                     t        dddt        j                  fd      }t        ddt        j                   t        j                  fd      }||gS )Nr  Fr   r	  rP  rg   r	  s      r5   rj   znct_gen._shape_info  sC    uq"&&k>Buw&7HSzr7   Nc                     t         j                  |||      }t        j                  |||      }|t        j                  |      z  t        j                  |      z  S )Nr  r  )r  r  r  rO   r   )rD   r  rP  r   r   ra   r  s          r5   r   znct_gen._rvs  sI    HH$\HBXXbt,X?2772;,,r7   c                 0    t        j                  |||      S rM   )rm   _nct_pdfr	  s       r5   rq   znct_gen._pdf  s    ||Ar2&&r7   c                 0    t        j                  |||      S rM   )rv   nctdtrr	  s       r5   rt   znct_gen._cdf  s    yyR##r7   c                 0    t        j                  |||      S rM   )rv   nctdtritr%	  s       r5   r}   znct_gen._ppf  s    {{2r1%%r7   c                     t        j                  d      5  t        j                  t        j                  |||      dd      cd d d        S # 1 sw Y   y xY w)Nr8  rp  r   r   )rO   r;  cliprm   _nct_sfr	  s       r5   rx   znct_gen._sf  s@    [[h' 	9773;;q"b11a8	9 	9 	9s   ,AAc                     t        j                  d      5  t        j                  |||      cd d d        S # 1 sw Y   y xY wro  )rO   r;  rm   _nct_isfr	  s       r5   r   znct_gen._isf  s3    [[h' 	+<<2r*	+ 	+ 	+rt  c                     t        j                  ||      }t        j                  ||      }d|v rt        j                  ||      nd }d|v rt        j                  ||      nd }||||fS )Nr  r  )rm   	_nct_mean_nct_variance_nct_skewness_nct_kurtosis_excess)rD   r  rP  r  rB  rC  rD  rE  s           r5   r   znct_gen._stats  sf    ]]2r"B'*-.Sr2&d14S%%b"-T3Br7   r  r  rM	  r   r7   r5   r{	  r{	    s5    @%
-
'$&9+r7   r{	  nctc                   t     e Zd ZdZd Zd Zd Zd Zd Zd Z	ddZ
d	 Ze ee       fd
              Z x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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zpareto_gen._shape_info  r
  r7   c                     ||| dz
  z  z  S r]   r   r  s      r5   rq   zpareto_gen._pdf  s    1r!t9}r7   c                     d|| z  z
  S r]   r   r  s      r5   rt   zpareto_gen._cdf  s    1r7{r7   c                 &    t        d|z
  d|z        S )Nr   r;  r2  r  s      r5   r}   zpareto_gen._ppf  s    1Q3Qr7   c                     || z  S rM   r   r  s      r5   rx   zpareto_gen._sf  s    A2wr7   c                 4    t        j                  |d|z        S r>  r  r  s      r5   r   zpareto_gen._isf    s    xx4!8$$r7   c                    d\  }}}}d|v rp|dkD  }t        j                  ||      }t        j                  t        j                  |      t         j                        }t        j
                  ||||dz
  z         d|v ry|dkD  }t        j                  ||      }t        j                  t        j                  |      t         j                        }t        j
                  ||||dz
  z  |dz
  dz  z         d	|v r|d
kD  }t        j                  ||      }t        j                  t        j                  |      t         j                        }d|dz   z  t        j                  |dz
        z  |dz
  t        j                  |      z  z  }	t        j
                  |||	       d|v r|dkD  }t        j                  ||      }t        j                  t        j                  |      t         j                        }dt        j                  g d|      z  t        j                  g d|      z  }	t        j
                  |||	       ||||fS )Nr  r:  r   r  r   r  rT   r   r  r  rC  r  r#  r}  )r   r   r  r  )r   g      r  r   )	rO   extractr  r  rh   placer  r   rG  )
rD   r   r  rB  rC  rD  rE  maskbtr  s
             r5   r   zpareto_gen._stats   s   0CR'>q5DD!$B!8BHHRrRV}-'>q5DD!$B''"((1+"&&9CHHS$bfC! ;<'>q5DD!$B!8BS>BGGBH$55"s(bggbk9QRDHHRt$'>q5DD!$B!8B

#5r::JJ5r:;DHHRt$3Br7   c                 >    dd|z  z   t        j                  |      z
  S r  r1  rD   r   s     r5   r   zpareto_gen._entropy       3q5y266!9$$r7   c                    t        | ||      }|\  }}|;t        j                        |z
  |xs dk  rt        ddt        j                        j
                  d   fd||cxu r9n n5fdfdfdfd	}t        |j                  d
d            }|dz  |dz  }
}	 ||	|
      sE|	dkD  s|
t        j                  k  r-|	dz  }	|
dz  }
 ||	|
      s|	dkD  r|
t        j                  k  r-t        |	|
g      }|j                  r|j                  }t        j                        |z
  }xs	  ||      }||z   t        j                        k  s.t        j                        |z
  }t        j                  |d      }|||fS t        | 4  fi |S |t        j                        |z
  }n|}|xs t        j                        |z
  }xs	  ||      }|||fS )Nr   paretor   r  c                 f    t        j                  t        j                  |z
  | z              z  S rM   rP  )r.   locationrE   ndatas     r5   	get_shapez!pareto_gen.fit.<locals>.get_shape.   s+     266"&&$/U)B"CDDDr7   c                     | z  |z  S rM   r   )r  r.   r	  s     r5   	dL_dScalez!pareto_gen.fit.<locals>.dL_dScale9   s     u}u,,r7   c                 F    | dz   t        j                  d|z
  z        z  S r]   r  )r  r	  rE   s     r5   dL_dLocationz$pareto_gen.fit.<locals>.dL_dLocation>   s&     	RVVA,A%BBBr7   c                 t    t        j                        | z
  }xs	  | |      } ||       ||       z
  S rM   )rO   r  )r.   r	  r  r	  r	  rE   rM  r	  s      r5   r  z$pareto_gen.fit.<locals>.fun_to_solveC   sA     66$<%/<)E8"<#E84y7NNNr7   c                 r    t        j                   |             t        j                   |            k7  S rM   rN   rQ   rR   r  s     r5   rS   z.pareto_gen.fit.<locals>.interval_contains_rootJ   s/    V 45V 456 7r7   r.   rT   r   )rE  rO   r  rJ  rh   r  rN  r<   r*   rY  rF  rX  r@   rB   )rD   rE   rF   r4   rZ  r   r   rS   r  rQ   rR   r  r.   r-   r  r	  r	  rM  r  r	  r	  r  s    `             @@@@@@r5   rB   zpareto_gen.fit!   s    1tT4H
%/"fdF tt 3v{ Cxq??

1	E
 6!!-
C
O O7  ! 45K(1_kAoFF .ff=
frvvo!! .ff=
frvvo lVV4DEC}}ffTlU*7)E3"7 rvvd|3FF4L3.ELL2Ec5((w{40400\&&,'CC ,"&&,,/)E3/c5  r7   r  )r   r   r   r   rj   rq   rt   r}   rx   r   r   r   rJ   r   r   rB   r  r  s   @r5   r	  r	    sT    *E %6% M*R! + R!r7   r	  r	  c                   L    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)	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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zlomax_gen._shape_info   r
  r7   c                 $    |dz  d|z   |dz   z  z  S r  r   r	  s      r5   rq   zlomax_gen._pdf   s    uc!equ%%%r7   c                 d    t        j                  |      |dz   t        j                  |      z  z
  S r]   r  r	  s      r5   r   zlomax_gen._logpdf   s&    vvayAaC!,,,r7   c                 \    t        j                  | t        j                  |      z         S rM   r  r	  s      r5   rt   zlomax_gen._cdf   s"    !BHHQK(((r7   c                 Z    t        j                  | t        j                  |      z        S rM   )rO   r   rv   r  r	  s      r5   rx   zlomax_gen._sf   s    vvqb!n%%r7   c                 4    | t        j                  |      z  S rM   r  r	  s      r5   r   zlomax_gen._logsf   s    r"((1+~r7   c                 \    t        j                  t        j                  |        |z        S rM   r  r  s      r5   r}   zlomax_gen._ppf   s!    xx1"a((r7   c                     |d|z  z  dz
  S r:  r   r  s      r5   r   zlomax_gen._isf   s    4!8}q  r7   c                 H    t         j                  |dd      \  }}}}||||fS )Nr;  r  )r-   r  )r	  r  r  s         r5   r   zlomax_gen._stats   s,     ,,qdF,CCR3Br7   c                 >    dd|z  z   t        j                  |      z
  S r  r1  r|  s     r5   r   zlomax_gen._entropy   s    Qwrvvay  r7   N)r   r   r   r   rj   rq   r   rt   rx   r   r}   r   r   r   r   r7   r5   r	  r	  {   s:    .E&-)&)!!r7   r	  lomaxc                        e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zdd
Zd Ze eed       fd              Z x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                     d}d}d}t        j                  d||      \  }}}|j                         }t        j                  |      |k  }| }d||   |z  z  }	||	z  dz  }
||
|	z  z
  }|	||   |z
  z  }||||||	|
|fS )Nr   r   g>r   rT   )rO   r  r  r  )rD   rp   r?  r-   r.   norm2pearson_transitionansr	  invmaskrm  r  r  transxs                r5   _preprocesszpearson3_gen._preprocess   s    
  #+**348Qhhj {{4 #::%d7me+,!UT\!7d*+AvtWdE4??r7   c                 ,    t        j                  |      S rM   r  )rD   r?  s     r5   rb   zpearson3_gen._argcheck!  s    
 {{4  r7   c                 ^    t        ddt        j                   t        j                  fd      gS )Nr?  Fr	  rg   ri   s    r5   rj   zpearson3_gen._shape_info!  s%    65BFF7BFF*;^LMMr7   c                 *    d}d}|}d|dz  z  }||||fS )Nr   r   r  rT   r   )rD   r?  r:  r  r  r  s         r5   r   zpearson3_gen._stats!  s,    aK!Qzr7   c                     t        j                  | j                  ||            }|j                  dk(  rt        j                  |      ry|S d|t        j                  |      <   |S )Nr   r   )rO   r   r   r*  r  )rD   rp   r?  r	  s       r5   rq   zpearson3_gen._pdf!  sR    
 ffT\\!T*+88q=xx}J BHHSM
r7   c                     | j                  ||      \  }}}}}}}}	t        j                  t        ||               ||<   t        j                  t	        |            t
        j                  ||      z   ||<   |S rM   )r	  rO   r   r   r  r  r  )
rD   rp   r?  r	  r	  r	  r	  rm  r  r	  s
             r5   r   zpearson3_gen._logpdf!  ss     Q% 	6QgtUA FF9QtW-.D	 vvc$i(5<<+FFG
r7   c                    | j                  ||      \  }}}}}}}}t        ||         ||<   t        j                  ||j                        }t        j
                  ||dkD        }	||   dkD  }
t        j                  ||
   ||
         ||	<   t        j
                  ||dk        }||   dk  }t        j                  ||   ||         ||<   |S r-  )	r	  r   rO   rh	  r  r  r  r   r  rD   rp   r?  r	  r	  r	  r	  r	  r  	invmask1a	invmask1b	invmask2a	invmask2bs                r5   rt   zpearson3_gen._cdf.!  s    Q% 	3Qgq% ag&D	tW]]3NN7D1H5	MA%	 6)#4eI6FGI NN7D1H5	MA%	&"3U95EFI
r7   c                    | j                  ||      \  }}}}}}}}t        ||         ||<   t        j                  ||j                        }t        j
                  ||dkD        }	||   dkD  }
t        j                  ||
   ||
         ||	<   t        j
                  ||dk        }||   dk  }t        j                  ||   ||         ||<   |S r-  )	r	  r   rO   rh	  r  r  r  r  r   r	  s                r5   rx   zpearson3_gen._sfF!  s    Q% 	3Qgq% QtW%D	tW]]3NN7D1H5	MA%	&"3U95EFINN7D1H5	MA%	6)#4eI6FGI
r7   c                    t        j                  ||      }| j                  dg|      \  }}}}}}}	}
|j                         }|j                  |z
  }|j                  |      ||<   |j                  |	|      |z  |
z   ||<   |dk(  r|d   }|S )Nr   r   )rO   rh	  r	  r  r   r   r$  )rD   r?  r   r   r	  r	  r	  r	  rm  r  r  nsmallnbigs                r5   r   zpearson3_gen._rvsW!  s    tT*aS$' 	4Q4$t yy6! 008D	#225$?DtKG2:a&C
r7   c                     | j                  ||      \  }}}}}}}}	t        ||         ||<   ||   }d||dk     z
  ||dk  <   t        j                  ||      |z  |	z   ||<   |S r  )r	  r   rv   r  )
rD   r|   r?  r	  r	  r	  r	  rm  r  r  s
             r5   r}   zpearson3_gen._ppfe!  s~    Q% 	4Q4$tag&D	gJ!D1H+o$(~~eQ/4t;G
r7   ze        Note that method of moments (`method='MM'`) is not
        available for this distribution.

r   c                 |    |j                  dd       dk(  rt        d      t        t        |       |   |g|i |S )Nr0   MMzhFit `method='MM'` is not available for the Pearson3 distribution. Please try the default `method='MLE'`.)r<   NotImplementedErrorr@   rA   rB   rO  s       r5   rB   zpearson3_gen.fitn!  sO    
 88Hd#t+% 'D E E dT.tCdCdCCr7   r  )r   r   r   r   r	  rb   rj   r   rq   r   rt   rx   r   r}   rJ   r	   r   rB   r  r  s   @r5   r	  r	     sg    ,Z@8!N0" } 50 1D1 Dr7   r	  pearson3c                        e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Z fdZe eed       fd              Z x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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zpowerlaw_gen._shape_info!  r
  r7   c                     |||dz
  z  z  S r  r   r  s      r5   rq   zpowerlaw_gen._pdf!  s    QsU|r7   c                 `    t        j                  |      t        j                  |dz
  |      z   S r]   )rO   r   rv   rw  r  s      r5   r   zpowerlaw_gen._logpdf!  s$    vvay288AE1---r7   c                     ||dz  z  S r  r   r  s      r5   rt   zpowerlaw_gen._cdf!  s    1S5zr7   c                 2    |t        j                  |      z  S rM   r1  r  s      r5   r   zpowerlaw_gen._logcdf!  r2  r7   c                      t        |d|z        S r  r2  r  s      r5   r}   zpowerlaw_gen._ppf!  s    1c!e}r7   c                 0    t        j                  ||       S rM   )rv   r  )rD   r  r   s      r5   rx   zpowerlaw_gen._sf!  s    Ar7   c                     |||z   z  S rM   r   r/  s      r5   r  zpowerlaw_gen._munp!  s    AE{r7   c                     ||dz   z  ||dz   z  |dz   dz  z  d|dz
  |dz   z  z  t        j                  |dz   |z        z  dt        j                  g d|      z  ||dz   z  |dz   z  z  fS )	Nr   r   rT   r  rC  r  )r   r  r  rT   r#  )rO   r   rG  r  s     r5   r   zpowerlaw_gen._stats!  s    QWQWSQ.SQW-.!c'Q1GGBJJ~q11Q!c']a!e5LMO 	Or7   c                 >    dd|z  z
  t        j                  |      z
  S r  r1  r  s     r5   r   zpowerlaw_gen._entropy!  r	  r7   c                 <    t         |   ||      |dk7  |dk\  z  z  S r  )r@   r  )rD   rp   r   r  s      r5   r  zpowerlaw_gen._support_mask!  s,    %a+FqAv&( 	)r7   a:          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                 R   |j                  dd      rt        |   g|i |S t        t	        j
                              dk(  rt        |   g|i |S t        | ||      \  }}| j                        fg}| j                  |i       d   }|Ej                         |kD  st        ddd      |#j                         ||z   k  st        ddd      |5|dk  rt        d      |t	        j                        k  rd}t        |      d d	 || ||      ||fS |t	        j                  j                         t        j                         }	xs
  |	|      }
 ||
|	|f      }t	        j                  j                         |z
  t        j                        }xs
  ||      } ||||f      }||k  r|
|	|fS |||fS | |      }xs
  ||      }|||fS fd
}d d fdfdfd}dk  r |       S dkD  r |       S  |       }| j!                  |      } |       }| j!                  |      }||k  r
|d   dk  r|S ||kD  r
|d   dkD  r|S t        |   g|i |S )Nr9  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                     t        |       }| t        j                  t        j                  | |z
              |t        j                  |      z  z
  z  S rM   )r  rO   r  r   )rE   r-   r.   r  s       r5   r	  z#powerlaw_gen.fit.<locals>.get_shape
"  sA     D	A3"&&s
!34qFGGr7   c                 (    | j                         |z
  S rM   )r  )rE   r-   s     r5   	get_scalez#powerlaw_gen.fit.<locals>.get_scale"  s     88:##r7   c                     t        j                  j                         t         j                         } t        j                  |       t        j
                  | j                        j                  k  r?t        j                  |       t        j
                  | j                        j                  z  } t        j                   |       t         j                        }xs
  | |      }|| |fS rM   )	rO   rX  r  rh   r  r"  r  r#  rP   )r-   r.   r  rE   rM  r	  r	  s      r5   fit_loc_scale_w_shape_lt_1z4powerlaw_gen.fit.<locals>.fit_loc_scale_w_shape_lt_18"  s    ,,txxzBFF73Cvvc{RXXcii0555ggclRXXcii%8%=%==LL4!5rvv>E9ic59E#u$$r7   c                 .    | j                   d    |z  |z  S r-  )r  )rE   r  r.   s      r5   r	  z#powerlaw_gen.fit.<locals>.dL_dScaleG"  s     JJqM>E)E11r7   c                 D    |dz
  t        j                  d|| z
  z        z  S r]   r  )rE   r  r-   s      r5   r	  z&powerlaw_gen.fit.<locals>.dL_dLocationL"  s%     AIS4Z(8!999r7   c                     t        j                   |       t         j                         }xs
  | |      } ||       S rM   rO   rX  rh   )r-   r.   r  r	  rE   rM  r	  r	  s      r5   dL_dLocation_starz+powerlaw_gen.fit.<locals>.dL_dLocation_starQ"  sD     LL4!5w?E9ic59EeS11r7   c                     t        j                   |       t         j                         }xs
  | |      } ||       ||       z
  S rM   r	  )	r-   r.   r  r	  r	  rE   rM  r	  r	  s	      r5   r  z&powerlaw_gen.fit.<locals>.fun_to_solveX"  sW     LL4!5w?E9ic59EdE51"445 6r7   c                     t        j                  
j                         t         j                         } 
j                         | z
  } 	|       dkD  r$
j                         |z
  } |dz  } 	|       dkD  r$fd}| dz
  }d} |||       sJ|t         j                   k7  r6
j                         |z
  }|dz  } |||       s|t         j                   k7  r6t	        j
                  || f      }t        j                  |j                  t         j                         }t        j                   
|      t         j                        }xs
  
||      }|||fS )Nr   rT   c                 r    t        j                   |             t        j                   |            k7  S rM   rN   r	  s     r5   rS   zTpowerlaw_gen.fit.<locals>.fit_loc_scale_w_shape_gt_1.<locals>.interval_contains_rootl"  s/    V 4577<#789 :r7   r   r   r   )rO   rX  r  rh   r   r*   rF  )rR   r$  rS   rQ   r  rF  r-   r.   r  r	  rE   rM  r  r	  r	  s            r5   fit_loc_scale_w_shape_gt_1z4powerlaw_gen.fit.<locals>.fit_loc_scale_w_shape_gt_1`"  s7    \\$((*rvvg6F XXZ&(E#F+a/e+
 $F+a/:
 aZF
 A-ff="&&(((*q.Q .ff="&&( ''vv>NOD,,tyy266'2CLL4!5rvv>E9ic59E#u$$r7   )r2   r@   rB   r  rO   uniquerE  r  _reduce_funcr  rJ  r  r   ptprX  rh   rT  )rD   rE   rF   r4   r   r   penalized_nllf_argspenalized_nllfrX   loc_lt1	shape_lt1ll_lt1loc_gt1	shape_gt1ll_gt1r.   r  r	  r	  fit_shape_lt1fit_shape_gt1r	  r	  r	  rM  r  r	  r	  r  s    `                   @@@@@@@r5   rB   zpowerlaw_gen.fit!  s    P 88J&7;t3d3d33ryy1$7;t3d3d33%@tAEt&M"fdF#dnnT&:%<=**+>CAF
 88:$":q!44!$((*v*E":q!44{  "F G G%H o%	H	$ $"2T40$>> ll488:w7GB)D'6"BI#Y$@$GF ll488:#6?GB)D'6"BI#Y$@$GF '611 '611 dD)E:idE:E$%%
	%	2
	:
	2 	2	6 	6!	% !	%H &A+-//FQJ-// 34=$/24=$/Va 0A 5  f_q!1A!5  7;t3d3d33r7   )r   r   r   r   rj   rq   r   rt   r   r}   rx   r  r   r   r  rJ   r	   r   rB   r  r  s   @r5   r	  r	  ~!  sl    @E.O%) } 5 H4 H4r7   r	  r	  c                   X    e Zd ZdZej
                  Zd Zd Zd Z	d Z
d Zd Zd Zd	 Zy
)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                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS )Nr  Fr   r	  r  rg   )rD   r   r  s      r5   rj   zpowerlognorm_gen._shape_info"  r  r7   c                 N    t        j                  | j                  |||            S rM   r  rD   rp   r  r  s       r5   rq   zpowerlognorm_gen._pdf"  rX  r7   c                    t        j                  |      t        j                  |      z
  t        j                  |      z
  t        t        j                  |      |z        z   t        t        j                  |       |z        |dz
  z  z   S r  rO   r   r   r   r
  s       r5   r   zpowerlognorm_gen._logpdf"  si    q	BFF1I%q	1RVVAY]+,bffQiZ!^,B78 	9r7   c                 P    t        j                  | j                  |||             S rM   r_  r
  s       r5   rt   zpowerlognorm_gen._cdf"  r`  r7   c                 .    | j                  d|z
  ||      S r]   )r   rD   r|   r  r  s       r5   r}   zpowerlognorm_gen._ppf"  s    yyQ1%%r7   c                 N    t        j                  | j                  |||            S rM   r5  r
  s       r5   rx   zpowerlognorm_gen._sf"  r6  r7   c                 L    t        t        j                  |       |z        |z  S rM   r  r
  s       r5   r   zpowerlognorm_gen._logsf"  s     RVVAYJN+a//r7   c                 R    t        j                  t        |d|z  z         |z        S r]   r=  r	
  s       r5   r   zpowerlognorm_gen._isf"  s&    vvyQqS**Q.//r7   N)r   r   r   r   r   r  r  rj   rq   r   rt   r}   rx   r   r   r   r7   r5   r
  r
  "  s<    . "44M
-9
/&,00r7   r
  powerlognormc                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)powernorm_genah  A power normal continuous random variable.

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

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

    %(example)s

    c                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zpowernorm_gen._shape_info"  r
  r7   c                 D    |t        |      z  t        |       |dz
  z  z  S r  r   r   r	  s      r5   rq   zpowernorm_gen._pdf"  s$    1~A23!788r7   c                 j    t        j                  |      t        |      z   |dz
  t        |       z  z   S r]   r
  r	  s      r5   r   zpowernorm_gen._logpdf"  s.    vvay<?*ac<3C-CCCr7   c                 N    t        j                  | j                  ||             S rM   r_  r	  s      r5   rt   zpowernorm_gen._cdf"  s    Q*+++r7   c                 :    t        t        d|z
  d|z               S r  )r   r  r  s      r5   r}   zpowernorm_gen._ppf"  s    #cAgsQw/000r7   c                 L    t        j                  | j                  ||            S rM   r5  r	  s      r5   rx   zpowernorm_gen._sf#  r0  r7   c                      |t        |       z  S rM   r   r	  s      r5   r   zpowernorm_gen._logsf#  s    <###r7   c                 l    t        t        j                  t        j                  |      |z               S rM   )r   rO   r   r   r  s      r5   r   zpowernorm_gen._isf#  s%    "&&Q/000r7   N)r   r   r   r   rj   rq   r   rt   r}   rx   r   r   r   r7   r5   r
  r
  "  s1    6E9D,1)$1r7   r
  	powernormc                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	dd	Z
d
 Zy)	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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zrdist_gen._shape_info0#  r
  r7   c                 L    t        j                  | j                  ||            S rM   r  r	  s      r5   rq   zrdist_gen._pdf4#  r  r7   c                 v    t        j                  d       t        j                  |dz   dz  |dz  |dz        z   S r  )rO   r   rm  r   r	  s      r5   r   zrdist_gen._logpdf7#  s4    q	zDLL!a%AaC1===r7   c                 H    t         j                  |dz   dz  |dz  |dz        S r0  r  r	  s      r5   rt   zrdist_gen._cdf:#  s%    yy!a%AaC1--r7   c                 H    t         j                  |dz   dz  |dz  |dz        S r0  r  r	  s      r5   rx   zrdist_gen._sf=#  s%    xxQ	1Q3!,,r7   c                 H    dt         j                  ||dz  |dz        z  dz
  S r  )rm  r}   r  s      r5   r}   zrdist_gen._ppf@#  s'    1ac1Q3''!++r7   Nc                 @    d|j                  |dz  |dz  |      z  dz
  S r  rl  r  s       r5   r   zrdist_gen._rvsC#  s)    <$$QqS!A#t44q88r7   c                     d|dz  z
  t        j                  |dz   dz  |dz        z  }|t        j                  d|dz        z  S )Nr   rT   r   r   r   rS  )rD   ra   r  	numerators       r5   r  zrdist_gen._munpF#  sE    !a%[BGGQWM1s7$CC	27761r6222r7   r  )r   r   r   r   rj   rq   r   rt   rx   r}   r   r  r   r7   r5   r
  r
  #  s1     BE*>.-,93r7   r
  r;  rdistc                        e Zd ZdZej
                  Zd ZddZd Z	d Z
d Zd Zd Zd	 Zd
 Zd Zd Ze eed       fd              Z x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                     g S rM   r   ri   s    r5   rj   zrayleigh_gen._shape_infof#  r   r7   c                 2    t         j                  d||      S )NrT   r  rr  r   s      r5   r   zrayleigh_gen._rvsi#  s    wwqt,w??r7   c                 J    t        j                  | j                  |            S rM   r  rD   r  s     r5   rq   zrayleigh_gen._pdfl#  r  r7   c                 >    t        j                  |      d|z  |z  z
  S r  r1  r+
  s     r5   r   zrayleigh_gen._logpdfp#  s    vvay37Q;&&r7   c                 :    t        j                  d|dz  z         S r  ru  r+
  s     r5   rt   zrayleigh_gen._cdfs#  s    1%%%r7   c                 Z    t        j                  dt        j                  |       z        S Nr  )rO   r   rv   r  r   s     r5   r}   zrayleigh_gen._ppfv#  s     wwrBHHaRL())r7   c                 J    t        j                  | j                  |            S rM   r5  r+
  s     r5   rx   zrayleigh_gen._sfy#  s    vvdkk!n%%r7   c                     d|z  |z  S )Nr"  r   r+
  s     r5   r   zrayleigh_gen._logsf|#  s    ax!|r7   c                 X    t        j                  dt        j                  |      z        S r/
  )rO   r   r   r   s     r5   r   zrayleigh_gen._isf#  s    wwrBFF1I~&&r7   c                 8   dt         j                  z
  }t        j                  t         j                  dz        |dz  dt         j                  dz
  z  t        j                  t         j                        z  |dz  z  dt         j                  z  |z  d|dz  z  z
  fS )Nr#  rT   r  r  r  r+  r}  r~  s     r5   r   zrayleigh_gen._stats#  sy    "%%ia A2557BGGBEEN*383"%%BsAvI%' 	'r7   c                 L    t         dz  dz   dt        j                  d      z  z
  S )Nr   r   r   rT   r6  ri   s    r5   r   zrayleigh_gen._entropy#  s!    czA~BFF1I--r7   a          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                    |j                  dd      rt        |   g|i |S t        | ||      \  }}fd}fd}|ffd	}|At	        j
                  |z
  dk        rt        ddt        j                  	      | ||      fS |j                  d
      }	|	| j                        d   }	||n|}
t	        j                  t	        j                        t        j                         }t        |
|      }t        j                  |
||f      }|j                  st!        |j"                        |j$                  }|xs  ||      }||fS )Nr9  Fc                 ^    t        j                  | z
  dz        dt              z  z  dz  S r  )rO   r  r  )r-   rE   s    r5   	scale_mlez#rayleigh_gen.fit.<locals>.scale_mle#  s/     FFD3J1,-SY?BFFr7   c                     | z
  }|j                         }|dz  j                         }d|z  j                         }||dt              z  z  |z  z
  S r  )r  r  )r-   r"  r[  ra  s3rE   s        r5   loc_mlez!rayleigh_gen.fit.<locals>.loc_mle#  sT     BBa%BB$BAc$iK(+++r7   c                 b    | z
  }|j                         |dz  d|z  j                         z  z
  S r  )r  )r-   r.   r"  rE   s      r5   loc_mle_scale_fixedz-rayleigh_gen.fit.<locals>.loc_mle_scale_fixed#  s2     B668eQh!B$555r7   r   rayleighr   r  r-   r   )r2   r@   rB   rE  rO   r  rJ  rh   r<   r  rX  r  rY   r   r*   rY  rV   flagrF  )rD   rE   rF   r4   r   r   r7
  r:
  r<
  loc0rH   rR   rQ   r  r-   r.   r  s    `              r5   rB   zrayleigh_gen.fit#  sF    88J&7;t3d3d338t9=tEdF	G
	, ,2 	6 vvdTkQ&'":QbffEEYt_,, xx<>>$'*Dg-@bffTlRVVG4"3/""30@A}} **hh()C.Ezr7   r  )r   r   r   r   r   r  r  rj   r   rq   r   rt   r}   rx   r   r   r   r   rJ   r	   rB   r  r  s   @r5   r'
  r'
  N#  su    * "44M@''&*&''. } 5. /// /r7   r'
  r=
  c                        e Zd ZdZd Zd Z fdZd Zd Zd Z	d Z
d	 Zd
 Zd ZdZ eee       fd       Z xZS )reciprocal_gena,  A loguniform or reciprocal continuous random variable.

    %(before_notes)s

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

    .. math::

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

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

    %(after_notes)s

    %(example)s

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

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

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

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

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

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

    c                     |dkD  ||kD  z  S r-  r   r  s      r5   rb   zreciprocal_gen._argcheck#      A!a%  r7   c                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS rf  rg   rg  s      r5   rj   zreciprocal_gen._shape_info$  rj  r7   c                     t        |t              r|j                         }t        |   |t        j                  |      t        j                  |      f      S NrL  r>   r)   r  r@   r  rO   r  r  rR  s     r5   r  zreciprocal_gen._fitstart$  sC    dL)>>#Dw RVVD\266$<,H IIr7   c                 
    ||fS rM   r   r  s      r5   r   zreciprocal_gen._get_support$  rT  r7   c                 N    t        j                  | j                  |||            S rM   r  rs  s       r5   rq   zreciprocal_gen._pdf$  r  r7   c                     t        j                  |       t        j                  t        j                  |      t        j                  |      z
        z
  S rM   r1  rs  s       r5   r   zreciprocal_gen._logpdf$  s5    q	zBFF266!9rvvay#8999r7   c                     t        j                  |      t        j                  |      z
  t        j                  |      t        j                  |      z
  z  S rM   r1  rs  s       r5   rt   zreciprocal_gen._cdf$  s7    q	"&&)#q	BFF1I(=>>r7   c                     t        j                  t        j                  |      |t        j                  |      t        j                  |      z
  z  z         S rM   rO   r   r   r  s       r5   r}   zreciprocal_gen._ppf$  s8    vvbffQi!RVVAY%:";;<<r7   c                 6   |dk(  rydt        j                  |      t        j                  |      z
  z  |z  }t        j                  t        j                  t	        |t        j                  |      z  |t        j                  |      z                    }||z  S )Nr   r   r   )rO   r   r  r   	_log_diff)rD   ra   r   r   r  r  s         r5   r  zreciprocal_gen._munp$  so    6"&&)bffQi'(1,WWRVVIa"&&)mQrvvay[ABCBwr7   c                     dt        j                  |      t        j                  |      z   z  t        j                  t        j                  |      t        j                  |      z
        z   S r  r1  r  s      r5   r   zreciprocal_gen._entropy#$  sE    BFF1Iq	)*RVVBFF1Iq	4I-JJJr7   z        `loguniform`/`reciprocal` is over-parameterized. `fit` automatically
         fixes `scale` to 1 unless `fscale` is provided by the user.

r   c                 R    |j                  dd      }t        |   |g|d|i|S )Nr   r   )r2   r@   rB   )rD   rE   rF   r4   r   r  s        r5   rB   zreciprocal_gen.fit*$  s1    (A&w{4>$>v>>>r7   )r   r   r   r   rb   rj   r  r   rq   r   rt   r}   r  r   fit_noter	   r   rB   r  r  s   @r5   rA
  rA
  #  s`    2f!
J-:?=KLH }H=? >?r7   rA
  
loguniform
reciprocalc                   <    e Zd ZdZd Zd Zd
dZd Zd Zd Z	d	 Z
y)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                     |dk\  S r-  r   r	  s     r5   rb   zrice_gen._argcheckW$  r  r7   c                 @    t        dddt        j                  fd      gS )Nr   Fr   rf   rg   ri   s    r5   rj   zrice_gen._shape_infoZ$  r  r7   Nc                     |t        j                  d      z  |j                  d|z         z   }t        j                  ||z  j                  d            S )NrT   )rT   r  r   r  )rO   r   r   r  )rD   r   r   r   r  s        r5   r   zrice_gen._rvs]$  sH    bggajL<77TD[7IIww!yyay())r7   c                 |    t        j                  t        j                  |      dt        j                  |            S r  )rv   chndtrrO   r!  r  s      r5   rt   zrice_gen._cdfb$  s%    yy1q"))A,77r7   c           	      |    t        j                  t        j                  |dt        j                  |                  S r  )rO   r   rv   chndtrixr!  r  s      r5   r}   zrice_gen._ppfe$  s&    wwr{{1a1677r7   c                 ~    |t        j                  ||z
   ||z
  z  dz        z  t        j                  ||z        z  S r=  )rO   r   rv   i0er  s      r5   rq   zrice_gen._pdfh$  s<     266AaC&!A#,s*++bffQqSk99r7   c                     |dz  }d|z   }||z  dz  }d|z  t        j                  |       z  t        j                  |      z  t        j                  |d|      z  S r  )rO   r   rv   r  hyp1f1)rD   ra   r   nd2n1r  s         r5   r  zrice_gen._munpq$  s^    eWqSWc
RVVRC[(288B<7		"a$% 	&r7   r  )r   r   r   r   rb   rj   r   rt   r}   rq   r  r   r7   r5   rV
  rV
  :$  s+    8D*
88:&r7   rV
  ricec                   x    e Zd ZdZ eed      d        Zd Zd Zd Z	d Z
ed	        Zd
 Zd Zd ZddZd Zy)irwinhall_gena\
  An Irwin-Hall (Uniform Sum) continuous random variable.

    An `Irwin-Hall <https://en.wikipedia.org/wiki/Irwin-Hall_distribution/>`_
    continuous random variable is the sum of :math:`n` independent
    standard uniform random variables [1]_ [2]_.

    %(before_notes)s

    Notes
    -----
    Applications include `Rao's Spacing Test
    <https://jammalam.faculty.pstat.ucsb.edu/html/favorite/test.htm>`_,
    a more powerful alternative to the Rayleigh test
    when the data are not unimodal, and radar [3]_.

    Conveniently, the pdf and cdf are the :math:`n`-fold convolution of
    the ones for the standard uniform distribution, which is also the
    definition of the cardinal B-splines of degree :math:`n-1`
    having knots evenly spaced from :math:`1` to :math:`n` [4]_ [5]_.

    The Bates distribution, which represents the *mean* of statistically
    independent, uniformly distributed random variables, is simply the
    Irwin-Hall distribution scaled by :math:`1/n`. For example, the frozen
    distribution ``bates = irwinhall(10, scale=1/10)`` represents the
    distribution of the mean of 10 uniformly distributed random variables.
    
    %(after_notes)s

    References
    ----------
    .. [1] P. Hall, "The distribution of means for samples of size N drawn
            from a population in which the variate takes values between 0 and 1,
            all such values being equally probable",
            Biometrika, Volume 19, Issue 3-4, December 1927, Pages 240-244,
            :doi:`10.1093/biomet/19.3-4.240`.
    .. [2] J. O. Irwin, "On the frequency distribution of the means of samples
            from a population having any law of frequency with finite moments,
            with special reference to Pearson's Type II,
            Biometrika, Volume 19, Issue 3-4, December 1927, Pages 225-239,
            :doi:`0.1093/biomet/19.3-4.225`.
    .. [3] K. Buchanan, T. Adeyemi, C. Flores-Molina, S. Wheeland and D. Overturf, 
            "Sidelobe behavior and bandwidth characteristics
            of distributed antenna arrays,"
            2018 United States National Committee of
            URSI National Radio Science Meeting (USNC-URSI NRSM),
            Boulder, CO, USA, 2018, pp. 1-2.
            https://www.usnc-ursi-archive.org/nrsm/2018/papers/B15-9.pdf.
    .. [4] Amos Ron, "Lecture 1: Cardinal B-splines and convolution operators", p. 1
            https://pages.cs.wisc.edu/~deboor/887/lec1new.pdf.
    .. [5] Trefethen, N. (2012, July). B-splines and convolution. Chebfun. 
            Retrieved April 30, 2024, from http://www.chebfun.org/examples/approx/BSplineConv.html.

    %(example)s
    z        Raises a ``NotImplementedError`` for the Irwin-Hall distribution because
        the generic `fit` implementation is unreliable and no custom implementation
        is available. Consider using `scipy.stats.fit`.

r   c                     d}t        |      )NzThe generic `fit` implementation is unreliable for this distribution, and no custom implementation is available. Consider using `scipy.stats.fit`.)r	  )rD   rE   rF   r4   	fit_notess        r5   rB   zirwinhall_gen.fit$  s    
9	 "),,r7   c                 P    |dkD  t        |      z  t        j                  |      z  S r-  )r   rO   	isrealobjr`   s     r5   rb   zirwinhall_gen._argcheck$  s"    AQ'",,q/99r7   c                 
    d|fS r-  r   r`   s     r5   r   zirwinhall_gen._get_support$  rT  r7   c                 @    t        dddt        j                  fd      gS re   rg   ri   s    r5   rj   zirwinhall_gen._shape_info$  rk   r7   c                 b    d } t        j                  |t         j                  g      ||      S )Nc                     t        j                  |t         j                        }t        j                  || z   |d      t        j
                  || z   |d      z  S )Nr  T)exact)rO   r   int64rv   	stirling2r  )rZ  ra   s     r5   vmunpz"irwinhall_gen._munp.<locals>.vmunp$  sH    

1BHH-ALL5!48ggagq56 7r7   r  r  )rD   rZ  ra   rr
  s       r5   r  zirwinhall_gen._munp$  s)    	7 8r||E2::,7qAAr7   c                 \    t        j                  | dz         }t        j                  |      S r]   )rO   rL  r   basis_element)ra   r  s     r5   	_cardbsplzirwinhall_gen._cardbspl$  s$    IIacN$$Q''r7   c                 h      fd} t        j                  |t         j                  g      ||      S )Nc                 2     j                  |      |       S rM   )ru
  rp   ra   rD   s     r5   vpdfz irwinhall_gen._pdf.<locals>.vpdf$  s    $4>>!$Q''r7   r  r  )rD   rp   ra   ry
  s   `   r5   rq   zirwinhall_gen._pdf$  s(    	(6r||D"**6q!<<r7   c                 h      fd} t        j                  |t         j                  g      ||      S )Nc                 N     j                  |      j                         |       S rM   ru
  antiderivativerx
  s     r5   vcdfz irwinhall_gen._cdf.<locals>.vcdf$  s"    54>>!$335a88r7   r  r  )rD   rp   ra   r~
  s   `   r5   rt   zirwinhall_gen._cdf$  s(    	96r||D"**6q!<<r7   c                 h      fd} t        j                  |t         j                  g      ||      S )Nc                 T     j                  |      j                         || z
        S rM   r|
  rx
  s     r5   vsfzirwinhall_gen._sf.<locals>.vsf$  s&    54>>!$335ac::r7   r  r  )rD   rp   ra   r
  s   `   r5   rx   zirwinhall_gen._sf$  s(    	;5r||C5a;;r7   Nc                 2    t         dd       } ||||      S )Nc                     t        j                  |       j                  t              } || fn| g|}|j	                  |      j                  d      S )Nr  r   r  )rO   rF  r  r  r  r  )ra   r   r   usizes       r5   _rvs1z!irwinhall_gen._rvs.<locals>._rvs1$  sO    ""3'A LQDqj4jE''U'377Q7??r7   r  r  )r   )rD   ra   r   r   rF   r
  s         r5   r   zirwinhall_gen._rvs$  s'    	#	@ 
$	@ QT==r7   c                 &    |dz  |dz  ddd|z  z  fS )NrT   r  r   r  rB  r   r`   s     r5   r   zirwinhall_gen._stats$  s#     sAbD!R1X%%r7   r  )r   r   r   r   r
   r   rB   rb   r   rj   r  r  ru
  rq   rt   rx   r   r   r   r7   r5   rf
  rf
  {$  sm    5n   6? @-	@-:C	B ( (=
=
<
>&r7   rf
  	irwinhall)r   ra   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd	dZ	y)
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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zrecipinvgauss_gen._shape_info%  r  r7   c                 L    t        j                  | j                  ||            S rM   r  r  s      r5   rq   zrecipinvgauss_gen._pdf%  s     vvdll1b)**r7   c                 ^    t        j                  |dkD  ||fd t        j                         S )Nr   c                     d|| z  z
  dz   d| z  |dz  z  z  dt        j                  dt         j                  z  | z        z  z
  S )Nr   r   rT   r   r   )rp   rB  s     r5   r  z+recipinvgauss_gen._logpdf.<locals>.<lambda>!%  sH    QAXO+qs2s7{; "%%	!223 r7   r  r   r  s      r5   r   zrecipinvgauss_gen._logpdf%  s.    EAr74w	  	 r7   c                     d|z  |z
  }d|z  |z   }dt        j                  |      z  }t        | |z        t        j                  d|z        t        | |z        z  z
  S Nr   r   rO   r   r   r   rD   rp   rB  trm1trm2isqxs         r5   rt   zrecipinvgauss_gen._cdf%%  s_    2vz2vz2771:~$t$rvvc"f~id
6K'KKKr7   c                     d|z  |z
  }d|z  |z   }dt        j                  |      z  }t        ||z        t        j                  d|z        t        | |z        z  z   S r
  r
  r
  s         r5   rx   zrecipinvgauss_gen._sf+%  s]    2vz2vz2771:~d#bffSVnYuTz5J&JJJr7   Nc                 0    d|j                  |d|      z  S r  r  r  s       r5   r   zrecipinvgauss_gen._rvs1%  s    <$$R4$888r7   r  )
r   r   r   r   rj   rq   r   rt   rx   r   r   r7   r5   r
  r
  $  s(    ,F+
 LK9r7   r
  recipinvgaussc                   B    e Zd ZdZd Zd Zd Zd Zd ZddZ	d	 Z
d
 Zy)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                     g S rM   r   ri   s    r5   rj   zsemicircular_gen._shape_infoW%  r   r7   c                 `    dt         j                  z  t        j                  d||z  z
        z  S r  r}  r   s     r5   rq   zsemicircular_gen._pdfZ%  s%    255y1Q3''r7   c                     t        j                  dt         j                  z        dt        j                  | |z        z  z   S r  r  r   s     r5   r   zsemicircular_gen._logpdf]%  s0    vvagRXXqbd^!333r7   c                     ddt         j                  z  |t        j                  d||z  z
        z  t        j                  |      z   z  z   S )Nr   r   r   )rO   r   r   r)  r   s     r5   rt   zsemicircular_gen._cdf`%  s<    3ruu9a!A#.1=>>>r7   c                 .    t         j                  |d      S Nr  )r%
  r}   r   s     r5   r}   zsemicircular_gen._ppfc%  s    zz!Qr7   Nc                     t        j                  |j                  |            }t        j                  t         j                  |j                  |      z        }||z  S r/  )rO   r   r  r   r   )rD   r   r   r  r   s        r5   r   zsemicircular_gen._rvsf%  sN     GGL((d(34FF255<//T/::;1ur7   c                      y)N)r   r  r   r;  r   ri   s    r5   r   zsemicircular_gen._statsm%  ri  r7   c                      y)NgzCϑ?r   ri   s    r5   r   zsemicircular_gen._entropyp%  s    %r7   r  )r   r   r   r   rj   rq   r   rt   r}   r   r   r   r   r7   r5   r
  r
  8%  s/    <(4?  &r7   r
  semicircularc                   <    e Zd ZdZd Zd Zd Zd Zd Zd
dZ	d Z
y	)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                 2    t        j                  |      dk  S r]   )rO   r  r  s     r5   rb   zskewcauchy_gen._argcheck%  s    vvay1}r7   c                      t        dddd      gS )Nr   F)r;  r   r	  r   ri   s    r5   rj   zskewcauchy_gen._shape_info%  s    3{NCDDr7   c                 x    dt         j                  |dz  |t        j                  |      z  dz   dz  z  dz   z  z  S r0  )rO   r   rP   r  s      r5   rq   zskewcauchy_gen._pdf%  s:    BEEQTQ^a%7!$;;a?@AAr7   c                    t        j                  |dk  d|z
  dz  d|z
  t         j                  z  t        j                  |d|z
  z        z  z   d|z
  dz  d|z   t         j                  z  t        j                  |d|z   z        z  z         S Nr   r   rT   )rO   rN  r   r  r  s      r5   rt   zskewcauchy_gen._cdf%  s    xxQQ!q1uo		!q1u+8N&NNQ!q1uo		!q1u+8N&NNP 	Pr7   c           
      >   || j                  d|      k  }t        j                  |t        j                  t        j                  d|z
  z  |d|z
  dz  z
  z        d|z
  z  t        j                  t        j                  d|z   z  |d|z
  dz  z
  z        d|z   z        S r
  )rt   rO   rN  r  r   )rD   rp   r   r  s       r5   r}   zskewcauchy_gen._ppf%  s    		!QxxruuA!q1uk/BCq1uMruuA!q1uk/BCq1uMO 	Or7   c                 ~    t         j                  t         j                  t         j                  t         j                  fS rM   r  )rD   r   r  s      r5   r   zskewcauchy_gen._stats%  r  r7   c                     t        |t              r|j                         }t        j                  |g d      \  }}}d|||z
  dz  fS )Nr  r   rT   r  )rD   rE   r  r  r  s        r5   r  zskewcauchy_gen._fitstart%  sE     dL)>>#DdL9S#C#)Q&&r7   Nr  )r   r   r   r   rb   rj   rq   rt   r}   r   r  r   r7   r5   r
  r
  w%  s/     BEBP
O.'r7   r
  
skewcauchyc                        e Zd ZdZd Zd Zd Zd Z fdZd Z	d Z
d	 Zdd
ZddZed        Zd Z eed       fd       Z xZS )skewnorm_genaA  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]_.

    This distribution uses routines from the Boost Math C++ library for
    the computation of ``cdf``, ``ppf`` and ``isf`` methods. [2]_

    %(after_notes)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`
    .. [2] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.

    %(example)s

    c                 ,    t        j                  |      S rM   r  r  s     r5   rb   zskewnorm_gen._argcheck%  r  r7   c                 ^    t        ddt        j                   t        j                  fd      gS )Nr   Fr	  rg   ri   s    r5   rj   zskewnorm_gen._shape_info%  r  r7   c                 @    t        j                  |dk(  ||fd d       S )Nr   c                     t        |       S rM   r   rp   r   s     r5   r  z#skewnorm_gen._pdf.<locals>.<lambda>%  s
    1 r7   c                 <    dt        |       z  t        || z        z  S r=  r
  r
  s     r5   r  z#skewnorm_gen._pdf.<locals>.<lambda>%  s    IaL1Q37 r7   r  r  s      r5   rq   zskewnorm_gen._pdf%  s&    FQF%79 	9r7   c                 @    t        j                  |dk(  ||fd d       S )Nr   c                     t        |       S rM   r   r
  s     r5   r  z&skewnorm_gen._logpdf.<locals>.<lambda>%  s
    a r7   c                 b    t        j                  d      t        |       z   t        || z        z   S r  r
  r
  s     r5   r  z&skewnorm_gen._logpdf.<locals>.<lambda>%  s%    <?2<!3DD r7   r  r  s      r5   r   zskewnorm_gen._logpdf%  s(    FQF(DF 	Fr7   c                    t        j                  |      }t        j                  |dd|      }t        j                  ||j
                        }|dk  |dkD  z  }t        |   ||   ||         ||<   t        j                  |dd      S )Nr   r   gư>r   r   )	rO   r  rm   _skewnorm_cdfrh	  r  r@   rt   r	  )rD   rp   r   r   i_small_cdfr  s        r5   rt   zskewnorm_gen._cdf%  s}    MM!3Q/OOAsyy)Tza!e, 7<++GKwwsAq!!r7   c                 2    t        j                  |dd|      S Nr   r   )rm   _skewnorm_ppfr  s      r5   r}   zskewnorm_gen._ppf%        Ca00r7   c                 *    | j                  | |       S rM   r  r  s      r5   rx   zskewnorm_gen._sf%  s     yy!aR  r7   c                 2    t        j                  |dd|      S r
  )rm   _skewnorm_isfr  s      r5   r   zskewnorm_gen._isf%  r
  r7   c                    |j                  |      }|j                  |      }|t        j                  d|dz  z         z  }||z  |t        j                  d|dz  z
        z  z   }t        j                  |dk\  ||       S )Nr  r   rT   r   )r0  rO   r   rN  )rD   r   r   r   u0r  r  r  s           r5   r   zskewnorm_gen._rvs&  s      d +T*bgga!Q$hrTAbgga!Q$h'''xxabS))r7   c                    g d}t        j                  dt         j                  z        |z  t        j                  d|dz  z         z  }d|v r||d<   d|v rd|dz  z
  |d<   d|v r;dt         j                  z
  dz  |t        j                  d|dz  z
        z  d	z  z  |d<   d
|v r+dt         j                  d	z
  z  |dz  d|dz  z
  dz  z  z  |d	<   |S )Nr  rT   r   r:  r   r  r  r#  r  r  rV  )rD   r   r  r,  consts        r5   r   zskewnorm_gen._stats	&  s    )"%% 1$RWWQAX%66'>F1I'>E1HF1I'>bee)Q5UAX1F+F*JJF1I'>BEEAI5!8Q\A4E+EFF1Ir7   c                     t        dg      t        ddg      t        g d      t        g d      t        g d      t        g d      t        g d      t        g d	      t        g d
      t        g d      d
}|S )Nr   r  r  )r  ir  )i   i?   i)i  iin  ir
  )(  iSi6Q  ii  iO)i iBi/ iio ir
  ) iԷi iYei{Hx ii i!)	i!iׅi쇀iiViX'ilir
  )
is_'il   </1 ldy( l   J8D l.~ l   -Rx iWi[i0)
r   r  rB  r  r  r     r        r   )rD   skewnorm_odd_momentss     r5   _skewnorm_odd_momentsz"skewnorm_gen._skewnorm_odd_moments&  s     1#1b'",'./78EF # $ 8 9 % &  2 3 
$ $#r7   c                    |dz  rP|dkD  rt        d      |t        j                  d|dz  z         z  }| | j                  |   |dz        z  t        z  S t        j                  |dz   dz        d|dz  z  z  t        z  S )NrT   r
  zKskewnorm noncentral moments not implemented for odd orders greater than 19.r   )r	  rO   r   r
  r&   rv   r  r%   )rD   rZ  r   r$  s       r5   r  zskewnorm_gen._munp4&  s    19rz) +5 6 6
 bgga!Q$h''E=D66u=eQhGG%& ' 88UQYM*Qq\9HDDr7   a          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           	      4   |j                  dd      rt        |   |g|i |S t        |t              r7|j                         dk(  r|j                         }nt        |   |g|i |S t        | |||      \  }}}}|j                  dd      j                         }d }d }	|dk(  rd	\  }
}}n6t        |      r|d   nd }
|j                  d
d       }|j                  dd       }||
t        j                  |      }|dk(  rt        j                  |dd      }n  |d      }t        j                  || |      } |	|      }t        j                  d      5  t        j                   t        j"                  |dz  d|dz  z
              t        j$                  |      z  }
d d d        n$||n|
}
|
t        j                   d|
dz  z         z  }|J|Ht        j&                  |      }t        j                   |dd|dz  z  t        j(                  z  z
  z        }n||}|G|Et        j*                  |      }|||z  t        j                   dt        j(                  z        z  z
  }n||}|dk(  r|
||fS t        |   ||
f||d|S # 1 sw Y   xY w)Nr9  Fr   r0   r:   c                     dt         j                  z
  dz  | t        j                  dt         j                  z        z  dz  dd| dz  z  t         j                  z  z
  dz  z  z  S )Nr#  rT   r  r   r  r}  r  s    r5   skew_dz skewnorm_gen.fit.<locals>.skew_de&  s]    beeGQ;1rwwq255y'9#9A"=%&1a4"%%%73$?#@ A Ar7   c                     t        j                  |       dz  }t        j                  |       t        j                  t         j                  dz  |z  |dt         j                  z
  dz  dz  z   z        z  S )Nr  rT   r#  )rO   r  rP   r   r   )r?  s_23s     r5   d_skewz skewnorm_gen.fit.<locals>.d_skewi&  s^    66$<#&D774=277a$$1ruu9a-3)?"?@$  r7   r;   r@  r-   r.   gGzgGz?r   r8  r9  rT   rD  )r2   r@   rB   r>   r)   r?   r  rE  r<   r=   r  r  r?  rO   r	  r;  r   r:  rP   r  r   r   )rD   rE   rF   r4   r  r   r   r0   r
  r
  r   r-   r.   r  s_maxr  r  r:  r  s                     r5   rB   zskewnorm_gen.fitH&  s    88J&7;t3d3d33dL)  "a'~~'w{47$7$77 "=T4=A4"Ib$(E*002	A	 T>,MAsEt9Q$A((5$'CHHWd+E:!) 

4 A GGAud+q	GGAvu-q	AH- BGGBIIadQq!tV56rwwqzAB B n!ABGGA1H%%A>emtAGGAQq!tVBEE\!123EE<CKAeAgbggag...CCT>c5=  7;tQECuEEE/B Bs   A	JJr  r  )r   r   r   r   rb   rj   rq   r   rt   r}   rx   r   r   r   r   r
  r  r	   r   rB   r  r  s   @r5   r
  r
  %  sz    :K9F"1!
1** $ $*E( } 5 GFGFr7   r
  skewnormc                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
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                 <    |dk\  |dk  z  |dk\  z  |dk  z  ||k\  z  S r  r   rD   r  r  s      r5   rb   ztrapezoid_gen._argcheck&  s0    Q16"a1f-a8AFCCr7   c                 B    t        dddd      }t        dddd      }||gS )Nr  Fr   r   TTr  r
  r  s      r5   rj   ztrapezoid_gen._shape_info&  s+    UHl;UHl;Bxr7   c                 j    d||z
  dz   z  }t        ||k  ||k  ||k  z  ||kD  gd d d g||||f      S )NrT   r   c                     || z  |z  S rM   r   rp   r  r  r  s       r5   r  z$trapezoid_gen._pdf.<locals>.<lambda>&  s    q1uqy r7   c                     |S rM   r   r
  s       r5   r  z$trapezoid_gen._pdf.<locals>.<lambda>&  s    q r7   c                     |d| z
  z  d|z
  z  S r]   r   r
  s       r5   r  z$trapezoid_gen._pdf.<locals>.<lambda>&  s    qAaCyAaC/@ r7   r   )rD   rp   r  r  r  s        r5   rq   ztrapezoid_gen._pdf&  s`    1QKAE!VQ/E# 90@B q!Q<) 	)r7   c                 R    t        ||k  ||k  ||k  z  ||kD  gd d d g|||f      S )Nc                 $    | dz  |z  ||z
  dz   z  S r  r   rp   r  r  s      r5   r  z$trapezoid_gen._cdf.<locals>.<lambda>&  s    AqD1H!A,> r7   c                 *    |d| |z
  z  z   ||z
  dz   z  S r  r   r
  s      r5   r  z$trapezoid_gen._cdf.<locals>.<lambda>&  s    Qac]qs1u,E r7   c                 6    dd| z
  dz  ||z
  dz   z  d|z
  z  z
  S r0  r   r
  s      r5   r  z$trapezoid_gen._cdf.<locals>.<lambda>&  s3    A!z23A#a%09<=aC0A -B r7   r   r2  s       r5   rt   ztrapezoid_gen._cdf&  sP    AE!VQ/E# ?EBC q!9& 	&r7   c                 R   | j                  |||      | j                  |||      }}||k  ||k  ||kD  g}t        j                  ||z  d|z   |z
  z        d|z  d|z   |z
  z  d|z  z   dt        j                  d|z
  ||z
  dz   z  d|z
  z        z
  g}t        j                  ||      S r"  )rt   rO   r   select)rD   r|   r  r  qcqdr  rs	  s           r5   r}   ztrapezoid_gen._ppf&  s    1a#TYYq!Q%7BFAGQV,gga!eq1uqy12AgQ+cAg5"''1q5QUQY"71q5"ABBD
 yy:..r7   c                     |dz   z  }t        |dk(  d|k  |dk  z  |dk(  gd fdfdg|g      }dd|z   |z
  z  ||z
  z  dz   dz   z  z  }|S )	Nr   r   r   c                      yr  r   r
  s    r5   r  z%trapezoid_gen._munp.<locals>.<lambda>&  s    r7   c                 l    t        j                  dz   t        j                  |       z        | dz
  z  S r  )rO   r  r   r  ra   s    r5   r  z%trapezoid_gen._munp.<locals>.<lambda>&  s*    rxx1q	 12ae< r7   c                     dz   S r  r   r
  s    r5   r  z%trapezoid_gen._munp.<locals>.<lambda>&  s    qs r7   r   rT   r   )rD   ra   r  r  ab_termdc_termrv  s    `     r5   r  ztrapezoid_gen._munp&  s     ac(#XaAG,a3h7< C SU1Wo7!23!!}E
r7   c                 h    dd|z
  |z   z  d|z   |z
  z  t        j                  dd|z   |z
  z        z   S r   r1  r
  s      r5   r   ztrapezoid_gen._entropy'  s=     c!eAg#a%'*RVVC3q57O-DDDr7   N)r   r   r   r   rb   rj   rq   rt   r}   r  r   r   r7   r5   r
  r
  &  s-     BD
	)&/2Er7   r
  	trapezoidc                   B    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zy)
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                 *    |j                  d|d|      S r  )
triangularr  s       r5   r   ztriang_gen._rvs$'  s    &&q!Q55r7   c                     |dk\  |dk  z  S r  r   r|  s     r5   rb   ztriang_gen._argcheck''  s    Q16""r7   c                      t        dddd      gS )Nr  Fr
  r
  r
  ri   s    r5   rj   ztriang_gen._shape_info*'  s    3x>??r7   c                 `    t        |dk(  ||k  ||k\  |dk7  z  |dk(  gd d d d g||f      }|S )Nr   r   c                     dd| z  z
  S r  r   r  s     r5   r  z!triang_gen._pdf.<locals>.<lambda>7'  s    a!a%i r7   c                     d| z  |z  S r  r   r  s     r5   r  z!triang_gen._pdf.<locals>.<lambda>8'      a!eai r7   c                     dd| z
  z  d|z
  z  S r  r   r  s     r5   r  z!triang_gen._pdf.<locals>.<lambda>9'  s    a1q5kQU&; r7   c                     d| z  S r  r   r  s     r5   r  z!triang_gen._pdf.<locals>.<lambda>:'  
    a!e r7   r   rD   rp   r  r  s       r5   rq   ztriang_gen._pdf-'  sZ     aQq&Q!V,a! 0/;+- A  r7   c                 `    t        |dk(  ||k  ||k\  |dk7  z  |dk(  gd d d d g||f      }|S )Nr   r   c                     d| z  | | z  z
  S r  r   r  s     r5   r  z!triang_gen._cdf.<locals>.<lambda>C'  s    acAaCi r7   c                     | | z  |z  S rM   r   r  s     r5   r  z!triang_gen._cdf.<locals>.<lambda>D'  r  r7   c                 *    | | z  d| z  z
  |z   |dz
  z  S r  r   r  s     r5   r  z!triang_gen._cdf.<locals>.<lambda>E'  s    qsQqSy1}1&= r7   c                     | | z  S rM   r   r  s     r5   r  z!triang_gen._cdf.<locals>.<lambda>F'  r  r7   r   r  s       r5   rt   ztriang_gen._cdf>'  sX    aQq&Q!V,a! 0/=+- A  r7   c           
          t        j                  ||k  t        j                  ||z        dt        j                  d|z
  d|z
  z        z
        S r]   )rO   rN  r   r  s      r5   r}   ztriang_gen._ppfJ'  s?    xxArwwq1u~q!A#!A#1G/GHHr7   c           	          |dz   dz  d|z
  ||z  z   dz  t        j                  d      d|z  dz
  z  |dz   z  |dz
  z  dt        j                  d|z
  ||z  z   d      z  z  dfS )	Nr   rC     rT   r   rB  r  g333333)rO   r   r  r|  s     r5   r   ztriang_gen._statsM'  sx    3QqsB
AaCE"AaC(!A#.!BHHc!eAaCi#4N2NO 	r7   c                 2    dt        j                  d      z
  S r  r1  r|  s     r5   r   ztriang_gen._entropyS'  s    266!9}r7   r  )r   r   r   r   r   rb   rj   rq   rt   r}   r   r   r   r7   r5   r
  r
  '  s1    *6#@"
Ir7   r
  triangc                   X     e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Z fd
Zd Z xZS )truncexpon_genad  A truncated exponential continuous random variable.

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

    %(example)s

    c                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   ztruncexpon_gen._shape_infop'  r
  r7   c                     | j                   |fS rM   r3  r	  s     r5   r   ztruncexpon_gen._get_supports'      vvqyr7   c                 ^    t        j                  |       t        j                  |        z  S rM   r  r  s      r5   rq   ztruncexpon_gen._pdfv'  s#    vvqbzBHHaRL=))r7   c                 ^    | t        j                  t        j                  |              z
  S rM   r  r  s      r5   r   ztruncexpon_gen._logpdfz'  s$    rBFFBHHaRL=)))r7   c                 \    t        j                  |       t        j                  |       z  S rM   ru  r  s      r5   rt   ztruncexpon_gen._cdf}'  s!    xx|BHHaRL((r7   c                 \    t        j                  |t        j                  |       z         S rM   )rv   r  r  r  s      r5   r}   ztruncexpon_gen._ppf'  s"    288QB<(((r7   c                     t        j                  |       t        j                  |       z
  t        j                  |       z  S rM   r  r  s      r5   rx   ztruncexpon_gen._sf'  s0    r
RVVQBZ'1"55r7   c                     t        j                  t        j                  |       |t        j                  |       z  z
         S rM   )rO   r   r   rv   r  r  s      r5   r   ztruncexpon_gen._isf'  s2    rvvqbzA!$44555r7   c                 2   |dk(  r7d|dz   t        j                  |       z  z
  t        j                  |        z  S |dk(  rFddd||z  d|z  z   dz   z  t        j                  |       z  z
  z  t        j                  |        z  S t        |   ||      S rH  )rO   r   rv   r  r@   r  )rD   ra   r   r  s      r5   r  ztruncexpon_gen._munp'  s     6qsBFFA2J&&"((A2,77!VaQqS1WQYr
223bhhrl]CC 7=A&&r7   c                     t        j                  |      }t        j                  |dz
        d||dz
  z  z   d|z
  z  z   S r  rM
  )rD   r   eBs      r5   r   ztruncexpon_gen._entropy'  s;    VVAYvvbd|Qr1S5z\CF333r7   )r   r   r   r   rj   r   rq   r   rt   r}   rx   r   r  r   r  r  s   @r5   r  r  Z'  s;    *E**))66	'4r7   r  
truncexpon)r   r   c                 4    t        j                  | |gd      S )Nr   r  )rv   r@  log_plog_qs     r5   _log_sumr&  '  s    <<Q//r7   c                 \    t        j                  | |t        j                  dz  z   gd      S )N              ?r   r  )rv   r@  rO   r   r#  s     r5   rO
  rO
  '  s$    <<beeBh/a88r7   c                    t        j                  | |      \  } }|dk  }| dkD  }||z   }d fd}d }t        j                  | t         j                  t         j                        }| |   j
                  r | |   ||         ||<   | |   j
                  r || |   ||         ||<   | |   j
                  r || |   ||         ||<   t        j                  |      S )z3Log of Gaussian probability mass within an intervalr   c                 >    t        t        |      t        |             S rM   )rO
  r   r  s     r5   mass_case_leftz'_log_gauss_mass.<locals>.mass_case_left'  s    a,q/::r7   c                      | |        S rM   r   )r   r   r+  s     r5   mass_case_rightz(_log_gauss_mass.<locals>.mass_case_right'  s    qb1"%%r7   c                 Z    t        j                  t        |        t        |       z
        S rM   )rv   r  r   r  s     r5   mass_case_centralz*_log_gauss_mass.<locals>.mass_case_central'  s$     xx1	1"566r7   )r  r  )rO   r  r
  r  
complex128r   r  )	r   r   	case_left
case_rightcase_centralr-  r/  r  r+  s	           @r5   _log_gauss_massr4  '  s    q!$DAq QIQJ+,L;&7 ,,qRVV2==
AC|')a	lCI})!J-:GJ-aoqOL773<r7   c                   x     e Zd ZdZd Zd Z fdZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd ZddZ xZS )truncnorm_genaw
  A truncated normal continuous random variable.

    %(before_notes)s

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

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

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

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

    %(example)s

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

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

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

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

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

    >>> fig, ax = plt.subplots(1, 1)
    >>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')
    >>> ax.hist(r, density=True, bins='auto', histtype='stepfilled', alpha=0.2)
    >>> ax.set_xlim(a-0.1, b+0.1)
    >>> ax.legend(loc='best', frameon=False)
    >>> plt.show()
    c                     ||k  S rM   r   r  s      r5   rb   ztruncnorm_gen._argcheck(  s    1ur7   c                     t        ddt        j                   t        j                  fd      }t        ddt        j                   t        j                  fd      }||gS )Nr   Frf   r   )FTrg   rg  s      r5   rj   ztruncnorm_gen._shape_info(  sI    UbffWbff$5}EUbffWbff$5}EBxr7   c                     t        |t              r|j                         }t        |   |t        j                  |      t        j                  |      f      S rF
  rG
  rR  s     r5   r  ztruncnorm_gen._fitstart(  sC    dL)>>#Dw RVVD\266$<,H IIr7   c                 
    ||fS rM   r   r  s      r5   r   ztruncnorm_gen._get_support(  rT  r7   c                 N    t        j                  | j                  |||            S rM   r  rs  s       r5   rq   ztruncnorm_gen._pdf!(  rX  r7   c                 2    t        |      t        ||      z
  S rM   )r   r4  rs  s       r5   r   ztruncnorm_gen._logpdf$(  s    AA!666r7   c                 N    t        j                  | j                  |||            S rM   rK  rs  s       r5   rt   ztruncnorm_gen._cdf'(  rX  r7   c           
      T   t        j                  |||      \  }}}t        j                  t        ||      t        ||      z
        }|dkD  }t        j                  |      rFt        j
                  t        j                  | j                  ||   ||   ||                      ||<   |S Ng)rO   r  r   r4  r  r  r   r   )rD   rp   r   r   logcdfr  s         r5   r   ztruncnorm_gen._logcdf*(  s    %%aA.1aOAq1OAq4IIJTM66!9"&&QqT1Q41)F"G!GHF1Ir7   c                 N    t        j                  | j                  |||            S rM   r5  rs  s       r5   rx   ztruncnorm_gen._sf2(  r6  r7   c           
      T   t        j                  |||      \  }}}t        j                  t        ||      t        ||      z
        }|dkD  }t        j                  |      rFt        j
                  t        j                  | j                  ||   ||   ||                      ||<   |S r?  )rO   r  r   r4  r  r  r   r   )rD   rp   r   r   logsfr  s         r5   r   ztruncnorm_gen._logsf5(  s    %%aA.1a

?1a0?1a3HHIDL66!9xxQqT1Q41(F!G GHE!Hr7   c                 &   t        |      }t        |      }||z
  }t        j                  t        j                  dt        j                  z  t        j
                  z        |z        }|t        |      z  |t        |      z  z
  d|z  z  }||z   }|S r  )r   rO   r   r   r   rk  r   )	rD   r   r   rl  rm  r2  rB  Dr  s	            r5   r   ztruncnorm_gen._entropy=(  s}    aLaLEFF2771ruu9rtt+,q011IaL 00QU;Er7   c                    t        j                  |||      \  }}}|dk  }| }d }d }t        j                  |      }||   }	||   }
|	j                  r ||	||   ||         ||<   |
j                  r ||
||   ||         ||<   |S )Nr   c                     t        t        |      t        j                  |       t	        ||      z         }t        j                  |      S rM   )r&  r   rO   r   r4  rv   	ndtri_expr|   r   r   	log_Phi_xs       r5   ppf_leftz$truncnorm_gen._ppf.<locals>.ppf_leftL(  s9     a!#_Q-B!BDI<<	**r7   c                     t        t        |       t        j                  |        t	        ||      z         }t        j                  |       S rM   )r&  r   rO   r  r4  rv   rH  rI  s       r5   	ppf_rightz%truncnorm_gen._ppf.<locals>.ppf_rightQ(  sA     qb!1!#1"10E!EGILL+++r7   rO   r  
empty_liker   )rD   r|   r   r   r1  r2  rK  rM  r  q_leftq_rights              r5   r}   ztruncnorm_gen._ppfF(  s    %%aA.1aE	Z
	+
	,
 mmA9J-;;%fa	lAiLIC	N<<':*NC
O
r7   c                    t        j                  |||      \  }}}|dk  }| }d }d }t        j                  |      }||   }	||   }
|	j                  r ||	||   ||         ||<   |
j                  r ||
||   ||         ||<   |S )Nr   c                     t        t        |      t        j                  |       t	        ||      z         }t        j                  t        j                  |            S rM   )rO
  r   rO   r   r4  rv   rH  r  rI  s       r5   isf_leftz$truncnorm_gen._isf.<locals>.isf_lefti(  sB    !,q/"$&&)oa.C"CEI<<	 233r7   c                     t        t        |       t        j                  |        t	        ||      z         }t        j                  t        j                  |             S rM   )rO
  r   rO   r  r4  rv   rH  r  rI  s       r5   	isf_rightz%truncnorm_gen._isf.<locals>.isf_rightn(  sJ    !,r"2"$((A2,A1F"FHILL!3444r7   rN  )rD   r|   r   r   r1  r2  rT  rV  r  rP  rQ  s              r5   r   ztruncnorm_gen._isfb(  s    %%aA.1aE	Z
	4
	5
 mmA9J-;;%fa	lAiLIC	N<<':*NC
O
r7   c                       fd}t        j                  |dk\  ||k(  z  ||k(  z  |||ft        j                  |t        j                  g      t        j
                        S )Nc                 t   t        j                  ||g      }j                  |||      \  }}t        j                  || g      }|dk7  }ddg}t        d| dz         D ]R  t	        j
                  |||ffdd      }	t        j                  |	      dz
  |d   z  z   }
|j                  |
       T |d   S )z
            Returns n-th moment. Defined only if n >= 0.
            Function cannot broadcast due to the loop over n
            r   r   c                     | |dz
  z  z  S r]   r   )rp   r  r  s     r5   r  z:truncnorm_gen._munp.<locals>.n_th_moment.<locals>.<lambda>(  s    AAaCL r7   r  r  r  )rO   r   rq   r  r  r  r  r  )ra   r   r   abpApBprobscondr  r  mkr  rD   s              @r5   n_th_momentz(truncnorm_gen._munp.<locals>.n_th_moment(  s    
 QF#BYYr1a(FBJJRCy)EA:D!fG1ac] 	#
 teR['@235 VVD\QqSGBK$77r"	# 2;r7   r   r  r  rT  )rD   ra   r   r   r`  s   `    r5   r  ztruncnorm_gen._munp(  sV    	, Q162a1f=1ay!||KM*,&&2 	2r7   c                     | j                  t        j                  ||g      ||      \  }}d }t        j                  |      } |||||      S )Nc                    t        j                  | |g      }||z
  }|}t        j                  || g      }|dk7  }t        j                  |||fd d      }	dt        j                  |	      z   }
t        j                  ||||z
  fd d      }	dt        j                  |	      z   }t        j                  |||fd d      }	d|z  t        j                  |	      z   }t        j                  |||fd d      }	d	|
z  t        j                  |	      z   }||d
|
z  d|dz  z  z   z  z   }|t        j
                  |d      z  }||d|z  d	|z  d|
z  |dz  z
  z  z   z  z   }||dz  z  d	z
  }||||fS )Nr   c                     | |z  S rM   r   r  s     r5   r  zGtruncnorm_gen._stats.<locals>._truncnorm_stats_scalar.<locals>.<lambda>(  s
    1Q3 r7   r  r   c                     | |z  S rM   r   r  s     r5   r  zGtruncnorm_gen._stats.<locals>._truncnorm_stats_scalar.<locals>.<lambda>(  s
    ! r7   c                     | |dz  z  S r  r   r  s     r5   r  zGtruncnorm_gen._stats.<locals>._truncnorm_stats_scalar.<locals>.<lambda>(      1QT6 r7   rT   c                     | |dz  z  S r
  r   r  s     r5   r  zGtruncnorm_gen._stats.<locals>._truncnorm_stats_scalar.<locals>.<lambda>(  rf  r7   r  r  r  r  )rO   r   r  r  r  r  )r   r   r[  r\  rZ  r<  rB  r]  r^  r  r=  rC  r>  m4mu3rD  mu4rE  s                     r5   _truncnorm_stats_scalarz5truncnorm_gen._stats.<locals>._truncnorm_stats_scalar(  s   QF#BbBBJJRCy)EA:D??4%6F./1DRVVD\!B??4%b)9;K./1D bffTl"C??4%6I./1D2t$B??4%6I./1D2t$BrRUQr1uW_--CrxxS))Br2b51R42A#6677CsAv!BsB?"r7   )pdfrO   r  r  )rD   r   r   r  r[  r\  rk  _truncnorm_statss           r5   r   ztruncnorm_gen._stats(  sM    "((Aq6*Aq1B	#8 <<(?@1b"--r7   r  )r   r   r   r   rb   rj   r  r   rq   r   rt   r   rx   r   r   r}   r   r  r   r  r  s   @r5   r6  r6  '  sU    >@
J-7-,8:26 .r7   r6  	truncnorm)r   r   c                        e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Ze ee       fd              Z xZS )truncpareto_genac  An upper truncated Pareto continuous random variable.

    %(before_notes)s

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

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

    .. math::

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

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

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

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

    %(after_notes)s

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

    %(example)s

    c                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS )Nr   Fr   r	  r  r   rg   )rD   ri  r   s      r5   rj   ztruncpareto_gen._shape_info(  s;    US"&&M>BUS"&&M>BBxr7   c                     |dkD  |dkD  z  S r
  r   rD   r   r  s      r5   rb   ztruncpareto_gen._argcheck(  s    B1r6""r7   c                     | j                   |fS rM   r3  rs  s      r5   r   ztruncpareto_gen._get_support(  r  r7   c                 2    |||dz    z  z  dd||z  z  z
  z  S r]   r   rD   rp   r   r  s       r5   rq   ztruncpareto_gen._pdf(  s'    1!f9}AadF
++r7   c           	          t        j                  |      t        j                  t        j                  | t        j                  |      z               z
  |dz   t        j                  |      z  z
  S r]   )rO   r   r  rv  s       r5   r   ztruncpareto_gen._logpdf(  sM    vvay266288QBrvvayL#9"9::ac266!9_LLr7   c                 ,    d|| z  z
  dd||z  z  z
  z  S r]   r   rv  s       r5   rt   ztruncpareto_gen._cdf(  s#    ArE	a!AqD&j))r7   c                 n    t        j                  || z         t        j                  d||z  z        z
  S r;  r8  rv  s       r5   r   ztruncpareto_gen._logcdf(  s/    xxQB"((2ad7"333r7   c                 >    t        ddd||z  z  z
  |z  z
  d|z        S Nr   r  r2  rD   r|   r   r  s       r5   r}   ztruncpareto_gen._ppf)  s(    1AadF
A~%r!t,,r7   c                 8    || z  d||z  z  z
  dd||z  z  z
  z  S r]   r   rv  s       r5   rx   ztruncpareto_gen._sf)  s+    A2!Q$1qAv:..r7   c                 ~    t        j                  || z  d||z  z  z
        t        j                  d||z  z        z
  S r{  r  rv  s       r5   r   ztruncpareto_gen._logsf)  s9    vva!ea1fn%AqD(999r7   c                 J    t        d||z  z  dd||z  z  z
  |z  z   d|z        S r{  r2  r|  s       r5   r   ztruncpareto_gen._isf)  s0    1QT6Q1a4ZN*BqD11r7   c                     t        j                  |dd||z  z  z
  z        |dz   t        j                  |      ||z  dz
  z  d|z  z
  z  z    S r]   r1  rs  s      r5   r   ztruncpareto_gen._entropy)  sW    1qAv:'aC"&&)QTAX.1456 7 	7r7   c                     ||k(  j                         r$|t        j                  |      z  dd||z  z  z
  z  S |||z
  z  ||z  ||z  z
  z  ||z  dz
  z  S r]   )r   rO   r   )rD   ra   r   r  s       r5   r  ztruncpareto_gen._munp)  s^    F<<>RVVAY;!a1f*--!91q!t,1q99r7   c                     t        |t              r|j                         }t        j	                  |      \  }}}t        |      |z
  |z  }||||fS rM   )r>   r)   r  r	  rB   r  )rD   rE   r   r-   r.   r  s         r5   r  ztruncpareto_gen._fitstart)  sM    dL)>>#D

4(3Y_e#!S%r7   c                     !"#$% |j                  dd      rt        &   g|i |S d #d ""#fd%fd $%fd}$fd!d !"fd		}d
 }& fd}t         ||      }|\  }	}
}}j	                         j                         c$%t        j                  $t        j                         }|	|
||t        d      |
|||	 !"fd}t        j                  $t        j                         }|}d}|dz
  }|t        j                   kD  r[ ||       ||      z  dk\  rG|dz  }|t        j                  d|      z
  }|t        j                   kD  r ||       ||      z  dk\  rG|t        j                   kD  s |g|i |S t        |||f      }|j                  s |g|i |S |j                  dz
  }|dz
  }d}|t        j                   kD  r[ ||       ||      z  dk\  rG|dz  }|t        j                  d|      z
  }|t        j                   kD  r ||       ||      z  dk\  rG|t        j                   kD  s |g|i |S t        |||f      }|j                  s |g|i |S |j                  } !|      }  ||      } |||      }|z
  |z  }t	        d #|      z  d "|      dz
  z        }||k  s |g|i |S |}|dz
  }d}|t        j                   kD  rN |||	       |||	      z  dk\  r8|dz  }|d|z  z
  }|t        j                   kD  r |||	       |||	      z  dk\  r8|t        j                   kD  s |g|i |S t        ||	f||f      }|j                  s |g|i |S |j                  } !|      }  ||      }|	}n||n ||
|      }|xs  !|      }|
xs	   ||      }|$j	                         |z
  dk  rt        dd|      |
r2|0|r.j                         |
|z  |z   kD  rt        dd  ||            |	|z
  |z  } #|      }t        j                  |      }d|z  |k  s |g|i |S d|z  d||z
  z  z   }t        j                  d|z  d      }	 t        |||f||f      }|j                  s |g|i |S |j                  }n|	}||z   $k  sF|r&t        j                  |t        j                         }n !|      }t        j                  |d      }||z  |z   %kD  s-  ||      }t        j                  |t        j                        }t        j                    j#                  ||            r|dkD  s |g|i |S ||||f}|9|7 |g|i |} j%                  |      } j%                  |      }||k  r|S |S # t        $ r |}Y w xY w)Nr9  Fc                 R    t        j                  t        j                  |             S rM   )rO   r   r   r   s    r5   log_meanz%truncpareto_gen.fit.<locals>.log_mean%)  s    77266!9%%r7   c                 8    dt        j                  d| z        z  S r]   )rO   r   r   s    r5   	harm_meanz&truncpareto_gen.fit.<locals>.harm_mean()  s    RWWQqS\>!r7   c                     |z
  |z  } |      } 	|      }|dz
  |z  }d|dz
  |dd| z  z
  |z  t        j                  |       z  z
  z  z
  |z  S r]   r1  )
r  r-   r.   r  harm_mlog_mquotrE   r  r  s
          r5   get_bz"truncpareto_gen.fit.<locals>.get_b+)  si    c5 Aq\FQKE1He#DaDA!GV+;BFF1I+E$EFFMMr7   c                     | z
  |z  S rM   r   )r-   r.   mxs     r5   get_cz"truncpareto_gen.fit.<locals>.get_c2)  s    He##r7   c                 <    |r|z
  }|S | r| z  z
  | dz
  z  }|S y r]   r   )rG  r   r-   r  r  s      r5   get_locz$truncpareto_gen.fit.<locals>.get_loc5)  s7    6k
"urzBF+
 r7   c                     | z
  S rM   r   )r-   r  s    r5   r	  z&truncpareto_gen.fit.<locals>.get_scale=)  s    8Or7   c                      	|       } | |      }|
 || |      n|} 
| z
  |z        }dd|dz
  ||dz   z  |z
  z  z   dd|dz   z  z
  z  |z  z
  S r]   r   )r-   r  r.   r  r   r  rE   r  r  r	  r  s         r5   rR  z$truncpareto_gen.fit.<locals>.dL_dLocC)  s|     cNEc5!A(*
ae$As
E12FQUQ1X\22q1ac7{CfLLLr7   c                 P    | t        j                  | |z  d| |z  z
  z        |z  z
  S r]   r8  )r   logclogms      r5   dL_dBz"truncpareto_gen.fit.<locals>.dL_dBL)  s.     rxx$!af* 56===r7   c                 2    t        t        
  | g|i |S rM   )r@   rp  rB   )rE   rF   kwargsr  rD   s      r5   fallbackz%truncpareto_gen.fit.<locals>.fallbackR)  s    $3DJ4J6JJr7   z2All parameters fixed.There is nothing to optimize.c                      |       } | |      } | z
  |z        }dd|dz
  z  z   t        j                  |      z  |z  dz
  S r]   r1  )r-   r.   r  r  rE   r  r	  r  s       r5   cond_bz#truncpareto_gen.fit.<locals>.cond_bc)  sT    %cNEc5)A&s
E'9:F1Q3K266!94v=AAr7   r   r   r   r   gMbP?rT   truncparetor  rM   )r2   r@   rB   rE  r  r  rO   rX  rh   r   r  r*   rY  rF  rJ  r   r   rb   rT  )'rD   rE   rF   r4   r  rR  r  r  rZ  r  rG  r   r   mn_infr  rR   r  rQ   r  r-   r.   r  r   std_data
up_bound_br  r  params_overrideparams_supernllf_override
nllf_superr  r  r	  r  r  r  r  r  s'   ``                             @@@@@@@r5   rB   ztruncpareto_gen.fit)  s    88J&7;t3d3d33	&	"	N	$			M 	M	>	K 1tT4H
%/"b"dFTXXZBb266'*NN$& = > >ZDLV^zB b266'2!"&&("6N6&>9Q>FA#bhhr1o5F "&&("6N6&>9Q> '#D848488!&662BC}}#D848488 D!"&&(#FOGFO;q@FA#bhhr1o5F "&&(#FOGFO;q@ '#D848488!'FF3CD}}#D848488hh!##u%!S%( 3J- 8H#5!5!"Ih$7$9!:<
J#D848488  !'#FB/%fb12567FA#ad]F	 '#FB/%fb12567 '#D848488!'B5+16*:<}}#D848488hh!##u% *$F0CC,inE'eC'A DHHJ$5$9"=CC t'V88:6	D 00&}A-23->@ @ z 3J-)vvay$#D8484884!TD[/1afa0%edD\/5v.>@C =='<t<t<<A  c	Rll30!#UA.%r!c5!AQ'At~~a+,%!)D040400QU*<FN
 $D84848L IIot<M<6JM)##E " As   -)W% W% %W43W4)r   r   r   r   rj   rb   r   rq   r   rt   r   r}   rx   r   r   r   r  r  rJ   r   r   rB   r  r  s   @r5   rp  rp  (  ss    'R
#,M*4-/:27:  M*Z + Zr7   rp  r  )r   r  c                   X    e Zd ZdZej
                  Zd Zd Zd Z	d Z
d Zd Zd Zd	 Zy
)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                 ,    t        j                  |      S rM   r  rD   lams     r5   rb   ztukeylambda_gen._argcheck*  s    {{3r7   c                 ^    t        ddt        j                   t        j                  fd      gS )Nr  Fr	  rg   ri   s    r5   rj   ztukeylambda_gen._shape_info*  s%    5%266'266):NKLLr7   c                 b    t        j                  |dkD  |d t        j                        }| |fS )Nr   c                     d| z  S r]   r   )r  s    r5   r  z.tukeylambda_gen._get_support.<locals>.<lambda>#*  s
    # r7   r  r   )rD   r  r   s      r5   r   ztukeylambda_gen._get_support!*  s/    OOC!GS-')vv/ r1ur7   c           	         t        j                  t        j                  ||            }||dz
  z  t        j                  d|z
        |dz
  z  z   }t        j                  d      5  dt        j                  |      z  }t        j
                  |dk  t        |      dt        j                  |      z  k  z  |d      cd d d        S # 1 sw Y   y xY w)Nr   r   r8  r9  r   r   )rO   r   rv   tklmbdar;  rN  r  )rD   rp   r  FxrY  s        r5   rq   ztukeylambda_gen._pdf'*  s    ZZ

1c*+#c']bjj2.#c'::[[) 	RRZZ^#B88SAX#a&3rzz#3F*FGSQ	R 	R 	Rs   'ACCc                 .    t        j                  ||      S rM   )rv   r  )rD   rp   r  s      r5   rt   ztukeylambda_gen._cdf.*  s    zz!S!!r7   c                 ^    t        j                  ||      t        j                  | |      z
  S rM   )rv   r  r  )rD   r|   r  s      r5   r}   ztukeylambda_gen._ppf1*  s%    yyC 2;;r3#777r7   c                 2    dt        |      dt        |      fS r-  )_tlvar_tlkurtr  s     r5   r   ztukeylambda_gen._stats4*  s    &+q'#,..r7   c                 B    fd}t        j                  |dd      d   S )Nc                 n    t        j                  t        | dz
        t        d| z
  dz
        z         S r]   )rO   r   r  )r  r  s    r5   integz'tukeylambda_gen._entropy.<locals>.integ8*  s/    66#aQ-AaCQ788r7   r   r   )r   r  )rD   r  r  s    ` r5   r   ztukeylambda_gen._entropy7*  s     	9~~eQ*1--r7   N)r   r   r   r   r   r  r  rb   rj   r   rq   rt   r}   r   r   r   r7   r5   r  r  *  s>    , "44M MR"8/.r7   r  tukeylambdac                       e Zd Zd Zy)FitUniformFixedScaleDataErrorc                      d| d| d| _         y )NzInvalid values in `data`.  Maximum likelihood estimation with the uniform distribution and fixed scale requires that np.ptp(data) <= fscale, but np.ptp(data) = z and fscale = r1   rL  )rD   r	  r   s      r5   rO  z&FitUniformFixedScaleDataError.__init__A*  s$    ::= ?xq" 		r7   N)r   r   r   rO  r   r7   r5   r  r  @*  s    
r7   r  c                   L    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
ed
        Zy)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                     g S rM   r   ri   s    r5   rj   zuniform_gen._shape_infoV*  r   r7   Nc                 (    |j                  dd|      S r
  )r  r   s      r5   r   zuniform_gen._rvsY*  s    ##Cd33r7   c                     d||k(  z  S r  r   r   s     r5   rq   zuniform_gen._pdf\*  s    AF|r7   c                     |S rM   r   r   s     r5   rt   zuniform_gen._cdf_*      r7   c                     |S rM   r   r   s     r5   r}   zuniform_gen._ppfb*  r  r7   c                      y)N)r   gUUUUUU?r   g333333r   ri   s    r5   r   zuniform_gen._statse*  s    #r7   c                      yrM  r   ri   s    r5   r   zuniform_gen._entropyh*  r  r7   c                    t        |      dkD  rt        d      |j                  dd      }|j                  dd      }t        |       ||t	        d      t        j                  |      }t        j                  |      j                         st	        d      |a|&|j                         }t        j                  |      }n{|}|j                         |z
  }|j                         |k  rSt        d|||z   	      t        j                  |      }||kD  rt        ||
      |j                         d||z
  z  z
  }|}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   r   )r  r3   r2   r6   r   rO   r   r   r   r  r	  r  rJ  r  rN  )	rD   rE   rF   r4   r   r   r-   r.   r	  s	            r5   rB   zuniform_gen.fitk*  sF   V t9q=122xx%(D)$T* 2 ) * * zz${{4 $$&CDD> >|hhjt 
S(88:#&y3;OO &&,CV|3FKK ((*sFSL11CE Sz5<''r7   r  )r   r   r   r   rj   r   rq   rt   r}   r   r   rJ   rB   r   r7   r5   r  r  J*  s@    
4$ R( R(r7   r  r  c                        e Zd ZdZd Zd ZddZ ee       fd       Z	d Z
d Zd Zd	 Zd
 Z eed      	 	 d fd	       Ze eed       fd              Z xZS )vonmises_genaU  A Von Mises continuous random variable.

    %(before_notes)s

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

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

    .. math::

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

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

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

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

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

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

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

    Define distribution parameters.

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

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

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

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

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

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

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

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

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

    The left image contains the Cartesian plot.

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

    The right image contains the polar plot.

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

    c                 @    t        dddt        j                  fd      gS )Nr  Fr   rf   rg   ri   s    r5   rj   zvonmises_gen._shape_infod+  s    7EArvv;FGGr7   c                     |dk\  S r-  r   r  s     r5   rb   zvonmises_gen._argcheckg+  s    zr7   c                 *    |j                  d||      S )Nr   r  )vonmises)rD   r  r   r   s       r5   r   zvonmises_gen._rvsj+  s    $$S%d$;;r7   c                     t        |   |i |}t        j                  |t        j                  z   dt        j                  z        t        j                  z
  S r  r@   r  rO   modr   rD   rF   r4   r  r  s       r5   r  zvonmises_gen.rvsm+  s@    gk4(4(vvcBEEk1RUU7+bee33r7   c                     t        j                  |t        j                  |      z        dt         j                  z  t        j
                  |      z  z  S r  )rO   r   rv   cosm1r   r_
  r  s      r5   rq   zvonmises_gen._pdfr+  s:    
 vveBHHQK'(AbeeGBFF5M,ABBr7   c                     |t        j                  |      z  t        j                  dt        j                  z        z
  t        j                  t        j
                  |            z
  S r  )rv   r  rO   r   r   r_
  r  s      r5   r   zvonmises_gen._logpdfy+  s@    rxx{"RVVAbeeG_4rvvbffUm7LLLr7   c                 .    t        j                  ||      S rM   )r   von_mises_cdfr  s      r5   rt   zvonmises_gen._cdf}+  s    ##E1--r7   c                      yrh  r   r  s     r5   _stats_skipzvonmises_gen._stats_skip+  ri  r7   c                     | t        j                  |      z  t        j                  |      z  t        j                  dt        j
                  z  t        j                  |      z        z   |z   S r  )rv   i1er_
  rO   r   r   r  s     r5   r   zvonmises_gen._entropy+  sV     &6q255y266%=01249: 	;r7   z        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   c           	          t         j                   t         j                  }
}	|||	z   }|||
z   }t        |   |||||||fi |S rM   )rO   r   r@   expect)rD   r]  rF   r-   r.   lbubconditionalr4   r  r  r  s              r5   r  zvonmises_gen.expect+  s_     %%B:rB:rBw~dD##R[B<@B 	Br7   a          Fit data is assumed to represent angles and will be wrapped onto the
        unit circle. `f0` and `fscale` are ignored; the returned shape is
        always the maximum likelihood estimate and the scale is always
        1. Initial guesses are ignored.

c                    |j                  dd      rt        |   |g|i |S t        | |||      \  }}}}| j                  t
        j                   k(  rt        |   |g|i |S t        j                  |dt
        j                  z        }d }d }||n ||      }	||n |||	      }
t        j                  |	t
        j                  z   dt
        j                  z        t
        j                  z
  }	|
|	dfS )Nr9  FrT   c                 ,    t        j                  |       S rM   )r  circmean)rE   s    r5   find_muz!vonmises_gen.fit.<locals>.find_mu+  s    >>$''r7   c                 j   t        j                  t        j                  || z
              t        |       z  dk(  rydkD  rNfd}dz
  z  dz   z  }d|z  } ||      dk\  r|S  ||      dk  r|S t	        |d||f      }|j
                  S t        j                  t              j                  S )Nr   g 7yACr   c                 `    t        j                  |       t        j                  |       z  z
  S rM   )rv   r  r_
  )r  r  s    r5   solve_for_kappaz=vonmises_gen.fit.<locals>.find_kappa.<locals>.solve_for_kappa+  s#    66%=6::r7   rT   r;  )r0   rC  )	rO   r  r   r  r*   rF  r"  rN  r#  )rE   r-   r  lower_boundupper_boundroot_resr  s         @r5   
find_kappaz$vonmises_gen.fit.<locals>.find_kappa+  s     rvvcDj)*3t94A Av Q;  1gqsmm #;/14&&$[1Q6&&*?84?3M OH#==( xx+++r7   r   )r2   r@   rB   rE  r   rO   r   r  )rD   rE   rF   r4   rM  r   r   r  r  r-   r  r  s              r5   rB   zvonmises_gen.fit+  s     88J&7;t3d3d33%@tAEt&M"fdF66beeV7;t3d3d33 vvdAI&	(6	,r &dGDM ,*T32GffS255[!bee),ruu4c1}r7   r  )Nr   r   r   NNF)r   r   r   r   rj   rb   r   r   r   r  rq   r   rt   r  r   r	   r  rJ   rB   r  r  s   @r5   r  r  +  s    ^~H< M*4 +4CM. 
; } 5  FJ 
B	
B } 5/ 0
N0 Nr7   r  r  vonmises_linec                   r    e Zd ZdZej
                  Zd ZddZd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zy)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                     g S rM   r   ri   s    r5   rj   zwald_gen._shape_info,  r   r7   Nc                 *    |j                  dd|      S r  r  r   s      r5   r   zwald_gen._rvs,  s      c 55r7   c                 .    t         j                  |d      S r  )r  rq   r   s     r5   rq   zwald_gen._pdf,  s    }}Q$$r7   c                 .    t         j                  |d      S r  )r  rt   r   s     r5   rt   zwald_gen._cdf,      }}Q$$r7   c                 .    t         j                  |d      S r  )r  rx   r   s     r5   rx   zwald_gen._sf,  s    ||As##r7   c                 .    t         j                  |d      S r  )r  r}   r   s     r5   r}   zwald_gen._ppf!,  r  r7   c                 .    t         j                  |d      S r  )r  r   r   s     r5   r   zwald_gen._isf$,  r  r7   c                 .    t         j                  |d      S r  )r  r   r   s     r5   r   zwald_gen._logpdf',      3''r7   c                 .    t         j                  |d      S r  )r  r   r   s     r5   r   zwald_gen._logcdf*,  r  r7   c                 .    t         j                  |d      S r  )r  r   r   s     r5   r   zwald_gen._logsf-,  s    q#&&r7   c                      y)N)r   r   rC  r  r   ri   s    r5   r   zwald_gen._stats0,  s    "r7   c                 ,    t         j                  d      S r  )r  r   ri   s    r5   r   zwald_gen._entropy3,  s      %%r7   r  )r   r   r   r   r   r  r  rj   r   rq   rt   rx   r}   r   r   r   r   r   r   r   r7   r5   r  r  +  sP    ( "44M6%%$%%(('#&r7   r  r  c                   b     e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
 ee       fd	       Z xZ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                     |dkD  |dk  z  S r  r   r|  s     r5   rb   zwrapcauchy_gen._argcheckP,  rC
  r7   c                      t        dddd      gS )Nr  F)r   r   r	  r
  ri   s    r5   rj   zwrapcauchy_gen._shape_infoS,  s    3v~>??r7   c                     d||z  z
  dt         j                  z  d||z  z   d|z  t        j                  |      z  z
  z  z  S r  r  r	  s      r5   rq   zwrapcauchy_gen._pdfV,  s?    AaC!BEE'1QqS51RVVAY#6788r7   c                 z    d }d }d|z   d|z
  z  }t        j                  |t        j                  k  ||f||      S )Nc                     dt         j                  z  t        j                  |t        j                  | dz        z        z  S r0  rO   r   r  r  rp   crs     r5   r  zwrapcauchy_gen._cdf.<locals>.f1\,  s.    RUU7RYYr"&&1+~666r7   c           	          ddt         j                  z  t        j                  |t        j                  dt         j                  z  | z
  dz        z        z  z
  S r0  r  r  s     r5   r  zwrapcauchy_gen._cdf.<locals>.f2`,  sA    qw2bffagk1_.E+E!FFFFr7   r   )r  r  rO   r   )rD   rp   r  r  r  r  s         r5   rt   zwrapcauchy_gen._cdfZ,  sA    	7	G !ea!e_q255y1b'2r::r7   c           
      v   d|z
  d|z   z  }dt        j                  |t        j                  t         j                  |z        z        z  }dt         j                  z  dt        j                  |t        j                  t         j                  d|z
  z        z        z  z
  }t        j                  |dk  ||      S )Nr   rT   r   r   )rO   r  r  r   rN  )rD   r|   r  rv  rcqrcmqs         r5   r}   zwrapcauchy_gen._ppfg,  s    1us1uo		#bffRUU1Wo-..wq3rvvbeeQqSk':#:;;;xxE	3--r7   c                 `    t        j                  dt         j                  z  d||z  z
  z        S r  r   r|  s     r5   r   zwrapcauchy_gen._entropym,  s%    vvagq1uo&&r7   c                     t        |t              r|j                         }dt        j                  |      t        j
                  |      dt        j                  z  z  fS r  )r>   r)   r  rO   r  r	  r   )rD   rE   s     r5   r  zwrapcauchy_gen._fitstartp,  sD     dL)>>#DBFF4L"&&,"%%"888r7   c                 p    t        |   |i |}t        j                  |dt        j                  z        S r  r  r  s       r5   r  zwrapcauchy_gen.rvsx,  s/    gk4(4(vvc1RUU7##r7   )r   r   r   r   rb   rj   rq   rt   r}   r   r  r   r   r  r  r  s   @r5   r  r  :,  sE    *!@9;.'9 M*$ +$r7   r  
wrapcauchyc                   T    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZddZy)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                 @    t        dddt        j                  fd      gS Nrm  Fr   r	  rg   ri   s    r5   rj   zgennorm_gen._shape_info,      651bff+~FGGr7   c                 L    t        j                  | j                  ||            S rM   r  rD   rp   rm  s      r5   rq   zgennorm_gen._pdf,  s    vvdll1d+,,r7   c                     t        j                  d|z        t        j                  d|z        z
  t	        |      |z  z
  S r   )rO   r   rv   r  r  r  s      r5   r   zgennorm_gen._logpdf,  s4    vvc$h"**SX"66QEEr7   c                     dt        j                  |      z  }d|z   |t        j                  d|z  t	        |      |z        z  z
  S r   )rO   rP   rv   r  r  rD   rp   rm  r  s       r5   rt   zgennorm_gen._cdf,  s?    "''!*a1r||CHc!fdlCCCCr7   c                     t        j                  |dz
        }|t        j                  d|z  d|z   d|z  |z  z
        d|z  z  z  S )Nr   r   r   )rO   rP   rv   r  r  s       r5   r}   zgennorm_gen._ppf,  sH    GGAG2??3t8cAgQq-@ACHMMMr7   c                 (    | j                  | |      S rM   r  r  s      r5   rx   zgennorm_gen._sf,  s    yy!T""r7   c                 (    | j                  ||       S rM   r  r  s      r5   r   zgennorm_gen._isf,  s    		!T"""r7   c                     |dk(  ry|dz  dk(  r;t        j                  d|z  |dz   |z  g      \  }}t        j                  ||z
        S y)Nr   r   rT   r   rv   r  rO   r   )rD   ra   rm  c1cns        r5   r  zgennorm_gen._munp,  sO    6q5A:ZZTAGT> :;FB66"r'?"r7   c                     t        j                  d|z  d|z  d|z  g      \  }}}dt        j                  ||z
        dt        j                  ||z   d|z  z
        dz
  fS )Nr   rC  r  r   r   r  )rD   rm  r  c3c5s        r5   r   zgennorm_gen._stats,  s_    ZZT3t8SX >?
B266"r'?BrBwR/?(@2(EEEr7   c                 p    d|z  t        j                  d|z        z
  t        j                  d|z        z   S r  r{  rD   rm  s     r5   r   zgennorm_gen._entropy,  s0    Dy266"t),,rzz"t)/DDDr7   Nc                     |j                  d|z  |      }|d|z  z  }t        j                  |      }|j                  |j                        dk  }||    ||<   |S )Nr   r  r   )r  rO   r   randomr  )rD   rm  r   r   r%  r  r	  s          r5   r   zgennorm_gen._rvs,  sg     qvD1!D&MJJqM"""036T7($r7   r  )r   r   r   r   rj   rq   r   rt   r}   rx   r   r  r   r   r   r   r7   r5   r  r  ,  sE    )TH-FD
N
##FE	r7   r  gennormc                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)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                 @    t        dddt        j                  fd      gS r  rg   ri   s    r5   rj   zhalfgennorm_gen._shape_info-  r  r7   c                 L    t        j                  | j                  ||            S rM   r  r  s      r5   rq   zhalfgennorm_gen._pdf
-  s     vvdll1d+,,r7   c                 j    t        j                  |      t        j                  d|z        z
  ||z  z
  S r  r{  r  s      r5   r   zhalfgennorm_gen._logpdf-  s+    vvd|bjjT22QW<<r7   c                 :    t        j                  d|z  ||z        S r  r  r  s      r5   rt   zhalfgennorm_gen._cdf-  s    {{3t8QW--r7   c                 @    t        j                  d|z  |      d|z  z  S r  r  r  s      r5   r}   zhalfgennorm_gen._ppf-  s     ~~c$h*SX66r7   c                 :    t        j                  d|z  ||z        S r  r  r  s      r5   rx   zhalfgennorm_gen._sf-  s    ||CHag..r7   c                 @    t        j                  d|z  |      d|z  z  S r  r+  r  s      r5   r   zhalfgennorm_gen._isf-  s     s4x+c$h77r7   c                 j    d|z  t        j                  |      z
  t        j                  d|z        z   S r  r{  r!  s     r5   r   zhalfgennorm_gen._entropy-  s+    4x"&&,&CH)===r7   Nr  r   r7   r5   r&  r&  ,  s1    "FH-=.7/8>r7   r&  halfgennormc                   R     e Zd ZdZd Zd Z fdZd Zd Zd Z	d Z
d	 Zd
 Z xZS )crystalball_gena  
    Crystalball distribution

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

    .. versionadded:: 0.19.0

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

    %(example)s
    c                     |dkD  |dkD  z  S )z@
        Shape parameter bounds are m > 1 and beta > 0.
        r   r   r   )rD   rm  r:  s      r5   rb   zcrystalball_gen._argcheckJ-  s     A$(##r7   c                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS )Nrm  Fr   r	  r:  r   rg   )rD   ibetaims      r5   rj   zcrystalball_gen._shape_infoP-  s<    651bff+~FUQK@r{r7   c                 &    t         |   |d      S )N)r   r  rL  rQ  rR  s     r5   r  zcrystalball_gen._fitstartU-  s    w H 55r7   c                     d||z  |dz
  z  t        j                  |dz   dz        z  t        t        |      z  z   z  }d }d }|t	        j
                  || kD  |||f||      z  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
                                            --
        r   r   rT   r   c                 :    t        j                  | dz   dz        S r  rq  rp   rm  r:  s      r5   rhsz!crystalball_gen._pdf.<locals>.rhsf-  s    661a4%!)$$r7   c                 l    ||z  |z  t        j                  |dz   dz        z  ||z  |z
  | z
  | z  z  S r   rq  r9  s      r5   lhsz!crystalball_gen._pdf.<locals>.lhsi-  sF    tVaK"&&$'C"88tVd]Q&1"-. /r7   rO   r   r   r   r  r  rD   rp   rm  r:  r  r:  r<  s          r5   rq   zcrystalball_gen._pdfY-  sw     1T6QqS>BFFD!G8c>$::401 2	%	/ 3??1u9q$lCEEEr7   c                     d||z  |dz
  z  t        j                  |dz   dz        z  t        t        |      z  z   z  }d }d }t        j                  |      t        j                  || kD  |||f||      z   S )zH
        Return the log of the PDF of the crystalball function.
        r   r   rT   r   c                     | dz   dz  S r  r   r9  s      r5   r:  z$crystalball_gen._logpdf.<locals>.rhsv-  s    qD57Nr7   c                     |t        j                  ||z        z  |dz  dz  z
  |t        j                  ||z  |z
  | z
        z  z
  S r  r1  r9  s      r5   r<  z$crystalball_gen._logpdf.<locals>.lhsy-  sF    RVVAdF^#dAgai/!BFF1T6D=1;L4M2MMMr7   )rO   r   r   r   r   r  r  r>  s          r5   r   zcrystalball_gen._logpdfo-  s     1T6QqS>BFFD!G8c>$::401 2		N vvay3??1u9q$lCMMMr7   c                     d||z  |dz
  z  t        j                  |dz   dz        z  t        t        |      z  z   z  }d }d }|t	        j
                  || kD  |||f||      z  S )z8
        Return CDF of the crystalball function
        r   r   rT   r   c                     ||z  t        j                  |dz   dz        z  |dz
  z  t        t        |       t        |       z
  z  z   S NrT   r   r   rO   r   r   r   r9  s      r5   r:  z!crystalball_gen._cdf.<locals>.rhs-  sN    tVrvvtQwhn551=9Q<)TE2B#BCD Er7   c                 ~    ||z  |z  t        j                  |dz   dz        z  ||z  |z
  | z
  | dz   z  z  |dz
  z  S rD  rq  r9  s      r5   r<  z!crystalball_gen._cdf.<locals>.lhs-  sV    tVaK"&&$'C"88tVd]Q&1"Q$/034Q38 9r7   r=  r>  s          r5   rt   zcrystalball_gen._cdf~-  sx     1T6QqS>BFFD!G8c>$::401 2	E	9 3??1u9q$lCEEEr7   c                 R     d } fd}t        j                  || kD  |||f||      S )zD
        Survival function of the crystalball distribution.
        c                     ||z  |dz
  z  t        j                  |dz   dz        z  t        t        |      z  z   }t        t	        |       z  |z  S r0  )rO   r   r   r   r   )rp   rm  r:  Ms       r5   r:  z crystalball_gen._sf.<locals>.rhs-  sM    $ArvvtQwhqj11K	$4OOAx{*1,,r7   c                 0    dj                  | ||      z
  S r]   r  )rp   rm  r:  rD   s      r5   r<  z crystalball_gen._sf.<locals>.lhs-  s    tyyD!,,,r7   r  )rD   rp   rm  r:  r:  r<  s   `     r5   rx   zcrystalball_gen._sf-  s0    
	-
	- qD5y1dA,SAAr7   c                    d||z  |dz
  z  t        j                  |dz   dz        z  t        t        |      z  z   z  }|||z  z  t        j                  |dz   dz        z  |dz
  z  }d }d }t	        j
                  ||k  |||f||      S )Nr   r   rT   r   c                     t        j                  |dz   dz        }||z  |z  |dz
  z  }d|t        t        |      z  z   z  }||z  |z
  |dz
  ||z  | z  z  |z  | z  |z  dd|z
  z  z  z
  S r  rE  r  rm  r:  eb2rB  r  s         r5   ppf_lessz&crystalball_gen._ppf.<locals>.ppf_less-  s    &&$'!$C43!A#&A1{Yt_445AdFTM!eaf^+C/1!3q!A#w?@ Ar7   c                     t        j                  |dz   dz        }||z  |z  |dz
  z  }d|t        t        |      z  z   z  }t	        t        |       dt        z  | |z  |z
  z  z         S r  )rO   r   r   r   r   rM  s         r5   ppf_greaterz)crystalball_gen._ppf.<locals>.ppf_greater-  sp    &&$'!$C43!A#&A1{Yt_445AYu-;1q0IIJJr7   r=  )rD   r  rm  r:  r  pbetarO  rQ  s           r5   r}   zcrystalball_gen._ppf-  s    1T6QqS>BFFD!G8c>$::401 2QtVrvvtQwhqj11QU;	A	K q5y1dA,+NNr7   c           	      2   d||z  |dz
  z  t        j                  |dz   dz        z  t        t        |      z  z   z  }d }|t	        j
                  |dz   |k  |||ft        j                  |t         j                  g      t         j                        z  S )zR
        Returns the n-th non-central moment of the crystalball function.
        r   r   rT   r   c                 
   ||z  |z  t        j                  |dz   dz        z  }||z  |z
  }d| dz
  dz  z  t        j                  | dz   dz        z  dd| z  t        j                  | dz   dz  |dz  dz        z  z   z  }t        j
                  |j                        }t        t        |       dz         D ]C  }|t        j                  | |      || |z
  z  z  d|z  z  ||z
  dz
  z  ||z  | |z   dz   z  z  z  }E ||z  |z   S )z
            Returns n-th moment. Defined only if n+1 < m
            Function cannot broadcast due to the loop over n
            rT   r   r   r   r  )
rO   r   rv   r  r  r  r  r  r  binom)ra   rm  r:  rl  rm  r:  r<  r  s           r5   r`  z*crystalball_gen._munp.<locals>.n_th_moment-  s!   
 4!bffdAgX^44A$A!Sy>BHHac1W$552'BKK1aq1$EEEGC((399%C3q6A:& 0AQqS1R!G;q1uqyI4A26A:./ 00 s7S= r7   r  r  )	rO   r   r   r   r  r  r  r  rh   )rD   ra   rm  r:  r  r`  s         r5   r  zcrystalball_gen._munp-  s     1T6QqS>BFFD!G8c>$::401 2	! 3??1q519q$l#%<<RZZL#Q.0ff6 6 	6r7   )r   r   r   r   rb   rj   r  rq   r   rt   rx   r}   r  r  r  s   @r5   r1  r1  &-  s;    "F$
6F,NF"B O(6r7   r1  crystalballzA Crystalball Function)r   longnamec                 @    t        j                  d| dz  dz        dz  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  rT   r  )r  s    r5   
_argus_phirY  -  s"     ;;sCF1H%))r7   c                   D    e Zd ZdZd Zd Zd Zd Zd ZddZ	dd	Z
d
 Zy)	argus_gena  
    Argus distribution

    %(before_notes)s

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

    .. math::

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

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

    .. math::

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

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

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

    %(after_notes)s

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

    .. versionadded:: 0.19.0

    %(example)s
    c                 @    t        dddt        j                  fd      gS )Nr  Fr   r	  rg   ri   s    r5   rj   zargus_gen._shape_info.      5%!RVVnEFFr7   c                 h   t        j                  d      5  d||z  z
  }dt        j                  |      z  t        z
  t        j                  t	        |            z
  }|t        j                  |      z   dt        j
                  | |z        z  z   |dz  |z  dz  z
  cd d d        S # 1 sw Y   y xY w)Nr8  r9  r   r  r   rT   )rO   r;  r   r   rY  r  )rD   rp   r  r  rl  s        r5   r   zargus_gen._logpdf.  s    [[) 	Gac	A"&&+.
31HHArvvay=3rxx1~#55Q
QF	G 	G 	Gs   BB((B1c                 L    t        j                  | j                  ||            S rM   r  rD   rp   r  s      r5   rq   zargus_gen._pdf.  s    vvdll1c*++r7   c                 ,    d| j                  ||      z
  S r  r   r`  s      r5   rt   zargus_gen._cdf.  s    TXXa%%%r7   c                 n    t        |t        j                  d|z
  d|z   z        z        t        |      z  S r]   )rY  rO   r   r`  s      r5   rx   zargus_gen._sf.  s0    #QQ 889JsOKKr7   Nc                 Z  	
 t        j                  |      }|j                  dk(  r| j                  |||      }nt	        |j
                  |      \  }	t        t        j                  |            }t        j                  |      }t        j                  |gdgdgg      

j                  sqt        	
fdt        t        |       d      D              }| j                  
d   ||      }|j                  |      ||<   
j                          
j                  sq|dk(  r|d   }|S )	Nr   )r  r   r  r  r  c              3   \   K   | ]#  }|   sj                   |   n
t        d        % y wrM   r  r  s     r5   r  z!argus_gen._rvs.<locals>.<genexpr>(.  r  r  r   r   )rO   r   r   r  r   r  r  r  r  r  r  r  r  r  rM  r  )rD   r  r   r   r  r  r  r  r  r  r  s            @@r5   r   zargus_gen._rvs.  s   jjo88q=""340< # >C #399d3GCRWWS\*J((4.CC5"/&0\N4B kk ;%*CI:q%9; ;$$RUz2> % @99S>C kk 2:b'C
r7   c                    t        t        j                  |            }t        t        j                  |            }t        j
                  |      }d}||z  }|dk  r| dz  }	||k  r||z
  }
|j                  |
      }|j                  |
      }|dz  }t        j                  |      |	|z  k  }t        j                  |      }|dkD  r(t        j                  d||   z
        }|||||z    ||z  }||k  rn8|dk  rt        j                  | dz        }||k  r||z
  }
|j                  |
      }|j                  |
      }dt        j                  |d|z
  z  |z         z  |z  }|dz  |z   dk  }t        j                  |      }|dkD  r(t        j                  d||   z         }|||||z    ||z  }||k  rns||k  rP||z
  }
|j                  d|
      }||dz  k  }t        j                  |      }|dkD  r||   ||||z    ||z  }||k  rPt        j                  dd|z  |z  z
        }t        j                  ||      S )	Nr   r   rT   r  r  r   g?r  )r  rO   r  r  r  r  r  r   r  r   r   r$  rM  )rD   r  r  r   r  r  rp   r  r  r  r  r  r  r%  r  r  r  echir  s                      r5   r  zargus_gen._rvs_scalar3.  sq   h r}}Z01 HHQK	Sy#:	Aa-	M ((a(0 ((a(0H&&)q1u,VVF^
>''!ai-0C<?AiZ!79+I a- CZ664%!)$Da-	M ((a(0 ((a(0tq1u~122T9 Q$(a-VVF^
>''!ai-0C<?AiZ!79+I a- a-	M //!/<tax-VVF^
><=fIAiZ!79+I a- AEDL()Azz!V$$r7   c                    t        j                  |t              }t        |      }t        j                  t         j
                  dz        |z  t        j                  d|dz  dz        z  |z  }t        j                  |      }|dkD  }||   }dd|dz  z  z
  |t        |      z  ||   z  z   ||<   ||    }g d}t        j                  ||      || <   |||dz  z
  d d fS )	Nr  r-  r   rT   r#  g?r  )	g_1g־r   gWBar   gp|RH?r   gE'卡?r   g?)rO   r   rN  rY  r   r   rv   r	  rO  r   rG  )rD   r  r  r:  rC  r	  r  coefs           r5   r   zargus_gen._stats.  s     jjE*oGGBEE!Gs"RVVAsAvax%883>mmC SyIAqDL1y|#3c$i#??D	JKZZa(TE
#1*dD((r7   r  )r   r   r   r   rj   r   rq   rt   rx   r   r  r   r   r7   r5   r[  r[  -  s5    'PGG,&L0c%J)r7   r[  arguszAn Argus Function)r   rW  r   r   c                   h     e Zd ZdZej
                  Zdd fd
Zd Zd Zd Z	d Z
d	 Z fd
Z xZS )rv_histograma3  
    Generates a distribution given by a histogram.
    This is useful to generate a template distribution from a binned
    datasample.

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

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

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

        .. versionadded:: 1.10.0

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

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

    .. versionadded:: 0.19.0

    Examples
    --------

    Create a scipy.stats distribution from a numpy histogram

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

    Behaves like an ordinary scipy rv_continuous distribution

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

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

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

    PDF and CDF follow the histogram

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

    N)densityc                t   || _         || _        t        |      dk7  rt        d      t	        j
                  |d         | _        t	        j
                  |d         | _        t        | j                        dz   t        | j                        k7  rt        d      | j                  dd | j                  dd z
  | _        t	        j                  | j                  | j                  d          }|#|r!d}t        j                  |t        d	       d
}n |s| j                  | j                  z  | _        | j                  t        t	        j                  | j                  | j                  z              z  | _        t	        j                  | j                  | j                  z        | _        t	        j"                  d| j                  dg      | _        t	        j"                  d| j                   g      | _        | j                  d   x|d<   | _        | j                  d   x|d<   | _        t)        | T  |i | y)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.
        rT   z)Expected length 2 for parameter histogramr   r   zbNumber of elements in histogram content and histogram boundaries do not match, expected n and n+1.Nr  zjBin widths are not constant. Assuming `density=True`.Specify `density` explicitly to silence this warning.rD  Tr   r   r   )
_histogram_densityr  r   rO   r   _hpdf_hbins_hbin_widthsallcloserG  rH  rI  rN  r  cumsum_hcdfhstackr   r   r@   rO  )rD   	histogramrl  rF   r  	bins_varyrK  r  s          r5   rO  zrv_histogram.__init__
/  s   & $y>QHIIZZ	!-
jj1.tzz?Q#dkk"22 3 4 4 !KKOdkk#2.>>D$5$5t7H7H7KLL	?yOGMM'>a@Gd&7&77DJZZ%tzzD<M<M/M(N"OO
YYtzzD,=,==>
YYTZZ56
YYTZZ01
#{{1~-sdf#{{2.sdf$)&)r7   c                 `    | j                   t        j                  | j                  |d         S )z&
        PDF of the histogram
        r&  )side)rp  rO   searchsortedrq  r   s     r5   rq   zrv_histogram._pdf:/  s$     zz"//$++qwGHHr7   c                 X    t        j                  || j                  | j                        S )z3
        CDF calculated from the histogram
        )rO   interprq  ru  r   s     r5   rt   zrv_histogram._cdf@/  s     yyDKK44r7   c                 X    t        j                  || j                  | j                        S )zC
        Percentile function calculated from the histogram
        )rO   r}  ru  rq  r   s     r5   r}   zrv_histogram._ppfF/  s     yyDJJ44r7   c                     | j                   dd |dz   z  | j                   dd |dz   z  z
  |dz   z  }t        j                  | j                  dd |z        S )z$Compute the n-th non-central moment.r   Nr  )rq  rO   r  rp  )rD   ra   	integralss      r5   r  zrv_histogram._munpL/  s[    [[_qs+dkk#2.>1.EE!A#N	vvdjj2&233r7   c                     | j                   dd }t        j                  |dkD  |t        j                  d      }t        j
                  ||z  | j                  z         S )zCompute entropy of distributionr   r  r   r  )rp  r  r  rO   r   r  rr  )rD   hpdfr  s      r5   r   zrv_histogram._entropyQ/  sO    zz!BoodSj$3GtczD$5$55666r7   c                 `    t         |          }| j                  |d<   | j                  |d<   |S )zF
        Set the histogram as additional constructor argument
        rw  rl  )r@   _updated_ctor_paramrn  ro  )rD   dctr  s     r5   r  z rv_histogram._updated_ctor_paramW/  s2     g)+??KI
r7   )r   r   r   r   r   r  rO  rq   rt   r}   r  r   r  r  r  s   @r5   rk  rk  .  sD    Zv "//M15 .*`I554
7 r7   rk  c                   @     e Zd ZdZd Zd Z fdZd Zd Zd Z	 xZ
S )studentized_range_genuO  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)

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

    >>> k, df = 3, 10
    >>> 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                     |dkD  |dkD  z  S r  r   )rD   r  r  s      r5   rb   zstudentized_range_gen._argcheck/  s    A"q&!!r7   c                     t        dddt        j                  fd      }t        dddt        j                  fd      }||gS )Nr  Fr   r	  r  r   rg   )rD   r  r	  s      r5   rj   z!studentized_range_gen._shape_info/  s<    UQK@uq"&&k>BCyr7   c                 &    t         |   |d      S )N)rT   r   rL  rQ  rR  s     r5   r  zstudentized_range_gen._fitstart/  s    w F 33r7   c                     d| j                         \  fd}t        j                  |dd      }t        j                   ||||      t        j                        d   S )N_studentized_range_momentc                    t        j                  ||      }| |||g}t        j                  |t              j
                  j                  t
        j                        }t        j                  t         |      }t        j                   t        j                  fdt        j                  f	
fg}t        dd      }t        j                  |||      d   S )Nr   r  -q=r  r  rangesopts)r   _studentized_range_pdf_logconstrO   r  rN  r  r  r  r   r  rh   dictr   nquad)r  r  r  	log_constargusr_datar  r  r  r  r  cython_symbols            r5   _single_momentz3studentized_range_gen._munp.<locals>._single_moment/  s    >>q"EIaY'CxxU+22::6??KH"..v}hOCw'!RVVr2h?FuU3D??3vDA!DDr7   r  r   r  r   )r   rO   
frompyfuncr   r  )	rD   r  r  r  r  ufuncr  r  r  s	         @@@r5   r  zstudentized_range_gen._munp/  sV    3""$B
	E na3zz%1b/<R@@r7   c                     d }t        j                  |dd      }t        j                   ||||      t         j                        d   S )Nc                    |dk  rd}t        j                  ||      }| |||g}t        j                  |t              j
                  j                  t
        j                        }t        j                   t        j                  fdt        j                  fg}nid}| |g}t        j                  |t              j
                  j                  t
        j                        }t        j                   t        j                  fg}t        j                  t         ||      }t        dd      }	t        j                  |||	      d   S )	N順 _studentized_range_pdfr   !_studentized_range_pdf_asymptoticr  r  r  r  )r   r  rO   r  rN  r  r  r  rh   r   r  r  r   r  
r|   r  r  r  r  r  r  r  r  r  s
             r5   _single_pdfz/studentized_range_gen._pdf.<locals>._single_pdf/  s     F{ 8"BB1bI	!R+88C/66>>vOFF7BFF+a[9 !D!f88C/66>>vOFF7BFF+,"..v}hOCuU3D??3vDA!DDr7   r  r   r  r   )rO   r  r   r  )rD   rp   r  r  r  r  s         r5   rq   zstudentized_range_gen._pdf/  s>    	E( k1a0zz%1b/<R@@r7   c           	          d }t        j                  |dd      }t        j                  t        j                   ||||      t         j                        d   dd      S )Nc                    |dk  rd}t        j                  ||      }| |||g}t        j                  |t              j
                  j                  t
        j                        }t        j                   t        j                  fdt        j                  fg}nid}| |g}t        j                  |t              j
                  j                  t
        j                        }t        j                   t        j                  fg}t        j                  t         ||      }t        dd      }	t        j                  |||	      d   S )	Nr  _studentized_range_cdfr   !_studentized_range_cdf_asymptoticr  r  r  r  )r   _studentized_range_cdf_logconstrO   r  rN  r  r  r  rh   r   r  r  r   r  r  s
             r5   _single_cdfz/studentized_range_gen._cdf.<locals>._single_cdf0  s    
 F{ 8"BB1bI	!R+88C/66>>vOFF7BFF+a[9 !D!f88C/66>>vOFF7BFF+,"..v}hOCuU3D??3vDA!DDr7   r  r   r  r   r   )rO   r  r	  r   r  )rD   rp   r  r  r  r  s         r5   rt   zstudentized_range_gen._cdf0  sM    	E, k1a0 wwrzz%1b/DRH!QOOr7   )r   r   r   r   rb   rj   r  r  rq   rt   r  r  s   @r5   r  r  a/  s+    hT"
4A*A2Pr7   r  studentized_range)r   r   r   c                   \     e Zd ZdZd Zd Zd Zd Zd Zd Z	 e
e       fd       Z xZS )	rel_breitwigner_gena  A relativistic Breit-Wigner random variable.

    %(before_notes)s

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

    Notes
    -----

    The probability density function for `rel_breitwigner` is

    .. math::

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

    where

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

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

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

    %(after_notes)s

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

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

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

    %(example)s

    c                     |dkD  S r-  r   rD   rhos     r5   rb   zrel_breitwigner_gen._argcheckf0  s    Qwr7   c                 @    t        dddt        j                  fd      gS )Nr  Fr   r	  rg   ri   s    r5   rj   zrel_breitwigner_gen._shape_infoi0  r]  r7   c           
      6   t        j                  ddd|dz  z  z   z  dt        j                  dd|dz  z  z         z   z        dz  t         j                  z  }t        j                  d      5  |||z
  ||z   z  |z  dz  dz   z  cd d d        S # 1 sw Y   y xY w)NrT   r   r8  rp  )rO   r   r   r;  )rD   rp   r  rB  s       r5   rq   zrel_breitwigner_gen._pdfl0  s    GGQsAvX!bgga!CF(l&;";<
 [[h' 	:!c'AG,S014q89	: 	: 	:s   .BBc           
         t        j                  ddt        j                  dd|dz  z  z         z   z        t         j                  z  }t        j                  dd|z  z         t        j                  |t        j                  | |dz   z        z        z  }|dz  t        j                  |      z  }t        j
                  |d d      S )NrT   r   r  r(  )rO   r   r   r  imagr	  )rD   rp   r  rB  r  s        r5   rt   zrel_breitwigner_gen._cdft0  s    GGAq2771qax<00122558GGBCK ii"''3$b/2234 	 Q(wwvtQ''r7   c                 R   |dk(  ry|dk(  rt        j                  ddd|dz  z  z   z  dt        j                  dd|dz  z  z         z   z        t         j                  z  |z  }|t         j                  dz  t        j                  |      z   z  S |dk(  rt        j                  dd|dz  z  z   ddt        j                  dd|dz  z  z         z   z  z        |z  }d|dz  z
  t        j                  dd|z  z
        z  }d|z  t        j                  |      z  S t         j
                  S )Nr   r   r   rT   r(  r  )rO   r   r   r  r  rh   )rD   ra   r  rB  r  s        r5   r  zrel_breitwigner_gen._munp0  s   66Q36\"a"''!aQh,*?&?@A a"))C.0116QsAvX!q2771qax<+@'@"ABA #(lbggb2c6k&::Fq52776?**66Mr7   c                 F    d d t         j                  t         j                  fS rM   r  r  s     r5   r   zrel_breitwigner_gen._stats0  s     T266266))r7   c                    t        | |||      \  }}}}t        |t              }|r!|j                         dk(  r|j                  }d}||rt        |   |g|i |S |8t        j                  ||z
  g d      \  }}	}
|
|z
  }|	|z  }|s|g}d|vr(||d<   n"t        j                  ||z
        }||z  }|s|g}t        |   |g|i |S )Nr   F)r  r   g      ?r.   )
rE  r>   r)   r?   rC   r@   rB   rO   quantiler  )rD   rE   rF   r4   r	  r   r   rG   r  r  r  scale_0rho_0M_0r  s                 r5   rB   zrel_breitwigner_gen.fit0  s    !<$d!
av dL1  "a' '' <87;t3d3d33> KKt5FGMCcCiG'MEwd" 'W))D4K(C&LEww{4/$/$//r7   )r   r   r   r   rb   rj   rq   rt   r  r   r   r   rB   r  r  s   @r5   r  r  (0  sA    <zG:	(&* M* 0 + 0r7   r  rel_breitwignerrM   (L  rG  collections.abcr   	functoolsr   r   r  r  numpyrO   numpy.polynomialr   scipy.interpolater   scipy._lib.doccerr	   r
   r   scipy._lib._ccallbackr   scipyr   r   scipy.specialspecialrv   scipy.special._ufuncsr  rm   scipy._lib._utilr   scipy._lib.array_api_extra_libarray_api_extrar  rT  r   _tukeylambda_statsr   r  r   r  _distn_infrastructurer   r   r   r   r   r   r   r   r   _ksstatsr   r   r    
_constantsr!   r"   r#   r$   r%   r&   r'   r(   _censored_datar)   scipy.optimizer*   scipy.stats._warnings_errorsr+   scipy.statsr  r6   rJ   rY   r[   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r3  r5  rH  r   rJ  rV   r^  rb  rd  rm  r  r  r  r  r  rX  rZ  rl  rn  r  r  r  r  r  r  r  r  r  r	  r  r   rP  rR  rk  rm  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r$  r&  rU  rK  rk  _supportrm  ry  r{  r  r  r  r  r  r  r  r  r   r  rB  rP  rR  rq  rs  r~  r  r  r  r  r  r  r  r  r  r
  r  r)  rG  rI  rY  r^  rj  rl  ru  rw  r  r  r  r  r  r  r/  r1  r?  rA  rV  rX  rc  re  rt  rv  r  r  r  r  r  rE  r  r  r  r  r  r  r  r  r  r+  r/  r1  rV  r`  rm  ro  r  r  r  r  r  r  r  r  r  r  r	  r		  r	  r3	  r5	  rN	  rP	  r  r{	  r	  r	  r	  r	  r	  r	  r	  r	  r	  r
  r
  r
  r
  r
  r%
  r'
  r=
  rA
  rS
  rT
  rV
  rd
  rf
  r
  r
  r
  r
  r
  r
  r
  r
  r
  r
  r
  r
  r  r  r!  r&  rO
  r4  r6  rn  rp  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r$  r&  r/  r1  rV  rY  r[  ri  rk  r  rh   r  r  r  listglobalsr  itemspairs_distn_names_distn_gen_names__all__r   r7   r5   <module>r     s  
  $ ,    ' %7 7 3    # # ( ( ( BJ J J 2 1H H H ( & 1 7&*.W! W!t 	C3W-Z) Z)| 	!sc85M 5p Ck2	 bggag$+(m} m` V3' 3'l 	Cg&( (V 
ruufQh"%%'	9*'- *'Z s
3

: 

	X 	w!} w!t #6*lM l^ Ck2	4#= 4#n #:6wE} wEt #F#T2 T2n 
c	)Ox Od #F#I" I"X 
	"NRm NRb % UD} UDp #F#4# 4#n 
ruufH	5J6 J6Z 
	"D- DN &0ABE= EP Z(j( j(Z 	Cg&K!M K!\ {+	&&E4M E4P Ck2	23= 23j #J/Jm JZ -8-.] -.` c5
k@M k@\ 
Cc;= ;| #J/^Fm ^FB -8h!= h!V (-?@ &  D4m D4N -8R0m R0j =1rM rj Ck2	=;= =;@ #J/h"] h"V .
)dO Od 	Cg&40 40n 
c	)]F= ]F@ #J//%- /%d &2CDb bJ "7->= ->` #J/*~= ~B Z(K= K\ Z(W] Wt c5
{} {|  #N;P= Pf #J/+M +\ {+	5] 5p cS|<
W= Wt #J/T!= T!n #J/ym yx	 -8P2} P2f  ^4@2] @2F al3
a
M a
H {+	56M 56p C3[9	ZM Zz {+	V Vr 
	"E- EP 9
%])] ])@ ,1EF .*bb.} b.J #F#b. b.J 
c	)q7= q7h Z(r@= r@j Z(^] ^@ c5
C!- C!L )
,:- :-z 
c	)>0- >0B )
,;P ;P| 
c	)LI LI^ 
	"JI JIZ 
c	)Y$ Y$x 	wa#= a#H #J/ Z
} Z
z #F#]m ]@ % oCM oCd 
sODm DN 5[! [!| 
c	)6! 6!r 	Cg&AD= ADH Z(W4= W4t #:640} 40n  #N;31M 31l {+	:3 :3z 	DCg.v= vr #J/c?] c?T .
.
 
  
 <&} <&~ #F#}&M }&@ {+		 39 39l "Co>9&} 9&x  $#NC@'] @'F .
^F= ^FB Z(gEM gET C3[9	F FR 
cSx	0<4] <4~ c5
 
 0
9%Pk.M k.\ {A6		 zm zz	 -8! 8.m 8.v =1
L 
t(- t(n s
3o= od Z(v_E:&| :&z #F#A$] A$F cQruuW<@
]- ]@ 9
%=>m =>@ 6e6m e6P =;ST*G) G)T 	w)<sKr= rj@PM @PF */Ba,.FF4 Q0- Q0h &2CD 	WY^^##%&!7}!M 
)
)^,<
<r7   