
    S_f                        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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  d dl!m"c m#Z# dd
l$m%Z%m&Z&m'Z' d Z( G d de      Z) e)d      Z* G d de)      Z+ e+dd      Z, G d de      Z- e-d      Z. G d de      Z/ e/d      Z0 G d de      Z1 e1d      Z2 G d de      Z3 e3ddd !      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.d/0      Z< G d1 d2e      Z= e=d d3d4!      Z> G d5 d6e      Z? e?d7d d89      Z@ G d: d;e      ZA eAd<d=0      ZB G d> d?e      ZC eCdd@dA!      ZDdB ZEdC ZFdD ZG G dE dFe      ZH eHddGdH!      ZI G dI dJe      ZJ eJej                   dKdL!      ZL G dM dNe      ZM eMej                   dOdP!      ZN G dQ dRe      ZO eOdSdT      ZPdU ZQ G dV dWe      ZR G dX dYeR      ZS eSdZd[0      ZT G d\ d]eR      ZU eUd^d_0      ZV eW eX       j                         j                               Z[ ee[e      \  Z\Z]e\e]z   Z^y)`    )partial)special)entr	logsumexpbetalngammalnzeta)
_lazywhererng_integers)interp1d)
floorceillogexpsqrtlog1pexpm1tanhcoshsinhN   )rv_discreteget_distribution_names_check_shape
_ShapeInfo)_PyFishersNCHypergeometric_PyWalleniusNCHypergeometric_PyStochasticLib3c                 2    | t        j                  |       k(  S N)nproundxs    <lib/python3.12/site-packages/scipy/stats/_discrete_distns.py_isintegralr&      s        c                   \    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd ZddZd Zy)	binom_gena  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.

    %(after_notes)s

    %(example)s

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

    c                 Z    t        dddt        j                  fd      t        dddd      gS 	NnTr   TFpFr   r   TTr   r!   infselfs    r%   _shape_infozbinom_gen._shape_info8   0    3q"&&k=A3v|<> 	>r'   Nc                 (    |j                  |||      S r    )binomialr4   r,   r.   sizerandom_states        r%   _rvszbinom_gen._rvs<   s    $$Q400r'   c                 <    |dk\  t        |      z  |dk\  z  |dk  z  S Nr   r   r&   r4   r,   r.   s      r%   	_argcheckzbinom_gen._argcheck?   s'    Q+a.(AF3qAv>>r'   c                     | j                   |fS r    ar@   s      r%   _get_supportzbinom_gen._get_supportB   s    vvqyr'   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)r4   r$   r,   r.   kcombilns         r%   _logpmfzbinom_gen._logpmfE   sb    !H1:qseAaCEl!:;q!,,wqsQB/GGGr'   c                 0    t        j                  |||      S r    )_boost
_binom_pdfr4   r$   r,   r.   s       r%   _pmfzbinom_gen._pmfJ   s      Aq))r'   c                 F    t        |      }t        j                  |||      S r    )r   rO   
_binom_cdfr4   r$   r,   r.   rK   s        r%   _cdfzbinom_gen._cdfN        !H  Aq))r'   c                 F    t        |      }t        j                  |||      S r    )r   rO   	_binom_sfrU   s        r%   _sfzbinom_gen._sfR   s     !H1a((r'   c                 0    t        j                  |||      S r    )rO   
_binom_isfrQ   s       r%   _isfzbinom_gen._isfV         Aq))r'   c                 0    t        j                  |||      S r    )rO   
_binom_ppfr4   qr,   r.   s       r%   _ppfzbinom_gen._ppfY   r^   r'   c                     t        j                  ||      }t        j                  ||      }d\  }}d|v rt        j                  ||      }d|v rt        j                  ||      }||||fS )NNNsrK   )rO   _binom_mean_binom_variance_binom_skewness_binom_kurtosis_excess)r4   r,   r.   momentsmuvarg1g2s           r%   _statszbinom_gen._stats\   so    1%$$Q*B'>''1-B'>..q!4B3Br'   c                     t         j                  d|dz    }| j                  |||      }t        j                  t	        |      d      S )Nr   r   axis)r!   r_rR   sumr   )r4   r,   r.   rK   valss        r%   _entropyzbinom_gen._entropyf   s<    EE!AENyyAq!vvd4jq))r'   re   mv__name__
__module____qualname____doc__r5   r<   rA   rE   rM   rR   rV   rZ   r]   rc   rp   rw    r'   r%   r)   r)      sD    6>1?H
**)***r'   r)   binom)namec                   Z    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y)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/   r0   r   r3   s    r%   r5   zbernoulli_gen._shape_info       3v|<==r'   Nc                 6    t         j                  | d|||      S )Nr   r:   r;   )r)   r<   r4   r.   r:   r;   s       r%   r<   zbernoulli_gen._rvs   s    ~~dAqt,~OOr'   c                     |dk\  |dk  z  S r>   r   r4   r.   s     r%   rA   zbernoulli_gen._argcheck   s    Q16""r'   c                 2    | j                   | j                  fS r    )rD   br   s     r%   rE   zbernoulli_gen._get_support   s    vvtvv~r'   c                 0    t         j                  |d|      S rG   )r   rM   r4   r$   r.   s      r%   rM   zbernoulli_gen._logpmf   s    }}Q1%%r'   c                 0    t         j                  |d|      S rG   )r   rR   r   s      r%   rR   zbernoulli_gen._pmf   s     zz!Q""r'   c                 0    t         j                  |d|      S rG   )r   rV   r   s      r%   rV   zbernoulli_gen._cdf       zz!Q""r'   c                 0    t         j                  |d|      S rG   )r   rZ   r   s      r%   rZ   zbernoulli_gen._sf   s    yyAq!!r'   c                 0    t         j                  |d|      S rG   )r   r]   r   s      r%   r]   zbernoulli_gen._isf   r   r'   c                 0    t         j                  |d|      S rG   )r   rc   )r4   rb   r.   s      r%   rc   zbernoulli_gen._ppf   r   r'   c                 .    t         j                  d|      S rG   )r   rp   r   s     r%   rp   zbernoulli_gen._stats   s    ||Aq!!r'   c                 6    t        |      t        d|z
        z   S rG   )r   r   s     r%   rw   zbernoulli_gen._entropy   s    Awac""r'   re   rz   r   r'   r%   r   r   o   sD    0>P#&#
#"##"#r'   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
y)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.

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

    %(after_notes)s

    .. 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-   rD   FFFr   r1   r3   s    r%   r5   zbetabinom_gen._shape_info   P    3q"&&k=A3266{NC3266{NCE 	Er'   Nc                 N    |j                  |||      }|j                  |||      S r    )betar8   r4   r,   rD   r   r:   r;   r.   s          r%   r<   zbetabinom_gen._rvs   s+    aD)$$Q400r'   c                 
    d|fS Nr   r   r4   r,   rD   r   s       r%   rE   zbetabinom_gen._get_support       !tr'   c                 <    |dk\  t        |      z  |dkD  z  |dkD  z  S r   r?   r   s       r%   rA   zbetabinom_gen._argcheck   '    Q+a.(AE2a!e<<r'   c                     t        |      }t        |dz          t        ||z
  dz   |dz         z
  }|t        ||z   ||z
  |z         z   t        ||      z
  S rG   )r   r   r   r4   r$   r,   rD   r   rK   rL   s          r%   rM   zbetabinom_gen._logpmf   s[    !Hq1u:+q1uqy!a% 88Aq1uqy11F1aL@@r'   c                 <    t        | j                  ||||            S r    r   rM   r4   r$   r,   rD   r   s        r%   rR   zbetabinom_gen._pmf       4<<1a+,,r'   c                 D   |||z   z  }d|z
  }||z  }|||z   |z   z  |z  |z  ||z   dz   z  }d\  }	}
d|v r3dt        |      z  }	|	||z   d|z  z   ||z
  z  z  }	|	||z   dz   ||z   z  z  }	d|v r||z   j                  |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   re   rf         ?   rK            )r   astypedtype)r4   r,   rD   r   rk   e_pe_qrl   rm   rn   ro   s              r%   rp   zbetabinom_gen._stats   s   1q5k#gW1q519o#c)QUQY7B'>tCy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r'   re   rx   )r{   r|   r}   r~   r5   r<   rE   rA   rM   rR   rp   r   r'   r%   r   r      s-    "FE
1=A
-r'   r   	betabinomc                   T    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zy)
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}

    %(after_notes)s

    %(example)s

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

    c                 Z    t        dddt        j                  fd      t        dddd      gS r+   r1   r3   s    r%   r5   znbinom_gen._shape_info;  r6   r'   Nc                 (    |j                  |||      S r    )negative_binomialr9   s        r%   r<   znbinom_gen._rvs?  s    --aD99r'   c                 $    |dkD  |dkD  z  |dk  z  S r>   r   r@   s      r%   rA   znbinom_gen._argcheckB  s    A!a% AF++r'   c                 0    t        j                  |||      S r    )rO   _nbinom_pdfrQ   s       r%   rR   znbinom_gen._pmfE  s    !!!Q**r'   c                     t        ||z         t        |dz         z
  t        |      z
  }||t        |      z  z   t        j                  ||       z   S rG   )rH   r   r   rJ   )r4   r$   r,   r.   coeffs        r%   rM   znbinom_gen._logpmfI  sJ    ac
U1Q3Z'%(2qQx'//!aR"888r'   c                 F    t        |      }t        j                  |||      S r    )r   rO   _nbinom_cdfrU   s        r%   rV   znbinom_gen._cdfM  s     !H!!!Q**r'   c                 J   t        |      }t        j                  |||      \  }}}| j                  |||      }|dkD  }d }|}t        j                  d      5   |||   ||   ||         ||<   t        j
                  ||          || <   d d d        |S # 1 sw Y   |S xY w)N      ?c                 d    t        j                  t        j                  | dz   |d|z
               S rG   )r!   r   r   betainc)rK   r,   r.   s      r%   f1znbinom_gen._logcdf.<locals>.f1V  s)    88W__QUAq1u==>>r'   ignore)divide)r   r!   broadcast_arraysrV   errstater   )	r4   r$   r,   r.   rK   cdfcondr   logcdfs	            r%   _logcdfznbinom_gen._logcdfQ  s    !H%%aA.1aii1a Sy	? [[) 	/agqw$8F4LFF3u:.FD5M	/ 	/ s   4BB"c                 F    t        |      }t        j                  |||      S r    )r   rO   
_nbinom_sfrU   s        r%   rZ   znbinom_gen._sf`  rW   r'   c                     t        j                  d      5  t        j                  |||      cd d d        S # 1 sw Y   y xY wNr   over)r!   r   rO   _nbinom_isfrQ   s       r%   r]   znbinom_gen._isfd  5    [[h' 	/%%aA.	/ 	/ 	/	   8Ac                     t        j                  d      5  t        j                  |||      cd d d        S # 1 sw Y   y xY wr   )r!   r   rO   _nbinom_ppfra   s       r%   rc   znbinom_gen._ppfh  r   r   c                     t        j                  ||      t        j                  ||      t        j                  ||      t        j                  ||      fS r    )rO   _nbinom_mean_nbinom_variance_nbinom_skewness_nbinom_kurtosis_excessr@   s      r%   rp   znbinom_gen._statsl  sL    1%##Aq)##Aq)**1a0	
 	
