o
    Ö­jGþ  ã                   @   sê  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 m!Z!m"Z" dd
l#m$Z$m%Z%m&Z& ddl'm(Z( d dl)m  m*Z+ G dd„ deƒZ,e,dd�Z-G dd„ de,ƒZ.e.ddd�Z/G dd„ deƒZ0e0dd�Z1G dd„ deƒZ2e2dd�Z3G dd„ deƒZ4e4dd�Z5G dd„ deƒZ6e6ddd d!�Z7G d"d#„ d#eƒZ8e8d$d�Z9G d%d&„ d&eƒZ:e:d'd�Z;G d(d)„ d)eƒZ<e<dd*d+d!�Z=G d,d-„ d-eƒZ>e>d.d/d0�Z?G d1d2„ d2eƒZ@e@d d3d4d!�ZAG d5d6„ d6eƒZBeBd7d d8d9�ZCG d:d;„ d;eƒZDeDd<d=d0�ZEG d>d?„ d?eƒZFeFdd@dAd!�ZGdBdC„ ZHdDdE„ ZIdFdG„ ZJG dHdI„ dIeƒZKeKddJdKd!�ZLG dLdM„ dMeƒZMeMejN dNdOd!�ZOG dPdQ„ dQeƒZPePdRdSdTdU�ZQdqdVdW„ZRdrdYdZ„ZSdsd[d\„ZTeQePZUZVeR WeUeV¡eQ_ReS WeUeV¡eQ_SeT WeUeV¡eQ_TG d]d^„ d^e"ƒZXG d_d`„ d`eƒZYeYejN dadbd!�ZZG dcdd„ ddeƒZ[e[deddf�Z\G dgdh„ dheƒZ]G didj„ dje]ƒZ^e^dkdld0�Z_G dmdn„ dne]ƒZ`e`dodpd0�Zaebecƒ  d¡  e¡ ƒZfeefeƒ\ZgZhegeh ZidS )té    )Ú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Ú_vectorize_rvs_over_shapesÚ
_ShapeInfoÚ_isintegralÚrv_discrete_frozen)Ú_PyFishersNCHypergeometricÚ_PyWalleniusNCHypergeometricÚ_PyStochasticLib3)Ú_poisson_binomc                   @   st   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zddd„Zdd„ ZdS )Ú	binom_gena2  A binomial discrete random variable.

    %(before_notes)s

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

    .. math::

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

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

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

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

    %(after_notes)s

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

    %(example)s

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

    c                 C   ó"   t dddtjfdƒt ddddƒgS ©	NÚnTr   ©TFÚpF©r   r   ©TT©r   ÚnpÚinf©Úself© r.   úY/var/www/html/CropPilot/venv/lib/python3.10/site-packages/scipy/stats/_discrete_distns.pyÚ_shape_infoA   ó   ÿzbinom_gen._shape_infoNc                 C   ó   |  |||¡S ©N)Úbinomial©r-   r$   r&   ÚsizeÚrandom_stater.   r.   r/   Ú_rvsE   ó   zbinom_gen._rvsc                 C   s    |dkt |ƒ@ |dk@ |dk@ S ©Nr   r   ©r   ©r-   r$   r&   r.   r.   r/   Ú	_argcheckH   ó    zbinom_gen._argcheckc                 C   s
   | j |fS r3   ©Úar<   r.   r.   r/   Ú_get_supportK   s   
zbinom_gen._get_supportc                 C   sR   t |ƒ}t|d ƒt|d ƒt|| d ƒ  }|t ||¡ t || | ¡ S ©Nr   )r   Úgamlnr   ÚxlogyÚxlog1py)r-   Úxr$   r&   ÚkÚcombilnr.   r.   r/   Ú_logpmfN   s   ("zbinom_gen._logpmfc                 C   ó   t  |||¡S r3   )ÚscuÚ
_binom_pmf©r-   rF   r$   r&   r.   r.   r/   Ú_pmfS   ó   zbinom_gen._pmfc                 C   ó   t |ƒ}t |||¡S r3   )r   rK   Ú
_binom_cdf©r-   rF   r$   r&   rG   r.   r.   r/   Ú_cdfW   ó   zbinom_gen._cdfc                 C   rP   r3   )r   rK   Ú	_binom_sfrR   r.   r.   r/   Ú_sf[   rT   zbinom_gen._sfc                 C   rJ   r3   )rK   Ú
_binom_isfrM   r.   r.   r/   Ú_isf_   r9   zbinom_gen._isfc                 C   rJ   r3   )rK   Ú
_binom_ppf©r-   Úqr$   r&   r.   r.   r/   Ú_ppfb   r9   zbinom_gen._ppfÚmvc                 C   s¨   || }||t  |¡  }d\}}d|v r2|t  |¡ }t  || ¡}	t  |	¡}
d| |	 }|
| }d|v rN|t  |¡ }|| }t  |¡}
d| }|
| }||||fS )N©NNÚsç       @rG   ç      @)r*   Úsquarer   Ú
reciprocal)r-   r$   r&   ÚmomentsÚmuÚvarÚg1Úg2ÚpqÚnpq_sqrtÚt1Út2Únpqr.   r.   r/   Ú_statse   s    

zbinom_gen._statsc                 C   s2   t jd|d … }|  |||¡}t jt|ƒdd�S )Nr   r   ©Úaxis)r*   Úr_rN   Úsumr   )r-   r$   r&   rG   Úvalsr.   r.   r/   Ú_entropyw   s   zbinom_gen._entropyr^   ©r]   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r0   r8   r=   rA   rI   rN   rS   rV   rX   r\   rn   rt   r.   r.   r.   r/   r!      s    #

r!   Úbinom)Únamec                   @   ór   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )Úbernoulli_gena  A Bernoulli discrete random variable.

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

    %(example)s

    c                 C   ó   t ddddƒgS ©Nr&   Fr'   r(   ©r   r,   r.   r.   r/   r0   ™   ó   zbernoulli_gen._shape_infoNc                 C   s   t j| d|||d�S )Nr   ©r6   r7   )r!   r8   ©r-   r&   r6   r7   r.   r.   r/   r8   œ   ó   zbernoulli_gen._rvsc                 C   s   |dk|dk@ S r:   r.   ©r-   r&   r.   r.   r/   r=   Ÿ   r‚   zbernoulli_gen._argcheckc                 C   s   | j | jfS r3   )r@   Úbr†   r.   r.   r/   rA   ¢   s   zbernoulli_gen._get_supportc                 C   ó   t  |d|¡S rB   )r{   rI   ©r-   rF   r&   r.   r.   r/   rI   ¦   r9   zbernoulli_gen._logpmfc                 C   rˆ   rB   )r{   rN   r‰   r.   r.   r/   rN   ©   ó   zbernoulli_gen._pmfc                 C   rˆ   rB   )r{   rS   r‰   r.   r.   r/   rS   ®   r9   zbernoulli_gen._cdfc                 C   rˆ   rB   )r{   rV   r‰   r.   r.   r/   rV   ±   r9   zbernoulli_gen._sfc                 C   rˆ   rB   )r{   rX   r‰   r.   r.   r/   rX   ´   r9   zbernoulli_gen._isfc                 C   rˆ   rB   )r{   r\   )r-   r[   r&   r.   r.   r/   r\   ·   r9   zbernoulli_gen._ppfc                 C   s   t  d|¡S rB   )r{   rn   r†   r.   r.   r/   rn   º   ó   zbernoulli_gen._statsc                 C   s   t |ƒt d| ƒ S rB   )r   r†   r.   r.   r/   rt   ½   r…   zbernoulli_gen._entropyr^   rv   r.   r.   r.   r/   r~   €   s    
