
    Yh                        d dl mZ d dlmZ d dlmZmZmZmZ	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mZmZmZmZmZmZmZmZ d dlZdd	lm Z m!Z!m"Z"m#Z#m$Z$m%Z% dd
l&m'Z'm(Z(m)Z) ddl*m+Z+ d dl,mc m-Z.  G d de           Z/ e/d          Z0 G d de/          Z1 e1dd          Z2 G d de           Z3 e3d          Z4 G d de           Z5 e5d          Z6 G d de           Z7 e7d          Z8 G d de           Z9 e9ddd !          Z: G d" d#e           Z; e;d$          Z< G d% d&e           Z= e=d'          Z> G d( d)e           Z? e?dd*d+!          Z@ G d, d-e           ZA eAd.d/0          ZB G d1 d2e           ZC eCd d3d4!          ZD G d5 d6e           ZE eEd7d d89          ZF G d: d;e           ZG eGd<d=0          ZH G d> d?e           ZI eIdd@dA!          ZJdB ZKdC ZLdD ZM G dE dFe           ZN eNddGdH!          ZO G dI dJe           ZP ePejQ         dKdL!          ZR G dM dNe           ZS eSdOdPdQR          ZTdkdSZUdldUZVdmdVZWeTeScZXZYeUZ                    eXeY          eT_U        eVZ                    eXeY          eT_V        eWZ                    eXeY          eT_W         G dW dXe%          Z[ G dY dZe           Z\ e\ejQ         d[d\!          Z] G d] d^e           Z^ e^d_d`          Z_ G da dbe           Z` G dc dde`          Za eadedf0          Zb G dg dhe`          Zc ecdidj0          Zd ee ef            g                                h                                          Zi e!eie           \  ZjZkejekz   ZldS )n    )partial)special)entr	logsumexpbetalngammalnzeta)rng_integersN)interp1d)
floorceillogexpsqrtlog1pexpm1tanhcoshsinh   )rv_discreteget_distribution_names_vectorize_rvs_over_shapes
_ShapeInfo_isintegralrv_discrete_frozen)_PyFishersNCHypergeometric_PyWalleniusNCHypergeometric_PyStochasticLib3)_poisson_binomc                   ^    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dZd ZdS )	binom_gena2  A binomial discrete random variable.

    %(before_notes)s

    Notes
    -----
    The probability mass function for `binom` is:

    .. math::

       f(k) = \binom{n}{k} p^k (1-p)^{n-k}

    for :math:`k \in \{0, 1, \dots, n\}`, :math:`0 \leq p \leq 1`

    `binom` takes :math:`n` and :math:`p` as shape parameters,
    where :math:`p` is the probability of a single success
    and :math:`1-p` is the probability of a single failure.

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

    %(after_notes)s

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

    %(example)s

    See Also
    --------
    hypergeom, nbinom, nhypergeom

    c                 b    t          dddt          j        fd          t          dddd          gS 	NnTr   TFpFr   r   TTr   npinfselfs    n/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/scipy/stats/_discrete_distns.py_shape_infozbinom_gen._shape_infoB   4    3q"&k=AA3v|<<> 	>    Nc                 0    |                     |||          S N)binomialr.   r%   r'   sizerandom_states        r/   _rvszbinom_gen._rvsF   s    $$Q4000r2   c                 J    |dk    t          |          z  |dk    z  |dk    z  S Nr   r   r   r.   r%   r'   s      r/   	_argcheckzbinom_gen._argcheckI   s)    Q+a..(AF3qAv>>r2   c                     | j         |fS r4   ar=   s      r/   _get_supportzbinom_gen._get_supportL   s    vqyr2   c                     t          |          }t          |dz             t          |dz             t          ||z
  dz             z   z
  }|t          j        ||          z   t          j        ||z
  |           z   S Nr   )r   gamlnr   xlogyxlog1py)r.   xr%   r'   kcombilns         r/   _logpmfzbinom_gen._logpmfO   sl    !HH1::qseAaCEll!:;q!,,,wqsQB/G/GGGr2   c                 .    t          j        |||          S r4   )scu
_binom_pmfr.   rH   r%   r'   s       r/   _pmfzbinom_gen._pmfT   s    ~aA&&&r2   c                 L    t          |          }t          j        |||          S r4   )r   rM   
_binom_cdfr.   rH   r%   r'   rI   s        r/   _cdfzbinom_gen._cdfX   !    !HH~aA&&&r2   c                 L    t          |          }t          j        |||          S r4   )r   rM   	_binom_sfrS   s        r/   _sfzbinom_gen._sf\   s!    !HH}Q1%%%r2   c                 .    t          j        |||          S r4   )rM   
_binom_isfrO   s       r/   _isfzbinom_gen._isf`       ~aA&&&r2   c                 .    t          j        |||          S r4   )rM   
_binom_ppfr.   qr%   r'   s       r/   _ppfzbinom_gen._ppfc   r\   r2   mvc                 x   ||z  }||t          j        |          z  z
  }d\  }}d|v rO|t          j        |          z
  }t          j        ||z            }	t          j        |	          }
d|z  |	z  }|
|z
  }d|v r:|t          j        |          z
  }||z  }t          j        |          }
d|z  }|
|z
  }||||fS )NNNs       @rI         @)r+   squarer   
reciprocal)r.   r%   r'   momentsmuvarg1g2pqnpq_sqrtt1t2npqs                r/   _statszbinom_gen._statsf   s    U1ry||##B'>>RYq\\!Bwq2vHx((B'X%BbB'>>RYq\\!Bb&Cs##BQBbB3Br2   c                     t           j        d|dz            }|                     |||          }t          j        t	          |          d          S )Nr   r   axis)r+   r_rP   sumr   )r.   r%   r'   rI   valss        r/   _entropyzbinom_gen._entropyx   sE    E!AE'NyyAq!!vd4jjq))))r2   rd   rb   __name__
__module____qualname____doc__r0   r9   r>   rB   rK   rP   rT   rX   r[   ra   rt   r{    r2   r/   r"   r"      s        " "F> > >1 1 1 1? ? ?  H H H
' ' '' ' '& & &' ' '' ' '   $* * * * *r2   r"   binom)namec                   \    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dS )bernoulli_gena  A Bernoulli discrete random variable.

    %(before_notes)s

    Notes
    -----
    The probability mass function for `bernoulli` is:

    .. math::

       f(k) = \begin{cases}1-p  &\text{if } k = 0\\
                           p    &\text{if } k = 1\end{cases}

    for :math:`k` in :math:`\{0, 1\}`, :math:`0 \leq p \leq 1`

    `bernoulli` takes :math:`p` as shape parameter,
    where :math:`p` is the probability of a single success
    and :math:`1-p` is the probability of a single failure.

    %(after_notes)s

    %(example)s

    c                 (    t          dddd          gS Nr'   Fr(   r)   r   r-   s    r/   r0   zbernoulli_gen._shape_info       3v|<<==r2   Nc                 @    t                               | d|||          S )Nr   r7   r8   )r"   r9   r.   r'   r7   r8   s       r/   r9   zbernoulli_gen._rvs   s    ~~dAqt,~OOOr2   c                     |dk    |dk    z  S r;   r   r.   r'   s     r/   r>   zbernoulli_gen._argcheck   s    Q16""r2   c                     | j         | j        fS r4   )rA   br   s     r/   rB   zbernoulli_gen._get_support   s    vtv~r2   c                 :    t                               |d|          S rD   )r   rK   r.   rH   r'   s      r/   rK   zbernoulli_gen._logpmf   s    }}Q1%%%r2   c                 :    t                               |d|          S rD   )r   rP   r   s      r/   rP   zbernoulli_gen._pmf   s     zz!Q"""r2   c                 :    t                               |d|          S rD   )r   rT   r   s      r/   rT   zbernoulli_gen._cdf       zz!Q"""r2   c                 :    t                               |d|          S rD   )r   rX   r   s      r/   rX   zbernoulli_gen._sf   s    yyAq!!!r2   c                 :    t                               |d|          S rD   )r   r[   r   s      r/   r[   zbernoulli_gen._isf   r   r2   c                 :    t                               |d|          S rD   )r   ra   )r.   r`   r'   s      r/   ra   zbernoulli_gen._ppf   r   r2   c                 8    t                               d|          S rD   )r   rt   r   s     r/   rt   zbernoulli_gen._stats   s    ||Aq!!!r2   c                 F    t          |          t          d|z
            z   S rD   )r   r   s     r/   r{   zbernoulli_gen._entropy   s    Awwac""r2   rd   r}   r   r2   r/   r   r      s         0> > >P P P P# # #  & & &# # #
# # #" " "# # ## # #" " "# # # # #r2   r   	bernoulli)r   r   c                   @    e Zd ZdZd ZddZd Zd Zd Zd Z	dd
Z
dS )betabinom_gena  A beta-binomial discrete random variable.

    %(before_notes)s

    Notes
    -----
    The beta-binomial distribution is a binomial distribution with a
    probability of success `p` that follows a beta distribution.

    The probability mass function for `betabinom` is:

    .. math::

       f(k) = \binom{n}{k} \frac{B(k + a, n - k + b)}{B(a, b)}

    for :math:`k \in \{0, 1, \dots, n\}`, :math:`n \geq 0`, :math:`a > 0`,
    :math:`b > 0`, where :math:`B(a, b)` is the beta function.

    `betabinom` takes :math:`n`, :math:`a`, and :math:`b` as shape parameters.

    %(after_notes)s

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Beta-binomial_distribution

    .. versionadded:: 1.4.0

    See Also
    --------
    beta, binom

    %(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%   Tr   r&   rA   FFFr   r*   r-   s    r/   r0   zbetabinom_gen._shape_info   S    3q"&k=AA326{NCC326{NCCE 	Er2   Nc                 ^    |                     |||          }|                    |||          S r4   )betar5   r.   r%   rA   r   r7   r8   r'   s          r/   r9   zbetabinom_gen._rvs   s1    aD))$$Q4000r2   c                 
    d|fS Nr   r   r.   r%   rA   r   s       r/   rB   zbetabinom_gen._get_support       !tr2   c                 J    |dk    t          |          z  |dk    z  |dk    z  S r   r<   r   s       r/   r>   zbetabinom_gen._argcheck   )    Q+a..(AE2a!e<<r2   c                     t          |          }t          |dz              t          ||z
  dz   |dz             z
  }|t          ||z   ||z
  |z             z   t          ||          z
  S rD   )r   r   r   r.   rH   r%   rA   r   rI   rJ   s          r/   rK   zbetabinom_gen._logpmf   sg    !HHq1u::+q1uqy!a% 8 88Aq1uqy111F1aLL@@r2   c                 L    t          |                     ||||                    S r4   r   rK   r.   rH   r%   rA   r   s        r/   rP   zbetabinom_gen._pmf   "    4<<1a++,,,r2   rb   c                 J   |||z   z  }d|z
  }||z  }|||z   |z   z  |z  |z  ||z   dz   z  }d\  }	}
d|v r7dt          |          z  }	|	||z   d|z  z   ||z
  z  z  }	|	||z   dz   ||z   z  z  }	d|v r||z                       |j                  }
|
||z   dz
  d|z  z   z  }