r'   re   )r{   r|   r}   r~   r5   r<   rA   rR   rM   rV   r   rZ   r]   rc   rp   r   r'   r%   r   r     s?    1d>:,+9+*//
r'   r   nbinomc                   8    e Zd ZdZd Zd	dZd Zd Zd Zd
dZ	y)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.

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

    %(after_notes)s

    .. 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   r1   r3   s    r%   r5   zbetanbinom_gen._shape_info  r   r'   Nc                 N    |j                  |||      }|j                  |||      S r    )r   r   r   s          r%   r<   zbetanbinom_gen._rvs  s+    aD)--aD99r'   c                 <    |dk\  t        |      z  |dkD  z  |dkD  z  S r   r?   r   s       r%   rA   zbetanbinom_gen._argcheck  r   r'   c                     t        |      }t        j                  ||z          t        ||dz         z
  }|t        ||z   ||z         z   t        ||      z
  S rG   )r   r!   r   r   r   s          r%   rM   zbetanbinom_gen._logpmf  sS    !H66!a%=.6!QU#33Aq1u--q!<<r'   c                 <    t        | j                  ||||            S r    r   r   s        r%   rR   zbetanbinom_gen._pmf  r   r'   c                 X   d }t        |dkD  |||f|t        j                        }d }t        |dkD  |||f|t        j                        }d\  }}	d }