r~   Ú	bernoulli)r‡   r|   c                   @   sL   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	ddd„Z
dS )Úbetabinom_gena  A beta-binomial discrete random variable.

    %(before_notes)s

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

    The probability mass function for `betabinom` is:

    .. math::

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

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

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

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

    %(after_notes)s

    .. versionadded:: 1.4.0

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

    %(example)s

    c                 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@   F©FFr‡   r)   r,   r.   r.   r/   r0   è   ó   þzbetabinom_gen._shape_infoNc                 C   ó   |  |||¡}| |||¡S r3   )Úbetar4   ©r-   r$   r@   r‡   r6   r7   r&   r.   r.   r/   r8   í   ó   zbetabinom_gen._rvsc                 C   s   d|fS ©Nr   r.   ©r-   r$   r@   r‡   r.   r.   r/   rA   ñ   ó   zbetabinom_gen._get_supportc                 C   ó    |dkt |ƒ@ |dk@ |dk@ S r–   r;   r—   r.   r.   r/   r=   ô   r>   zbetabinom_gen._argcheckc                 C   sP   t |ƒ}t|d ƒ t|| d |d ƒ }|t|| || | ƒ t||ƒ S rB   )r   r   r   ©r-   rF   r$   r@   r‡   rG   rH   r.   r.   r/   rI   ÷   s   $$zbetabinom_gen._logpmfc                 C   ó   t |  ||||¡ƒS r3   ©r   rI   ©r-   rF   r$   r@   r‡   r.   r.   r/   rN   ü   r…   zbetabinom_gen._pmfr]   c                 C   s€  |||  }d| }|| }||| |  | | || d  }d\}	}
d|v rHdt |ƒ }	|	|| d|  ||  9 }	|	|| d ||   }	d|v rº||  |j¡}
|
|| d d|  9 }
|
d| | |d  7 }
|
d|d  7 }
|
d| | | d|  8 }
|
d	| | |d  8 }
|
|| d d| |  9 }
|
|| | || d  || d  || |   }
|
d8 }
|||	|
fS )
Nr   r^   r_   ç      ð?é   rG   é   é   é   )r   ÚastypeÚdtype)r-   r$   r@   r‡   rd   Úe_pÚe_qre   rf   rg   rh   r.   r.   r/   rn   ÿ   s(   $4zbetabinom_gen._statsr^   ru   )rw   rx   ry   rz   r0   r8   rA   r=   rI   rN   rn   r.   r.   r.   r/   r�   Ä   s    #
r�   Ú	betabinomc                   @   ój   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )Ú
nbinom_gena×  A negative binomial discrete random variable.

    %(before_notes)s

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

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

    .. math::

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

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

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

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

    .. math::

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

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

    .. math::

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

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

    %(after_notes)s

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

    %(example)s

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

    c                 C   r"   r#   r)   r,   r.   r.   r/   r0   T  r1   znbinom_gen._shape_infoNc                 C   r2   r3   )Únegative_binomialr5   r.   r.   r/   r8   X  r9   znbinom_gen._rvsc                 C   s   |dk|dk@ |dk@ S r:   r.   r<   r.   r.   r/   r=   [  ó   znbinom_gen._argcheckc                 C   rJ   r3   )rK   Ú_nbinom_pmfrM   r.   r.   r/   rN   ^  rO   znbinom_gen._pmfc                 C   s>   t || ƒt |d ƒ t |ƒ }||t|ƒ  t || ¡ S rB   )rC   r   r   rE   )r-   rF   r$   r&   Úcoeffr.   r.   r/   rI   b  s    znbinom_gen._logpmfc                 C   rP   r3   )r   rK   Ú_nbinom_cdfrR   r.   r.   r/   rS   f  rT   znbinom_gen._cdfc           	      C   s¢   t |ƒ}t |||¡\}}}|  |||¡}|dk}dd„ }|}tjdd��" ||| || || ƒ||< t ||  ¡|| < W d   ƒ |S 1 sJw   Y  |S )Nç      à?c                 S   s   t  t | d |d| ¡ ¡S rB   )r*   r   r   Úbetainc)rG   r$   r&   r.   r.   r/   Úf1o  ó   znbinom_gen._logcdf.<locals>.f1Úignore)Údivide)r   r*   Úbroadcast_arraysrS   Úerrstater   )	r-   rF   r$   r&   rG   ÚcdfÚcondr±   Úlogcdfr.   r.   r/   Ú_logcdfj  s   
þýznbinom_gen._logcdfc                 C   rP   r3   )r   rK   Ú
_nbinom_sfrR   r.   r.   r/   rV   y  rT   znbinom_gen._sfc                 C   ó>   t jdd�� t |||¡W  d   ƒ S 1 sw   Y  d S ©Nr³   ©Úover)r*   r¶   rK   Ú_nbinom_isfrM   r.   r.   r/   rX   }  ó   $ÿznbinom_gen._isfc                 C   r¼   r½   )r*   r¶   rK   Ú_nbinom_ppfrZ   r.   r.   r/   r\   �  rÁ   znbinom_gen._ppfc                 C   s,   t  ||¡t  ||¡t  ||¡t  ||¡fS r3   )rK   Ú_nbinom_meanÚ_nbinom_varianceÚ_nbinom_skewnessÚ_nbinom_kurtosis_excessr<   r.   r.   r/   rn   …  s
   



üznbinom_gen._statsr^   )rw   rx   ry   rz   r0   r8   r=   rN   rI   rS   rº   rV   rX   r\   rn   r.   r.   r.   r/   r©     s    :
r©   Únbinomc                   @   sD   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ Zdd„ Zddd„Z	dS )Úbetanbinom_genaK  A beta-negative-binomial discrete random variable.

    %(before_notes)s

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

    The probability mass function for `betanbinom` is:

    .. math::

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

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

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

    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                 C   rŽ   r�   r)   r,   r.   r.   r/   r0   ¶  r‘   zbetanbinom_gen._shape_infoNc                 C   r’   r3   )r“   rª   r”   r.   r.   r/   r8   »  r•   zbetanbinom_gen._rvsc                 C   r™   r–   r;   r—   r.   r.   r/   r=   ¿  r>   zbetanbinom_gen._argcheckc                 C   sF   t |ƒ}t || ¡ t||d ƒ }|t|| || ƒ t||ƒ S rB   )r   r*   r   r   rš   r.   r.   r/   rI   Â  s    zbetanbinom_gen._logpmfc                 C   r›   r3   rœ   r�   r.   r.   r/   rN   Ç  r…   zbetanbinom_gen._pmfr]   c                 C   s´   dd„ }t |dk|||f|tjd�}dd„ }t |dk|||f|tjd�}d\}}	d	d