|
d|z  |z  |dz
  z  z  }
|
d|dz  z  z  }
|
d|z  |z  |z  d|z
  z  z  }
|
d	|z  |z  |dz  z  z  }
|
||z   dz  d|z   |z   z  z  }
|
||z  |z  ||z   dz   z  ||z   dz   z  ||z   |z   z  z  }
|
dz  }
|||	|
fS )
Nr   rd   re         ?   rI            )r   astypedtype)r.   r%   rA   r   rj   e_pe_qrk   rl   rm   rn   s              r/   rt   zbetabinom_gen._stats   s   1q5k#gW1q519o#c)QUQY7B'>>tCyyB1q51q5=QU++B1q519Q''B'>>a%	**B1q519q1u$%B!a%!)q1u%%B!a1f*B!c'A+/QU++B"s(S.16))B1q5Q,!a%!),,B1q519A	*a!eai8AEAIFGB!GB3Br2   rd   r|   )r~   r   r   r   r0   r9   rB   r>   rK   rP   rt   r   r2   r/   r   r      s        " "FE E E
1 1 1 1  = = =A A A
- - -     r2   r   	betabinomc                   V    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S )
nbinom_gena  A negative binomial discrete random variable.

    %(before_notes)s

    Notes
    -----
    Negative binomial distribution describes a sequence of i.i.d. Bernoulli
    trials, repeated until a predefined, non-random number of successes occurs.

    The probability mass function of the number of failures for `nbinom` is:

    .. math::

       f(k) = \binom{k+n-1}{n-1} p^n (1-p)^k

    for :math:`k \ge 0`, :math:`0 < p \leq 1`

    `nbinom` takes :math:`n` and :math:`p` as shape parameters where :math:`n`
    is the number of successes, :math:`p` is the probability of a single
    success, and :math:`1-p` is the probability of a single failure.

    Another common parameterization of the negative binomial distribution is
    in terms of the mean number of failures :math:`\mu` to achieve :math:`n`
    successes. The mean :math:`\mu` is related to the probability of success
    as

    .. math::

       p = \frac{n}{n + \mu}

    The number of successes :math:`n` may also be specified in terms of a
    "dispersion", "heterogeneity", or "aggregation" parameter :math:`\alpha`,
    which relates the mean :math:`\mu` to the variance :math:`\sigma^2`,
    e.g. :math:`\sigma^2 = \mu + \alpha \mu^2`. Regardless of the convention
    used for :math:`\alpha`,

    .. math::

       p &= \frac{\mu}{\sigma^2} \\
       n &= \frac{\mu^2}{\sigma^2 - \mu}

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

    %(after_notes)s

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

    %(example)s

    See Also
    --------
    hypergeom, binom, nhypergeom

    c                 b    t          dddt          j        fd          t          dddd          gS r$   r*   r-   s    r/   r0   znbinom_gen._shape_infoU  r1   r2   Nc                 0    |                     |||          S r4   )negative_binomialr6   s        r/   r9   znbinom_gen._rvsY  s    --aD999r2   c                 *    |dk    |dk    z  |dk    z  S r;   r   r=   s      r/   r>   znbinom_gen._argcheck\  s    A!a% AF++r2   c                 .    t          j        |||          S r4   )rM   _nbinom_pmfrO   s       r/   rP   znbinom_gen._pmf_  s    q!Q'''r2   c                     t          ||z             t          |dz             z
  t          |          z
  }||t          |          z  z   t          j        ||           z   S rD   )rE   r   r   rG   )r.   rH   r%   r'   coeffs        r/   rK   znbinom_gen._logpmfc  sS    ac

U1Q3ZZ'%((2qQx'/!aR"8"888r2   c                 L    t          |          }t          j        |||          S r4   )r   rM   _nbinom_cdfrS   s        r/   rT   znbinom_gen._cdfg  s!    !HHq!Q'''r2   c                 x   t          |          }t          j        |||          \  }}}|                     |||          }|dk    }d }|}t          j        d          5   |||         ||         ||                   ||<   t          j        ||                    || <   d d d            n# 1 swxY w Y   |S )N      ?c                 `    t          j        t          j        | dz   |d|z
                       S rD   )r+   r   r   betainc)rI   r%   r'   s      r/   f1znbinom_gen._logcdf.<locals>.f1p  s+    8W_QUAq1u===>>>r2   ignore)divide)r   r+   broadcast_arraysrT   errstater   )	r.   rH   r%   r'   rI   cdfcondr   logcdfs	            r/   _logcdfznbinom_gen._logcdfk  s   !HH%aA..1aii1a  Sy	? 	? 	? [))) 	/ 	/2agqw$88F4LF3u:..FD5M	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ s   !AB//B36B3c                 L    t          |          }t          j        |||          S r4   )r   rM   
_nbinom_sfrS   s        r/   rX   znbinom_gen._sfz  rU   r2   c                     t          j        d          5  t          j        |||          cd d d            S # 1 swxY w Y   d S Nr   over)r+   r   rM   _nbinom_isfrO   s       r/   r[   znbinom_gen._isf~      [h''' 	, 	,?1a++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,   9= =c                     t          j        d          5  t          j        |||          cd d d            S # 1 swxY w Y   d S r   )r+   r   rM   _nbinom_ppfr_   s       r/   ra   znbinom_gen._ppf  r   r   c                     t          j        ||          t          j        ||          t          j        ||          t          j        ||          fS r4   )rM   _nbinom_mean_nbinom_variance_nbinom_skewness_nbinom_kurtosis_excessr=   s      r/   rt   znbinom_gen._stats  sL    Q"" A&& A&&'1--	
 	
r2   rd   )r~   r   r   r   r0   r9   r>   rP   rK   rT   r   rX   r[   ra   rt   r   r2   r/   r   r     s        9 9t> > >: : : :, , ,( ( (9 9 9( ( (  ' ' ', , ,, , ,
 
 
 
 
r2   r   nbinomc                   :    e Zd ZdZd Zd
dZd Zd Zd Zdd	Z	dS )betanbinom_genaK  A beta-negative-binomial discrete random variable.

    %(before_notes)s

    Notes
    -----
    The beta-negative-binomial distribution is a negative binomial
    distribution with a probability of success `p` that follows a
    beta distribution.

    The probability mass function for `betanbinom` is:

    .. math::

       f(k) = \binom{n + k - 1}{k} \frac{B(a + n, b + k)}{B(a, b)}

    for :math:`k \ge 0`, :math:`n \geq 0`, :math:`a > 0`,
    :math:`b > 0`, where :math:`B(a, b)` is the beta function.

    `betanbinom` takes :math:`n`, :math:`a`, and :math:`b` as shape parameters.

    %(after_notes)s

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Beta_negative_binomial_distribution

    .. versionadded:: 1.12.0

    See Also
    --------
    betabinom : Beta binomial distribution

    %(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 r   r*   r-   s    r/   r0   zbetanbinom_gen._shape_info  r   r2   Nc                 ^    |                     |||          }|                    |||          S r4   )r   r   r   s          r/   r9   zbetanbinom_gen._rvs  s1    aD))--aD999r2   c                 J    |dk    t          |          z  |dk    z  |dk    z  S r   r<   r   s       r/   r>   zbetanbinom_gen._argcheck  r   r2   c                     t          |          }t          j        ||z              t          ||dz             z
  }|t          ||z   ||z             z   t          ||          z
  S rD   )r   r+   r   r   r   s          r/   rK   zbetanbinom_gen._logpmf  s]    !HH6!a%==.6!QU#3#33Aq1u---q!<<r2   c                 L    t          |                     ||||                    S r4   r   r   s        r/   rP   zbetanbinom_gen._pmf  r   r2   rb   c                    d }t          j        |dk    |||f|t          j                  }d }t          j        |dk    |||f|t          j                  }d\  }}	d }
d|v r)t          j        |d	k    |||f|
t          j                  }d
 }d|v r)t          j        |dk    |||f|t          j                  }	||||	fS )Nc                     | |z  |dz
  z  S Nr   r   r%   rA   r   s      r/   meanz#betanbinom_gen._stats.<locals>.mean  s    q5AF##r2   r   
fill_valuec                 N    | |z  | |z   dz
  z  ||z   dz
  z  |dz
  |dz
  dz  z  z  S )Nr   rf   r   r   s      r/   rl   z"betanbinom_gen._stats.<locals>.var  sA    EQURZ(AEBJ7B1r6B,.0 1r2   r   rd   c                     d| z  |z   dz
  d|z  |z   dz
  z  |dz
  z  t          | |z  | |z   dz
  z  ||z   dz
  z  |dz
  z            z  S )Nr   r         @rf   r   r   s      r/   skewz#betanbinom_gen._stats.<locals>.skew  sq    UQY^A	B72v!%a!eq1urz&:a!ebj&I2v' "  "   !r2   re   r   c                 z   |dz
  }|dz
  dz  |dz  |d|z  dz
  z  z   d|dz
  z  |z  z   z  d| dz  z  |dz   |dz  z  |dz   |dz
  z  |z  z   d|dz
  dz  z  z   z  z   d|dz
  z  | z  |dz   |dz  z  |dz   |dz
  z  |z  z   d|dz
  dz  z  z   z  z   }|d	z
  |dz
  z  |z  | z  ||z   dz
  z  || z   dz
  z  }||z  |z  dz
  S )