d|v r#t        |d	kD  |||f|
t        j                        }d
 }d|v r#t        |dkD  |||f|t        j                        }	||||	fS )Nc                     | |z  |dz
  z  S Nr   r   r,   rD   r   s      r%   meanz#betanbinom_gen._stats.<locals>.mean  s    q5AF##r'   r   )f	fillvaluec                 N    | |z  | |z   dz
  z  ||z   dz
  z  |dz
  |dz
  dz  z  z  S )Nr          @r   r   s      r%   rm   z"betanbinom_gen._stats.<locals>.var  sA    EQURZ(AEBJ7B1r6B,.0 1r'   r   re   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         @r   r   r   s      r%   skewz#betanbinom_gen._stats.<locals>.skew  sl    UQY^A	B72v!%a!eq1urz&:a!ebj&I2v' "   !r'   rf   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 )
Nr   r   r         @r         @r   r   g      @r   )r,   rD   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3r'   rK      r
   r!   r2   )r4   r,   rD   r   rk   r   rl   rm   rn   ro   r   r   s               r%   rp   zbetanbinom_gen._stats  s    	$A1ayDBFFC	1 QAq	SBFFCB	! '>AEAq!9GB	4 '>AEAq!9BFFKB3Br'   re   rx   )
r{   r|   r}   r~   r5   r<   rA   rM   rR   rp   r   r'   r%   r   r   x  s'    #HE
:==
-!r'   r   
betanbinomc                   T    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zy)geom_gena  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.

    %(after_notes)s

    See Also
    --------
    planck

    %(example)s

    c                      t        dddd      gS r   r   r3   s    r%   r5   zgeom_gen._shape_info  r   r'   Nc                 (    |j                  ||      S Nr:   )	geometricr   s       r%   r<   zgeom_gen._rvs  s    %%ad%33r'   c                     |dk  |dkD  z  S Nr   r   r   r   s     r%   rA   zgeom_gen._argcheck  s    Q1q5!!r'   c                 @    t        j                  d|z
  |dz
        |z  S rG   )r!   powerr4   rK   r.   s      r%   rR   zgeom_gen._pmf  s     xx!QqS!A%%r'   c                 N    t        j                  |dz
  |       t        |      z   S rG   )r   rJ   r   r  s      r%   rM   zgeom_gen._logpmf  s"    q1uqb)CF22r'   c                 J    t        |      }t        t        |       |z         S r    )r   r   r   r4   r$   r.   rK   s       r%   rV   zgeom_gen._cdf  s#    !HeQBik"""r'   c                 L    t        j                  | j                  ||            S r    )r!   r   _logsfr   s      r%   rZ   zgeom_gen._sf  s    vvdkk!Q'((r'   c                 6    t        |      }|t        |       z  S r    )r   r   r  s       r%   r  zgeom_gen._logsf  s    !Hr{r'   c                     t        t        |       t        |       z        }| j                  |dz
  |      }t        j                  ||k\  |dkD  z  |dz
  |      S r
  )r   r   rV   r!   where)r4   rb   r.   rv   temps        r%   rc   zgeom_gen._ppf  sU    E1"Iqb	)*yya#xxtax0$q&$??r'   c                     d|z  }d|z
  }||z  |z  }d|z
  t        |      z  }t        j                  g d|      d|z
  z  }||||fS )Nr   r   )r   ir   )r   r!   polyval)r4   r.   rl   qrrm   rn   ro   s          r%   rp   zgeom_gen._stats  sZ    UU1fqj!etBxZZ
A&A.3Br'   c                 n    t        j                  |       t        j                  |       d|z
  z  |z  z
  S r   )r!   r   r   r   s     r%   rw   zgeom_gen._entropy  s/    q	zBHHaRLCE2Q666r'   re   )r{   r|   r}   r~   r5   r<   rA   rR   rM   rV   rZ   r  rc   rp   rw   r   r'   r%   r  r    s?    8>4"&3#)@
7r'   r  geomzA geometric)rD   r   longnamec                   Z    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y)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)!}.

    %(after_notes)s

    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,   Nr1   r3   s    r%   r5   zhypergeom_gen._shape_infof  P    3q"&&k=A3q"&&k=A3q"&&k=AC 	Cr'   Nc                 2    |j                  |||z
  ||      S r  )hypergeometric)r4   r   r,   r!  r:   r;   s         r%   r<   zhypergeom_gen._rvsk  s     **1ac14*@@r'   c                 f    t        j                  |||z
  z
  d      t        j                  ||      fS r   r!   maximumminimum)r4   r   r,   r!  s       r%   rE   zhypergeom_gen._get_supportn  s+    zz!QqS'1%rzz!Q'777r'   c                     |dkD  |dk\  z  |dk\  z  }|||k  ||k  z  z  }|t        |      t        |      z  t        |      z  z  }|S r   r?   )r4   r   r,   r!  r   s        r%   rA   zhypergeom_gen._argcheckq  sY    A!q&!Q!V,aAF##AQ/+a.@@r'   c                    ||}}||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 rG   r   )	r4   rK   r   r,   r!  totgoodbadresults	            r%   rM   zhypergeom_gen._logpmfw  s    qTDja#fSUA&66Aa19MM1d1fQh'(*01QAa	*BCQ"# r'   c                 2    t        j                  ||||      S r    )rO   _hypergeom_pdfr4   rK   r   r,   r!  s        r%   rR   zhypergeom_gen._pmf      $$Q1a00r'   c                 2    t        j                  ||||      S r    )rO   _hypergeom_cdfr2  s        r%   rV   zhypergeom_gen._cdf  r3  r'   c                 ~   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   r   r   r   r   r   )rO   _hypergeom_mean_hypergeom_variance_hypergeom_skewness)r4   r   r,   r!  mro   s         r%   rp   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+&&q!Q/&&q!Q/	
 	