„ }
d|v r>t |dk|||f|
tjd�}dd„ }d|v rTt |dk|||f|tjd�}	||||	fS )Nc                 S   s   | | |d  S ©Nrž   r.   ©r$   r@   r‡   r.   r.   r/   ÚmeanÍ  r‚   z#betanbinom_gen._stats.<locals>.meanr   )ÚfÚ	fillvaluec                 S   s4   | | | | d  || d  |d |d d   S )Nrž   r`   r.   rÊ   r.   r.   r/   rf   Ð  s   ÿz"betanbinom_gen._stats.<locals>.varrŸ   r^   c                 S   sT   d|  | d d| | d  |d  t | | | | d  || d  |d  ƒ S )NrŸ   rž   ç      @r`   ©r   rÊ   r.   r.   r/   ÚskewÕ  s   ÿ ÿÿz#betanbinom_gen._stats.<locals>.skewr_   r¡   c                 S   s   |d }|d d |d |d| d   d|d  |   d| d  |d |d  |d |d  |  d|d d     d|d  |  |d |d  |d |d  |  d|d d     }|d	 |d  | |  || d  ||  d  }|| | d S )
Nr`   rž   r    ra   rÎ   ç      @rŸ   r¡   g      @r.   )r$   r@   r‡   ÚtermÚterm_2Údenominatorr.   r.   r/   ÚkurtosisÛ  s0    ÿÿÿÿþ"ÿÿü
ÿ
ÿz'betanbinom_gen._stats.<locals>.kurtosisrG   é   ©r	   r*   r+   )r-   r$   r@   r‡   rd   rË   re   rf   rg   rh   rÐ   rÕ   r.   r.   r/   rn   Ê  s   zbetanbinom_gen._statsr^   ru   )
rw   rx   ry   rz   r0   r8   r=   rI   rN   rn   r.   r.   r.   r/   rÈ   ‘  s    $
rÈ   Ú
betanbinomc                   @   r¨   )Úgeom_gena5  A geometric discrete random variable.

    %(before_notes)s

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

    .. math::

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

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

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

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

    %(after_notes)s

    See Also
    --------
    planck

    %(example)s

    c                 C   r   r€   r�   r,   r.   r.   r/   r0     r‚   zgeom_gen._shape_infoNc                 C   s.   |j ||d�}t |j¡j}t |dk ||¡S )N©r6   r   )Ú	geometricr*   Úiinfor¤   ÚmaxÚwhere)r-   r&   r6   r7   ÚresÚmax_intr.   r.   r/   r8     s   zgeom_gen._rvsc                 C   s   |dk|dk@ S ©Nr   r   r.   r†   r.   r.   r/   r=     r‚   zgeom_gen._argcheckc                 C   s   t  d| |d ¡| S rB   )r*   Úpower©r-   rG   r&   r.   r.   r/   rN      r«   zgeom_gen._pmfc                 C   s   t  |d | ¡t|ƒ S rB   )r   rE   r   rã   r.   r.   r/   rI   #  ó   zgeom_gen._logpmfc                 C   s   t |ƒ}tt| ƒ| ƒ S r3   )r   r   r   ©r-   rF   r&   rG   r.   r.   r/   rS   &  ó   zgeom_gen._cdfc                 C   s   t  |  ||¡¡S r3   )r*   r   Ú_logsfr‰   r.   r.   r/   rV   *  s   zgeom_gen._sfc                 C   s   t |ƒ}|t| ƒ S r3   )r   r   rå   r.   r.   r/   rç   -  rT   zgeom_gen._logsfc                 C   sF   t t| ƒt| ƒ ƒ}|  |d |¡}t ||k|dk@ |d |¡S rá   )r   r   rS   r*   rÞ   )r-   r[   r&   rs   Útempr.   r.   r/   r\   1  s   zgeom_gen._ppfc                 C   sP   d| }d| }|| | }d| t |ƒ }t g d¢|¡d|  }||||fS )Nrž   r`   )r   iúÿÿÿr    )r   r*   Úpolyval)r-   r&   re   Úqrrf   rg   rh   r.   r.   r/   rn   6  s   zgeom_gen._statsc                 C   s$   t  |¡ t  | ¡d|  |  S rÉ   )r*   r   r   r†   r.   r.   r/   rt   >  s   $zgeom_gen._entropyr^   )rw   rx   ry   rz   r0   r8   r=   rN   rI   rS   rV   rç   r\   rn   rt   r.   r.   r.   r/   rÙ   ñ  s    !
rÙ   ÚgeomzA geometric)r@   r|   Úlongnamec                   @   r}   )Úhypergeom_gena	  A hypergeometric discrete random variable.

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

    %(before_notes)s

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

    The probability mass function is defined as,

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

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

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

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

    %(after_notes)s

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

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

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

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

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

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

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

    And to generate random numbers:

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

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

    c                 C   ó:   t dddtjfdƒt dddtjfdƒt dddtjfdƒgS )NÚMTr   r%   r$   ÚNr)   r,   r.   r.   r/   r0   �  r‘   zhypergeom_gen._shape_infoNc                 C   s   |j ||| ||d�S ©NrÚ   )Úhypergeometric)r-   rï   r$   rð   r6   r7   r.   r.   r/   r8   ”  ó   zhypergeom_gen._rvsc                 C   s    t  |||  d¡t  ||¡fS r–   ©r*   ÚmaximumÚminimum)r-   rï   r$   rð   r.   r.   r/   rA   —  r>   zhypergeom_gen._get_supportc                 C   sL   |dk|dk@ |dk@ }|||k||k@ M }|t |ƒt |ƒ@ t |ƒ@ M }|S r–   r;   )r-   rï   r$   rð   r¸   r.   r.   r/   r=   š  s   zhypergeom_gen._argcheckc           	      C   sŠ   ||}}|| }t |d dƒt |d dƒ t || d |d ƒ t |d || d ƒ t || d || | d ƒ t |d dƒ }|S rB   ©r   )	r-   rG   rï   r$   rð   ÚtotÚgoodÚbadÚresultr.   r.   r/   rI      s   