Nrf   r   r   rg   r         @r   r   g      @r   )r%   rA   r   termterm_2denominators         r/   kurtosisz'betanbinom_gen._stats.<locals>.kurtosis  sN   FD2vlaea1q52:.>&>a"f)'* +QU
q2vB&6!b&R:!#$:% '%')QVaK'7'8 99 QVq(b&ArE)QVB,?!,CCa"fr\)*+	+F Fq2v.2Q6!ebj*-.URZ9K &=;.33r2   rI      xpxapply_wherer+   r,   )r.   r%   rA   r   rj   r   rk   rl   rm   rn   r   r   s               r/   rt   zbetanbinom_gen._stats  s    	$ 	$ 	$_QUQ1ItGGG	1 	1 	1 oa!eaAYGGGB	! 	! 	! '>>QAq	4BFKKKB	4 	4 	4 '>>QAq	8OOOB3Br2   rd   r|   )
r~   r   r   r   r0   r9   r>   rK   rP   rt   r   r2   r/   r   r     s        # #HE E E
: : : := = == = =
- - -! ! ! ! ! !r2   r   
betanbinomc                   V    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S )geom_gena5  A geometric discrete random variable.

    %(before_notes)s

    Notes
    -----
    The probability mass function for `geom` is:

    .. math::

        f(k) = (1-p)^{k-1} p

    for :math:`k \ge 1`, :math:`0 < p \leq 1`

    `geom` takes :math:`p` as shape parameter,
    where :math:`p` is the probability of a single success
    and :math:`1-p` is the probability of a single failure.

    Note that when drawing random samples, the probability of observations that exceed
    ``np.iinfo(np.int64).max`` increases rapidly as $p$ decreases below $10^{-17}$. For
    $p < 10^{-20}$, almost all observations would exceed the maximum ``int64``; however,
    the output dtype is always ``int64``, so these values are clipped to the maximum.

    %(after_notes)s

    See Also
    --------
    planck

    %(example)s

    c                 (    t          dddd          gS r   r   r-   s    r/   r0   zgeom_gen._shape_info  r   r2   Nc                     |                     ||          }t          j        |j                  j        }t          j        |dk     ||          S )Nr7   r   )	geometricr+   iinfor   maxwhere)r.   r'   r7   r8   resmax_ints         r/   r9   zgeom_gen._rvs  sH    $$QT$22 (39%%)xa#...r2   c                     |dk    |dk    z  S Nr   r   r   r   s     r/   r>   zgeom_gen._argcheck  s    Q1q5!!r2   c                 >    t          j        d|z
  |dz
            |z  S rD   )r+   powerr.   rI   r'   s      r/   rP   zgeom_gen._pmf!  s!    x!QqS!!A%%r2   c                 T    t          j        |dz
  |           t          |          z   S rD   )r   rG   r   r  s      r/   rK   zgeom_gen._logpmf$  s%    q1uqb))CFF22r2   c                 b    t          |          }t          t          |           |z             S r4   )r   r   r   r.   rH   r'   rI   s       r/   rT   zgeom_gen._cdf'  s*    !HHeQBiik""""r2   c                 R    t          j        |                     ||                    S r4   )r+   r   _logsfr   s      r/   rX   zgeom_gen._sf+  s     vdkk!Q''(((r2   c                 F    t          |          }|t          |           z  S r4   )r   r   r  s       r/   r  zgeom_gen._logsf.  s    !HHr{r2   c                     t          t          |           t          |           z            }|                     |dz
  |          }t          j        ||k    |dk    z  |dz
  |          S r  )r   r   rT   r+   r  )r.   r`   r'   rz   temps        r/   ra   zgeom_gen._ppf2  s`    E1"IIqb		)**yya##xtax0$q&$???r2   c                     d|z  }d|z
  }||z  |z  }d|z
  t          |          z  }t          j        g d|          d|z
  z  }||||fS )Nr   rf   )r   ir   )r   r+   polyval)r.   r'   rk   qrrl   rm   rn   s          r/   rt   zgeom_gen._stats7  sa    UU1fqj!etBxxZ


A&&A.3Br2   c                 j    t          j        |           t          j        |           d|z
  z  |z  z
  S r   )r+   r   r   r   s     r/   r{   zgeom_gen._entropy?  s/    q		zBHaRLLCE2Q666r2   rd   )r~   r   r   r   r0   r9   r>   rP   rK   rT   rX   r  ra   rt   r{   r   r2   r/   r  r    s         B> > >/ / / /" " "& & &3 3 3# # #) ) )  @ @ @
  7 7 7 7 7r2   r  geomzA geometric)rA   r   longnamec                   \    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dS )hypergeom_gena	  A hypergeometric discrete random variable.

    The hypergeometric distribution models drawing objects from a bin.
    `M` is the total number of objects, `n` is total number of Type I objects.
    The random variate represents the number of Type I objects in `N` drawn
    without replacement from the total population.

    %(before_notes)s

    Notes
    -----
    The symbols used to denote the shape parameters (`M`, `n`, and `N`) are not
    universally accepted.  See the Examples for a clarification of the
    definitions used here.

    The probability mass function is defined as,

    .. math:: p(k, M, n, N) = \frac{\binom{n}{k} \binom{M - n}{N - k}}
                                   {\binom{M}{N}}

    for :math:`k \in [\max(0, N - M + n), \min(n, N)]`, where the binomial
    coefficients are defined as,

    .. math:: \binom{n}{k} \equiv \frac{n!}{k! (n - k)!}.

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

    %(after_notes)s

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

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.stats import hypergeom
    >>> import matplotlib.pyplot as plt

    Suppose we have a collection of 20 animals, of which 7 are dogs.  Then if
    we want to know the probability of finding a given number of dogs if we
    choose at random 12 of the 20 animals, we can initialize a frozen
    distribution and plot the probability mass function:

    >>> [M, n, N] = [20, 7, 12]
    >>> rv = hypergeom(M, n, N)
    >>> x = np.arange(0, n+1)
    >>> pmf_dogs = rv.pmf(x)

    >>> fig = plt.figure()
    >>> ax = fig.add_subplot(111)
    >>> ax.plot(x, pmf_dogs, 'bo')
    >>> ax.vlines(x, 0, pmf_dogs, lw=2)
    >>> ax.set_xlabel('# of dogs in our group of chosen animals')
    >>> ax.set_ylabel('hypergeom PMF')
    >>> plt.show()

    Instead of using a frozen distribution we can also use `hypergeom`
    methods directly.  To for example obtain the cumulative distribution
    function, use:

    >>> prb = hypergeom.cdf(x, M, n, N)

    And to generate random numbers:

    >>> R = hypergeom.rvs(M, n, N, size=10)

    See Also
    --------
    nhypergeom, binom, nbinom

    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 )NMTr   r&   r%   Nr*   r-   s    r/   r0   zhypergeom_gen._shape_info  S    3q"&k=AA3q"&k=AA3q"&k=AAC 	Cr2   Nc                 :    |                     |||z
  ||          S Nr	  )hypergeometric)r.   r&  r%   r'  r7   r8   s         r/   r9   zhypergeom_gen._rvs  s#    **1ac14*@@@r2   c                 b    t          j        |||z
  z
  d          t          j        ||          fS r   r+   maximumminimum)r.   r&  r%   r'  s       r/   rB   zhypergeom_gen._get_support  s-    z!QqS'1%%rz!Q'7'777r2   c                     |dk    |dk    z  |dk    z  }|||k    ||k    z  z  }|t          |          t          |          z  t          |          z  z  }|S r   r<   )r.   r&  r%   r'  r   s        r/   r>   zhypergeom_gen._argcheck  s_    A!q&!Q!V,aAF##AQ/+a..@@r2   c                 6   ||}}||z
  }t          |dz   d          t          |dz   d          z   t          ||z
  dz   |dz             z   t          |dz   ||z
  dz             z
  t          ||z
  dz   ||z
  |z   dz             z
  t          |dz   d          z
  }|S rD   r   )	r.   rI   r&  r%   r'  totgoodbadresults	            r/   rK   zhypergeom_gen._logpmf  s    qTDja##fSUA&6&66Aa19M9MM1d1fQh''(*01QAa	*B*BCQ""# r2   c                 0    t          j        ||||          S r4   )rM   _hypergeom_pmfr.   rI   r&  r%   r'  s        r/   rP   zhypergeom_gen._pmf      !!Q1---r2   c                 0    t          j        ||||          S r4   )rM   _hypergeom_cdfr9  s        r/   rT   zhypergeom_gen._cdf  r:  r2   c                 x   d|z  d|z  d|z  }}}||z
  }||dz   z  d|z  ||z
  z  z
  d|z  |z  z
  }||dz
  |z  |z  z  }|d|z  |z  ||z
  z  |z  d|z  dz
  z  z  }|||z  ||z
  z  |z  |dz
  z  |dz
  z  z  }t          j        |||          t          j        |||          t          j        |||          |fS )Nr   r   rg   r   r   rf   r   )rM   _hypergeom_mean_hypergeom_variance_hypergeom_skewness)r.   r&  r%   r'  mrn   s         r/   rt   zhypergeom_gen._stats  s   q&"q&"q&a1E !a%[26QU++b1fqj8
q1ukAo
b1fqjAE"Q&"q&1*55
a!eq1uo!QV,B771a((#Aq!,,#Aq!,,	
 	
r2   c                     t           j        |||z
  z
  t          ||          dz            }|                     ||||          }t          j        t          |          d          S )Nr   r   rv   )r+   rx   minpmfry   r   )r.   r&  r%   r'  rI   rz   s         r/   r{   zhypergeom_gen._entropy  sY    E!q1u+c!Qii!m+,xx1a##vd4jjq))))r2   c                 0    t          j        ||||          S r4   )rM   _hypergeom_sfr9  s        r/   rX   zhypergeom_gen._sf  s     Aq!,,,r2   c                    g }t          t          j        ||||           D ]\  }}}}	|dz   |dz   z  |dz
  |	dz
  z  k     rG|                    t	          t          |                     ||||	                                          ft          j        |dz   |	dz             }
|                    t          | 	                    |
|||	                               t          j
        |          S )Nr   r   )zipr+   r   appendr   r   r   aranger   rK   asarrayr.   rI   r&  r%   r'  r  quantr3  r4  drawk2s              r/   r  zhypergeom_gen._logsf  s    &)2+>q!Q+J+J&K 	I 	I"E3dc	*dSjTCZ-HHH

5#dkk%dD&I&I"J"J!JKKLLLL Yuqy$(33

9T\\"c4%F%FGGHHHHz#r2   c                    g }t          t          j        ||||           D ]\  }}}}	|dz   |dz   z  |dz
  |	dz
  z  k    rG|                    t	          t          |                     ||||	                                          ft          j        d|dz             }
|                    t          | 	                    |
|||	                               t          j
        |          S )Nr   r   r   )rH  r+   r   rI  r   r   logsfrJ  r   rK   rK  rL  s              r/   r   zhypergeom_gen._logcdf  s    &)2+>q!Q+J+J&K 	I 	I"E3dc	*dSjTCZ-HHH

5#djjT4&H&H"I"I!IJJKKKK Yq%!),,

9T\\"c4%F%FGGHHHHz#r2   rd   )r~   r   r   r   r0   r9   rB   r>   rK   rP   rT   rt   r{   rX   r  r   r   r2   r/   r$  r$  F  s        H HRC C C
A A A A8 8 8    . . .. . .
 
 
"* * *
- - -
 
 

 
 
 
 
r2   r$  	hypergeomc                   >    e Zd ZdZd Zd Zd Zd
dZd Zd Z	d	 Z
dS )nhypergeom_genab  A negative hypergeometric discrete random variable.

    Consider a box containing :math:`M` balls:, :math:`n` red and
    :math:`M-n` blue. We randomly sample balls from the box, one
    at a time and *without* replacement, until we have picked :math:`r`
    blue balls. `nhypergeom` is the distribution of the number of
    red balls :math:`k` we have picked.

    %(before_notes)s

    Notes
    -----
    The symbols used to denote the shape parameters (`M`, `n`, and `r`) are not
    universally accepted. See the Examples for a clarification of the
    definitions used here.

    The probability mass function is defined as,

    .. math:: f(k; M, n, r) = \frac{{{k+r-1}\choose{k}}{{M-r-k}\choose{n-k}}}
                                   {{M \choose n}}

    for :math:`k \in [0, n]`, :math:`n \in [0, M]`, :math:`r \in [0, M-n]`,
    and the binomial coefficient is:

    .. math:: \binom{n}{k} \equiv \frac{n!}{k! (n - k)!}.

    It is equivalent to observing :math:`k` successes in :math:`k+r-1`
    samples with :math:`k+r`'th sample being a failure. The former
    can be modelled as a hypergeometric distribution. The probability
    of the latter is simply the number of failures remaining
    :math:`M-n-(r-1)` divided by the size of the remaining population
    :math:`M-(k+r-1)`. This relationship can be shown as:

    .. math:: NHG(k;M,n,r) = HG(k;M,n,k+r-1)\frac{(M-n-(r-1))}{(M-(k+r-1))}

    where :math:`NHG` is probability mass function (PMF) of the
    negative hypergeometric distribution and :math:`HG` is the
    PMF of the hypergeometric distribution.

    %(after_notes)s

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.stats import nhypergeom
    >>> import matplotlib.pyplot as plt

    Suppose we have a collection of 20 animals, of which 7 are dogs.
    Then if we want to know the probability of finding a given number
    of dogs (successes) in a sample with exactly 12 animals that
    aren't dogs (failures), we can initialize a frozen distribution
    and plot the probability mass function:

    >>> M, n, r = [20, 7, 12]
    >>> rv = nhypergeom(M, n, r)
    >>> x = np.arange(0, n+2)
    >>> pmf_dogs = rv.pmf(x)

    >>> fig = plt.figure()
    >>> ax = fig.add_subplot(111)
    >>> ax.plot(x, pmf_dogs, 'bo')
    >>> ax.vlines(x, 0, pmf_dogs, lw=2)
    >>> ax.set_xlabel('# of dogs in our group with given 12 failures')
    >>> ax.set_ylabel('nhypergeom PMF')
    >>> plt.show()

    Instead of using a frozen distribution we can also use `nhypergeom`
    methods directly.  To for example obtain the probability mass
    function, use:

    >>> prb = nhypergeom.pmf(x, M, n, r)

    And to generate random numbers:

    >>> R = nhypergeom.rvs(M, n, r, size=10)

    To verify the relationship between `hypergeom` and `nhypergeom`, use:

    >>> from scipy.stats import hypergeom, nhypergeom
    >>> M, n, r = 45, 13, 8
    >>> k = 6
    >>> nhypergeom.pmf(k, M, n, r)
    0.06180776620271643
    >>> hypergeom.pmf(k, M, n, k+r-1) * (M - n - (r-1)) / (M - (k+r-1))
    0.06180776620271644

    See Also
    --------
    hypergeom, binom, nbinom

    References
    ----------
    .. [1] Negative Hypergeometric Distribution on Wikipedia
           https://en.wikipedia.org/wiki/Negative_hypergeometric_distribution

    .. [2] Negative Hypergeometric Distribution from
           http://www.math.wm.edu/~leemis/chart/UDR/PDFs/Negativehypergeometric.pdf

    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&  Tr   r&   r%   rr*   r-   s    r/   r0   znhypergeom_gen._shape_infoI  r(  r2   c                 
    d|fS r   r   )r.   r&  r%   rV  s       r/   rB   znhypergeom_gen._get_supportN  r   r2   c                     |dk    ||k    z  |dk    z  |||z
  k    z  }|t          |          t          |          z  t          |          z  z  }|S r   r<   )r.   r&  r%   rV  r   s        r/   r>   znhypergeom_gen._argcheckQ  sU    Q16"a1f-ac:AQ/+a..@@r2   Nc                 H     t            fd            } ||||||          S )Nc                 \                        | ||          \  }}t          j        ||dz             }                    || ||          }t	          ||dd          }	 |	|                    |                                        t                    }
||
                                S |
S )Nr   nextextrapolate)kindr   r	  )	supportr+   rJ  r   r   uniformr   intitem)r&  r%   rV  r7   r8   rA   r   ksr   ppfrvsr.   s              r/   _rvs1z"nhypergeom_gen._rvs.<locals>._rvs1X  s     <<1a((DAq1ac""B((2q!Q''C3MJJJC#l***5566==cBBC|xxzz!Jr2   r   r   )r.   r&  r%   rV  r7   r8   re  s   `      r/   r9   znhypergeom_gen._rvsV  sD    	#		 		 		 		 
$	#		 uQ14lCCCCr2   c                 R    t          j        |dk    |dk    z  ||||fd d          S )Nr   c                 "   t          | dz   |           t          | |z   d          z   t          || z
  dz   ||z
  |z
  dz             z
  t          ||z
  | z
  dz   d          z   t          |dz   ||z
  dz             z   t          |dz   d          z
  S rD   r2  )rI   r&  r%   rV  s       r/   <lambda>z(nhypergeom_gen._logpmf.<locals>.<lambda>i  s    1a..6!A#q>>1!A#a%1Qq))*,21Q3q57A,>,>?!A#qs1u%%&(.qsA7 r2           r   )r  r  r.   rI   r&  r%   rV  s        r/   rK   znhypergeom_gen._logpmff  sD    !VQ!Q18 8    	r2   c                 L    t          |                     ||||                    S r4   r   rk  s        r/   rP   znhypergeom_gen._pmfo  s$     4<<1a++,,,r2   c                     d|z  d|z  d|z  }}}||z  ||z
  dz   z  }||dz   z  |z  ||z
  dz   ||z
  dz   z  z  d|||z
  dz   z  z
  z  }d\  }}||||fS )Nr   r   r   rd   r   )r.   r&  r%   rV  rk   rl   rm   rn   s           r/   rt   znhypergeom_gen._statst  s     Q$1bda1qSAaCE]1gaiAaCEAaCE?+q1!A;? B3Br2   rd   )r~   r   r   r   r0   rB   r>   r9   rK   rP   rt   r   r2   r/   rT  rT    s        b bHC C C
    
D D D D   - - -
    r2   rT  
nhypergeomc                   2    e Zd ZdZd ZddZd Zd Zd ZdS )	
logser_gena  A Logarithmic (Log-Series, Series) discrete random variable.

    %(before_notes)s

    Notes
    -----
    The probability mass function for `logser` is:

    .. math::

        f(k) = - \frac{p^k}{k \log(1-p)}

    for :math:`k \ge 1`, :math:`0 < p < 1`

    `logser` takes :math:`p` as shape parameter,
    where :math:`p` is the probability of a single success
    and :math:`1-p` is the probability of a single failure.

    %(after_notes)s

    %(example)s

    c                 (    t          dddd          gS r   r   r-   s    r/   r0   zlogser_gen._shape_info  r   r2   Nc                 0    |                     ||          S r*  )	logseriesr   s       r/   r9   zlogser_gen._rvs  s     %%ad%333r2   c                     |dk    |dk     z  S r;   r   r   s     r/   r>   zlogser_gen._argcheck  s    A!a%  r2   c                 f    t          j        ||           dz  |z  t          j        |           z  S r   )r+   r  r   r   r  s      r/   rP   zlogser_gen._pmf  s/    A$q(7=!+<+<<<r2   c                    t          j        |           }||dz
  z  |z  }| |z  |dz
  dz  z  }|||z  z
  }| |z  d|z   z  d|z
  dz  z  }|d|z  |z  z
  d|dz  z  z   }|t          j        |d          z  }| |z  d|dz
  dz  z  d|z  |dz
  dz  z  z
  d|z  |z  |dz
  dz  z  z   z  }	|	d|z  |z  z
  d|z  |z  |z  z   d|dz  z  z
  }
|
|dz  z  dz
  }||||fS )	Nr   r   r         ?r   r   r   r   )r   r   r+   r  )r.   r'   rV  rk   mu2prl   mu3pmu3rm   mu4pmu4rn   s               r/   rt   zlogser_gen._stats  s@   M1"!c']QrAvS1$RUlrAvQ37Q,.QrT$Y2q5(28C%%%rAv1Q3(NQqSAEA:--!A1q0@@BQtVBY42-"a%736\C3Br2   rd   )	r~   r   r   r   r0   r9   r>   rP   rt   r   r2   r/   rp  rp    sn         0> > >4 4 4 4
! ! != = =    r2   rp  logserzA logarithmicc                   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 ZdS )poisson_gena  A Poisson discrete random variable.

    %(before_notes)s

    Notes
    -----
    The probability mass function for `poisson` is:

    .. math::

        f(k) = \exp(-\mu) \frac{\mu^k}{k!}

    for :math:`k \ge 0`.

    `poisson` takes :math:`\mu \geq 0` as shape parameter.
    When :math:`\mu = 0`, the ``pmf`` method
    returns ``1.0`` at quantile :math:`k = 0`.

    %(after_notes)s

    %(example)s

    c                 @    t          dddt          j        fd          gS )Nrk   Fr   r&   r*   r-   s    r/   r0   zpoisson_gen._shape_info  s    4BF]CCDDr2   c                     |dk    S r   r   )r.   rk   s     r/   r>   zpoisson_gen._argcheck  s    Qwr2   Nc                 .    |                     ||          S r4   poisson)r.   rk   r7   r8   s       r/   r9   zpoisson_gen._rvs  s    ##B---r2   c                 \    t          j        ||          t          |dz             z
  |z
  }|S rD   )r   rF   rE   )r.   rI   rk   Pks       r/   rK   zpoisson_gen._logpmf  s,    ]1b!!E!a%LL025	r2   c                 H    t          |                     ||                    S r4   r   )r.   rI   rk   s      r/   rP   zpoisson_gen._pmf  s    4<<2&&'''r2   c                 J    t          |          }t          j        ||          S r4   )r   r   pdtrr.   rH   rk   rI   s       r/   rT   zpoisson_gen._cdf  s    !HH|Ar"""r2   c                 J    t          |          }t          j        ||          S r4   )r   r   pdtrcr  s       r/   rX   zpoisson_gen._sf  s    !HH}Q###r2   c                     t          t          j        ||                    }t          j        |dz
  d          }t          j        ||          }t          j        ||k    ||          S r  )r   r   pdtrikr+   r.  r  r  )r.   r`   rk   rz   vals1r  s         r/   ra   zpoisson_gen._ppf  sY    GN1b))**
4!8Q''|E2&&x	5$///r2   c                     |}t          j        |          }|dk    }t          j        ||d t           j                  }t          j        ||d t           j                  }||||fS )Nr   c                 &    t          d| z            S r   r   rH   s    r/   ri  z$poisson_gen._stats.<locals>.<lambda>  s    SU r2   r   c                     d| z  S r   r   r  s    r/   ri  z$poisson_gen._stats.<locals>.<lambda>  s
    A r2   )r+   rK  r  r  r,   )r.   rk   rl   tmp
mu_nonzerorm   rn   s          r/   rt   zpoisson_gen._stats  sg    jnn1W
_Z.C.CPRPVWWW_Zoo"&QQQ3Br2   rd   )r~   r   r   r   r0   r>   r9   rK   rP   rT   rX   ra   rt   r   r2   r/   r  r    s         0E E E  . . . .  ( ( (# # #$ $ $0 0 0    r2   r  r  z	A Poisson)r   r"  c                   P    e 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d	S )
planck_gena  A Planck discrete exponential random variable.

    %(before_notes)s

    Notes
    -----
    The probability mass function for `planck` is:

    .. math::

        f(k) = (1-\exp(-\lambda)) \exp(-\lambda k)

    for :math:`k \ge 0` and :math:`\lambda > 0`.

    `planck` takes :math:`\lambda` as shape parameter. The Planck distribution
    can be written as a geometric distribution (`geom`) with
    :math:`p = 1 - \exp(-\lambda)` shifted by ``loc = -1``.

    %(after_notes)s

    See Also
    --------
    geom

    %(example)s

    c                 @    t          dddt          j        fd          gS )Nlambda_Fr   r   r*   r-   s    r/   r0   zplanck_gen._shape_info"  s    9ea[.IIJJr2   c                     |dk    S r   r   )r.   r  s     r/   r>   zplanck_gen._argcheck%  s    {r2   c                 L    t          |            t          | |z            z  S r4   )r   r   )r.   rI   r  s      r/   rP   zplanck_gen._pmf(  s$    whWHQJ//r2   c                 N    t          |          }t          | |dz   z             S rD   )r   r   r.   rH   r  rI   s       r/   rT   zplanck_gen._cdf+  s(    !HHwh!n%%%%r2   c                 H    t          |                     ||                    S r4   )r   r  )r.   rH   r  s      r/   rX   zplanck_gen._sf/  s    4;;q'**+++r2   c                 2    t          |          }| |dz   z  S rD   r   r  s       r/   r  zplanck_gen._logsf2  s    !HHx1~r2   c                     t          d|z  t          |           z  dz
            } |dz
  j        |                     |           }|                     ||          }t          j        ||k    ||          S )N      r   )r   r   cliprB   rT   r+   r  )r.   r`   r  rz   r  r  s         r/   ra   zplanck_gen._ppf6  sp    DL5!99,Q.//a 1 1' : :<yy((x	5$///r2   Nc                 X    t          |            }|                    ||          dz
  S )Nr	  r   )r   r
  )r.   r  r7   r8   r'   s        r/   r9   zplanck_gen._rvs<  s0    G8__%%ad%33c99r2   c                     dt          |          z  }t          |           t          |           dz  z  }dt          |dz            z  }ddt          |          z  z   }||||fS )Nr   r   rf   r   )r   r   r   )r.   r  rk   rl   rm   rn   s         r/   rt   zplanck_gen._statsA  si    uW~~7(mmUG8__q00tGCK   qg3Br2   c                 p    t          |            }|t          |           z  |z  t          |          z
  S r4   )r   r   r   )r.   r  Cs      r/   r{   zplanck_gen._entropyH  s5    G8__sG8}}$Q&Q//r2   rd   )r~   r   r   r   r0   r>   rP   rT   rX   r  ra   r9   rt   r{   r   r2   r/   r  r    s         6K K K  0 0 0& & &, , ,  0 0 0: : : :
  0 0 0 0 0r2   r  planckzA discrete exponential c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