r'   c                     t         j                  |||z
  z
  t        ||      dz    }| j                  ||||      }t        j                  t        |      d      S )Nr   r   rr   )r!   rt   minpmfru   r   )r4   r   r,   r!  rK   rv   s         r%   rw   zhypergeom_gen._entropy  sM    EE!q1u+c!Qi!m,xx1a#vvd4jq))r'   c                 2    t        j                  ||||      S r    )rO   _hypergeom_sfr2  s        r%   rZ   zhypergeom_gen._sf  s    ##Aq!Q//r'   c                    g }t        t        j                  ||||       D ]  \  }}}}	|dz   |dz   z  |dz
  |	dz
  z  k  r7|j                  t	        t        | j                  ||||	                          Vt        j                  |dz   |	dz         }
|j                  t        | j                  |
|||	                    t        j                  |      S )Nr   r   )zipr!   r   appendr   r   r   aranger   rM   asarrayr4   rK   r   r,   r!  resquantr,  r-  drawk2s              r%   r  zhypergeom_gen._logsf  s    &)2+>+>q!Q+J&K 	I"E3dc	*dSjTCZ-HH

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

9T\\"c4%FGH	I zz#r'   c                    g }t        t        j                  ||||       D ]  \  }}}}	|dz   |dz   z  |dz
  |	dz
  z  kD  r7|j                  t	        t        | j                  ||||	                          Vt        j                  d|dz         }
|j                  t        | j                  |
|||	                    t        j                  |      S )Nr   r   r   )rA  r!   r   rB  r   r   logsfrC  r   rM   rD  rE  s              r%   r   zhypergeom_gen._logcdf  s    &)2+>+>q!Q+J&K 	I"E3dc	*dSjTCZ-HH

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

9T\\"c4%FGH	I zz#r'   re   )r{   r|   r}   r~   r5   r<   rE   rA   rM   rR   rV   rp   rw   rZ   r  r   r   r'   r%   r  r  #  sG    ADC
A811
"*
0

r'   r  	hypergeomc                   <    e Zd ZdZd Zd Zd Zd
dZd Zd Z	d	 Z
y)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,   rr1   r3   s    r%   r5   znhypergeom_gen._shape_info  r"  r'   c                 
    d|fS r   r   )r4   r   r,   rP  s       r%   rE   znhypergeom_gen._get_support$  r   r'   c                     |dk\  ||k  z  |dk\  z  |||z
  k  z  }|t        |      t        |      z  t        |      z  z  }|S r   r?   )r4   r   r,   rP  r   s        r%   rA   znhypergeom_gen._argcheck'  sO    Q16"a1f-ac:AQ/+a.@@r'   Nc                 :     t          fd       } ||||||      S )Nc                 &   j                  | ||      \  }}t        j                  ||dz         }j                  || ||      }t	        ||dd      }	 |	|j                  |            j                  t              }
||
j                         S |
S )Nr   nextextrapolate)kind
fill_valuer  )	supportr!   rC  r   r   uniformr   intitem)r   r,   rP  r:   r;   rD   r   ksr   ppfrvsr4   s              r%   _rvs1z"nhypergeom_gen._rvs.<locals>._rvs1.  s     <<1a(DAq1ac"B((2q!Q'C3MJCl***56==cBC|xxz!Jr'   r   _vectorize_rvs_over_shapes)r4   r   r,   rP  r:   r;   r`  s   `      r%   r<   znhypergeom_gen._rvs,  s*    	#		 
$		 Q14lCCr'   c                 F    |dk(  |dk(  z  }t        | ||||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 rG   r+  )rK   r   r,   rP  s       r%   <lambda>z(nhypergeom_gen._logpmf.<locals>.<lambda>?  s    "(1a.6!A#q>!A!'!Aqs1uQw!7"8:@1Qq!:L"M!'!QqSU!3"46<QqS!n"E r'           )r   )r
   )r4   rK   r   r,   rP  r   r/  s          r%   rM   znhypergeom_gen._logpmf<  s>    aAF#TEAq!Q<F '*+ r'   c                 <    t        | j                  ||||            S r    r   )r4   rK   r   r,   rP  s        r%   rR   znhypergeom_gen._pmfF  s     4<<1a+,,r'   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   re   r   )r4   r   r,   rP  rl   rm   rn   ro   s           r%   rp   znhypergeom_gen._statsK  s     Q$1bda1qSAaCE]1gaiAaCEAaCE?+q1!A;? B3Br'   re   )r{   r|   r}   r~   r5   rE   rA   r<   rM   rR   rp   r   r'   r%   rN  rN    s.    bHC