0ÿÿþzhypergeom_gen._logpmfc                 C   ó   t  ||||¡S r3   )rK   Ú_hypergeom_pmf©r-   rG   rï   r$   rð   r.   r.   r/   rN   ¨  r‚   zhypergeom_gen._pmfc                 C   rü   r3   )rK   Ú_hypergeom_cdfrþ   r.   r.   r/   rS   «  r‚   zhypergeom_gen._cdfc                 C   sÚ   d| d| d| }}}|| }||d  d| ||   d| |  }||d | | 9 }|d| | ||  | d| d  7 }||| ||  | |d  |d   }t  |||¡t  |||¡t  |||¡|fS )Nrž   r   ra   rÑ   r    r`   rÎ   )rK   Ú_hypergeom_meanÚ_hypergeom_varianceÚ_hypergeom_skewness)r-   rï   r$   rð   Úmrh   r.   r.   r/   rn   ®  s   (((üzhypergeom_gen._statsc                 C   sB   t j|||  t||ƒd … }|  ||||¡}t jt|ƒdd�S )Nr   r   ro   )r*   rq   ÚminÚpmfrr   r   )r-   rï   r$   rð   rG   rs   r.   r.   r/   rt   ¿  s    zhypergeom_gen._entropyc                 C   rü   r3   )rK   Ú_hypergeom_sfrþ   r.   r.   r/   rV   Ä  r‚   zhypergeom_gen._sfc                 C   s    g }t t ||||¡Ž D ]>\}}}}	|d |d  |d |	d  k r3| tt|  ||||	¡ƒ ƒ¡ qt |d |	d ¡}
| t|  	|
|||	¡ƒ¡ qt 
|¡S )Nr¯   r   )Úzipr*   rµ   Úappendr   r   r¹   Úaranger   rI   Úasarray©r-   rG   rï   r$   rð   rß   Úquantrø   rù   ÚdrawÚk2r.   r.   r/   rç   Ç  s     "
zhypergeom_gen._logsfc                 C   sœ   g }t t ||||¡Ž D ]<\}}}}	|d |d  |d |	d  kr3| tt|  ||||	¡ƒ ƒ¡ qt d|d ¡}
| t|  	|
|||	¡ƒ¡ qt 
|¡S )Nr¯   r   r   )r  r*   rµ   r  r   r   Úlogsfr	  r   rI   r
  r  r.   r.   r/   rº   Ó  s     "
zhypergeom_gen._logcdfr^   )rw   rx   ry   rz   r0   r8   rA   r=   rI   rN   rS   rn   rt   rV   rç   rº   r.   r.   r.   r/   rí   E  s    I
rí   Ú	hypergeomc                   @   sJ   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	d
„Zdd„ Zdd„ Z	dd„ Z
dS )Ú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                 C   rî   )Nrï   Tr   r%   r$   Úrr)   r,   r.   r.   r/   r0   H  r‘   znhypergeom_gen._shape_infoc                 C   ó   d|fS r–   r.   )r-   rï   r$   r  r.   r.   r/   rA   M  r˜   znhypergeom_gen._get_supportc                 C   sD   |dk||k@ |dk@ ||| k@ }|t |ƒt |ƒ@ t |ƒ@ M }|S r–   r;   )r-   rï   r$   r  r¸   r.   r.   r/   r=   P  s   $znhypergeom_gen._argcheckNc                    s"   t ‡ fdd„ƒ}||||||d�S )Nc                    sl   ˆ   | ||¡\}}t ||d ¡}ˆ  || ||¡}t||ddd�}	|	|j|d�ƒ t¡}
|d u r4|
 ¡ S |
S )Nr   ÚnextÚextrapolate)ÚkindÚ
fill_valuerÚ   )	Úsupportr*   r	  r·   r   Úuniformr£   ÚintÚitem)rï   r$   r  r6   r7   r@   r‡   Úksr·   ÚppfÚrvsr,   r.   r/   Ú_rvs1W  s   z"nhypergeom_gen._rvs.<locals>._rvs1rƒ   ©r   )r-   rï   r$   r  r6   r7   r  r.   r,   r/   r8   U  s   znhypergeom_gen._rvsc                 C   s2   |dk|dk@ }t | ||||fdd„ dd�}|S )Nr   c                 S   sv   t | d |ƒ t | | dƒ t ||  d || | d ƒ t || |  d dƒ t |d || d ƒ t |d dƒ S rB   r÷   )rG   rï   r$   r  r.   r.   r/   Ú<lambda>h  s   ÿÿþþz(nhypergeom_gen._logpmf.<locals>.<lambda>ç        )rÍ   )r	   )r-   rG   rï   r$   r  r¸   rû   r.   r.   r/   rI   e  s   ûznhypergeom_gen._logpmfc                 C   r›   r3   rœ   )r-   rG   rï   r$   r  r.   r.   r/   rN   o  s   znhypergeom_gen._pmfc                 C   s€   d| d| d| }}}|| || d  }||d  | || d || d   d||| d    }d\}}||||fS )Nrž   r   rŸ   r^   r.   )r-   rï   r$   r  re   rf   rg   rh   r.   r.   r/   rn   t  s
   <znhypergeom_gen._statsr^   )rw   rx   ry   rz   r0   rA   r=   r8   rI   rN   rn   r.   r.   r.   r/   r  ã  s    d

r  Ú
nhypergeomc                   @   ó:   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ Zdd„ ZdS )Ú
logser_genaÔ  A Logarithmic (Log-Series, Series) discrete random variable.

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

    %(example)s

    c                 C   r   r€   r�   r,   r.   r.   r/   r0   Ÿ  r‚   zlogser_gen._shape_infoNc                 C   ó   |j ||d�S rñ   )Ú	logseriesr„   r.   r.   r/   r8   ¢  rŠ   zlogser_gen._rvsc                 C   s   |dk|dk @ S r:   r.   r†   r.   r.   r/   r=   §  r‚   zlogser_gen._argcheckc                 C   s"   t  ||¡ d | t | ¡ S rÉ   )r*   râ   r   r   rã   r.   r.   r/   rN   ª  ó   "zlogser_gen._pmfc                 C   s  t  | ¡}||d  | }| | |d d  }|||  }| | d|  d| d  }|d| |  d|d   }|t |d¡ }| | d|d d  d| |d d   d| | |d d    }	|	d| |  d| | |  d|d   }
|
|d  d }||||fS )	Nrž   rŸ   r¡   ç      ø?r   r    rÖ   rÎ   )r   r   r*   râ   )r-   r&   r  re   Úmu2prf   Úmu3pÚmu3rg   Úmu4pÚmu4rh   r.   r.   r/   rn   ®  s   :ÿ,zlogser_gen._statsr^   )	rw   rx   ry   rz   r0   r8   r=   rN   rn   r.   r.   r.   r/   r%  †  s    
r%  ÚlogserzA logarithmicc                   @   sZ   e Zd ZdZdd„ Zdd„ Zddd„Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )Úpoisson_gena›  A Poisson discrete random variable.

    %(before_notes)s

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

    .. math::

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

    for :math:`k \ge 0`.

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

    %(after_notes)s

    %(example)s

    c                 C   ó   t dddtjfdƒgS )Nre   Fr   r%   r)   r,   r.   r.   r/   r0   Ú  ró   zpoisson_gen._shape_infoc                 C   s   |dkS r–   r.   )r-   re   r.   r.   r/   r=   Þ  r˜   zpoisson_gen._argcheckNc                 C   s   |  ||¡S r3   ©Úpoisson)r-   re   r6   r7   r.   r.   r/   r8   á  r‹   zpoisson_gen._rvsc                 C   s    t  ||¡t|d ƒ | }|S rB   )r   rD   rC   )r-   rG   re   ÚPkr.   r.   r/   rI   ä  s   zpoisson_gen._logpmfc                 C   ó   t |  ||¡ƒS r3   rœ   )r-   rG   re   r.   r.   r/   rN   è  s   zpoisson_gen._pmfc                 C   ó   t |ƒ}t ||¡S r3   )r   r   Úpdtr©r-   rF   re   rG   r.   r.   r/   rS   ì  ó   zpoisson_gen._cdfc                 C   r6  r3   )r   r   Úpdtrcr8  r.   r.   r/   rV   ð  r9  zpoisson_gen._sfc                 C   s>   t t ||¡ƒ}t |d d¡}t ||¡}t ||k||¡S rá   )r   r   Úpdtrikr*   rõ   r7  rÞ   )r-   r[   re   rs   Úvals1rè   r.   r.   r/   r\   ô  s   zpoisson_gen._ppfc                 C   sN   |}t  |¡}|dk}t||fdd„ t jƒ}t||fdd„ t jƒ}||||fS )Nr   c                 S   s   t d|  ƒS rÉ   rÏ   ©rF   r.   r.   r/   r!  þ  s    z$poisson_gen._stats.<locals>.<lambda>c                 S   s   d|  S rÉ   r.   r=  r.   r.   r/   r!  ÿ  s    )r*   r
  r	   r+   )r-   re   rf   ÚtmpÚ
mu_nonzerorg   rh   r.   r.   r/   rn   ú  s   
zpoisson_gen._statsr^   )rw   rx   ry   rz   r0   r=   r8   rI   rN   rS   rV   r\   rn   r.   r.   r.   r/   r0  Á  s    
r0  r3  z	A Poisson)r|   rì   c                   @   sb   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
ddd„Zdd„ Zdd„ ZdS )Ú
planck_gena  A Planck discrete exponential random variable.

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

    See Also
    --------
    geom

    %(example)s

    c                 C   r1  )NÚlambdaFr   r�   r)   r,   r.   r.   r/   r0   "  ró   zplanck_gen._shape_infoc                 C   ó   |dkS r–   r.   )r-   Úlambda_r.   r.   r/   r=   %  r˜   zplanck_gen._argcheckc                 C   s   t | ƒ t| | ƒ S r3   )r   r   )r-   rG   rC  r.   r.   r/   rN   (  rä   zplanck_gen._pmfc                 C   s   t |ƒ}t| |d  ƒ S rB   )r   r   ©r-   rF   rC  rG   r.   r.   r/   rS   +  ræ   zplanck_gen._cdfc                 C   r5  r3   )r   rç   )r-   rF   rC  r.   r.   r/   rV   /  r‚   zplanck_gen._sfc                 C   s   t |ƒ}| |d  S rB   ©r   rD  r.   r.   r/   rç   2  rT   zplanck_gen._logsfc                 C   sL   t d| t| ƒ d ƒ}|d j|  |¡Ž }|  ||¡}t ||k||¡S )Nç      ð¿r   )r   r   ÚcliprA   rS   r*   rÞ   )r-   r[   rC  rs   r<  rè   r.   r.   r/   r\   6  s   zplanck_gen._ppfNc                 C   s   t | ƒ }|j||d�d S )NrÚ   rž   )r   rÛ   )r-   rC  r6   r7   r&   r.   r.   r/   r8   <  s   zplanck_gen._rvsc                 C   sP   dt |ƒ }t| ƒt | ƒd  }dt|d ƒ }ddt|ƒ  }||||fS )Nr   rŸ   r`   rÖ   )r   r   r   )r-   rC  re   rf   rg   rh   r.   r.   r/   rn   A  s
   zplanck_gen._statsc                 C   s&   t | ƒ }|t| ƒ | t|ƒ S r3   )r   r   r   )r-   rC  ÚCr.   r.   r/   rt   H  s   zplanck_gen._entropyr^   )rw   rx   ry   rz   r0   r=   rN   rS   rV   rç   r\   r8   rn   rt   r.   r.   r.   r/   r@    s    
