
    9i                     v   S SK Jr  S SKJr  S SKJrJrJrJr	J
r
  S SKJr  S SKJs  Jr  S SKJr  S SKJrJrJrJrJrJrJrJrJrJr  S SKrSS	KJ r J!r!J"r"J#r#J$r$J%r%  SS
K&J'r'J(r(J)r)  SSK*J+r+  S SK,Js  J-r.   " S S\ 5      r/\/" SS9r0 " S S\/5      r1\1" SSS9r2 " S S\ 5      r3\3" SS9r4 " S S\ 5      r5\5" SS9r6 " S S\ 5      r7\7" SS9r8 " S S\ 5      r9\9" SSS S!9r: " S" S#\ 5      r;\;" S$S9r< " S% S&\ 5      r=\=" S'S9r> " S( S)\ 5      r?\?" SS*S+S!9r@ " S, S-\ 5      rA\A" S.S/S09rB " S1 S2\ 5      rC\C" S S3S4S!9rD " S5 S6\ 5      rE\E" S7S S8S99rF " S: S;\ 5      rG\G" S<S=S09rH " S> S?\ 5      rI\I" SS@SAS!9rJSB rKSC rLSD rM " SE SF\ 5      rN\N" SSGSHS!9rO " SI SJ\ 5      rP\P" \R                  * SKSLS!9rR " SM SN\ 5      rS\S" SOSPSQSR9rTSjSS jrUSkST jrVSlSU jrW\T\SsrXrY\UR                  \X\Y5      \TlU        \VR                  \X\Y5      \TlV        \WR                  \X\Y5      \TlW         " SV SW\%5      r[ " SX SY\ 5      r\\\" \R                  * SZS[S!9r] " S\ S]\ 5      r^\^" S^SS_9r_ " S` Sa\ 5      r` " Sb Sc\`5      ra\a" SdSeS09rb " Sf Sg\`5      rc\c" ShSiS09rd\e" \f" 5       R                  5       R                  5       5      ri\!" \i\ 5      u  rjrk\j\k-   rlg)m    )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                   h    \ rS rSrSrS rSS jrS rS rS r	S	 r
S
 rS rS rS rSS jrS rSrg)	binom_gen   a  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                 Z    [        SSS[        R                  4S5      [        SSSS5      /$ 	NnTr   TFpFr   r   TTr   npinfselfs    \/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/scipy/stats/_discrete_distns.py_shape_infobinom_gen._shape_infoB   0    3q"&&k=A3v|<> 	>    Nc                 &    UR                  XU5      $ N)binomialr/   r&   r(   sizerandom_states        r0   _rvsbinom_gen._rvsF   s    $$Q400r4   c                 <    US:  [        U5      -  US:  -  US:*  -  $ Nr   r   r   r/   r&   r(   s      r0   	_argcheckbinom_gen._argcheckI   s'    Q+a.(AF3qAv>>r4   c                     U R                   U4$ r6   ar@   s      r0   _get_supportbinom_gen._get_supportL   s    vvqyr4   c                     [        U5      n[        US-   5      [        US-   5      [        X$-
  S-   5      -   -
  nU[        R                  " XC5      -   [        R                  " X$-
  U* 5      -   $ Nr   )r   gamlnr   xlogyxlog1py)r/   xr&   r(   kcombilns         r0   _logpmfbinom_gen._logpmfO   s\    !H1:qseACEl!:;q,,wqsQB/GGGr4   c                 0    [         R                  " XU5      $ r6   )scu
_binom_pmfr/   rM   r&   r(   s       r0   _pmfbinom_gen._pmfT   s    ~~aA&&r4   c                 F    [        U5      n[        R                  " XBU5      $ r6   )r   rS   
_binom_cdfr/   rM   r&   r(   rN   s        r0   _cdfbinom_gen._cdfX       !H~~aA&&r4   c                 F    [        U5      n[        R                  " XBU5      $ r6   )r   rS   	_binom_sfrZ   s        r0   _sfbinom_gen._sf\   s    !H}}Q1%%r4   c                 0    [         R                  " XU5      $ r6   )rS   
_binom_isfrU   s       r0   _isfbinom_gen._isf`       ~~aA&&r4   c                 0    [         R                  " XU5      $ r6   )rS   
_binom_ppfr/   qr&   r(   s       r0   _ppfbinom_gen._ppfc   rf   r4   c                    X-  nXA[         R                  " U5      -  -
  nSu  pgSU;   aS  U[         R                  " U5      -
  n[         R                  " X-  5      n	[         R                  " U	5      n
SU-  U	-  nX-
  nSU;   a<  U[         R                  " U5      -
  nX-  n[         R                  " U5      n
SU-  nX-
  nXEXg4$ )NNNs       @rN         @)r,   squarer   
reciprocal)r/   r&   r(   momentsmuvarg1g2pqnpq_sqrtt1t2npqs                r0   _statsbinom_gen._statsf   s    Uryy|##'>RYYq\!BwwqvHx(B'X%BB'>RYYq\!B&Cs#BQBBr4   c                     [         R                  SUS-    nU R                  X1U5      n[         R                  " [	        U5      SS9$ )Nr   r   axis)r,   r_rV   sumr   )r/   r&   r(   rN   valss        r0   _entropybinom_gen._entropyx   s:    EE!AENyyq!vvd4jq))r4    rn   mv__name__
__module____qualname____firstlineno____doc__r1   r;   rA   rF   rP   rV   r[   r`   rd   rk   r~   r   __static_attributes__r   r4   r0   r"   r"      sE    "F>1?H
''&''$*r4   r"   binom)namec                   d    \ rS rSrSrS rSS jrS rS rS r	S	 r
S
 rS rS rS rS rS rSrg)bernoulli_gen   a  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                      [        SSSS5      /$ Nr(   Fr)   r*   r   r.   s    r0   r1   bernoulli_gen._shape_info       3v|<==r4   Nc                 .    [         R                  U SXUS9$ )Nr   r9   r:   )r"   r;   r/   r(   r9   r:   s       r0   r;   bernoulli_gen._rvs   s    ~~dAq,~OOr4   c                     US:  US:*  -  $ r>   r   r/   r(   s     r0   rA   bernoulli_gen._argcheck   s    Q16""r4   c                 2    U R                   U R                  4$ r6   )rE   br   s     r0   rF   bernoulli_gen._get_support   s    vvtvv~r4   c                 0    [         R                  USU5      $ rI   )r   rP   r/   rM   r(   s      r0   rP   bernoulli_gen._logpmf   s    }}Q1%%r4   c                 0    [         R                  USU5      $ rI   )r   rV   r   s      r0   rV   bernoulli_gen._pmf   s     zz!Q""r4   c                 0    [         R                  USU5      $ rI   )r   r[   r   s      r0   r[   bernoulli_gen._cdf       zz!Q""r4   c                 0    [         R                  USU5      $ rI   )r   r`   r   s      r0   r`   bernoulli_gen._sf   s    yyAq!!r4   c                 0    [         R                  USU5      $ rI   )r   rd   r   s      r0   rd   bernoulli_gen._isf   r   r4   c                 0    [         R                  USU5      $ rI   )r   rk   )r/   rj   r(   s      r0   rk   bernoulli_gen._ppf   r   r4   c                 .    [         R                  SU5      $ rI   )r   r~   r   s     r0   r~   bernoulli_gen._stats   s    ||Aq!!r4   c                 6    [        U5      [        SU-
  5      -   $ rI   )r   r   s     r0   r   bernoulli_gen._entropy   s    Awac""r4   r   rn   r   r   r4   r0   r   r      sD    0>P#&#
#"##"#r4   r   	bernoulli)r   r   c                   J    \ rS rSrSrS rSS jrS rS rS r	S	 r
SS
 jrSrg)betabinom_gen   a  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                     [        SSS[        R                  4S5      [        SSS[        R                  4S5      [        SSS[        R                  4S5      /$ 	Nr&   Tr   r'   rE   FFFr   r+   r.   s    r0   r1   betabinom_gen._shape_info   P    3q"&&k=A3266{NC3266{NCE 	Er4   Nc                 J    UR                  X#U5      nUR                  XU5      $ r6   )betar7   r/   r&   rE   r   r9   r:   r(   s          r0   r;   betabinom_gen._rvs   s'    aD)$$Q400r4   c                 
    SU4$ Nr   r   r/   r&   rE   r   s       r0   rF   betabinom_gen._get_support       !tr4   c                 <    US:  [        U5      -  US:  -  US:  -  $ r   r?   r   s       r0   rA   betabinom_gen._argcheck   '    Q+a.(AE2a!e<<r4   c                     [        U5      n[        US-   5      * [        X%-
  S-   US-   5      -
  nU[        XS-   X%-
  U-   5      -   [        X45      -
  $ rI   )r   r   r   r/   rM   r&   rE   r   rN   rO   s          r0   rP   betabinom_gen._logpmf   sS    !Hq1u:+quqy!a% 88quqy11F1L@@r4   c                 8    [        U R                  XX45      5      $ r6   r   rP   r/   rM   r&   rE   r   s        r0   rV   betabinom_gen._pmf       4<<a+,,r4   c                 (   X"U-   -  nSU-
  nX-  nXU-   U-   -  U-  U-  X#-   S-   -  nSu  pSU;   a/  S[        U5      -  n	XU-   SU-  -   X2-
  -  -  n	XU-   S-   X#-   -  -  n	SU;   a  X#-   R                  UR                  5      n
XU-   S-
  SU-  -   -  n
U
SU-  U-  US-
  -  -  n
U
SUS-  -  -  n
U
SU-  U-  U-  SU-
  -  -  n
U
S	U-  U-  US-  -  -  n
XU-   S-  SU-   U-   -  -  n
XU-  U-  X#-   S-   -  X#-   S-   -  X#-   U-   -  -  n
U
S-  n
XxX4$ )
Nr   rn   ro         ?   rN            )r   astypedtype)r/   r&   rE   r   rt   e_pe_qru   rv   rw   rx   s              r0   r~   betabinom_gen._stats   s   q5k#gWq519o#c)QUQY7'>tCyBq51q5=QU++Bq519''B'>%		*Bq519q1u$%B!a%!)q1u%%B!a1f*B!c'A+/QU++B"s(S.16))Bq5Q,!a%!),,Bq519	*aeai8AEAIFGB!GBr4   r   rn   r   )r   r   r   r   r   r1   r;   rF   rA   rP   rV   r~   r   r   r4   r0   r   r      s-    "FE
1=A
-r4   r   	betabinomc                   ^    \ rS rSrSrS rSS jrS rS rS r	S	 r
S
 rS rS rS rS rSrg)
nbinom_geni  a?  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                 Z    [        SSS[        R                  4S5      [        SSSS5      /$ r%   r+   r.   s    r0   r1   nbinom_gen._shape_infoU  r3   r4   Nc                 &    UR                  XU5      $ r6   )negative_binomialr8   s        r0   r;   nbinom_gen._rvsY  s    --aD99r4   c                 $    US:  US:  -  US:*  -  $ r>   r   r@   s      r0   rA   nbinom_gen._argcheck\  s    A!a% AF++r4   c                 0    [         R                  " XU5      $ r6   )rS   _nbinom_pmfrU   s       r0   rV   nbinom_gen._pmf_  s    qQ''r4   c                     [        X!-   5      [        US-   5      -
  [        U5      -
  nXB[        U5      -  -   [        R                  " X* 5      -   $ rI   )rJ   r   r   rL   )r/   rM   r&   r(   coeffs        r0   rP   nbinom_gen._logpmfc  sD    ac
U1Q3Z'%(2Qx'//!R"888r4   c                 F    [        U5      n[        R                  " XBU5      $ r6   )r   rS   _nbinom_cdfrZ   s        r0   r[   nbinom_gen._cdfg  s    !HqQ''r4   c                 B   [        U5      n[        R                  " XBU5      u  pBnU R                  XBU5      nUS:  nS nUn[        R                  " SS9   U" XF   X&   X6   5      X'   [        R
                  " XV)    5      X) '   S S S 5        U$ ! , (       d  f       U$ = f)N      ?c                 h    [         R                  " [        R                  " U S-   USU-
  5      * 5      $ rI   )r,   r   r   betainc)rN   r&   r(   s      r0   f1nbinom_gen._logcdf.<locals>.f1p  s)    88W__QUAq1u==>>r4   ignore)divide)r   r,   broadcast_arraysr[   errstater   )	r/   rM   r&   r(   rN   cdfcondr   logcdfs	            r0   _logcdfnbinom_gen._logcdfk  s    !H%%aA.aiia Sy	? [[)agqw8FLFF3u:.F5M *  *) s   /B
Bc                 F    [        U5      n[        R                  " XBU5      $ r6   )r   rS   
_nbinom_sfrZ   s        r0   r`   nbinom_gen._sfz  r]   r4   c                     [         R                  " SS9   [        R                  " XU5      sS S S 5        $ ! , (       d  f       g = fNr   over)r,   r   rS   _nbinom_isfrU   s       r0   rd   nbinom_gen._isf~  (    [[h'??1+ (''	   6
Ac                     [         R                  " SS9   [        R                  " XU5      sS S S 5        $ ! , (       d  f       g = fr  )r,   r   rS   _nbinom_ppfri   s       r0   rk   nbinom_gen._ppf  r  r  c                     [         R                  " X5      [         R                  " X5      [         R                  " X5      [         R                  " X5      4$ r6   )rS   _nbinom_mean_nbinom_variance_nbinom_skewness_nbinom_kurtosis_excessr@   s      r0   r~   nbinom_gen._stats  sD    Q"  &  &''-	
 	
r4   r   rn   )r   r   r   r   r   r1   r;   rA   rV   rP   r[   r   r`   rd   rk   r~   r   r   r4   r0   r   r     s?    9t>:,(9(',,
r4   r   nbinomc                   D    \ rS rSrSrS rSS jrS rS rS r	SS	 jr
S
rg)betanbinom_geni  a  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                     [        SSS[        R                  4S5      [        SSS[        R                  4S5      [        SSS[        R                  4S5      /$ r   r+   r.   s    r0   r1   betanbinom_gen._shape_info  r   r4   Nc                 J    UR                  X#U5      nUR                  XU5      $ r6   )r   r   r   s          r0   r;   betanbinom_gen._rvs  s'    aD)--aD99r4   c                 <    US:  [        U5      -  US:  -  US:  -  $ r   r?   r   s       r0   rA   betanbinom_gen._argcheck  r   r4   c                     [        U5      n[        R                  " X%-   5      * [        X%S-   5      -
  nU[        X2-   XE-   5      -   [        X45      -
  $ rI   )r   r,   r   r   r   s          r0   rP   betanbinom_gen._logpmf  sI    !H66!%=.6!U#33qu--q<<r4   c                 8    [        U R                  XX45      5      $ r6   r   r   s        r0   rV   betanbinom_gen._pmf  r   r4   c                    S n[         R                  " US:  XU4U[        R                  S9nS n[         R                  " US:  XU4U[        R                  S9nSu  pS n
SU;   a*  [         R                  " US	:  XU4U
[        R                  S9nS
 nSU;   a*  [         R                  " US:  XU4U[        R                  S9n	XgX4$ )Nc                     X-  US-
  -  $ Nr   r   r&   rE   r   s      r0   mean#betanbinom_gen._stats.<locals>.mean  s    5AF##r4   r   
fill_valuec                 H    X-  X-   S-
  -  X-   S-
  -  US-
  US-
  S-  -  -  $ )Nr   rp   r   r&  s      r0   rv   "betanbinom_gen._stats.<locals>.var  s;    EQURZ(AEBJ7B1r6B,.0 1r4   r   rn   c                     SU -  U-   S-
  SU-  U-   S-
  -  US-
  -  [        X-  X-   S-
  -  X!-   S-
  -  US-
  -  5      -  $ )Nr   r         @rp   r   r&  s      r0   skew#betanbinom_gen._stats.<locals>.skew  sf    UQY^A	B72v!%aequrz&:aebj&I2v' "   !r4   ro   r   c                 t   US-
  nUS-
  S-  US-  USU-  S-
  -  -   SUS-
  -  U-  -   -  SU S-  -  US-   US-  -  US-   US-
  -  U-  -   SUS-
  S-  -  -   -  -   SUS-
  -  U -  US-   US-  -  US-   US-
  -  U-  -   SUS-
  S-  -  -   -  -   nUS	-
  US-
  -  U-  U -  X-   S-
  -  X-   S-
  -  nX4-  U-  S-
  $ )
Nrp   r   r   rq   r.        @r   r   g      @r   )r&   rE   r   termterm_2denominators         r0   kurtosis'betanbinom_gen._stats.<locals>.kurtosis  sH   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3r4   rN      xpxapply_wherer,   r-   )r/   r&   rE   r   rt   r'  ru   rv   rw   rx   r0  r7  s               r0   r~   betanbinom_gen._stats  s    	$__QUQ1ItG	1 ooa!eaAYG	! '>Qq	4BFFKB	4 '>Qq	8OBr4   r   rn   r   )r   r   r   r   r   r1   r;   rA   rP   rV   r~   r   r   r4   r0   r  r    s'    #HE
:==
-!r4   r  
betanbinomc                   ^    \ rS rSrSrS rSS jrS rS rS r	S	 r
S
 rS rS rS rS rSrg)geom_geni  a  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                      [        SSSS5      /$ r   r   r.   s    r0   r1   geom_gen._shape_info  r   r4   Nc                     UR                  XS9n[        R                  " UR                  5      R                  n[        R
                  " US:  XT5      $ )Nr9   r   )	geometricr,   iinfor   maxwhere)r/   r(   r9   r:   resmax_ints         r0   r;   geom_gen._rvs  sD    $$Q$2 ((399%))xxa..r4   c                     US:*  US:  -  $ Nr   r   r   r   s     r0   rA   geom_gen._argcheck  s    Q1q5!!r4   c                 B    [         R                  " SU-
  US-
  5      U-  $ rI   )r,   powerr/   rN   r(   s      r0   rV   geom_gen._pmf!  s     xx!QqS!A%%r4   c                 P    [         R                  " US-
  U* 5      [        U5      -   $ rI   )r   rL   r   rQ  s      r0   rP   geom_gen._logpmf$  s"    q1uqb)CF22r4   c                 J    [        U5      n[        [        U* 5      U-  5      * $ r6   )r   r   r   r/   rM   r(   rN   s       r0   r[   geom_gen._cdf'  s#    !HeQBik"""r4   c                 L    [         R                  " U R                  X5      5      $ r6   )r,   r   _logsfr   s      r0   r`   geom_gen._sf+  s    vvdkk!'((r4   c                 6    [        U5      nU[        U* 5      -  $ r6   )r   r   rV  s       r0   rY  geom_gen._logsf.  s    !Hr{r4   c                     [        [        U* 5      [        U* 5      -  5      nU R                  US-
  U5      n[        R                  " XA:  US:  -  US-
  U5      $ rM  )r   r   r[   r,   rH  )r/   rj   r(   r   temps        r0   rk   geom_gen._ppf2  sS    E1"Iqb	)*yya#xxtax0$q&$??r4   c                     SU-  nSU-
  nX1-  U-  nSU-
  [        U5      -  n[        R                  " / SQU5      SU-
  -  nX$XV4$ )Nr   rp   )r   ir   )r   r,   polyval)r/   r(   ru   qrrv   rw   rx   s          r0   r~   geom_gen._stats7  sT    UUfqj!etBxZZ
A&A.r4   c                 r    [         R                  " U5      * [         R                  " U* 5      SU-
  -  U-  -
  $ r%  )r,   r   r   r   s     r0   r   geom_gen._entropy?  s/    q	zBHHaRLCE2Q666r4   r   rn   )r   r   r   r   r   r1   r;   rA   rV   rP   r[   r`   rY  rk   r~   r   r   r   r4   r0   r@  r@    s@    B>/"&3#)@
7r4   r@  geomzA geometric)rE   r   longnamec                   d    \ rS rSrSrS rSS jrS rS rS r	S	 r
S
 rS rS rS rS rS rSrg)hypergeom_geniF  a?  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                     [        SSS[        R                  4S5      [        SSS[        R                  4S5      [        SSS[        R                  4S5      /$ )NMTr   r'   r&   Nr+   r.   s    r0   r1   hypergeom_gen._shape_info  P    3q"&&k=A3q"&&k=A3q"&&k=AC 	Cr4   Nc                 (    UR                  X!U-
  X4S9$ NrD  )hypergeometric)r/   rk  r&   rl  r9   r:   s         r0   r;   hypergeom_gen._rvs  s    **1c1*@@r4   c                 f    [         R                  " X1U-
  -
  S5      [         R                  " X#5      4$ r   r,   maximumminimum)r/   rk  r&   rl  s       r0   rF   hypergeom_gen._get_support  s'    zz!qS'1%rzz!'777r4   c                     US:  US:  -  US:  -  nXBU:*  X1:*  -  -  nU[        U5      [        U5      -  [        U5      -  -  nU$ r   r?   )r/   rk  r&   rl  r   s        r0   rA   hypergeom_gen._argcheck  sU    A!q&!Q!V,aAF##AQ/+a.@@r4   c                     X#peXV-
  n[        US-   S5      [        US-   S5      -   [        XT-
  S-   US-   5      -   [        US-   Xa-
  S-   5      -
  [        XA-
  S-   Xt-
  U-   S-   5      -
  [        US-   S5      -
  nU$ rI   r   )	r/   rN   rk  r&   rl  totgoodbadresults	            r0   rP   hypergeom_gen._logpmf  s    Tja#fSUA&66a19MM1dfQh'(*0Qa	*BCQ"# r4   c                 0    [         R                  " XXB5      $ r6   )rS   _hypergeom_pmfr/   rN   rk  r&   rl  s        r0   rV   hypergeom_gen._pmf      !!!--r4   c                 0    [         R                  " XXB5      $ r6   )rS   _hypergeom_cdfr  s        r0   r[   hypergeom_gen._cdf  r  r4   c                 n   SU-  SU-  SU-  p2nX-
  nXS-   -  SU-  X-
  -  -
  SU-  U-  -
  nXQS-
  U-  U-  -  nUSU-  U-  X-
  -  U-  SU-  S-
  -  -  nXRU-  X-
  -  U-  US-
  -  US-
  -  -  n[         R                  " X#U5      [         R                  " X#U5      [         R                  " X#U5      U4$ )Nr   r   rq   r3  r   rp   r.  )rS   _hypergeom_mean_hypergeom_variance_hypergeom_skewness)r/   rk  r&   rl  mrx   s         r0   r~   hypergeom_gen._stats  s    q&"q&"q&aE a%[26QU++b1fqj8
1ukAo
b1fqjAE"Q&"q&1*55
!equo!QV,B77a(##A!,##A!,	
 	
r4   c                     [         R                  X1U-
  -
  [        X#5      S-    nU R                  XAX#5      n[         R                  " [        U5      SS9$ )Nr   r   r   )r,   r   minpmfr   r   )r/   rk  r&   rl  rN   r   s         r0   r   hypergeom_gen._entropy  sE    EE!1u+c!i!m,xxa#vvd4jq))r4   c                 0    [         R                  " XXB5      $ r6   )rS   _hypergeom_sfr  s        r0   r`   hypergeom_gen._sf  s      q,,r4   c                    / n[        [        R                  " XX45      6  H  u  pgpUS-   US-   -  US-
  U	S-
  -  :  a6  UR                  [	        [        U R                  XgX5      5      * 5      5        MT  [        R                  " US-   U	S-   5      n
UR                  [        U R                  XX5      5      5        M     [        R                  " U5      $ )Nr   r   )zipr,   r   appendr   r   r   aranger   rP   asarrayr/   rN   rk  r&   rl  rI  quantr|  r}  drawk2s              r0   rY  hypergeom_gen._logsf  s    &)2+>+>qQ+J&K"Ec	*dSjTCZ-HH

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

9T\\"4%FGH 'L zz#r4   c                    / n[        [        R                  " XX45      6  H  u  pgpUS-   US-   -  US-
  U	S-
  -  :  a6  UR                  [	        [        U R                  XgX5      5      * 5      5        MT  [        R                  " SUS-   5      n
UR                  [        U R                  XX5      5      5        M     [        R                  " U5      $ )Nr   r   r   )r  r,   r   r  r   r   logsfr  r   rP   r  r  s              r0   r   hypergeom_gen._logcdf  s    &)2+>+>qQ+J&K"Ec	*dSjTCZ-HH

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

9T\\"4%FGH 'L zz#r4   r   rn   )r   r   r   r   r   r1   r;   rF   rA   rP   rV   r[   r~   r   r`   rY  r   r   r   r4   r0   ri  ri  F  sG    HRC
A8..
"*
-

r4   ri  	hypergeomc                   F    \ rS rSrSrS rS rS rSS jrS r	S	 r
S
 rSrg)nhypergeom_geni  a>  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                     [        SSS[        R                  4S5      [        SSS[        R                  4S5      [        SSS[        R                  4S5      /$ )Nrk  Tr   r'   r&   rr+   r.   s    r0   r1   nhypergeom_gen._shape_infoI  rn  r4   c                 
    SU4$ r   r   )r/   rk  r&   r  s       r0   rF   nhypergeom_gen._get_supportN  r   r4   c                     US:  X!:*  -  US:  -  X1U-
  :*  -  nU[        U5      [        U5      -  [        U5      -  -  nU$ r   r?   )r/   rk  r&   r  r   s        r0   rA   nhypergeom_gen._argcheckQ  sK    Q16"a1f-c:AQ/+a.@@r4   Nc                 2   ^  [         U 4S j5       nU" XX4US9$ )Nc                   > TR                  XU5      u  pV[        R                  " XVS-   5      nTR                  XpX5      n[	        XSSS9n	U	" UR                  US95      R                  [        5      n
Uc  U
R                  5       $ U
$ )Nr   nextextrapolate)kindr*  rD  )	supportr,   r  r   r   uniformr   intitem)rk  r&   r  r9   r:   rE   r   ksr   ppfrvsr/   s              r0   _rvs1"nhypergeom_gen._rvs.<locals>._rvs1X  s     <<a(DA1c"B((2!'C3MJCl***56==cBC|xxz!Jr4   r   r   )r/   rk  r&   r  r9   r:   r  s   `      r0   r;   nhypergeom_gen._rvsV  s&    	#		 
$		 Q1lCCr4   c                 H    [         R                  " US:g  US:g  -  XX44S SS9$ )Nr   c                     [        U S-   U5      * [        X-   S5      -   [        X -
  S-   X-
  U-
  S-   5      -
  [        X-
  U -
  S-   S5      -   [        US-   X-
  S-   5      -   [        US-   S5      -
  $ rI   r{  )rN   rk  r&   r  s       r0   <lambda>(nhypergeom_gen._logpmf.<locals>.<lambda>i  s    1a.6!#q>1!#a%Qq)*,213q57A,>?!A#qs1u%&(.qsA7r4           r)  )r;  r<  r/   rN   rk  r&   r  s        r0   rP   nhypergeom_gen._logpmff  s3    !VQ!8  	r4   c                 8    [        U R                  XX45      5      $ r6   r   r  s        r0   rV   nhypergeom_gen._pmfo  s     4<<a+,,r4   c                     SU-  SU-  SU-  p2nX2-  X-
  S-   -  nX1S-   -  U-  X-
  S-   X-
  S-   -  -  SX1U-
  S-   -  -
  -  nSu  pgXEXg4$ )Nr   r   r   rn   r   )r/   rk  r&   r  ru   rv   rw   rx   s           r0   r~   nhypergeom_gen._statst  sv     Q$1bdaSACE]1gaiACEACE?+q1!A;? r4   r   rn   )r   r   r   r   r   r1   rF   rA   r;   rP   rV   r~   r   r   r4   r0   r  r    s.    bHC

D -
r4   r  
nhypergeomc                   :    \ rS rSrSrS rS
S jrS rS rS r	S	r
g)
logser_geni  a  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                      [        SSSS5      /$ r   r   r.   s    r0   r1   logser_gen._shape_info  r   r4   Nc                      UR                  XS9$ rp  )	logseriesr   s       r0   r;   logser_gen._rvs  s     %%a%33r4   c                     US:  US:  -  $ r>   r   r   s     r0   rA   logser_gen._argcheck  s    A!a%  r4   c                 l    [         R                  " X!5      * S-  U-  [        R                  " U* 5      -  $ r%  )r,   rP  r   r   rQ  s      r0   rV   logser_gen._pmf  s,    $q(7==!+<<<r4   c                    [         R                  " U* 5      nXS-
  -  U-  nU* U-  US-
  S-  -  nXCU-  -
  nU* U-  SU-   -  SU-
  S-  -  nUSU-  U-  -
  SUS-  -  -   nU[        R                  " US5      -  nU* U-  SUS-
  S-  -  SU-  US-
  S-  -  -
  SU-  U-  US-
  S-  -  -   -  n	U	SU-  U-  -
  SU-  U-  U-  -   SUS-  -  -
  n
XS-  -  S-
  nX5X4$ )	Nr   r   r         ?r   r   r9  r.  )r   r   r,   rP  )r/   r(   r  ru   mu2prv   mu3pmu3rw   mu4pmu4rx   s               r0   r~   logser_gen._stats  s4   MM1"c']QrAvS1$UlrAvQ37Q,.QrT$Y2q5(288C%%rAv1Q3(NQqSAEA:--!A1q0@@BQtVBY42-"a%76\Cr4   r   rn   )r   r   r   r   r   r1   r;   rA   rV   r~   r   r   r4   r0   r  r    s     0>4
!=r4   r  logserzA logarithmicc                   R    \ rS rSrSrS rS rSS jrS rS r	S	 r
S
 rS rS rSrg)poisson_geni  ag  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                 @    [        SSS[        R                  4S5      /$ )Nru   Fr   r'   r+   r.   s    r0   r1   poisson_gen._shape_info  s    4BFF]CDDr4   c                     US:  $ r   r   )r/   ru   s     r0   rA   poisson_gen._argcheck  s    Qwr4   Nc                 $    UR                  X5      $ r6   poisson)r/   ru   r9   r:   s       r0   r;   poisson_gen._rvs  s    ##B--r4   c                 V    [         R                  " X5      [        US-   5      -
  U-
  nU$ rI   )r   rK   rJ   )r/   rN   ru   Pks       r0   rP   poisson_gen._logpmf  s'    ]]1!E!a%L025	r4   c                 6    [        U R                  X5      5      $ r6   r   )r/   rN   ru   s      r0   rV   poisson_gen._pmf  s    4<<&''r4   c                 D    [        U5      n[        R                  " X25      $ r6   )r   r   pdtrr/   rM   ru   rN   s       r0   r[   poisson_gen._cdf  s    !H||A""r4   c                 D    [        U5      n[        R                  " X25      $ r6   )r   r   pdtrcr  s       r0   r`   poisson_gen._sf  s    !H}}Q##r4   c                     [        [        R                  " X5      5      n[        R                  " US-
  S5      n[        R
                  " XB5      n[        R                  " XQ:  XC5      $ rM  )r   r   pdtrikr,   ru  r  rH  )r/   rj   ru   r   vals1r^  s         r0   rk   poisson_gen._ppf  sJ    GNN1)*

4!8Q'||E&xx	5//r4   c                     Un[         R                  " U5      nUS:  n[        R                  " XCS [         R                  S9n[        R                  " XCS [         R                  S9nXXV4$ )Nr   c                     [        SU -  5      $ r%  r/  rM   s    r0   r  $poisson_gen._stats.<locals>.<lambda>  s    SUr4   r)  c                     SU -  $ r%  r   r  s    r0   r  r    s    Ar4   )r,   r  r;  r<  r-   )r/   ru   rv   tmp
mu_nonzerorw   rx   s          r0   r~   poisson_gen._stats  sW    jjn1W
__Z.CPRPVPVW__Zo"&&Qr4   r   rn   )r   r   r   r   r   r1   rA   r;   rP   rV   r[   r`   rk   r~   r   r   r4   r0   r  r    s5    0E.(#$0r4   r  r  z	A Poisson)r   rg  c                   X    \ rS rSrSrS rS rS rS rS r	S r
S	 rSS jrS rS rSrg
)
planck_geni  a  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                 @    [        SSS[        R                  4S5      /$ )Nlambda_Fr   r   r+   r.   s    r0   r1   planck_gen._shape_info"  s    9ea[.IJJr4   c                     US:  $ r   r   )r/   r  s     r0   rA   planck_gen._argcheck%  s    {r4   c                 <    [        U* 5      * [        U* U-  5      -  $ r6   )r   r   )r/   rN   r  s      r0   rV   planck_gen._pmf(  s     whWHQJ//r4   c                 >    [        U5      n[        U* US-   -  5      * $ rI   )r   r   r/   rM   r  rN   s       r0   r[   planck_gen._cdf+  s#    !Hwh!n%%%r4   c                 6    [        U R                  X5      5      $ r6   )r   rY  )r/   rM   r  s      r0   r`   planck_gen._sf/  s    4;;q*++r4   c                 *    [        U5      nU* US-   -  $ rI   r   r	  s       r0   rY  planck_gen._logsf2  s    !Hx1~r4   c                     [        SU-  [        U* 5      -  S-
  5      nUS-
  R                  " U R                  U5      6 nU R	                  XB5      n[
        R                  " XQ:  XC5      $ )N      r   )r   r   cliprF   r[   r,   rH  )r/   rj   r  r   r  r^  s         r0   rk   planck_gen._ppf6  s^    DL5!9,Q./a 1 1' :<yy(xx	5//r4   Nc                 @    [        U* 5      * nUR                  XBS9S-
  $ )NrD  r   )r   rE  )r/   r  r9   r:   r(   s        r0   r;   planck_gen._rvs<  s)    G8_%%a%3c99r4   c                     S[        U5      -  n[        U* 5      [        U* 5      S-  -  nS[        US-  5      -  nSS[        U5      -  -   nX#XE4$ )Nr   r   rp   r9  )r   r   r   )r/   r  ru   rv   rw   rx   s         r0   r~   planck_gen._statsA  sZ    uW~7(mUG8_q00tGCK  qgr4   c                 X    [        U* 5      * nU[        U* 5      -  U-  [        U5      -
  $ r6   )r   r   r   )r/   r  Cs      r0   r   planck_gen._entropyH  s/    G8_sG8}$Q&Q//r4   r   rn   )r   r   r   r   r   r1   rA   rV   r[   r`   rY  rk   r;   r~   r   r   r   r4   r0   r   r     s:    6K0&,0:
0r4   r   planckzA discrete exponential c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)boltzmann_geniP  ak  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    [        SSS[        R                  4S5      [        SSS[        R                  4S5      /$ )Nr  Fr   r   rl  Tr+   r.   s    r0   r1   boltzmann_gen._shape_infof  s:    9ea[.I3q"&&k>BD 	Dr4   c                 0    US:  US:  -  [        U5      -  $ r   r?   r/   r  rl  s      r0   rA   boltzmann_gen._argcheckj  s    !A&Q77r4   c                 $    U R                   US-
  4$ rI   rD   r!  s      r0   rF   boltzmann_gen._get_supportm  s    vvq1u}r4   c                 j    S[        U* 5      -
  S[        U* U-  5      -
  -  nU[        U* U-  5      -  $ rI   r   )r/   rN   r  rl  facts        r0   rV   boltzmann_gen._pmfp  s<     #wh-!C
O"34C
O##r4   c                 h    [        U5      nS[        U* US-   -  5      -
  S[        U* U-  5      -
  -  $ rI   )r   r   )r/   rM   r  rl  rN   s        r0   r[   boltzmann_gen._cdfv  s9    !H#wh!n%%#whqj/(9::r4   c                    US[        U* U-  5      -
  -  n[        SU-  [        SU-
  5      -  S-
  5      nUS-
  R                  S[        R
                  5      nU R                  XbU5      n[        R                  " Xq:  Xe5      $ )Nr   r  r  )r   r   r   r  r,   r-   r[   rH  )r/   rj   r  rl  qnewr   r  r^  s           r0   rk   boltzmann_gen._ppfz  sv    !C
O#$DL3qv;.q01ac266*yy+xx	5//r4   c                    [        U* 5      n[        U* U-  5      nUSU-
  -  X$-  SU-
  -  -
  nUSU-
  S-  -  X"-  U-  SU-
  S-  -  -
  nSU-
  SU-
  -  nX7S-  -  X"-  U-  -
  nUSU-   -  US-  -  US-  U-  SU-   -  -
  n	XS-  -  n	USSU-  -   X3-  -   -  US-  -  US-  U-  SSU-  -   XD-  -   -  -
  n
X-  U-  n
XVX4$ )Nr   r   r   r   r  r9  r&  )r/   r  rl  zzNru   rv   trmtrm2rw   rx   s              r0   r~   boltzmann_gen._stats  s   M'!_AYqtQrT{"Q
lQSVQrTAI--taclq&13r6!!WS!V^ad2gqtn,+!A#ac	]36!AqD2Iq2vbe|$<<Yr4   r   N)r   r   r   r   r   r1   rA   rF   rV   r[   rk   r~   r   r   r4   r0   r  r  P  s+    *D8$;0r4   r  	boltzmannz!A truncated discrete exponential )r   rE   rg  c                   R    \ rS rSrSrS rS rS rS rS r	S r
S	 rSS jrS rSrg
)randint_geni  a+  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                     [        SS[        R                  * [        R                  4S5      [        SS[        R                  * [        R                  4S5      /$ )NlowTr   highr+   r.   s    r0   r1   randint_gen._shape_info  sH    5$"&&"&&(9>J64266'266):NKM 	Mr4   c                 :    X!:  [        U5      -  [        U5      -  $ r6   r?   r/   r8  r9  s      r0   rA   randint_gen._argcheck  s    
k#..T1BBBr4   c                     XS-
  4$ rI   r   r<  s      r0   rF   randint_gen._get_support  s    F{r4   c                     [         R                  " U5      [         R                  " U[         R                  S9U-
  -  n[         R                  " X:  X:  -  US5      $ )Nr   r  )r,   	ones_liker  int64rH  )r/   rN   r8  r9  r(   s        r0   rV   randint_gen._pmf  sD    LLOrzz$bhh?#EFxxah/B77r4   c                 0    [        U5      nXB-
  S-   X2-
  -  $ r%  r  )r/   rM   r8  r9  rN   s        r0   r[   randint_gen._cdf  s    !H",,r4   c                     [        XU-
  -  U-   5      S-
  nUS-
  R                  X#5      nU R                  XRU5      n[        R                  " Xa:  XT5      $ rI   )r   r  r[   r,   rH  )r/   rj   r8  r9  r   r  r^  s          r0   rk   randint_gen._ppf  sR    A$s*+a/*yyT*xx	5//r4   c                     [         R                  " U5      [         R                  " U5      pCX4-   S-
  S-  nX4-
  nXf-  S-
  S-  nSnSXf-  S-   -  Xf-  S-
  -  n	XWX4$ )Nr   r   r   g      (@r  g333333)r,   r  )
r/   r8  r9  m2m1ru   drv   rw   rx   s
             r0   r~   randint_gen._stats  sk    D!2::c?Bgmq GsQw$s#qsSy1r4   Nc                    [         R                  " U5      R                  S:X  a.  [         R                  " U5      R                  S:X  a
  [        XAX#S9$ Ub,  [         R                  " X5      n[         R                  " X#5      n[         R
                  " [        [        U5      [         R                  " [        5      /S9nU" X5      $ )z=An array of *size* random integers >= ``low`` and < ``high``.r   rD  )otypes)	r,   r  r9   r
   broadcast_to	vectorizer   r   r  )r/   r8  r9  r9   r:   randints         r0   r;   randint_gen._rvs  s    ::c?1$D)9)>)>!)C4CC
 //#,C??4.D,,w|\B')xx}o7s!!r4   c                     [        X!-
  5      $ r6   )r   r<  s      r0   r   randint_gen._entropy  s    4:r4   r   rn   )r   r   r   r   r   r1   rA   rF   rV   r[   rk   r~   r;   r   r   r   r4   r0   r6  r6    s7    =~MC8
-0""r4   r6  rR  z#A discrete uniform (random integer)c                   :    \ rS rSrSrS rS
S jrS rS rS r	S	r
g)zipf_geni  aA  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                 @    [        SSS[        R                  4S5      /$ )NrE   Fr   r   r+   r.   s    r0   r1   zipf_gen._shape_info;      3266{NCDDr4   Nc                      UR                  XS9$ rp  )zipf)r/   rE   r9   r:   s       r0   r;   zipf_gen._rvs>  s       ..r4   c                     US:  $ rI   r   r/   rE   s     r0   rA   zipf_gen._argcheckA  s    1ur4   c                     UR                  [        R                  5      nS[        R                  " US5      -  X* -  -  nU$ Nr   r   )r   r,   float64r   r	   )r/   rN   rE   r  s       r0   rV   zipf_gen._pmfD  s7    HHRZZ 7<<1%%2-	r4   c                 Z    [         R                  " X!S-   :  X!4S [        R                  S9$ )Nr   c                 d    [         R                  " X-
  S5      [         R                  " U S5      -  $ rI   )r   r	   )rE   r&   s     r0   r   zipf_gen._munp.<locals>.<lambda>M  s!    aeQ/',,q!2DDr4   r)  r:  )r/   r&   rE   s      r0   _munpzipf_gen._munpJ  s*    AIvDvv 	r4   r   rn   )r   r   r   r   r   r1   r;   rA   rV   rh  r   r   r4   r0   rW  rW    s"    )VE/r4   rW  r\  zA Zipfc                 8    [        US5      [        XS-   5      -
  $ )z"Generalized harmonic number, a > 1r   )r	   r&   rE   s     r0   _gen_harmonic_gt1rl  T  s     1:Q!$$r4   c                 `   [         R                  " U 5      (       d  U $ [         R                  " U 5      n[         R                  " U[        S9n[         R
                  " USS[        S9 H  nX@:*  nX5==   SXAU   -  -  -  ss'   M     [         R                  U[         R                  " U 5      '   U$ )z#Generalized harmonic number, a <= 1rA  r   r   )r,   r9   nanmax
zeros_likefloatr  nanisnan)r&   rE   n_maxoutimasks         r0   _gen_harmonic_leq1rx  Z  s    771::IIaLE
--
'CYYua51v	QqD'z\!	 2 vvCJr4   c                 |    [         R                  " X5      u  p[        R                  " US:  X4[        [
        5      $ )zGeneralized harmonic numberr   )r,   r   r;  r<  rl  rx  rk  s     r0   _gen_harmonicrz  h  s1    q$DA??1q51&*;=OPPr4   c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)zipfian_genin  a  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    [        SSS[        R                  4S5      [        SSS[        R                  4S5      /$ )NrE   Fr   r'   r&   Tr   r+   r.   s    r0   r1   zipfian_gen._shape_info  s:    3266{MB3q"&&k>BD 	Dr4   c                 R    US:  US:  -  U[         R                  " U[        S9:H  -  $ )Nr   rA  )r,   r  r  r/   rE   r&   s      r0   rA   zipfian_gen._argcheck  s*    Q1q5!Q"**Qc*B%BCCr4   c                 
    SU4$ rI   r   r  s      r0   rF   zipfian_gen._get_support  r   r4   c                 h    UR                  [        R                  5      nS[        X25      -  X* -  -  $ r%  )r   r,   rc  rz  r/   rN   rE   r&   s       r0   rV   zipfian_gen._pmf  s-    HHRZZ ]1((1b500r4   c                 \    [         R                  " U5      n[        X5      [        X25      -  $ r6   r,   r   rz  r  s       r0   r[   zipfian_gen._cdf  s$    HHQKQ"]1%888r4   c                     [         R                  " US-   5      nX-  [        X25      [        X5      -
  -  S-   X-  [        X25      -  -  $ rI   r  r  s       r0   r`   zipfian_gen._sf  sJ    HHQUO}Q*]1-@@AAE4a++- 	.r4   c                    [        X!5      n[        X!S-
  5      n[        X!S-
  5      n[        X!S-
  5      n[        X!S-
  5      nXC-  nXS-  US-  -
  n	US-  n
X-  nXc-  SU-  U-  US-  -  -
  SUS-  -  US-  -  -   US-  -  nUS-  U-  SUS-  -  U-  U-  -
  SU-  US-  -  U-  -   SUS-  -  -
  U	S-  -  nUS-  nXX4$ )Nr   r   r   r9  r  r   )rz  )r/   rE   r&   HnaHna1Hna2Hna3Hna4mu1mu2nmu2dmu2rw   rx   s                 r0   r~   zipfian_gen._stats  s   A!Q!$Q!$Q!$Q!$h47"Avkh4S!V++aaiQ.>>c
J1fTkAc1fHTM$..3tQwt1CC$'	!1W%
ar4   r   N)r   r   r   r   r   r1   rA   rF   rV   r[   r`   r~   r   r   r4   r0   r|  r|  n  s-    ,\DD19. r4   r|  zipfianz	A Zipfianc                   F    \ rS rSrSrS rS rS rS rS r	S r
SS
 jrSrg	)dlaplace_geni  a   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                 @    [        SSS[        R                  4S5      /$ )NrE   Fr   r   r+   r.   s    r0   r1   dlaplace_gen._shape_info  rZ  r4   c                 P    [        US-  5      [        U* [        U5      -  5      -  $ Nrp   )r   r   abs)r/   rN   rE   s      r0   rV   dlaplace_gen._pmf  s$    AcE{S!c!f---r4   c                 \    [        U5      nS nS n[        R                  " US:  X24XE5      $ )Nc                 D    S[        U* U -  5      [        U5      S-   -  -
  $ rb  r&  rN   rE   s     r0   r   dlaplace_gen._cdf.<locals>.f1  s$    aR!VA
333r4   c                 @    [        XS-   -  5      [        U5      S-   -  $ rI   r&  r  s     r0   f2dlaplace_gen._cdf.<locals>.f2  s     qE{#s1vz22r4   r   )r   r;  r<  )r/   rM   rE   rN   r   r  s         r0   r[   dlaplace_gen._cdf  s0    !H	4	3 qAvvr66r4   c           
      *   S[        U5      -   n[        [        R                  " USS[        U* 5      -   -  :  [	        X-  5      U-  S-
  [	        SU-
  U-  5      * U-  5      5      nUS-
  n[        R                  " U R                  XR5      U:  XT5      $ )Nr   r   )r   r   r,   rH  r   r[   )r/   rj   rE   constr   r  s         r0   rk   dlaplace_gen._ppf  s    CF
BHHQCG!44 \A-1!1Q3%-00146 7 qxx		%+q0%>>r4   c                     [        U5      nSU-  US-
  S-  -  nSU-  US-  SU-  -   S-   -  US-
  S-  -  nSUSXCS-  -  S-
  4$ )Nrp   r   r   g      $@r9  r  r.  r&  )r/   rE   ear  r  s        r0   r~   dlaplace_gen._stats  se    VeRUQJeRU3r6\"_%B
23CQJO++r4   c                 N    U[        U5      -  [        [        US-  5      5      -
  $ r  )r   r   r   r_  s     r0   r   dlaplace_gen._entropy  s"    47{Sae---r4   Nc                     [         R                  " [         R                  " U5      * 5      * nUR                  XBS9nUR                  XBS9nXV-
  $ rp  )r,   r   r  rE  )r/   rE   r9   r:   probOfSuccessrM   ys          r0   r;   dlaplace_gen._rvs  sL      2::a=.11""="<""="<ur4   r   rn   )r   r   r   r   r   r1   rV   r[   rk   r~   r   r;   r   r   r4   r0   r  r    s+    ,E.	7?,.r4   r  dlaplacezA discrete Laplacianc                   R    \ rS rSrSrS rS rSSS.S jrS rS	 r	S
 r
S rS rSrg)poisson_binom_geni  u  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                     / $ r6   r   r.   s    r0   r1   poisson_binom_gen._shape_infoH  s	     	r4   c                 l    [         R                  " USS9nSU:*  US:*  -  n[         R                  " USS9$ Nr   r   r   )r,   stackall)r/   argsr(   condss       r0   rA   poisson_binom_gen._argcheckM  s5    HHT"aAF#vve!$$r4   Nr   c                (   [         R                  " USS9nUc  UR                  O,[         R                  " U5      (       a  US4O[	        U5      S-   n[         R
                  " UR                  U5      n[        R                  XAUS9R                  SS9$ )Nrn  r   r   )r   r   )	r,   r  shapeisscalartuplebroadcast_shapesr   r;   r   )r/   r9   r:   r  r(   s        r0   r;   poisson_binom_gen._rvsR  s|    HHT#  <[[..q	E$K$4F 	""177D1~~a~FJJPRJSSr4   c                     S[        U5      4$ r   )len)r/   r  s     r0   rF   poisson_binom_gen._get_support\  s    #d)|r4   c                     [         R                  " U5      R                  [         R                  5      n[         R                  " U/UQ76 tp[         R
                  " U[         R                  S9n[        XS5      $ )NrA  r  r,   
atleast_1dr   rC  r   r  rc  r    r/   rN   r  s      r0   rV   poisson_binom_gen._pmf_  W    MM!##BHH-&&q040zz$bjj1au--r4   c                     [         R                  " U5      R                  [         R                  5      n[         R                  " U/UQ76 tp[         R
                  " U[         R                  S9n[        XS5      $ )NrA  r   r  r  s      r0   r[   poisson_binom_gen._cdfe  r  r4   c                     [         R                  " USS9n[         R                  " USS9n[         R                  " USU-
  -  SS9nXES S 4$ r  )r,   r  r   )r/   r  kwdsr(   r'  rv   s         r0   r~   poisson_binom_gen._statsk  sG    HHT"vvaa ffQ!A#YQ'4&&r4   c                      [        U /UQ70 UD6$ r6   )poisson_binomial_frozen)r/   r  r  s      r0   __call__poisson_binom_gen.__call__q  s    &t;d;d;;r4   r   )r   r   r   r   r   r1   rA   r;   rF   rV   r[   r~   r  r   r   r4   r0   r  r    s8    'P
%
  $$ T..'<r4   r  poisson_binomzA Poisson binomialr(   )r   rg  shapesc                 L    [        [        R                  " USS5      5      USU4$ Nrn  r   r   r  r,   moveaxis)r/   r(   locr9   s       r0   _parse_args_rvsr  }  s#    QA&'c477r4   c                 L    [        [        R                  " USS5      5      USU4$ r  r  )r/   r(   r  rt   s       r0   _parse_args_statsr    s#    QA&'c7::r4   c                 J    [        [        R                  " USS5      5      US4$ r  r  )r/   r(   r  s      r0   _parse_argsr    s!    QA&'c11r4   c                   $    \ rS rSrS rSS jrSrg)r  i  c                     X l         X0l        UR                  " S0 UR                  5       D6U l        [
        R                  [        [        5      U R                  l        [        R                  [        [        5      U R                  l	        [        R                  [        [        5      U R                  l
        U R                  R                  " U0 UD6u  n  nU R                  R                  " U6 u  U l        U l        g )Nr   )r  r  	__class___updated_ctor_paramdistr  __get___pb_obj_pb_clsr  r  rF   rE   r   )r/   r  r  r  r  _s         r0   __init__ poisson_binomial_frozen.__init__  s    		 NN@T%=%=%?@	 %4$;$;GW$M		!&7&?&?&Q		# + 3 3GW E		yy,,d;d;1//8r4   Nc                     U R                   R                  " U R                  0 U R                  D6u  pgnU R                   R                  " XR                  XrX440 UD6$ r6   )r  r  r  r  expect)	r/   funclbubconditionalr  rE   r  scales	            r0   r  poisson_binomial_frozen.expect  sK    		--tyyFDIIF yyii"RTRRr4   )rE   r  r   r  r  )NNNF)r   r   r   r   r  r  r   r   r4   r0   r  r    s    9Sr4   r  c                   :    \ rS rSrSrS rS
S jrS rS rS r	S	r
g)skellam_geni  a  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    [        SSS[        R                  4S5      [        SSS[        R                  4S5      /$ )Nr  Fr   r   r  r+   r.   s    r0   r1   skellam_gen._shape_info  s:    5%!RVVnE5%!RVVnEG 	Gr4   Nc                 L    UnUR                  X5      UR                  X%5      -
  $ r6   r  )r/   r  r  r9   r:   r&   s         r0   r;   skellam_gen._rvs  s-    $$S,$$S,- 	.r4   c                 .   [         R                  " SS9   [         R                  " US:  [        R                  " SU-  SSU-
  -  SU-  5      S-  [        R                  " SU-  SSU-   -  SU-  5      S-  5      nS S S 5        U$ ! , (       d  f       W$ = f)Nr   r  r   r   r   )r,   r   rH  rS   	_ncx2_pdfr/   rM   r  r  pxs        r0   rV   skellam_gen._pmf  s    [[h'!a%--#q!A#w#>q@--#q!A#w#>q@BB (
 	 ('
 	s   A&B
Bc                 8   [        U5      n[        R                  " SS9   [        R                  " US:  [        R
                  " SU-  SU-  SU-  5      S[        R
                  " SU-  SUS-   -  SU-  5      -
  5      nS S S 5        U$ ! , (       d  f       W$ = f)Nr   r  r   r   r   )r   r,   r   rH  rS   	_ncx2_cdfr  s        r0   r[   skellam_gen._cdf  s    !H[[h'!a%--#r!tQsU;cmmAcE1ac7AcEBBDB ( 		 (' 	s   A B


Bc                 F    X-
  nX-   nU[        US-  5      -  nSU-  nX4XV4$ )Nr   r   r/  )r/   r  r  r'  rv   rw   rx   s          r0   r~   skellam_gen._stats  s6    yiD#N"W"  r4   r   rn   )r   r   r   r   r   r1   r;   rV   r[   r~   r   r   r4   r0   r  r    s!    :G.
!r4   r  skellamz	A Skellamc                   R    \ rS rSrSrS rSS jrS rS rS r	S	 r
S
 rS rS rSrg)yulesimon_geni  a  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                 @    [        SSS[        R                  4S5      /$ )NalphaFr   r   r+   r.   s    r0   r1   yulesimon_gen._shape_info	  s    7EArvv;GHHr4   Nc           	          UR                  U5      nUR                  U5      n[        U* [        [        U* U-  5      * 5      -  5      nU$ r6   )standard_exponentialr   r   r   )r/   r  r9   r:   E1E2anss          r0   r;   yulesimon_gen._rvs  sK    ..t4..t4B3RC%K 00112
r4   c                 :    U[         R                  " XS-   5      -  $ rI   r   r   r/   rM   r  s      r0   rV   yulesimon_gen._pmf  s    w||Aqy111r4   c                     US:  $ r   r   )r/   r  s     r0   rA   yulesimon_gen._argcheck  s    	r4   c                 L    [        U5      [        R                  " XS-   5      -   $ rI   r   r   r   r  s      r0   rP   yulesimon_gen._logpmf  s    5zGNN1ai888r4   c                 @    SU[         R                  " XS-   5      -  -
  $ rI   r  r  s      r0   r[   yulesimon_gen._cdf  s    1w||Aqy1111r4   c                 :    U[         R                  " XS-   5      -  $ rI   r  r  s      r0   r`   yulesimon_gen._sf  s    7<<19---r4   c                 L    [        U5      [        R                  " XS-   5      -   $ rI   r  r  s      r0   rY  yulesimon_gen._logsf!  s    1vq!)444r4   c                    [         R                  " US:*  [         R                  XS-
  -  5      n[         R                  " US:  US-  US-
  US-
  S-  -  -  [         R                  5      n[         R                  " US:*  [         R                  U5      n[         R                  " US:  [	        US-
  5      US-   S-  -  XS-
  -  -  [         R                  5      n[         R                  " US:*  [         R                  U5      n[         R                  " US:  US-   SUS-  -  SU-  -
  S-
  XS-
  -  US-
  -  -  -   [         R                  5      n[         R                  " US:*  [         R                  U5      nX#XE4$ )	Nr   r   rp   r   r9     1      )r,   rH  r-   rr  r   )r/   r  ru   r  rw   rx   s         r0   r~   yulesimon_gen._stats$  sQ   XXeqj"&&%19*=>hhuqyaxECKEAI>#ABvv hhuz2663/XXeai519oQ6%19:MNff XXeqj"&&"-XXeaiaiBMBJ$>$C$)QY$7519$E$G Hff XXeqj"&&"-r4   r   rn   )r   r   r   r   r   r1   r;   rV   rA   rP   r[   r`   rY  r~   r   r   r4   r0   r
  r
    s6     BI292.5r4   r
  	yulesimon)r   rE   c                   L    \ rS rSrSrSrSrS rS rS r	SS jr
S rSS	 jrS
rg)_nchypergeom_geni9  zA noncentral hypergeometric discrete random variable.

For subclassing by nchypergeom_fisher_gen and nchypergeom_wallenius_gen.

Nc           	          [        SSS[        R                  4S5      [        SSS[        R                  4S5      [        SSS[        R                  4S5      [        SSS[        R                  4S	5      /$ )
Nrk  Tr   r'   r&   rl  oddsFr   r+   r.   s    r0   r1   _nchypergeom_gen._shape_infoC  sf    3q"&&k=A3q"&&k=A3q"&&k=A651bff+~FH 	Hr4   c                 v    XUp%nX5-
  n[         R                  " SX&-
  5      n[         R                  " X%5      nXx4$ r   rt  )	r/   rk  r&   rl  r,  rK  rJ  x_minx_maxs	            r0   rF   _nchypergeom_gen._get_supportI  s:    qV

1af%

1!|r4   c                 ,   [         R                  " U5      [         R                  " U5      p![         R                  " U5      [         R                  " U5      pC[         R                  " U5      ) UR                  [        5      U:H  -  US:  -  n[         R                  " U5      ) UR                  [        5      U:H  -  US:  -  n[         R                  " U5      ) UR                  [        5      U:H  -  US:  -  nUS:  nX1:*  n	X!:*  n
XV-  U-  U-  U	-  U
-  $ r   )r,   r  rs  r   r  )r/   rk  r&   rl  r,  cond1cond2cond3cond4cond5cond6s              r0   rA   _nchypergeom_gen._argcheckP  s    zz!}bjjm1**Q-D!14((1+!((3-1"45a@((1+!((3-1"45a@((1+!((3-1"45a@q}u$u,u4u<<r4   c           	      2   ^  [         U 4S j5       nU" XX4XVS9$ )Nc                   > [         R                  " U 5      [         R                  " U5      -  [         R                  " U5      -  (       a%  [         R                  " U[         R                  5      $ [         R                  " U5      n[        5       n[        UT
R                  5      nU" X!XXe5      n	U	R                  U5      n	U	$ r6   )	r,   rs  fullrr  prodr   getattrrvs_namereshape)rk  r&   rl  r,  r9   r:   lengthurnrv_genr  r/   s             r0   r  $_nchypergeom_gen._rvs.<locals>._rvs1]  s    xx{RXXa[(288A;6wwtRVV,,WWT]F#%CS$--0Fq=C++d#CJr4   r   r  )r/   rk  r&   rl  r,  r9   r:   r  s   `       r0   r;   _nchypergeom_gen._rvs[  s&    	#	 
$	 Q1IIr4   c                    ^  [         R                  " XX4U5      u  pp4nUR                  S:X  a  [         R                  " U5      $ [         R                  U 4S j5       nU" XX4U5      $ )Nr   c                 ,  > [         R                  " U 5      [         R                  " U5      -  [         R                  " U5      -  [         R                  " U5      -  (       a  [         R                  $ TR                  X2XS5      nUR	                  U 5      $ Ng-q=)r,   rs  rr  r  probability)rM   rk  r&   rl  r,  rB  r/   s         r0   _pmf1$_nchypergeom_gen._pmf.<locals>._pmf1p  s_    xx{RXXa[(288A;6!Dvv))A!51C??1%%r4   )r,   r   r9   
empty_likerQ  )r/   rM   rk  r&   rl  r,  rJ  s   `      r0   rV   _nchypergeom_gen._pmfj  s_    ..qQ4@aD66Q;==##		& 
	& Q1&&r4   c                 x   ^  [         R                  U 4S j5       nSU;   d  SU;   a	  U" XX45      OSu  pxSu  pXxX4$ )Nc                   > [         R                  " U 5      [         R                  " U5      -  [         R                  " U5      -  (       a   [         R                  [         R                  4$ TR                  X!XS5      nUR	                  5       $ rH  )r,   rs  rr  r  rt   )rk  r&   rl  r,  rB  r/   s        r0   	_moments1*_nchypergeom_gen._stats.<locals>._moments1{  sX    xx{RXXa[(288A;6vvrvv~%))A!51C;;= r4   r  vrn   )r,   rQ  )r/   rk  r&   rl  r,  rt   rP  r  rR  ro   rN   s   `          r0   r~   _nchypergeom_gen._statsy  sL    		! 
	! .1G^sg~	!(! 	Qzr4   r   rn   r   )r   r   r   r   r   r?  r  r1   rF   rA   r;   rV   r~   r   r   r4   r0   r*  r*  9  s3     HDH	=J'r4   r*  c                        \ rS rSrSrSr\rSrg)nchypergeom_fisher_geni  a  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_fisherr   N)	r   r   r   r   r   r?  r   r  r   r   r4   r0   rU  rU    s    GR H%Dr4   rU  nchypergeom_fisherz$A Fisher's noncentral hypergeometricc                        \ rS rSrSrSr\rSrg)nchypergeom_wallenius_geni  a  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_walleniusr   N)	r   r   r   r   r   r?  r   r  r   r   r4   r0   rY  rY    s    GR H'Dr4   rY  nchypergeom_walleniusz&A Wallenius' noncentral hypergeometric)r   N)r   r   )r   )m	functoolsr   scipyr   scipy.specialr   r   r   r   rJ   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_ufuncsrS   r"   r   r   r   r   r   r   r  r  r>  r@  rf  ri  r  r  r  r  r  r  r  r   r  r  r4  r6  rR  rW  r\  rl  rx  rz  r|  r  r  r-   r  r  r  r  r  r  r  r  r  r  r  r  r
  r(  r*  rU  rW  rY  r[  listglobalscopyitemspairs_distn_names_distn_gen_names__all__r   r4   r0   <module>rr     s  
   I I ) ( ( & M M M 8 8, , + # #]* ]*@ 	w>#I >#B AK0	OK Od {+	r
 r
j 
	"Z[ Zz .
N7{ N7b !&=9XK Xv {+	[[ [| .
5 5p 
ah	A?+ ?D 9{
;D0 D0N 
ah1J	K<K <~ {a#FH	t+ tn 9 0) *
?{ ?D !&84%QW + W t 	K
@M; M` 266''2HJS< S<l "AU),.8;2
 !"3  / 7 7 I "3";";GW"M '//A S0 S0<!+ <!~ i+
FLK L^ {a0	L{ L^K&- K&\ ,	35 
K( 0 K(\ 2	 57  	WY^^##%&!7{!K 
)
)r4   