D -
r'   rN  
nhypergeomc                   0    e Zd ZdZd ZddZd Zd Zd Zy)	
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   r3   s    r%   r5   zlogser_gen._shape_infov  r   r'   Nc                 (    |j                  ||      S r  )	logseriesr   s       r%   r<   zlogser_gen._rvsy  s     %%ad%33r'   c                     |dkD  |dk  z  S r>   r   r   s     r%   rA   zlogser_gen._argcheck~  s    A!a%  r'   c                 j    t        j                  ||       dz  |z  t        j                  |       z  S r   )r!   r  r   r   r  s      r%   rR   zlogser_gen._pmf  s.    A$q(7==!+<<<r'   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  )r4   r.   rP  rl   mu2prm   mu3pmu3rn   mu4pmu4ro   s               r%   rp   zlogser_gen._stats  s>   MM1"!c']QrAvS1$RUlrAvQ37Q,.QrT$Y2q5(288C%%rAv1Q3(NQqSAEA:--!A1q0@@BQtVBY42-"a%736\C3Br'   re   )	r{   r|   r}   r~   r5   r<   rA   rR   rp   r   r'   r%   rk  rk  ]  s     0>4
!=r'   rk  logserzA logarithmicc                   H    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y)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 )Nrl   Fr   r-   r1   r3   s    r%   r5   zpoisson_gen._shape_info  s    4BFF]CDDr'   c                     |dk\  S r   r   )r4   rl   s     r%   rA   zpoisson_gen._argcheck  s    Qwr'   Nc                 &    |j                  ||      S r    poisson)r4   rl   r:   r;   s       r%   r<   zpoisson_gen._rvs  s    ##B--r'   c                 V    t        j                  ||      t        |dz         z
  |z
  }|S rG   )r   rI   rH   )r4   rK   rl   Pks       r%   rM   zpoisson_gen._logpmf  s)    ]]1b!E!a%L025	r'   c                 8    t        | j                  ||            S r    r   )r4   rK   rl   s      r%   rR   zpoisson_gen._pmf  s    4<<2&''r'   c                 D    t        |      }t        j                  ||      S r    )r   r   pdtrr4   r$   rl   rK   s       r%   rV   zpoisson_gen._cdf  s    !H||Ar""r'   c                 D    t        |      }t        j                  ||      S r    )r   r   pdtrcr  s       r%   rZ   zpoisson_gen._sf  s    !H}}Q##r'   c                     t        t        j                  ||            }t        j                  |dz
  d      }t        j
                  ||      }t        j                  ||k\  ||      S r
  )r   r   pdtrikr!   r'  r  r  )r4   rb   rl   rv   vals1r  s         r%   rc   zpoisson_gen._ppf  sR    GNN1b)*

4!8Q'||E2&xx	5$//r'   c                     |}t        j                  |      }|dkD  }t        ||fd t         j                        }t        ||fd t         j                        }||||fS )Nr   c                     t        d| z        S r   r   r#   s    r%   re  z$poisson_gen._stats.<locals>.<lambda>  s    d3q5k r'   c                     d| z  S r   r   r#   s    r%   re  z$poisson_gen._stats.<locals>.<lambda>  s
    c!e r'   )r!   rD  r
   r2   )r4   rl   rm   tmp
mu_nonzerorn   ro   s          r%   rp   zpoisson_gen._stats  sX    jjn1W

SF,A266J
SFORVVD3Br'   re   )r{   r|   r}   r~   r5   rA   r<   rM   rR   rV   rZ   rc   rp   r   r'   r%   rz  rz    s5    0E.(#$0r'   rz  r  z	A Poisson)r   r  c                   N    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y	)
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lambdaFr   r   r1   r3   s    r%   r5   zplanck_gen._shape_info  s    8UQKHIIr'   c                     |dkD  S r   r   )r4   lambda_s     r%   rA   zplanck_gen._argcheck  s    {r'   c                 <    t        |        t        | |z        z  S r    )r   r   )r4   rK   r  s      r%   rR   zplanck_gen._pmf  s     whWHQJ//r'   c                 >    t        |      }t        | |dz   z         S rG   )r   r   r4   r$   r  rK   s       r%   rV   zplanck_gen._cdf  s#    !Hwh!n%%%r'   c                 8    t        | j                  ||            S r    )r   r  )r4   r$   r  s      r%   rZ   zplanck_gen._sf  s    4;;q'*++r'   c                 *    t        |      }| |dz   z  S rG   r   r  s       r%   r  zplanck_gen._logsf	  s    !Hx1~r'   c                     t        d|z  t        |       z  dz
        } |dz
  j                  | j                  |       }| j	                  ||      }t        j                  ||k\  ||      S )N      r   )r   r   cliprE   rV   r!   r  )r4   rb   r  rv   r  r  s         r%   rc   zplanck_gen._ppf  sf    DL5!9,Q./a 1 1' :<yy(xx	5$//r'   Nc                 H    t        |        }|j                  ||      dz
  S )Nr  r   )r   r  )r4   r  r:   r;   r.   s        r%   r<   zplanck_gen._rvs  s+    G8_%%ad%3c99r'   c                     dt        |      z  }t        |       t        |       dz  z  }dt        |dz        z  }ddt        |      z  z   }||||fS )Nr   r   r   r   )r   r   r   )r4   r  rl   rm   rn   ro   s         r%   rp   zplanck_gen._stats  s^    uW~7(mUG8_q00tGCK  qg3Br'   c                 X    t        |        }|t        |       z  |z  t        |      z
  S r    )r   r   r   )r4   r  Cs      r%   rw   zplanck_gen._entropy  s/    G8_sG8}$Q&Q//r'   re   )r{   r|   r}   r~   r5   rA   rR   rV   rZ   r  rc   r<   rp   rw   r   r'   r%   r  r    s:    6J0&,0:
0r'   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
y	)
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!  Tr1   r3   s    r%   r5   zboltzmann_gen._shape_info=  s:    9ea[.I3q"&&k>BD 	Dr'   c                 0    |dkD  |dkD  z  t        |      z  S r   r?   r4   r  r!  s      r%   rA   zboltzmann_gen._argcheckA  s    !A&Q77r'   c                 $    | j                   |dz
  fS rG   rC   r  s      r%   rE   zboltzmann_gen._get_supportD  s    vvq1u}r'   c                 j    dt        |       z
  dt        | |z        z
  z  }|t        | |z        z  S rG   r   )r4   rK   r  r!  facts        r%   rR   zboltzmann_gen._pmfG  s<     #wh-!C
O"34C
O##r'   c                 h    t        |      }dt        | |dz   z        z
  dt        | |z        z
  z  S rG   )r   r   )r4   r$   r  r!  rK   s        r%   rV   zboltzmann_gen._cdfM  s9    !H#wh!n%%#whqj/(9::r'   c                    |dt        | |z        z
  z  }t        d|z  t        d|z
        z  dz
        }|dz
  j                  dt        j
                        }| j                  |||      }t	        j                  ||k\  ||      S )Nr   r  rf  )r   r   r   r  r!   r2   rV   r  )r4   rb   r  r!  qnewrv   r  r  s           r%   rc   zboltzmann_gen._ppfQ  s|    !C