r@  ÚplanckzA discrete exponential c                   @   óH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )Ú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                 C   s(   t dddtjfdƒt dddtjfdƒgS )NrC  Fr   r�   rð   Tr)   r,   r.   r.   r/   r0   f  ó   ÿzboltzmann_gen._shape_infoc                 C   s   |dk|dk@ t |ƒ@ S r–   r;   ©r-   rC  rð   r.   r.   r/   r=   j  r«   zboltzmann_gen._argcheckc                 C   s   | j |d fS rB   r?   rM  r.   r.   r/   rA   m  r9   zboltzmann_gen._get_supportc                 C   s2   dt | ƒ dt | | ƒ  }|t | | ƒ S rB   ©r   )r-   rG   rC  rð   Úfactr.   r.   r/   rN   p  s    zboltzmann_gen._pmfc                 C   s0   t |ƒ}dt| |d  ƒ dt| | ƒ  S rB   )r   r   )r-   rF   rC  rð   rG   r.   r.   r/   rS   v  s   (zboltzmann_gen._cdfc                 C   sd   |dt | | ƒ  }td| td| ƒ d ƒ}|d  dtj¡}|  |||¡}t ||k||¡S )Nr   rF  r"  )r   r   r   rG  r*   r+   rS   rÞ   )r-   r[   rC  rð   Úqnewrs   r<  rè   r.   r.   r/   r\   z  s
   zboltzmann_gen._ppfc                 C   s  t | ƒ}t | | ƒ}|d|  || d|   }|d| d  || | d| d   }d| d|  }||d  || |  }|d|  |d  |d | d|   }	|	|d  }	|dd|  ||   |d  |d | dd|  ||    }
|
| | }
|||	|
fS )Nrž   r   rŸ   r¡   r)  rÖ   rN  )r-   rC  rð   ÚzÚzNre   rf   ÚtrmÚtrm2rg   rh   r.   r.   r/   rn   �  s   
((@zboltzmann_gen._statsN)rw   rx   ry   rz   r0   r=   rA   rN   rS   r\   rn   r.   r.   r.   r/   rK  P  s    rK  Ú	boltzmannz!A truncated discrete exponential )r|   r@   rì   c                   @   sZ   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
ddd„Zdd„ ZdS )Úrandint_genaÏ  A uniform discrete random variable.

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

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

    Calculate the first four moments:

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

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

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

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

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

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

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

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

    Generate random numbers:

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

    c                 C   s0   t ddtj tjfdƒt ddtj tjfdƒgS )NÚlowTr�   Úhighr)   r,   r.   r.   r/   r0   Ó  s   ÿzrandint_gen._shape_infoc                 C   s   ||kt |ƒ@ t |ƒ@ S r3   r;   ©r-   rW  rX  r.   r.   r/   r=   ×  r«   zrandint_gen._argcheckc                 C   s   ||d fS rB   r.   rY  r.   r.   r/   rA   Ú  r‹   zrandint_gen._get_supportc                 C   s8   t  |¡t j|t jd�|  }t  ||k||k @ |d¡S )N©r¤   r"  )r*   Ú	ones_liker
  Úint64rÞ   )r-   rG   rW  rX  r&   r.   r.   r/   rN   Ý  s   zrandint_gen._pmfc                 C   s   t |ƒ}|| d ||  S rÉ   rE  )r-   rF   rW  rX  rG   r.   r.   r/   rS   â  ræ   zrandint_gen._cdfc                 C   sH   t |||  | ƒd }|d  ||¡}|  |||¡}t ||k||¡S rB   )r   rG  rS   r*   rÞ   )r-   r[   rW  rX  rs   r<  rè   r.   r.   r/   r\   æ  s   zrandint_gen._ppfc           
      C   sj   t  |¡t  |¡}}|| d d }|| }|| d d }d}d|| d  || d  }	||||	fS )Nrž   rŸ   r   g      (@r"  g333333ó¿)r*   r
  )