boltzmann_gena  A Boltzmann (Truncated Discrete Exponential) random variable.

    %(before_notes)s

    Notes
    -----
    The probability mass function for `boltzmann` is:

    .. math::

        f(k) = (1-\exp(-\lambda)) \exp(-\lambda k) / (1-\exp(-\lambda N))

    for :math:`k = 0,..., N-1`.

    `boltzmann` takes :math:`\lambda > 0` and :math:`N > 0` as shape parameters.

    %(after_notes)s

    %(example)s

    c                 z    t          dddt          j        fd          t          dddt          j        fd          gS )Nr  Fr   r   r'  Tr*   r-   s    r/   r0   zboltzmann_gen._shape_infof  s<    9ea[.II3q"&k>BBD 	Dr2   c                 <    |dk    |dk    z  t          |          z  S r   r<   r.   r  r'  s      r/   r>   zboltzmann_gen._argcheckj  s     !A&Q77r2   c                     | j         |dz
  fS rD   r@   r  s      r/   rB   zboltzmann_gen._get_supportm  s    vq1u}r2   c                     dt          |           z
  dt          | |z            z
  z  }|t          | |z            z  S rD   r   )r.   rI   r  r'  facts        r/   rP   zboltzmann_gen._pmfp  sB     #wh--!C