O#$DL3qv;.q01ac266*yy+xx	5$//r'   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   rr  r   r  )r4   r  r!  zzNrl   rm   trmtrm2rn   ro   s              r%   rp   zboltzmann_gen._statsX  s(   M'!_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r'   N)r{   r|   r}   r~   r5   rA   rE   rR   rV   rc   rp   r   r'   r%   r  r  '  s+    *D8$;0r'   r  	boltzmannz!A truncated discrete exponential )r   rD   r  c                   H    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y	)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   highr1   r3   s    r%   r5   zrandint_gen._shape_info  sH    5$"&&"&&(9>J64266'266):NKM 	Mr'   c                 <    ||kD  t        |      z  t        |      z  S r    r?   r4   r  r  s      r%   rA   zrandint_gen._argcheck  s     s
k#..T1BBBr'   c                     ||dz
  fS rG   r   r  s      r%   rE   zrandint_gen._get_support  s    DF{r'   c                 x    t        j                  |      ||z
  z  }t        j                  ||k\  ||k  z  |d      S )Nrf  )r!   	ones_liker  )r4   rK   r  r  r.   s        r%   rR   zrandint_gen._pmf  s8    LLOtcz*xxca$h/B77r'   c                 4    t        |      }||z
  dz   ||z
  z  S r   r  )r4   r$   r  r  rK   s        r%   rV   zrandint_gen._cdf  s"    !HC",,r'   c                     t        |||z
  z  |z         dz
  }|dz
  j                  ||      }| j                  |||      }t        j                  ||k\  ||      S rG   )r   r  rV   r!   r  )r4   rb   r  r  rv   r  r  s          r%   rc   zrandint_gen._ppf  s\    A$s*+a/T*yyT*xx	5$//r'   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      (@rf  g333333)r!   rD  )
r4   r  r  m2m1rl   drm   rn   ro   s
             r%   rp   zrandint_gen._stats  s{    D!2::c?B2gmq GsQw$1s#qsSy13Br'   Nc                    t        j                  |      j                  dk(  r1t        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  )otypes)	r!   rD  r:   r   broadcast_to	vectorizer   r   r[  )r4   r  r  r:   r;   randints         r%   r<   zrandint_gen._rvs  s    ::c?1$D)9)>)>!)Cc4dCC
 //#t,C??4.D,,w|\B')xx}o7sD!!r'   c                     t        ||z
        S r    )r   r  s      r%   rw   zrandint_gen._entropy  s    4#:r'   re   )r{   r|   r}   r~   r5   rA   rE   rR   rV   rc   rp   r<   rw   r   r'   r%   r  r  j  s7    =~MC8
-0""r'   r  r  z#A discrete uniform (random integer)c                   0    e Zd ZdZd ZddZd Zd Zd Zy)	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 )NrD   Fr   r   r1   r3   s    r%   r5   zzipf_gen._shape_info      3266{NCDDr'   Nc                 (    |j                  ||      S r  )zipf)r4   rD   r:   r;   s       r%   r<   zzipf_gen._rvs  s       ..r'   c                     |dkD  S rG   r   r4   rD   s     r%   rA   zzipf_gen._argcheck  s    1ur'   c                     |j                  t        j                        }dt        j                  |d      z  || z  z  }|S Nr   r   )r   r!   float64r   r	   )r4   rK   rD   r  s       r%   rR   zzipf_gen._pmf  s9    HHRZZ 7<<1%%A2-	r'   c                 L    t        ||dz   kD  ||fd t        j                        S )Nr   c                 b    t        j                  | |z
  d      t        j                  | d      z  S rG   )r   r	   )rD   r,   s     r%   re  z zipf_gen._munp.<locals>.<lambda>$  s%    a!eQ/',,q!2DD r'   r   )r4   r,   rD   s      r%   _munpzzipf_gen._munp!  s*    AI1vDFF 	r'   re   )	r{   r|   r}   r~   r5   r<   rA   rR   r  r   r'   r%   r  r    s"    )VE/r'   r  r  zA Zipfc                 :    t        |d      t        || dz         z
  S )z"Generalized harmonic number, a > 1r   )r	   r,   rD   s     r%   _gen_harmonic_gt1r  +  s     1:Q!$$r'   c                    t        j                  |       s| S t        j                  |       }t        j                  |t              }t        j
                  |ddt              D ]  }|| k  }||xx   d|||   z  z  z  cc<    |S )z#Generalized harmonic number, a <= 1r   r   r   )r!   r:   max
zeros_likefloatrC  )r,   rD   n_maxoutimasks         r%   _gen_harmonic_leq1r  1  sw    771:FF1IE
--
'CYYua51 "AvD	Qq!D'z\!	" Jr'   c                 l    t        j                  | |      \  } }t        |dkD  | |ft        t              S )zGeneralized harmonic numberr   r   f2)r!   r   r
   r  r  r  s     r%   _gen_harmonicr  >  s9    q!$DAqa!eaV).@B Br'   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
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 )NrD   Fr   r-   r,   Tr   r1   r3   s    r%   r5   zzipfian_gen._shape_infot  s:    3266{MB3q"&&k>BD 	Dr'   c                 V    |dk\  |dkD  z  |t        j                  |t              k(  z  S )Nr   r  )r!   rD  r[  r4   rD   r,   s      r%   rA   zzipfian_gen._argcheckx  s*    Q1q5!Q"**Qc*B%BCCr'   c                 
    d|fS rG   r   r  s      r%   rE   zzipfian_gen._get_support|  r   r'   c                 l    |j                  t        j                        }dt        ||      z  || z  z  S r   )r   r!   r  r  r4   rK   rD   r,   s       r%   rR   zzipfian_gen._pmf  s1    HHRZZ ]1a((1qb500r'   c                 4    t        ||      t        ||      z  S r    r  r  s       r%   rV   zzipfian_gen._cdf  s    Q"]1a%888r'   c                 v    |dz   }||z  t        ||      t        ||      z
  z  dz   ||z  t        ||      z  z  S rG   r  r  s       r%   rZ   zzipfian_gen._sf  sL    EA}Q*]1a-@@AAEa4a++- 	.r'   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   rr  r   r  )r4   rD   r,   HnaHna1Hna2Hna3Hna4mu1mu2nmu2dmu2rn   ro   s                 r%   rp   zzipfian_gen._stats  s&   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r'   N)r{   r|   r}   r~   r5   rA   rE   rR   rV   rZ   rp   r   r'   r%   r  r  E  s-    ,\DD19. r'   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