r-   rW  rX  Úm2Úm1re   Údrf   rg   rh   r.   r.   r/   rn   ì  s   zrandint_gen._statsNc                 C   sv   t  |¡jdkrt  |¡jdkrt||||d�S |dur(t  ||¡}t  ||¡}t jtt|ƒt  t¡gd�}|||ƒS )z=An array of *size* random integers >= ``low`` and < ``high``.r   rÚ   N)Úotypes)	r*   r
  r6   r
   Úbroadcast_toÚ	vectorizer   r¤   r  )r-   rW  rX  r6   r7   Úrandintr.   r.   r/   r8   õ  s    
ÿ
zrandint_gen._rvsc                 C   s   t || ƒS r3   )r   rY  r.   r.   r/   rt     r‹   zrandint_gen._entropyr^   )rw   rx   ry   rz   r0   r=   rA   rN   rS   r\   rn   r8   rt   r.   r.   r.   r/   rV  “  s    ?
	rV  rc  z#A discrete uniform (random integer)c                   @   r$  )Ú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                 C   r1  )Nr@   Fr   r�   r)   r,   r.   r.   r/   r0   ;  ró   zzipf_gen._shape_infoNc                 C   r&  rñ   )Úzipf)r-   r@   r6   r7   r.   r.   r/   r8   >  r9   zzipf_gen._rvsc                 C   rB  rB   r.   ©r-   r@   r.   r.   r/   r=   A  r˜   zzipf_gen._argcheckc                 C   s*   |  tj¡}dt |d¡ ||   }|S ©Nrž   r   )r£   r*   Úfloat64r   r   )r-   rG   r@   r4  r.   r.   r/   rN   D  s   zzipf_gen._pmfc                 C   s    t ||d k||fdd„ tjƒS )Nr   c                 S   s   t  | | d¡t  | d¡ S rB   )r   r   )r@   r$   r.   r.   r/   r!  M  s    z zipf_gen._munp.<locals>.<lambda>r×   )r-   r$   r@   r.   r.   r/   Ú_munpJ  s
   ýzzipf_gen._munpr^   )	rw   rx   ry   rz   r0   r8   r=   rN   ri  r.   r.   r.   r/   rd    s    +
rd  re  zA Zipfc                 C   s   t |dƒt || d ƒ S )z"Generalized harmonic number, a > 1r   )r   ©r$   r@   r.   r.   r/   Ú_gen_harmonic_gt1T  s   rk  c                 C   sf   t  | ¡s| S t  | ¡}t j|td�}t j|ddtd�D ]}|| k}||  d|||   7  < q|S )z#Generalized harmonic number, a <= 1rZ  r   éÿÿÿÿr   )r*   r6   rÝ   Ú
zeros_likeÚfloatr	  )r$   r@   Ún_maxÚoutÚiÚmaskr.   r.   r/   Ú_gen_harmonic_leq1Z  s   

rs  c                 C   s(   t  | |¡\} }t|dk| |fttd�S )zGeneralized harmonic numberr   ©rÌ   Úf2)r*   rµ   r	   rk  rs  rj  r.   r.   r/   Ú_gen_harmonicg  s   ÿrv  c                   @   rJ  )Ú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                 C   s(   t dddtjfdƒt dddtjfdƒgS )Nr@   Fr   r%   r$   Tr�   r)   r,   r.   r.   r/   r0   �  rL  zzipfian_gen._shape_infoc                 C   s"   |dk|dk@ |t j|td�k@ S )Nr   rZ  )r*   r
  r  ©r-   r@   r$   r.   r.   r/   r=   ¡  r(  zzipfian_gen._argcheckc                 C   r  rB   r.   rx  r.   r.   r/   rA   ¥  r˜   zzipfian_gen._get_supportc                 C   s$   |  tj¡}dt||ƒ ||   S rÉ   )r£   r*   rh  rv  ©r-   rG   r@   r$   r.   r.   r/   rN   ¨  s   zzipfian_gen._pmfc                 C   s   t ||ƒt ||ƒ S r3   ©rv  ry  r.   r.   r/   rS   ¬  r…   zzipfian_gen._cdfc                 C   s:   |d }|| t ||ƒt ||ƒ  d || t ||ƒ  S rB   rz  ry  r.   r.   r/   rV   ¯  s   ÿzzipfian_gen._sfc                 C   sþ   t ||ƒ}t ||d ƒ}t ||d ƒ}t ||d ƒ}t ||d ƒ}|| }|| |d  }	|d }
|	|
 }|| d| | |d   d|d  |d   |d  }|d | d|d  | |  d| |d  |  d|d   |	d  }|d8 }||||fS )Nr   rŸ   r¡   rÖ   r)  r    rz  )r-   r@   r$   ÚHnaÚHna1ÚHna2ÚHna3ÚHna4Úmu1Úmu2nÚmu2dÚmu2rg   rh   r.   r.   r/   rn   µ  s"   