OO"34C
OO##r2   c                     t          |          }dt          | |dz   z            z
  dt          | |z            z
  z  S rD   )r   r   )r.   rH   r  r'  rI   s        r/   rT   zboltzmann_gen._cdfv  s@    !HH#wh!n%%%#whqj//(9::r2   c                 ,   |dt          | |z            z
  z  }t          d|z  t          d|z
            z  dz
            }|dz
                      dt          j                  }|                     |||          }t	          j        ||k    ||          S )Nr   r  rj  )r   r   r   r  r+   r,   rT   r  )r.   r`   r  r'  qnewrz   r  r  s           r/   ra   zboltzmann_gen._ppfz  s    !C
OO#$DL3qv;;.q011ac26**yy++x	5$///r2   c                    t          |           }t          | |z            }|d|z
  z  ||z  d|z
  z  z
  }|d|z
  dz  z  ||z  |z  d|z
  dz  z  z
  }d|z
  d|z
  z  }||dz  z  ||z  |z  z
  }|d|z   z  |dz  z  |dz  |z  d|z   z  z
  }	|	|dz  z  }	|dd|z  z   ||z  z   z  |dz  z  |dz  |z  dd|z  z   ||z  z   z  z
  }
|
|z  |z  }
|||	|
fS )Nr   r   r   r   rw  r   r  )r.   r  r'  zzNrk   rl   trmtrm2rm   rn   s              r/   rt   zboltzmann_gen._stats  s,   MM'!__AYqtQrT{"Q
lQqSVQrTAI--tacl#q&1Q3r6!!WS!V^ad2gqtn,$+!A#ac	]36!AqD2Iq2vbe|$<<$Y3Br2   N)r~   r   r   r   r0   r>   rB   rP   rT   ra   rt   r   r2   r/   r  r  P  s         *D D D8 8 8  $ $ $; ; ;0 0 0    r2   r  	boltzmannz!A truncated discrete exponential )r   rA   r"  c                   J    e 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	S )randint_gena  A uniform discrete random variable.

    %(before_notes)s

    Notes
    -----
    The probability mass function for `randint` is:

    .. math::

        f(k) = \frac{1}{\texttt{high} - \texttt{low}}

    for :math:`k \in \{\texttt{low}, \dots, \texttt{high} - 1\}`.

    `randint` takes :math:`\texttt{low}` and :math:`\texttt{high}` as shape
    parameters.

    %(after_notes)s

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

    Calculate the first four moments:

    >>> low, high = 7, 31
    >>> mean, var, skew, kurt = randint.stats(low, high, moments='mvsk')

    Display the probability mass function (``pmf``):

    >>> x = np.arange(low - 5, high + 5)
    >>> ax.plot(x, randint.pmf(x, low, high), 'bo', ms=8, label='randint pmf')
    >>> ax.vlines(x, 0, randint.pmf(x, low, high), colors='b', lw=5, alpha=0.5)

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

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

    >>> rv = randint(low, high)
    >>> ax.vlines(x, 0, rv.pmf(x), colors='k', linestyles='-',
    ...           lw=1, label='frozen pmf')
    >>> ax.legend(loc='lower center')
    >>> plt.show()

    Check the relationship between the cumulative distribution function
    (``cdf``) and its inverse, the percent point function (``ppf``):

    >>> q = np.arange(low, high)
    >>> p = randint.cdf(q, low, high)
    >>> np.allclose(q, randint.ppf(p, low, high))
    True

    Generate random numbers:

    >>> r = randint.rvs(low, high, size=1000)

    c                     t          ddt          j         t          j        fd          t          ddt          j         t          j        fd          gS )NlowTr   highr*   r-   s    r/   r0   zrandint_gen._shape_info  sF    5$"&"&(9>JJ6426'26):NKKM 	Mr2   c                 N    ||k    t          |          z  t          |          z  S r4   r<   r.   r  r  s      r/   r>   zrandint_gen._argcheck  s&    s
k#...T1B1BBBr2   c                     ||dz
  fS rD   r   r  s      r/   rB   zrandint_gen._get_support  s    DF{r2   c                     t          j        |          t          j        |t           j                  |z
  z  }t          j        ||k    ||k     z  |d          S )Nr   rj  )r+   	ones_likerK  int64r  )r.   rI   r  r  r'   s        r/   rP   zrandint_gen._pmf  sK    LOOrz$bh???#EFxca$h/B777r2   c                 <    t          |          }||z
  dz   ||z
  z  S r   r  )r.   rH   r  r  rI   s        r/   rT   zrandint_gen._cdf  s$    !HHC",,r2   c                     t          |||z
  z  |z             dz
  }|dz
                      ||          }|                     |||          }t          j        ||k    ||          S rD   )r   r  rT   r+   r  )r.   r`   r  r  rz   r  r  s          r/   ra   zrandint_gen._ppf  sf    A$s*++a/T**yyT**x	5$///r2   c                     t          j        |          t          j        |          }}||z   dz
  dz  }||z
  }||z  dz
  dz  }d}d||z  dz   z  ||z  dz
  z  }	||||	fS )Nr   r   r   g      (@rj  g333333)r+   rK  )