y)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 )NrD   Fr   r   r1   r3   s    r%   r5   zdlaplace_gen._shape_info  r  r'   c                 P    t        |dz        t        | t        |      z        z  S Nr   )r   r   abs)r4   rK   rD   s      r%   rR   zdlaplace_gen._pmf  s$    AcE{S!c!f---r'   c                 L    t        |      }d }d }t        |dk\  ||f||      S )Nc                 D    dt        | | z        t        |      dz   z  z
  S r  r  rK   rD   s     r%   r   zdlaplace_gen._cdf.<locals>.f  s$    aR!VA
333r'   c                 B    t        || dz   z        t        |      dz   z  S rG   r  r
  s     r%   r  zdlaplace_gen._cdf.<locals>.f2  s"    qAE{#s1vz22r'   r   r  )r   r
   )r4   r$   rD   rK   r   r  s         r%   rV   zdlaplace_gen._cdf  s0    !H	4	3 !q&1a&A"55r'   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                  | j                  ||      |k\  ||      S )Nr   r   )r   r   r!   r  r   rV   )r4   rb   rD   constrv   r  s         r%   rc   zdlaplace_gen._ppf  s    CF
BHHQCG!44 5\A-1!1Q3%-00146 7 qxx		%+q0%>>r'   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 )Nr   r   r   g      $@r   rf  r   r  )r4   rD   ear   rw  s        r%   rp   zdlaplace_gen._stats  sg    VeRUQJeRU3r6\"_%B
23CQJO++r'   c                 N    |t        |      z  t        t        |dz              z
  S r  )r   r   r   r  s     r%   rw   zdlaplace_gen._entropy  s"    47{Sae---r'   Nc                     t        j                  t        j                  |              }|j                  ||      }|j                  ||      }||z
  S r  )r!   r   rD  r  )r4   rD   r:   r;   probOfSuccessr$   ys          r%   r<   zdlaplace_gen._rvs  sR      2::a=.11""=t"<""=t"<1ur'   re   )r{   r|   r}   r~   r5   rR   rV   rc   rp   rw   r<   r   r'   r%   r  r    s+    ,E.	6?,.r'   r  dlaplacezA discrete Laplacianc                   0    e Zd ZdZd ZddZd Zd Zd Zy)	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   r1   r3   s    r%   r5   zskellam_gen._shape_info  s:    5%!RVVnE5%!RVVnEG 	Gr'   Nc                 P    |}|j                  ||      |j                  ||      z
  S r    r~  )r4   r  r   r:   r;   r,   s         r%   r<   zskellam_gen._rvs  s1    $$S!,$$S!,- 	.r'   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        |S # 1 sw Y   S xY w)Nr   r   r   r   r   )r!   r   r  rO   	_ncx2_pdfr4   r$   r  r   pxs        r%   rR   zskellam_gen._pmf  s    [[h' 	E!a% **1S5!QqS'1S5A!C **1S5!QqS'1S5A!CEB	E
 		E
 	s   A#BBc                 ,   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        |S # 1 sw Y   S xY w)Nr   r   r   r   r   )r   r!   r   r  rO   	_ncx2_cdfr  s        r%   rV   zskellam_gen._cdf$  s    !H[[h' 	G!a% **1S5"Q$#>f..qua1gquEEGB	G 			G 	s   AB		Bc                 N    ||z
  }||z   }|t        |dz        z  }d|z  }||||fS )Nr   r   r   )r4   r  r   r   rm   rn   ro   s          r%   rp   zskellam_gen._stats,  s>    SyCiD#N"WS"b  r'   re   )	r{   r|   r}   r~   r5   r<   rR   rV   rp   r   r'   r%   r  r    s!    :G.
!r'   r  skellamz	A Skellamc                   H    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zy)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   r1   r3   s    r%   r5   zyulesimon_gen._shape_infoY  s    7EArvv;GHHr'   Nc           	          |j                  |      }|j                  |      }t        | t        t        | |z               z        }|S r    )standard_exponentialr   r   r   )r4   r%  r:   r;   E1E2anss          r%   r<   zyulesimon_gen._rvs\  sK    ..t4..t4B3RC%K 00112
r'   c                 :    |t        j                  ||dz         z  S rG   r   r   r4   r$   r%  s      r%   rR   zyulesimon_gen._pmfb  s    w||Auqy111r'   c                     |dkD  S r   r   )r4   r%  s     r%   rA   zyulesimon_gen._argchecke  s    	r'   c                 L    t        |      t        j                  ||dz         z   S rG   r   r   r   r-  s      r%   rM   zyulesimon_gen._logpmfh  s     5zGNN1eai888r'   c                 @    d|t        j                  ||dz         z  z
  S rG   r,  r-  s      r%   rV   zyulesimon_gen._cdfk  s!    1w||Auqy1111r'   c                 :    |t        j                  ||dz         z  S rG   r,  r-  s      r%   rZ   zyulesimon_gen._sfn  s    7<<519---r'   c                 L    t        |      t        j                  ||dz         z   S rG   r0  r-  s      r%   r  zyulesimon_gen._logsfq  s     1vq%!)444r'   c                    t        j                  |dk  t         j                  ||dz
  z        }t        j                  |dkD  |dz  |dz
  |dz
  dz  z  z  t         j                        }t        j                  |dk  t         j                  |      }t        j                  |dkD  t	        |dz
        |dz   dz  z  ||dz
  z  z  t         j                        }t        j                  |dk  t         j                  |      }t        j                  |dkD  |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   r   r   r      1      )r!   r  r2   nanr   )r4   r%  rl   r   rn   ro   s         r%   rp   zyulesimon_gen._statst  s[   XXeqj"&&%519*=>hhuqyaxECKEAI>#ABvv hhuz2663/XXeai519oQ6%519:MNff XXeqj"&&"-XXeaiaiBMBJ$>$C$)UQY$7519$E$G Hff XXeqj"&&"-3Br'   re   )r{   r|   r}   r~   r5   r<   rR   rA   rM   rV   rZ   r  rp   r   r'   r%   r#  r#  7  s6     BI292.5r'   r#  	yulesimon)r   rD   c                       fd}|S )z?Decorator that vectorizes _rvs method to work on ndarray shapesc           
         t        |d   j                  |       \  }}t        j                  |       } t        j                  |      }t        j                  |      }t        j                  |      r 