82
ÿÿzzipfian_gen._statsN)rw   rx   ry   rz   r0   r=   rA   rN   rS   rV   rn   r.   r.   r.   r/   rw  n  s    .rw  Úzipfianz	A Zipfianc                   @   sJ   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	ddd„Z
dS )Údlaplace_genaL  A  Laplacian discrete random variable.

    %(before_notes)s

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

    .. math::

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

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

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

    %(after_notes)s

    %(example)s

    c                 C   r1  )Nr@   Fr   r�   r)   r,   r.   r.   r/   r0   á  ró   zdlaplace_gen._shape_infoc                 C   s   t |d ƒt| t|ƒ ƒ S ©Nr`   )r   r   Úabs)r-   rG   r@   r.   r.   r/   rN   ä  s   zdlaplace_gen._pmfc                 C   s0   t |ƒ}dd„ }dd„ }t|dk||f||d�S )Nc                 S   s   dt | |  ƒt |ƒd   S rg  rN  ©rG   r@   r.   r.   r/   rÌ   ë  r²   zdlaplace_gen._cdf.<locals>.fc                 S   s   t || d  ƒt |ƒd  S rB   rN  rˆ  r.   r.   r/   ru  î  ó   zdlaplace_gen._cdf.<locals>.f2r   rt  )r   r	   )r-   rF   r@   rG   rÌ   ru  r.   r.   r/   rS   è  s   zdlaplace_gen._cdfc                 C   st   dt |ƒ }tt |ddt | ƒ  k t|| ƒ| d td| | ƒ | ¡ƒ}|d }t |  ||¡|k||¡S )Nr   rž   )r   r   r*   rÞ   r   rS   )r-   r[   r@   Úconstrs   r<  r.   r.   r/   r\   ó  s   þzdlaplace_gen._ppfc                 C   s\   t |ƒ}d| |d d  }d| |d d|  d  |d d  }d|d||d  d fS )Nr`   rž   rŸ   g      $@rÖ   r"  rÎ   rN  )r-   r@   Úearƒ  r.  r.   r.   r/   rn   û  s   (zdlaplace_gen._statsc                 C   s   |t |ƒ tt|d ƒƒ S r†  )r   r   r   rf  r.   r.   r/   rt     r‰  zdlaplace_gen._entropyNc                 C   s8   t  t  |¡ ¡ }|j||d�}|j||d�}|| S rñ   )r*   r   r
  rÛ   )r-   r@   r6   r7   ÚprobOfSuccessrF   Úyr.   r.   r/   r8     s   zdlaplace_gen._rvsr^   )rw   rx   ry   rz   r0   rN   rS   r\   rn   rt   r8   r.   r.   r.   r/   r…  Ê  s    r…  ÚdlaplacezA discrete Laplacianc                   @   sX   e Zd ZdZdd„ Zdd„ Zdddœdd	„Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )Úpoisson_binom_genul  A Poisson Binomial discrete random variable.

    %(before_notes)s

    See Also
    --------
    binom

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

    .. math::

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

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

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

    %(after_notes)s

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

    %(example)s

    c                 C   s   g S r3   r.   r,   r.   r.   r/   r0   G  s   zpoisson_binom_gen._shape_infoc                 G   s,   t j|dd�}d|k|dk@ }t j|dd�S ©Nr   ro   r   )r*   ÚstackÚall)r-   Úargsr&   Úcondsr.   r.   r/   r=   L  s   zpoisson_binom_gen._argcheckNrƒ   c                G   s`   t j|dd�}|d u r|jnt  |¡r|dfnt|ƒd }t  |j|¡}tj|||d�jdd�S )Nrl  ro   r   )r   rƒ   )	r*   r‘  ÚshapeÚisscalarÚtupleÚbroadcast_shapesrŒ   r8   rr   )r-   r6   r7   r“  r&   r.   r.   r/   r8   Q  s   ÿzpoisson_binom_gen._rvsc                 G   s   dt |ƒfS r–   )Úlen)r-   r“  r.   r.   r/   rA   [  r‹   zpoisson_binom_gen._get_supportc                 G   óD   t  |¡ t j¡}t j|g|¢R Ž ^}}t j|t jd�}t||dƒS )NrZ  r  ©r*   Ú
atleast_1dr£   r\  rµ   r
  rh  r    ©r-   rG   r“  r.   r.   r/   rN   ^  ó   zpoisson_binom_gen._pmfc                 G   rš  )NrZ  r·   r›  r�  r.   r.   r/   rS   d  rž  zpoisson_binom_gen._cdfc                 O   s>   t j|dd�}t j|dd�}t j|d|  dd�}||d d fS r�  )r*   r‘  rr   )r-   r“  Úkwdsr&   rË   rf   r.   r.   r/   rn   j  s   zpoisson_binom_gen._statsc                 O   s   t | g|¢R i |¤ŽS r3   )Úpoisson_binomial_frozen)r-   r“  rŸ  r.   r.   r/   Ú__call__p  ró   zpoisson_binom_gen.__call__)rw   rx   ry   rz   r0   r=   r8   rA   rN   rS   rn   r¡  r.   r.   r.   r/   r�    s    (
r�  Úpoisson_binomzA Poisson binomialr&   )r|   rì   Úshapesc                 C   ó   t t |dd¡ƒ|d|fS ©Nrl  r   rž   ©r—  r*   Úmoveaxis)r-   r&   Úlocr6   r.   r.   r/   Ú_parse_args_rvs|  rä   r©  r]   c                 C   r¤  r¥  r¦  )r-   r&   r¨  rd   r.   r.   r/   Ú_parse_args_stats  rä   rª  c                 C   s   t t |dd¡ƒ|dfS r¥  r¦  )r-   r&   r¨  r.   r.   r/   Ú_parse_args‚  r«   r«  c                   @   s   e Zd Zdd„ Zddd„ZdS )r   c                 O   s‚   || _ || _|jdi | ¡ ¤Ž| _t tt¡| j_t	 tt¡| j_	t
 tt¡| j_
| jj
|i |¤Ž\}}}| jj|Ž \| _| _d S )Nr.   )r“  rŸ  Ú	__class__Ú_updated_ctor_paramÚdistr©  Ú__get__Ú_pb_objÚ_pb_clsrª  r«  rA   r@   r‡   )r-   r®  r“  rŸ  r£  Ú_r.   r.   r/   Ú__init__Ž  s   z poisson_binomial_frozen.__init__NFc           	      K   s<   | j j| ji | j¤Ž\}}}| j j|| j||||fi |¤ŽS r3   )r®  r«  r“  rŸ  Úexpect)	r-   ÚfuncÚlbÚubÚconditionalrŸ  r@   r¨  Úscaler.   r.   r/   r´  �  s    zpoisson_binomial_frozen.expect)NNNF)rw   rx   ry   r³  r´  r.   r.   r.   r/   r   Œ  s    r   c                   @   r$  )Ú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                 C   s(   t dddtjfdƒt dddtjfdƒgS )Nr€  Fr   r�   rƒ  r)   r,   r.   r.   r/   r0   Â  rL  zskellam_gen._shape_infoNc                 C   s   |}|  ||¡|  ||¡ S r3   r2  )r-   r€  rƒ  r6   r7   r$   r.   r.   r/   r8   Æ  s   

ÿzskellam_gen._rvsc                 C   s€   t jdd��0 t  |dk t d| dd|  d| ¡d t d| dd|  d| ¡d ¡}W d   ƒ |S 1 s9w   Y  |S )Nr³   r¾   r   rŸ   r   )r*   r¶   rÞ   rK   Ú	_ncx2_pdf©r-   rF   r€  rƒ  Úpxr.   r.   r/   rN   Ë  s   
  þ
ÿûzskellam_gen._pmfc                 C   s€   t |ƒ}tjdd��, t |dk t d| d| d| ¡dt d| d|d  d| ¡ ¡}W d   ƒ |S 1 s9w   Y  |S )Nr³   r¾   r   rŸ   éþÿÿÿr   )r   r*   r¶   rÞ   rK   Ú	_ncx2_cdfr¼  r.   r.   r/   rS   Ó  s   
 þ
ÿüzskellam_gen._cdfc                 C   s4   || }|| }|t |d ƒ }d| }||||fS )Nr¡   r   rÏ   )r-   r€  rƒ  rË   rf   rg   rh   r.   r.   r/   rn   Û  s
   zskellam_gen._statsr^   )	rw   rx   ry   rz   r0   r8   rN   rS   rn   r.   r.   r.   r/   rº  ¤  s    
rº  Úskellamz	A Skellamc                   @   sZ   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )Ú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                 C   r1  )NÚalphaFr   r�   r)   r,   r.   r.   r/   r0     ró   zyulesimon_gen._shape_infoNc                 C   s6   |  |¡}|  |¡}t| tt| | ƒ ƒ ƒ}|S r3   )Ústandard_exponentialr   r   r   )r-   rÂ  r6   r7   ÚE1ÚE2Úansr.   r.   r/   r8     s   

zyulesimon_gen._rvsc                 C   s   |t  ||d ¡ S rB   ©r   r“   ©r-   rF   rÂ  r.   r.   r/   rN     r…   zyulesimon_gen._pmfc                 C   rB  r–   r.   )r-   rÂ  r.   r.   r/   r=     r˜   zyulesimon_gen._argcheckc                 C   s   t |ƒt ||d ¡ S rB   ©r   r   r   rÈ  r.   r.   r/   rI     r«   zyulesimon_gen._logpmfc                 C   s   d|t  ||d ¡  S rB   rÇ  rÈ  r.   r.   r/   rS     r«   zyulesimon_gen._cdfc                 C   s   |t  ||d ¡ S rB   rÇ  rÈ  r.   r.   r/   rV     r…   zyulesimon_gen._sfc                 C   s   t |ƒt ||d ¡ S rB   rÉ  rÈ  r.   r.   r/   rç      r«   zyulesimon_gen._logsfc                 C   s  t  |dkt j||d  ¡}t  |dk|d |d |d d   t j¡}t  |dkt j|¡}t  |dkt|d ƒ|d d  ||d   t j¡}t  |dkt j|¡}t  |dk|d d|d  d|  d ||d  |d    t j¡}t  |dkt j|¡}||||fS )	Nr   rŸ   r`   r¡   rÖ   é   é1   é   )r*   rÞ   r+   Únanr   )r-   rÂ  re   rƒ  rg   rh   r.   r.   r/   rn   #  s&   
þ
"þ
ÿýzyulesimon_gen._statsr^   )rw   rx   ry   rz   r0   r8   rN   r=   rI   rS   rV   rç   rn   r.   r.   r.   r/   rÁ  æ  s    !
rÁ  Ú	yulesimon)r|   r@   c                   @   sJ   e Zd ZdZdZdZdd„ Zdd„ Zdd„ Zdd	d
„Z	dd„ Z
dd„ ZdS )Ú_nchypergeom_genz‰A noncentral hypergeometric discrete random variable.

    For subclassing by nchypergeom_fisher_gen and nchypergeom_wallenius_gen.

    Nc                 C   sL   t dddtjfdƒt dddtjfdƒt dddtjfdƒt dddtjfd	ƒgS )