r.   r  r  m2m1rk   drl   rm   rn   s
             r/   rt   zrandint_gen._stats  s|    D!!2:c??B2gmq GsQw$1s#qsSy13Br2   Nc                    t          j        |          j        dk    r0t          j        |          j        dk    rt          ||||          S |*t          j        ||          }t          j        ||          }t          j        t          t          |          t          j        t                    g          } |||          S )z=An array of *size* random integers >= ``low`` and < ``high``.r   r	  N)otypes)	r+   rK  r7   r
   broadcast_to	vectorizer   r   r`  )r.   r  r  r7   r8   randints         r/   r9   zrandint_gen._rvs  s    :c??1$$D)9)9)>!)C)Cc4dCCCC
 /#t,,C?4..D,w|\BB')x}}o7 7 7wsD!!!r2   c                 &    t          ||z
            S r4   )r   r  s      r/   r{   zrandint_gen._entropy  s    4#:r2   rd   )r~   r   r   r   r0   r>   rB   rP   rT   ra   rt   r9   r{   r   r2   r/   r  r    s        = =~M M MC C C  8 8 8
- - -0 0 0  " " " ""    r2   r  r  z#A discrete uniform (random integer)c                   2    e Zd ZdZd ZddZd Zd Zd ZdS )	zipf_gena  A Zipf (Zeta) discrete random variable.

    %(before_notes)s

    See Also
    --------
    zipfian

    Notes
    -----
    The probability mass function for `zipf` is:

    .. math::

        f(k, a) = \frac{1}{\zeta(a) k^a}

    for :math:`k \ge 1`, :math:`a > 1`.

    `zipf` takes :math:`a > 1` as shape parameter. :math:`\zeta` is the
    Riemann zeta function (`scipy.special.zeta`)

    The Zipf distribution is also known as the zeta distribution, which is
    a special case of the Zipfian distribution (`zipfian`).

    %(after_notes)s

    References
    ----------
    .. [1] "Zeta Distribution", Wikipedia,
           https://en.wikipedia.org/wiki/Zeta_distribution

    %(example)s

    Confirm that `zipf` is the large `n` limit of `zipfian`.

    >>> import numpy as np
    >>> from scipy.stats import zipf, zipfian
    >>> k = np.arange(11)
    >>> np.allclose(zipf.pmf(k, a), zipfian.pmf(k, a, n=10000000))
    True

    c                 @    t          dddt          j        fd          gS )NrA   Fr   r   r*   r-   s    r/   r0   zzipf_gen._shape_info;      326{NCCDDr2   Nc                 0    |                     ||          S r*  )zipf)r.   rA   r7   r8   s       r/   r9   zzipf_gen._rvs>  s       ...r2   c                     |dk    S rD   r   r.   rA   s     r/   r>   zzipf_gen._argcheckA  s    1ur2   c                     |                     t          j                  }dt          j        |d          z  || z  z  }|S Nr   r   )r   r+   float64r   r	   )r.   rI   rA   r  s       r/   rP   zzipf_gen._pmfD  s;    HHRZ  7<1%%%A2-	r2   c                 Z    t          j        ||dz   k    ||fd t          j                  S )Nr   c                 ^    t          j        | |z
  d          t          j        | d          z  S rD   )r   r	   )rA   r%   s     r/   ri  z zipf_gen._munp.<locals>.<lambda>M  s'    a!eQ//',q!2D2DD r2   r   r  )r.   r%   rA   s      r/   _munpzzipf_gen._munpJ  s7    AI1vDDv   	r2   rd   )	r~   r   r   r   r0   r9   r>   rP   r  r   r2   r/   r  r    sr        ) )VE E E/ / / /        r2   r  r  zA Zipfc                 J    t          |d          t          || dz             z
  S )z"Generalized harmonic number, a > 1r   )r	   r%   rA   s     r/   _gen_harmonic_gt1r  T  s#     1::Q!$$r2   c                 V   t          j        |           s| S t          j        |           }t          j        |t                    }t          j        |ddt                    D ]$}|| k    }||xx         d|||         z  z  z  cc<   %t           j        |t          j        |           <   |S )z#Generalized harmonic number, a <= 1r  r   r   )r+   r7   nanmax
zeros_likefloatrJ  nanisnan)r%   rA   n_maxoutimasks         r/   _gen_harmonic_leq1r  Z  s    71:: IaLLE
-
'
'
'CYua5111 " "AvD			Qq!D'z\!				vCJr2   c                     t          j        | |          \  } }t          j        |dk    | |ft          t
                    S )zGeneralized harmonic numberr   )r+   r   r  r  r  r  r  s     r/   _gen_harmonicr  h  s8    q!$$DAq?1q51a&*;=OPPPr2   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
zipfian_gena  A Zipfian discrete random variable.

    %(before_notes)s

    See Also
    --------
    zipf

    Notes
    -----
    The probability mass function for `zipfian` is:

    .. math::

        f(k, a, n) = \frac{1}{H_{n,a} k^a}

    for :math:`k \in \{1, 2, \dots, n-1, n\}`, :math:`a \ge 0`,
    :math:`n \in \{1, 2, 3, \dots\}`.

    `zipfian` takes :math:`a` and :math:`n` as shape parameters.
    :math:`H_{n,a}` is the :math:`n`:sup:`th` generalized harmonic
    number of order :math:`a`.

    The Zipfian distribution reduces to the Zipf (zeta) distribution as
    :math:`n \rightarrow \infty`.

    %(after_notes)s

    References
    ----------
    .. [1] "Zipf's Law", Wikipedia, https://en.wikipedia.org/wiki/Zipf's_law
    .. [2] Larry Leemis, "Zipf Distribution", Univariate Distribution
           Relationships. http://www.math.wm.edu/~leemis/chart/UDR/PDFs/Zipf.pdf

    %(example)s

    Confirm that `zipfian` reduces to `zipf` for large `n`, ``a > 1``.

    >>> import numpy as np
    >>> from scipy.stats import zipf, zipfian
    >>> k = np.arange(11)
    >>> np.allclose(zipfian.pmf(k, a=3.5, n=10000000), zipf.pmf(k, a=3.5))
    True

    c                 z    t          dddt          j        fd          t          dddt          j        fd          gS )NrA   Fr   r&   r%   Tr   r*   r-   s    r/   r0   zzipfian_gen._shape_info  s<    326{MBB3q"&k>BBD 	Dr2   c                 \    |dk    |dk    z  |t          j        |t                    k    z  S )Nr   r  )r+   rK  r`  r.   rA   r%   s      r/   r>   zzipfian_gen._argcheck  s.    Q1q5!Q"*Qc*B*B*B%BCCr2   c                 
    d|fS rD   r   r  s      r/   rB   zzipfian_gen._get_support  r   r2   c                 t    |                     t          j                  }dt          ||          z  || z  z  S r   )r   r+   r  r  r.   rI   rA   r%   s       r/   rP   zzipfian_gen._pmf  s5    HHRZ  ]1a(((1qb500r2   c                 l    t          j        |          }t          ||          t          ||          z  S r4   r+   r   r  r  s       r/   rT   zzipfian_gen._cdf  s.    HQKKQ""]1a%8%888r2   c                     t          j        |dz             }||z  t          ||          t          ||          z
  z  dz   ||z  t          ||          z  z  S rD   r  r  s       r/   rX   zzipfian_gen._sf  s]    HQUOOA}Q**]1a-@-@@AAEa4a+++- 	.r2   c                    t          ||          }t          ||dz
            }t          ||dz
            }t          ||dz
            }t          ||dz
            }||z  }||z  |dz  z
  }	|dz  }
|	|
z  }||z  d|z  |z  |dz  z  z
  d|dz  z  |dz  z  z   |dz  z  }|dz  |z  d|dz  z  |z  |z  z
  d|z  |dz  z  |z  z   d|dz  z  z
  |	dz  z  }|dz  }||||fS )Nr   r   r   r   rw  r   )r  )r.   rA   r%   HnaHna1Hna2Hna3Hna4mu1mu2nmu2dmu2rm   rn   s                 r/   rt   zzipfian_gen._stats  s5   Aq!!Q!$$Q!$$Q!$$Q!$$3hS47"AvTk3h4S!V++aaiQ.>>c
J1fTkAc1fHTM$..3tQwt1CC$'	!1W%
aCRr2   N)r~   r   r   r   r0   r>   rB   rP   rT   rX   rt   r   r2   r/   r  r  n  s        , ,\D D DD D D  1 1 19 9 9. . .         r2   r  zipfianz	A Zipfianc                   >    e Zd ZdZd Zd Zd Zd Zd Zd Z	d
d	Z
dS )dlaplace_genaL  A  Laplacian discrete random variable.

    %(before_notes)s

    Notes
    -----
    The probability mass function for `dlaplace` is:

    .. math::

        f(k) = \tanh(a/2) \exp(-a |k|)

    for integers :math:`k` and :math:`a > 0`.

    `dlaplace` takes :math:`a` as shape parameter.

    %(after_notes)s

    %(example)s

    c                 @    t          dddt          j        fd          gS )NrA   Fr   r   r*   r-   s    r/   r0   zdlaplace_gen._shape_info  r  r2   c                 h    t          |dz            t          | t          |          z            z  S Nrf   )r   r   abs)r.   rI   rA   s      r/   rP   zdlaplace_gen._pmf  s+    AcE{{S!c!ff----r2   c                 f    t          |          }d }d }t          j        |dk    ||f||          S )Nc                 T    dt          | | z            t          |          dz   z  z
  S r  r  rI   rA   s     r/   r   zdlaplace_gen._cdf.<locals>.f1  s(    aR!VA
333r2   c                 R    t          || dz   z            t          |          dz   z  S rD   r  r  s     r/   f2zdlaplace_gen._cdf.<locals>.f2  s'    qAE{##s1vvz22r2   r   )r   r  r  )r.   rH   rA   rI   r   r  s         r/   rT   zdlaplace_gen._cdf  sK    !HH	4 	4 	4	3 	3 	3 qAv1vr2666r2   c           
      \   dt          |          z   }t          t          j        |ddt          |           z   z  k     t	          ||z            |z  dz
  t	          d|z
  |z             |z                      }|dz
  }t          j        |                     ||          |k    ||          S )Nr   r   )r   r   r+   r  r   rT   )r.   r`   rA   constrz   r  s         r/   ra   zdlaplace_gen._ppf  s    CFF
BHQCGG!44 5\\A-1!1Q3%-000146 6 7 7 qx		%++q0%>>>r2   c                     t          |          }d|z  |dz
  dz  z  }d|z  |dz  d|z  z   dz   z  |dz
  dz  z  }d|d||dz  z  dz
  fS )Nrf   r   r   g      $@r   rj  r   r  )r.   rA   ear  r|  s        r/   rt   zdlaplace_gen._stats  si    VVeRUQJeRU3r6\"_%B
23CQJO++r2   c                 f    |t          |          z  t          t          |dz                      z
  S r  )r   r   r   r  s     r/   r{   zdlaplace_gen._entropy  s)    477{Sae----r2   Nc                     t          j        t          j        |                      }|                    ||          }|                    ||          }||z
  S r*  )r+   r   rK  r
  )r.   rA   r7   r8   probOfSuccessrH   ys          r/   r9   zdlaplace_gen._rvs  sY      2:a==.111""=t"<<""=t"<<1ur2   rd   )r~   r   r   r   r0   rP   rT   ra   rt   r{   r9   r   r2   r/   r	  r	    s         ,E E E. . .	7 	7 	7? ? ?, , ,. . .     r2   r	  dlaplacezA discrete Laplacianc                   J    e Zd ZdZd Zd ZddddZd Zd Zd	 Z	d
 Z
d ZdS )poisson_binom_genul  A Poisson Binomial discrete random variable.

    %(before_notes)s

    See Also
    --------
    binom

    Notes
    -----
    The probability mass function for `poisson_binom` is:

    .. math::

     f(k; p_1, p_2, ..., p_n) = \sum_{A \in F_k} \prod_{i \in A} p_i \prod_{j \in A^C} 1 - p_j

    where :math:`k \in \{0, 1, \dots, n-1, n\}`, :math:`F_k` is the set of all
    subsets of :math:`k` integers that can be selected :math:`\{0, 1, \dots, n-1, n\}`,
    and :math:`A^C` is the complement of a set :math:`A`.

    `poisson_binom` accepts a single array argument ``p`` for shape parameters
    :math:`0 ≤ p_i ≤ 1`, where the last axis corresponds with the index :math:`i` and
    any others are for batch dimensions. Broadcasting behaves according to the usual
    rules except that the last axis of ``p`` is ignored. Instances of this class do
    not support serialization/unserialization.

    %(after_notes)s

    References
    ----------
    .. [1] "Poisson binomial distribution", Wikipedia,
           https://en.wikipedia.org/wiki/Poisson_binomial_distribution
    .. [2] Biscarri, William, Sihai Dave Zhao, and Robert J. Brunner. "A simple and
           fast method for computing the Poisson binomial distribution function".
           Computational Statistics & Data Analysis 122 (2018) 92-100.
           :doi:`10.1016/j.csda.2018.01.007`

    %(example)s

    c                     g S r4   r   r-   s    r/   r0   zpoisson_binom_gen._shape_infoH  s	     	r2   c                 t    t          j        |d          }d|k    |dk    z  }t          j        |d          S Nr   rv   r   )r+   stackall)r.   argsr'   condss       r/   r>   zpoisson_binom_gen._argcheckM  s=    HT"""aAF#ve!$$$$r2   Nr   c                *   t          j        |d          }||j        n)t          j        |          r|dfnt	          |          dz   }t          j        |j        |          }t                              |||                              d          S )Nr  rv   r   )r   r   )	r+   r!  shapeisscalartuplebroadcast_shapesr   r9   ry   )r.   r7   r8   r#  r'   s        r/   r9   zpoisson_binom_gen._rvsR  s    HT###  <[..Fq		E$KK$4F 	"17D11~~ad~FFJJPRJSSSr2   c                 $    dt          |          fS r   )len)r.   r#  s     r/   rB   zpoisson_binom_gen._get_support\  s    #d))|r2   c                     t          j        |                              t           j                  }t          j        |g|R  ^}}t          j        |t           j                  }t          ||d          S )Nr  rD  r+   
atleast_1dr   r  r   rK  r  r    r.   rI   r#  s      r/   rP   zpoisson_binom_gen._pmf_  e    M!##BH--&q04000Dz$bj111au---r2   c                     t          j        |                              t           j                  }t          j        |g|R  ^}}t          j        |t           j                  }t          ||d          S )Nr  r   r-  r/  s      r/   rT   zpoisson_binom_gen._cdfe  r0  r2   c                     t          j        |d          }t          j        |d          }t          j        |d|z
  z  d          }||d d fS r   )r+   r!  ry   )r.   r#  kwdsr'   r   rl   s         r/   rt   zpoisson_binom_gen._statsk  sU    HT"""vaa   fQ!A#YQ'''c4&&r2   c                 "    t          | g|R i |S r4   )poisson_binomial_frozen)r.   r#  r3  s      r/   __call__zpoisson_binom_gen.__call__q  s     &t;d;;;d;;;r2   )r~   r   r   r   r0   r>   r9   rB   rP   rT   rt   r6  r   r2   r/   r  r    s        ' 'P  
% % %
  $$ T T T T T  . . .. . .' ' '< < < < <r2   r  poisson_binomzA Poisson binomialr'   )r   r"  shapesc                 P    t          t          j        |dd                    |d|fS Nr  r   r   r(  r+   moveaxis)r.   r'   locr7   s       r/   _parse_args_rvsr>  }  s'    QA&&''c477r2   rb   c                 P    t          t          j        |dd                    |d|fS r:  r;  )r.   r'   r=  rj   s       r/   _parse_args_statsr@    s'    QA&&''c7::r2   c                 N    t          t          j        |dd                    |dfS r:  r;  )r.   r'   r=  s      r/   _parse_argsrB    s%    QA&&''c11r2   c                       e Zd Zd ZddZdS )r5  c                    || _         || _         |j        di |                                | _        t
                              t          t                    | j        _        t                              t          t                    | j        _	        t                              t          t                    | j        _
         | j        j
        |i |\  }}} | j        j        | \  | _        | _        d S )Nr   )r#  r3  	__class___updated_ctor_paramdistr>  __get___pb_obj_pb_clsr@  rB  rB   rA   r   )r.   rG  r#  r3  r8  _s         r/   __init__z poisson_binomial_frozen.__init__  s    		 #DN@@T%=%=%?%?@@	 %4$;$;GW$M$M	!&7&?&?&Q&Q	# + 3 3GW E E	,ty,d;d;;1//8r2   NFc                 |     | j         j        | j        i | j        \  }}} | j         j        || j        ||||fi |S r4   )rG  rB  r#  r3  expect)	r.   funclbubconditionalr3  rA   r=  scales	            r/   rN  zpoisson_binomial_frozen.expect  sP    -	-tyFDIFF3  tydib"kRRTRRRr2   )NNNF)r~   r   r   rL  rN  r   r2   r/   r5  r5    s=        9 9 9S S S S S Sr2   r5  c                   2    e Zd ZdZd ZddZd Zd Zd ZdS )	skellam_gena  A  Skellam discrete random variable.

    %(before_notes)s

    Notes
    -----
    Probability distribution of the difference of two correlated or
    uncorrelated Poisson random variables.

    Let :math:`k_1` and :math:`k_2` be two Poisson-distributed r.v. with
    expected values :math:`\lambda_1` and :math:`\lambda_2`. Then,
    :math:`k_1 - k_2` follows a Skellam distribution with parameters
    :math:`\mu_1 = \lambda_1 - \rho \sqrt{\lambda_1 \lambda_2}` and
    :math:`\mu_2 = \lambda_2 - \rho \sqrt{\lambda_1 \lambda_2}`, where
    :math:`\rho` is the correlation coefficient between :math:`k_1` and
    :math:`k_2`. If the two Poisson-distributed r.v. are independent then
    :math:`\rho = 0`.

    Parameters :math:`\mu_1` and :math:`\mu_2` must be strictly positive.

    For details see: https://en.wikipedia.org/wiki/Skellam_distribution

    `skellam` takes :math:`\mu_1` and :math:`\mu_2` as shape parameters.

    %(after_notes)s

    %(example)s

    c                 z    t          dddt          j        fd          t          dddt          j        fd          gS )Nr  Fr   r   r  r*   r-   s    r/   r0   zskellam_gen._shape_info  s<    5%!RVnEE5%!RVnEEG 	Gr2   Nc                 `    |}|                     ||          |                     ||          z
  S r4   r  )r.   r  r  r7   r8   r%   s         r/   r9   zskellam_gen._rvs  s7    $$S!,,$$S!,,- 	.r2   c                     t          j        d          5  t          j        |dk     t          j        d|z  dd|z
  z  d|z            dz  t          j        d|z  dd|z   z  d|z            dz            }d d d            n# 1 swxY w Y   |S )Nr   r   r   r   r   )r+   r   r  rM   	_ncx2_pdfr.   rH   r  r  pxs        r/   rP   zskellam_gen._pmf  s    [h''' 	B 	B!a%-#q!A#w#>>q@-#q!A#w#>>q@B BB	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B
 	s   A!BB