g || | S t        j
                  |       }t        j                  |j                        }t        j                  ||    ||   f      }t        j                  |||      }t        j                  | |     D ]5  } 
g |D 	cg c]  }	t        j                  |	      |    c}	|| ||<   7 t        j                  |||      S c c}	w r   )r   shaper!   arrayallemptyrC  ndimhstackmoveaxisndindexsqueeze)r:   r;   args
_rvs1_size_rvs1_indicesr  j0j1r  argr`  s             r%   r<   z(_vectorize_rvs_over_shapes.<locals>._rvs  s4   $0a$E!
Mxx~XXj)
/66- 3$33l33hhtn
 YYsxx YYM>*B},=>?kk#r2&T=.12 	5A  54@CRZZ_Q/@ 5%5'35CF	5 {{3B'' As   Er   )r`  r<   s   ` r%   rb  rb    s    (4 Kr'   c                   >    e Zd ZdZdZdZd Zd Zd Zd	dZ	d Z
d Zy)
_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   r1   r3   s    r%   r5   z_nchypergeom_gen._shape_info  sf    3q"&&k=A3q"&&k=A3q"&&k=A651bff+~FH 	Hr'   c                 ~    |||}}}||z
  }t        j                  d||z
        }t        j                  ||      }||fS r   r&  )	r4   r   r,   r!  rN  r  r  x_minx_maxs	            r%   rE   z_nchypergeom_gen._get_support  sF    aq2V

1a"f%

1b!e|r'   c                    t        j                  |      t        j                  |      }}t        j                  |      t        j                  |      }}|j                  t              |k(  |dk\  z  }|j                  t              |k(  |dk\  z  }|j                  t              |k(  |dk\  z  }|dkD  }||k  }	||k  }
||z  |z  |z  |	z  |
z  S r   )r!   rD  r   r[  )r4   r   r,   r!  rN  cond1cond2cond3cond4cond5cond6s              r%   rA   z_nchypergeom_gen._argcheck  s    zz!}bjjm1**Q-D!14#!#Q/#!#Q/#!#Q/qQQu}u$u,u4u<<r'   c                 <     t          fd       } |||||||      S )Nc                     t        j                  |      }t               }t        |
j                        } |||| |||      }	|	j                  |      }	|	S r    )r!   prodr   getattrrvs_namereshape)r   r,   r!  rN  r:   r;   lengthurnrv_genr_  r4   s             r%   r`  z$_nchypergeom_gen._rvs.<locals>._rvs1  sO    WWT]F#%CS$--0FAq$=C++d#CJr'   r   ra  )r4   r   r,   r!  rN  r:   r;   r`  s   `       r%   r<   z_nchypergeom_gen._rvs  s,    	#	 
$	 Q1dLIIr'   c                      t        j                  |||||      \  }}}}}|j                  dk(  rt        j                  |      S t         j                   fd       } ||||||      S )Nr   c                 P    j                  ||||d      }|j                  |       S Ng-q=)distprobability)r$   r   r,   r!  rN  r`  r4   s         r%   _pmf1z$_nchypergeom_gen._pmf.<locals>._pmf1  s(    ))Aq!T51C??1%%r'   )r!   r   r:   
empty_liker  )r4   r$   r   r,   r!  rN  rg  s   `      r%   rR   z_nchypergeom_gen._pmf  sk    ..q!Q4@1aD66Q;==##		& 
	& Q1a&&r'   c                 z     t         j                   fd       }d|v sd|v r |||||      nd\  }}d\  }	}
|||	|
fS )Nc                 N    j                  ||| |d      }|j                         S rd  )re  rk   )r   r,   r!  rN  r`  r4   s        r%   	_moments1z*_nchypergeom_gen._stats.<locals>._moments1  s%    ))Aq!T51C;;= r'   r:  vre   )r!   r  )r4   r   r,   r!  rN  rk   rk  r:  rl  rf   rK   s   `          r%   rp   z_nchypergeom_gen._stats  sX    		! 
	! .1G^sg~	!Q4(! 	11!Qzr'   re   )r{   r|   r}   r~   r]  re  r5   rE   rA   r<   rR   rp   r   r'   r%   rL  rL    s3     HDH	=J'
r'   rL  c                       e Zd ZdZdZeZy)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   re  r   r'   r%   rn  rn    s    GR H%Dr'   rn  nchypergeom_fisherz$A Fisher's noncentral hypergeometricc                       e Zd ZdZdZeZy)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   re  r   r'   r%   rr  rr  K  s    GR H'Dr'   rr  nchypergeom_walleniusz&A Wallenius' noncentral hypergeometric)_	functoolsr   scipyr   scipy.specialr   r   r   r   rH   r	   scipy._lib._utilr
   r   scipy.interpolater   numpyr   r   r   r   r   r   r   r   r   r   r!   _distn_infrastructurer   r   r   r   scipy.stats._booststatsrO   
_biasedurnr   r   r   r&   r)   r   r   r   r   r   r   r   r   r  r  r  r  rL  rN  ri  rk  rx  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r2   r  r  r!  r#  r9  rb  rL  rn  rp  rr  rt  listglobalscopyitemspairs_distn_names_distn_gen_names__all__r   r'   r%   <module>r     s  
   I I 5 & M M M > > # #, ,
M* M*` 	w>#I >#B AK0	OK Od {+	j
 j
Z 
	"Z[ Zz .
E7{ E7P !&=9QK Qh {+	\[ \~ .
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%
BV + V r 	K
@M; M` 266''2HJ<!+ <!~ i+
FLK L^ {a0	#LF{ FRK&- K&\ ,	35 
K( 0 K(\ 2	 57  	WY^^##%&!7{!K 
)
)r'   