Nrï   Tr   r%   r$   rð   ÚoddsFr�   r)   r,   r.   r.   r/   r0   B  s
   ýz_nchypergeom_gen._shape_infoc           	      C   s<   |||}}}|| }t  d|| ¡}t  ||¡}||fS r–   rô   )	r-   rï   r$   rð   rÐ  r^  r]  Úx_minÚx_maxr.   r.   r/   rA   H  s
   z_nchypergeom_gen._get_supportc                 C   sž   t  |¡t  |¡}}t  |¡t  |¡}}| t¡|k|dk@ }| t¡|k|dk@ }| t¡|k|dk@ }|dk}||k}	||k}
||@ |@ |@ |	@ |
@ S r–   )r*   r
  r£   r  )r-   rï   r$   rð   rÐ  Úcond1Úcond2Úcond3Úcond4Úcond5Úcond6r.   r.   r/   r=   O  s   z_nchypergeom_gen._argcheckc                    s$   t ‡ fdd„ƒ}|||||||d�S )Nc           
         s<   t  |¡}tƒ }t|ˆ jƒ}|||| |||ƒ}	|	 |¡}	|	S r3   )r*   Úprodr   ÚgetattrÚrvs_nameÚreshape)
rï   r$   rð   rÐ  r6   r7   ÚlengthÚurnÚrv_genr  r,   r.   r/   r  \  s   

z$_nchypergeom_gen._rvs.<locals>._rvs1rƒ   r   )r-   rï   r$   rð   rÐ  r6   r7   r  r.   r,   r/   r8   Z  s   z_nchypergeom_gen._rvsc                    sR   t  |||||¡\}}}}}|jdkrt  |¡S t j‡ fdd„ƒ}||||||ƒS )Nr   c                    s   ˆ   ||||d¡}| | ¡S ©Ngê-�™—q=)r®  Úprobability)rF   rï   r$   rð   rÐ  rÞ  r,   r.   r/   Ú_pmf1m  s   
z$_nchypergeom_gen._pmf.<locals>._pmf1)r*   rµ   r6   Ú
empty_likerb  )r-   rF   rï   r$   rð   rÐ  râ  r.   r,   r/   rN   g  s   

z_nchypergeom_gen._pmfc                    sL   t j‡ fdd„ƒ}d|v sd|v r|||||ƒnd\}}d\}	}
|||	|
fS )Nc                    s   ˆ   ||| |d¡}| ¡ S rà  )r®  rd   )rï   r$   rð   rÐ  rÞ  r,   r.   r/   Ú	_moments1v  s   z*_nchypergeom_gen._stats.<locals>._moments1r  Úvr^   )r*   rb  )r-   rï   r$   rð   rÐ  rd   rä  r  rå  r_   rG   r.   r,   r/   rn   t  s   ÿz_nchypergeom_gen._statsr^   )rw   rx   ry   rz   rÛ  r®  r0   rA   r=   r8   rN   rn   r.   r.   r.   r/   rÏ  8  s    
rÏ  c                   @   ó   e Zd ZdZdZeZdS )Únchypergeom_fisher_genag	  A Fisher's noncentral hypergeometric discrete random variable.

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

    %(before_notes)s

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

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

    The probability mass function is defined as

    .. math::

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

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

    .. math::

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

    and the binomial coefficients are defined as

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

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

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

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

    %(after_notes)s

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

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

    %(example)s

    Ú
rvs_fisherN)rw   rx   ry   rz   rÛ  r   r®  r.   r.   r.   r/   rç  �  ó    Irç  Únchypergeom_fisherz$A Fisher's noncentral hypergeometricc                   @   ræ  )Ú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)rw   rx   ry   rz   rÛ  r   r®  r.   r.   r.   r/   rë  Ô  ré  rë  Únchypergeom_walleniusz&A Wallenius' noncentral hypergeometric)r   N)r   r]   )r   )jÚ	functoolsr   Úscipyr   Úscipy.specialr   r   r   r   rC   r   Úscipy._lib._utilr	   r
   Ú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Ú_ufuncsrK   r!   r{   r~   rŒ   r�   r§   r©   rÇ   rÈ   rØ   rÙ   rë   rí   r  r  r#  r%  r/  r0  r3  r@  rI  rK  rU  rV  rc  rd  re  rk  rs  rv  rw  r„  r…  r+   rŽ  r�  r¢  r©  rª  r«  r°  r±  r¯  r   rº  rÀ  rÁ  rÎ  rÏ  rç  rê  rë  rí  ÚlistÚglobalsÚcopyÚitemsÚpairsÚ_distn_namesÚ_distn_gen_namesÚ__all__r.   r.   r.   r/   Ú<module>   s¤   0 
`A
R
u
]Q 
 
 8BG?ÿwBYPÿVÿ



?OINþNþ