Bc                 2   t          |          }t          j        d          5  t          j        |dk     t	          j        d|z  d|z  d|z            dt	          j        d|z  d|dz   z  d|z            z
            }d d d            n# 1 swxY w Y   |S )Nr   r   r   r   r   )r   r+   r   r  rM   	_ncx2_cdfrZ  s        r/   rT   zskellam_gen._cdf  s    !HH[h''' 	D 	D!a%-#r!tQsU;;cmAcE1ac7AcEBBBD DB	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	s   ABBBc                 V    ||z
  }||z   }|t          |dz            z  }d|z  }||||fS )Nr   r   r   )r.   r  r  r   rl   rm   rn   s          r/   rt   zskellam_gen._stats  s@    SyCiD#NN"WS"b  r2   rd   )	r~   r   r   r   r0   r9   rP   rT   rt   r   r2   r/   rU  rU    sq         :G G G. . . .
    ! ! ! ! !r2   rU  skellamz	A Skellamc                   J    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S )yulesimon_gena  A Yule-Simon discrete random variable.

    %(before_notes)s

    Notes
    -----

    The probability mass function for the `yulesimon` is:

    .. math::

        f(k) =  \alpha B(k, \alpha+1)

    for :math:`k=1,2,3,...`, where :math:`\alpha>0`.
    Here :math:`B` refers to the `scipy.special.beta` function.

    The sampling of random variates is based on pg 553, Section 6.3 of [1]_.
    Our notation maps to the referenced logic via :math:`\alpha=a-1`.

    For details see the wikipedia entry [2]_.

    References
    ----------
    .. [1] Devroye, Luc. "Non-uniform Random Variate Generation",
         (1986) Springer, New York.

    .. [2] https://en.wikipedia.org/wiki/Yule-Simon_distribution

    %(after_notes)s

    %(example)s

    c                 @    t          dddt          j        fd          gS )NalphaFr   r   r*   r-   s    r/   r0   zyulesimon_gen._shape_info	  s    7EArv;GGHHr2   Nc           	          |                     |          }|                     |          }t          | t          t          | |z                       z            }|S r4   )standard_exponentialr   r   r   )r.   rd  r7   r8   E1E2anss          r/   r9   zyulesimon_gen._rvs  sZ    ..t44..t44B3RC%K 0 0011122
r2   c                 8    |t          j        ||dz             z  S rD   r   r   r.   rH   rd  s      r/   rP   zyulesimon_gen._pmf  s    w|Auqy1111r2   c                     |dk    S r   r   )r.   rd  s     r/   r>   zyulesimon_gen._argcheck  s    	r2   c                 R    t          |          t          j        ||dz             z   S rD   r   r   r   rl  s      r/   rK   zyulesimon_gen._logpmf  s#    5zzGN1eai8888r2   c                 >    d|t          j        ||dz             z  z
  S rD   rk  rl  s      r/   rT   zyulesimon_gen._cdf  s"    1w|Auqy11111r2   c                 8    |t          j        ||dz             z  S rD   rk  rl  s      r/   rX   zyulesimon_gen._sf  s    7<519----r2   c                 R    t          |          t          j        ||dz             z   S rD   ro  rl  s      r/   r  zyulesimon_gen._logsf!  s#    1vvq%!)4444r2   c                    t          j        |dk    t           j        ||dz
  z            }t          j        |dk    |dz  |dz
  |dz
  dz  z  z  t           j                  }t          j        |dk    t           j        |          }t          j        |dk    t	          |dz
            |dz   dz  z  ||dz
  z  z  t           j                  }t          j        |dk    t           j        |          }t          j        |dk    |dz   d|dz  z  d|z  z
  dz
  ||dz
  z  |dz
  z  z  z   t           j                  }t          j        |dk    t           j        |          }||||fS )	Nr   r   rf   r   r      1      )r+   r  r,   r  r   )r.   rd  rk   r  rm   rn   s         r/   rt   zyulesimon_gen._stats$  s\   Xeqj"&%519*=>>huqyaxECKEAI>#ABv  huz263//Xeai519ooQ6%519:MNf  Xeqj"&"--XeaiaiBMBJ$>$C$)UQY$7519$E$G Hf  Xeqj"&"--3Br2   rd   )r~   r   r   r   r0   r9   rP   r>   rK   rT   rX   r  rt   r   r2   r/   rb  rb    s           BI I I   2 2 2  9 9 92 2 2. . .5 5 5    r2   rb  	yulesimon)r   rA   c                   B    e Zd ZdZdZdZd Zd Zd Zd
dZ	d Z
dd	ZdS )_nchypergeom_genzA noncentral hypergeometric discrete random variable.

    For subclassing by nchypergeom_fisher_gen and nchypergeom_wallenius_gen.

    Nc           	          t          ddd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&  Tr   r&   r%   r'  oddsFr   r*   r-   s    r/   r0   z_nchypergeom_gen._shape_infoC  sj    3q"&k=AA3q"&k=AA3q"&k=AA651bf+~FFH 	Hr2   c                 z    |||}}}||z
  }t          j        d||z
            }t          j        ||          }||fS r   r-  )	r.   r&  r%   r'  r{  r  r  x_minx_maxs	            r/   rB   z_nchypergeom_gen._get_supportI  sH    aq2V
1a"f%%
1b!!e|r2   c                 J   t          j        |          t          j        |          }}t          j        |          t          j        |          }}t          j        |           |                    t                    |k    z  |dk    z  }t          j        |           |                    t                    |k    z  |dk    z  }t          j        |           |                    t                    |k    z  |dk    z  }|dk    }||k    }	||k    }
||z  |z  |z  |	z  |
z  S r   )r+   rK  r  r   r`  )r.   r&  r%   r'  r{  cond1cond2cond3cond4cond5cond6s              r/   r>   z_nchypergeom_gen._argcheckP  s    z!}}bjmm1*Q--D!1!14(1++!((3--1"45a@(1++!((3--1"45a@(1++!((3--1"45a@qQQu}u$u,u4u<<r2   c                 J     t            fd            } |||||||          S )Nc                 z   t          j        |           t          j        |          z  t          j        |          z  rt          j        |t           j                  S t          j        |          }t                      }t          |
j                  } |||| |||          }	|	                    |          }	|	S r4   )	r+   r  fullr  prodr   getattrrvs_namereshape)r&  r%   r'  r{  r7   r8   lengthurnrv_genrd  r.   s             r/   re  z$_nchypergeom_gen._rvs.<locals>._rvs1]  s    x{{RXa[[(28A;;6 -wtRV,,,WT]]F#%%CS$-00F&Aq$==C++d##CJr2   r   rf  )r.   r&  r%   r'  r{  r7   r8   re  s   `       r/   r9   z_nchypergeom_gen._rvs[  sF    	#	 	 	 	 
$	#	 uQ1dLIIIIr2   c                      t          j        |||||          \  }}}}}|j        dk    rt          j        |          S t           j         fd            } ||||||          S )Nr   c                    t          j        |           t          j        |          z  t          j        |          z  t          j        |          z  rt           j        S                     ||||d          }|                    |           S Ng-q=)r+   r  r  rG  probability)rH   r&  r%   r'  r{  r  r.   s         r/   _pmf1z$_nchypergeom_gen._pmf.<locals>._pmf1p  sl    x{{RXa[[(28A;;6!D v))Aq!T511C??1%%%r2   )r+   r   r7   
empty_liker  )r.   rH   r&  r%   r'  r{  r  s   `      r/   rP   z_nchypergeom_gen._pmfj  s    .q!Q4@@1aD6Q;;=###		& 	& 	& 	& 
	& uQ1a&&&r2   rb   c                 ~     t           j         fd            }d|v sd|v r |||||          nd\  }}d\  }	}
|||	|
fS )Nc                 
   t          j        |           t          j        |          z  t          j        |          z  rt           j        t           j        fS                     ||| |d          }|                                S r  )r+   r  r  rG  rj   )r&  r%   r'  r{  r  r.   s        r/   	_moments1z*_nchypergeom_gen._stats.<locals>._moments1{  sb    x{{RXa[[(28A;;6 &vrv~%))Aq!T511C;;== r2   rA  vrd   )r+   r  )r.   r&  r%   r'  r{  rj   r  rA  r  re   rI   s   `          r/   rt   z_nchypergeom_gen._statsy  ss    		! 	! 	! 	! 
	! .1G^^sg~~		!Q4(((! 	11!Qzr2   rd   r|   )r~   r   r   r   r  rG  r0   rB   r>   r9   rP   rt   r   r2   r/   ry  ry  9  s          HDH H H  	= 	= 	=J J J J' ' '     r2   ry  c                       e Zd ZdZdZeZdS )nchypergeom_fisher_genag	  A Fisher's noncentral hypergeometric discrete random variable.

    Fisher's noncentral hypergeometric distribution models drawing objects of
    two types from a bin. `M` is the total number of objects, `n` is the
    number of Type I objects, and `odds` is the odds ratio: the odds of
    selecting a Type I object rather than a Type II object when there is only
    one object of each type.
    The random variate represents the number of Type I objects drawn if we
    take a handful of objects from the bin at once and find out afterwards
    that we took `N` objects.

    %(before_notes)s

    See Also
    --------
    nchypergeom_wallenius, hypergeom, nhypergeom

    Notes
    -----
    Let mathematical symbols :math:`N`, :math:`n`, and :math:`M` correspond
    with parameters `N`, `n`, and `M` (respectively) as defined above.

    The probability mass function is defined as

    .. math::

        p(x; M, n, N, \omega) =
        \frac{\binom{n}{x}\binom{M - n}{N-x}\omega^x}{P_0},

    for
    :math:`x \in [x_l, x_u]`,
    :math:`M \in {\mathbb N}`,
    :math:`n \in [0, M]`,
    :math:`N \in [0, M]`,
    :math:`\omega > 0`,
    where
    :math:`x_l = \max(0, N - (M - n))`,
    :math:`x_u = \min(N, n)`,

    .. math::

        P_0 = \sum_{y=x_l}^{x_u} \binom{n}{y}\binom{M - n}{N-y}\omega^y,

    and the binomial coefficients are defined as

    .. math:: \binom{n}{k} \equiv \frac{n!}{k! (n - k)!}.

    `nchypergeom_fisher` uses the BiasedUrn package by Agner Fog with
    permission for it to be distributed under SciPy's license.

    The symbols used to denote the shape parameters (`N`, `n`, and `M`) are not
    universally accepted; they are chosen for consistency with `hypergeom`.

    Note that Fisher's noncentral hypergeometric distribution is distinct
    from Wallenius' noncentral hypergeometric distribution, which models
    drawing a pre-determined `N` objects from a bin one by one.
    When the odds ratio is unity, however, both distributions reduce to the
    ordinary hypergeometric distribution.

    %(after_notes)s

    References
    ----------
    .. [1] Agner Fog, "Biased Urn Theory".
           https://cran.r-project.org/web/packages/BiasedUrn/vignettes/UrnTheory.pdf

    .. [2] "Fisher's noncentral hypergeometric distribution", Wikipedia,
           https://en.wikipedia.org/wiki/Fisher's_noncentral_hypergeometric_distribution

    %(example)s

    
rvs_fisherN)r~   r   r   r   r  r   rG  r   r2   r/   r  r    s'        G GR H%DDDr2   r  nchypergeom_fisherz$A Fisher's noncentral hypergeometricc                       e Zd ZdZdZeZdS )nchypergeom_wallenius_gena}	  A Wallenius' noncentral hypergeometric discrete random variable.

    Wallenius' noncentral hypergeometric distribution models drawing objects of
    two types from a bin. `M` is the total number of objects, `n` is the
    number of Type I objects, and `odds` is the odds ratio: the odds of
    selecting a Type I object rather than a Type II object when there is only
    one object of each type.
    The random variate represents the number of Type I objects drawn if we
    draw a pre-determined `N` objects from a bin one by one.

    %(before_notes)s

    See Also
    --------
    nchypergeom_fisher, hypergeom, nhypergeom

    Notes
    -----
    Let mathematical symbols :math:`N`, :math:`n`, and :math:`M` correspond
    with parameters `N`, `n`, and `M` (respectively) as defined above.

    The probability mass function is defined as

    .. math::

        p(x; N, n, M) = \binom{n}{x} \binom{M - n}{N-x}
        \int_0^1 \left(1-t^{\omega/D}\right)^x\left(1-t^{1/D}\right)^{N-x} dt

    for
    :math:`x \in [x_l, x_u]`,
    :math:`M \in {\mathbb N}`,
    :math:`n \in [0, M]`,
    :math:`N \in [0, M]`,
    :math:`\omega > 0`,
    where
    :math:`x_l = \max(0, N - (M - n))`,
    :math:`x_u = \min(N, n)`,

    .. math::

        D = \omega(n - x) + ((M - n)-(N-x)),

    and the binomial coefficients are defined as

    .. math:: \binom{n}{k} \equiv \frac{n!}{k! (n - k)!}.

    `nchypergeom_wallenius` uses the BiasedUrn package by Agner Fog with
    permission for it to be distributed under SciPy's license.

    The symbols used to denote the shape parameters (`N`, `n`, and `M`) are not
    universally accepted; they are chosen for consistency with `hypergeom`.

    Note that Wallenius' noncentral hypergeometric distribution is distinct
    from Fisher's noncentral hypergeometric distribution, which models
    take a handful of objects from the bin at once, finding out afterwards
    that `N` objects were taken.
    When the odds ratio is unity, however, both distributions reduce to the
    ordinary hypergeometric distribution.

    %(after_notes)s

    References
    ----------
    .. [1] Agner Fog, "Biased Urn Theory".
           https://cran.r-project.org/web/packages/BiasedUrn/vignettes/UrnTheory.pdf

    .. [2] "Wallenius' noncentral hypergeometric distribution", Wikipedia,
           https://en.wikipedia.org/wiki/Wallenius'_noncentral_hypergeometric_distribution

    %(example)s

    rvs_walleniusN)r~   r   r   r   r  r   rG  r   r2   r/   r  r    s'        G GR H'DDDr2   r  nchypergeom_walleniusz&A Wallenius' noncentral hypergeometric)r   N)r   rb   )r   )m	functoolsr   scipyr   scipy.specialr   r   r   r   rE   r	   scipy._lib._utilr
   scipy._lib.array_api_extra_libarray_api_extrar  scipy.interpolater   numpyr   r   r   r   r   r   r   r   r   r   r+   _distn_infrastructurer   r   r   r   r   r   
_biasedurnr   r   r   _stats_pythranr    scipy.special._ufuncs_ufuncsrM   r"   r   r   r   r   r   r   r   r   r  r  r!  r$  rR  rT  rn  rp  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r,   r  r  r7  r>  r@  rB  rI  rJ  rH  r5  rU  r`  rb  rw  ry  r  r  r  r  listglobalscopyitemspairs_distn_names_distn_gen_names__all__r   r2   r/   <module>r     s/	  
             I I I I I I I I I I I I I I ) ) ) ) ) ) ( ( ( ( ( ( ( ( ( & & & & & & M M M M M M M M M M M M M M M M M M M M M M M M    8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8, , , , , , , , , , + * * * * * # # # # # # # # #]* ]* ]* ]* ]* ]* ]* ]*@ 		w># ># ># ># >#I ># ># >#B MAK000	O O O O OK O O Od M{+++	r
 r
 r
 r
 r
 r
 r
 r
j 
	"	"	"Z Z Z Z Z[ Z Z Zz ^...
N7 N7 N7 N7 N7{ N7 N7 N7b x!&=999X X X X XK X X Xv M{+++	[ [ [ [ [[ [ [ [| ^...
5 5 5 5 5 5 5 5p 
ah	A	A	A? ? ? ? ?+ ? ? ?D +9{
;
;
;D0 D0 D0 D0 D0 D0 D0 D0N 
ah1J	K	K	K< < < < <K < < <~ M{a#FH H H	t t t t t+ t t tn +9 0) * * *
? ? ? ? ?{ ? ? ?D x!&8444% % %  Q Q QW  W  W  W  W + W  W  W t +	K
@
@
@M M M M M; M M M` <26''2HJ J JS< S< S< S< S< S< S< S<l "!AU),. . .8 8 8 8; ; ; ;2 2 2 2
 !"3  / 7 7 I I "3";";GW"M"M '//AA S S S S S0 S S S0<! <! <! <! <!+ <! <! <!~ +i+
F
F
FL L L L LK L L L^ M{a000	L L L L L{ L L L^K& K& K& K& K&- K& K& K&\ ,+	35 5 5 
K( K( K( K( K( 0 K( K( K(\ 21	 57 7 7  	WWYY^^##%%&&!7!7{!K!K 
)
)r2   