
    (ph$P                       S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJ	r	  S SK
Jr  SSKJrJr  S SK JrJr  S SKJrJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,  S SKr-SSK.J/r/J0r0  SSK1J2r2  S SK3J4r4  SSSS.r5Sr6Sr7Sr8Sr9Sr:Sr;Sr<Sr=Sr>Sr?Sr@S rAS!rBS"rCS#rDS$rES%rFS&rGS'rHS(rIS)rJS*rKS+R                  \5S,   \6\7\8\;\<\=\>\?\@\A\B\C\D\E\G\H\I\J\K/5      rMS-rNS.rOS/rPS0rQS+R                  \N\MS1\P/5      rRS+R                  \N\M/5      rS0 S2\6_S3\7_S4\8_S5\;_S6\<_S7\=_S8\>_S9\?_S:\@_S;\B_S<\C_S=\D_S>\A_S?\E_S@\K_SA\H_SB\J_\I\G\M\N\O\P\R\S\QSC.	ErT\TR                  5       rV\9\VSD'   \:\VSE'   \F\VS?'   / SFQrW\W H  rX\V\X   R                  SGS+5      \V\X'   M     / SHQrZ\Z H  rX\V\X   R                  SISJ5      \V\X'   M     \VR                  S35        \VR                  S45        S+R                  \W V s/ s H  n \VU    PM
     sn 5      rM\5S,   \M-   \VSK'   \NR                  SLSM5      \VSN'   SOrO\O\VSP'   SQr\SRr]\\\VSS'   \]\VST'   S+R                  \VSN   \VSK   /5      rS\S\VSU'   S+R                  \VSN   \VSK   \VSP   \VSS   /5      r^\^\VSV'   \_" 5        Vs/ s H  oR                  SW5      (       d  M  UPM     sn H  rX\a" SX\X-   5        M     CXSxSY jrbSZ rcS[ rdS\ reS] rfS^ rgS_ rhS` ri " Sa Sb5      rj " Sc Sd\j5      rk " Se Sf\j5      rlSg rmShrn " Si Sj5      ro " Sk Sl5      rpSm rq " Sn SL\o5      rrSo rsSp rt " Sq SM\o5      ru  SySr jrvSzSs jrw " St Su\u5      rxSv rySw rzgs  sn f s  snf ){    )getfullargspec_no_selfN)zip_longest)doccer   )distcontdistdiscrete)check_random_state
_lazywhere)combentr)optimize)	integrate)_derivative)stats)arangeputmaskonesshapendarrayzerosfloorlogical_andlogsqrtplaceargmax	vectorizeasarraynaninfisinfempty)_XMAX_LOGXMAX)CensoredData)FitErrorz
Methods
-------
z
Notes
-----
z
Examples
--------
)methodsnotesexampleszPrvs(%(shapes)s, loc=0, scale=1, size=1, random_state=None)
    Random variates.
zEpdf(x, %(shapes)s, loc=0, scale=1)
    Probability density function.
zSlogpdf(x, %(shapes)s, loc=0, scale=1)
    Log of the probability density function.
zBpmf(k, %(shapes)s, loc=0, scale=1)
    Probability mass function.
zPlogpmf(k, %(shapes)s, loc=0, scale=1)
    Log of the probability mass function.
zIcdf(x, %(shapes)s, loc=0, scale=1)
    Cumulative distribution function.
zWlogcdf(x, %(shapes)s, loc=0, scale=1)
    Log of the cumulative distribution function.
z}sf(x, %(shapes)s, loc=0, scale=1)
    Survival function  (also defined as ``1 - cdf``, but `sf` is sometimes more accurate).
zGlogsf(x, %(shapes)s, loc=0, scale=1)
    Log of the survival function.
zdppf(q, %(shapes)s, loc=0, scale=1)
    Percent point function (inverse of ``cdf`` --- percentiles).
zVisf(q, %(shapes)s, loc=0, scale=1)
    Inverse survival function (inverse of ``sf``).
zYmoment(order, %(shapes)s, loc=0, scale=1)
    Non-central moment of the specified order.
zostats(%(shapes)s, loc=0, scale=1, moments='mv')
    Mean('m'), variance('v'), skew('s'), and/or kurtosis('k').
zJentropy(%(shapes)s, loc=0, scale=1)
    (Differential) entropy of the RV.
a  fit(data)
    Parameter estimates for generic data.
    See `scipy.stats.rv_continuous.fit <https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.fit.html#scipy.stats.rv_continuous.fit>`__ for detailed documentation of the
    keyword arguments.
zexpect(func, args=(%(shapes_)s), loc=0, scale=1, lb=None, ub=None, conditional=False, **kwds)
    Expected value of a function (of one argument) with respect to the distribution.
zexpect(func, args=(%(shapes_)s), loc=0, lb=None, ub=None, conditional=False)
    Expected value of a function (of one argument) with respect to the distribution.
zCmedian(%(shapes)s, loc=0, scale=1)
    Median of the distribution.
z?mean(%(shapes)s, loc=0, scale=1)
    Mean of the distribution.
zBvar(%(shapes)s, loc=0, scale=1)
    Variance of the distribution.
zLstd(%(shapes)s, loc=0, scale=1)
    Standard deviation of the distribution.
zminterval(confidence, %(shapes)s, loc=0, scale=1)
    Confidence interval with equal areas around the median.
 r'   zAs an instance of the `rv_continuous` class, `%(name)s` object inherits from it
a collection of generic methods (see below for the full list),
and completes them with details specific for this particular distribution.
a+  
Alternatively, the object may be called (as a function) to fix the shape,
location, and scale parameters returning a "frozen" continuous RV object:

rv = %(name)s(%(shapes)s, loc=0, scale=1)
    - Frozen RV object with the same methods but holding the given shape,
      location, and scale fixed.
a  Examples
--------
>>> import numpy as np
>>> from scipy.stats import %(name)s
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(1, 1)

Calculate the first four moments:

%(set_vals_stmt)s
>>> mean, var, skew, kurt = %(name)s.stats(%(shapes)s, moments='mvsk')

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

>>> x = np.linspace(%(name)s.ppf(0.01, %(shapes)s),
...                 %(name)s.ppf(0.99, %(shapes)s), 100)
>>> ax.plot(x, %(name)s.pdf(x, %(shapes)s),
...        'r-', lw=5, alpha=0.6, label='%(name)s pdf')

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

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

>>> rv = %(name)s(%(shapes)s)
>>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

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

>>> vals = %(name)s.ppf([0.001, 0.5, 0.999], %(shapes)s)
>>> np.allclose([0.001, 0.5, 0.999], %(name)s.cdf(vals, %(shapes)s))
True

Generate random numbers:

>>> r = %(name)s.rvs(%(shapes)s, size=1000)

And compare the histogram:

>>> ax.hist(r, density=True, bins='auto', histtype='stepfilled', alpha=0.2)
>>> ax.set_xlim([x[0], x[-1]])
>>> ax.legend(loc='best', frameon=False)
>>> plt.show()

a  The probability density above is defined in the "standardized" form. To shift
and/or scale the distribution use the ``loc`` and ``scale`` parameters.
Specifically, ``%(name)s.pdf(x, %(shapes)s, loc, scale)`` is identically
equivalent to ``%(name)s.pdf(y, %(shapes)s) / scale`` with
``y = (x - loc) / scale``. Note that shifting the location of a distribution
does not make it a "noncentral" distribution; noncentral generalizations of
some distributions are available in separate classes.

rvspdflogpdfcdflogcdfsflogsfppfisfr   entropyfitmomentexpectintervalmeanstd)	varmedian
allmethodslongsummary
frozennoteexampledefaultbefore_notesafter_notespmflogpmf)r,   rE   rF   r/   r0   r1   r2   r3   r4   r   r5   r8   r=   r:   r<   r;   r9   z	, scale=1)r/   r0   r1   r2   z(x, z(k, r>   rv_continuousrv_discreter?   a  
Alternatively, the object may be called (as a function) to fix the shape and
location parameters returning a "frozen" discrete RV object:

rv = %(name)s(%(shapes)s, loc=0)
    - Frozen RV object with the same methods but holding the given shape and
      location fixed.
r@   a  Examples
--------
>>> import numpy as np
>>> from scipy.stats import %(name)s
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(1, 1)

Calculate the first four moments:

%(set_vals_stmt)s
>>> mean, var, skew, kurt = %(name)s.stats(%(shapes)s, moments='mvsk')

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

>>> x = np.arange(%(name)s.ppf(0.01, %(shapes)s),
...               %(name)s.ppf(0.99, %(shapes)s))
>>> ax.plot(x, %(name)s.pmf(x, %(shapes)s), 'bo', ms=8, label='%(name)s pmf')
>>> ax.vlines(x, 0, %(name)s.pmf(x, %(shapes)s), 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 = %(name)s(%(shapes)s)
>>> ax.vlines(x, 0, rv.pmf(x), colors='k', linestyles='-', lw=1,
...         label='frozen pmf')
>>> ax.legend(loc='best', frameon=False)
>>> plt.show()

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

>>> prob = %(name)s.cdf(x, %(shapes)s)
>>> np.allclose(x, %(name)s.ppf(prob, %(shapes)s))
True

Generate random numbers:

>>> r = %(name)s.rvs(%(shapes)s, size=1000)
zThe probability mass function above is defined in the "standardized" form.
To shift distribution use the ``loc`` parameter.
Specifically, ``%(name)s.pmf(k, %(shapes)s, loc)`` is identically
equivalent to ``%(name)s.pmf(k - loc, %(shapes)s)``.
rA   rD   rC   rB   _doc_zdel c                 R    Uc  U R                  5       nX-
  U-  R                  5       $ N)r:   )datanmus      T/var/www/html/venv/lib/python3.13/site-packages/scipy/stats/_distn_infrastructure.py_momentrP   k  s'    	zYY[YN  ""    c                    U S:X  a  gU S:X  a  Uc  U" S/UQ76 nU$ Un U$ U S:X  a  Ub  Uc  U" S/UQ76 nU$ X!U-  -   n U$ U S:X  aD  Ub  Ub  Uc  U" S/UQ76 nU$ U[         R                  " US5      -  nUSU-  U-  -   X-  U-  -   n U$ U S:X  aa  Ub	  Ub  Ub  Uc  U" S/UQ76 nU$ US-   US	-  -  n	U[         R                  " US5      -  nU	SU-  U-  -   S
U-  U-  U-  -   X-  U-  U-  -   n U$ U" U /UQ76 nU$ )Nr         ?r               ?         @       @   )nppower)
rM   rN   mu2g1g2moment_funcargsvalmu3mu4s
             rO   _moment_from_statsre   q  s   	Q
q&:a'$'C0 J- C, J+ q&;"*a'$'C& J# 2+C" J! q&:
a'$'C J rxxS))Cad3h,ruRx'C J q&:s{bja'$'C J c6CH%CRXXc3''Cad3h,qtBws{*258B;6C J !#d#JrQ   c                     [         R                  " U 5      n U R                  5       nX-
  S-  R                  5       nX-
  S-  R                  5       nU[         R                  " US5      -  $ )z0
skew is third central moment / variance**(1.5)
rT   rU   rV   )r[   ravelr:   r\   )rL   rN   m2m3s       rO   _skewrj     sZ     88D>D	B9q.			 B9q.			 BS!!!rQ   c                     [         R                  " U 5      n U R                  5       nX-
  S-  R                  5       nX-
  S-  R                  5       nX2S-  -  S-
  $ )zDFisher's excess kurtosis is fourth central moment / variance**2 - 3.rT   rW   rU   )r[   rg   r:   )rL   rN   rh   m4s       rO   	_kurtosisrm     sR    88D>D	B9q.			 B9q.			 BA:>rQ   c                    ^  U 4S jnU$ )z?Decorator that vectorizes _rvs method to work on ndarray shapesc           
        > [        US   R                  U 5      u  p4[        R                  " U 5      n [        R                  " U5      n[        R                  " U5      n[        R                  " U5      (       a  T
" / UQU PUP76 $ [        R
                  " U 5      n[        R                  " UR                  5      n[        R                  " Xd)    Xd   45      n[        R                  " XWU5      n[        R                  " X)    6  H9  nT
" / U V	s/ s H  n	[        R                  " U	5      U   PM     sn	QUPUP76 XX'   M;     [        R                  " XVU5      $ s  sn	f Nr   )_check_shaper   r[   arrayallr"   r   ndimhstackmoveaxisndindexsqueeze)sizerandom_statera   
_rvs1_size_rvs1_indicesoutj0j1iarg_rvs1s             rO   _rvs(_vectorize_rvs_over_shapes.<locals>._rvs  s(   $0a$E!
xx~XXj)
/66-  3$33l33hhtn
 YYsxx YY>*B,=>?kk#2&T.12A  54@4CRZZ_Q/4@ 5%5'35CF 3 {{3B'' As   #E )r   r   s   ` rO   _vectorize_rvs_over_shapesr     s    (4 KrQ   c                     [        U 5      (       dK  [        U [        5      (       a6  U R                  S5      (       d  SU -   n U S:X  a  Sn  [	        [
        U 5      n U $ U $ ! [         a  n[        U  S35      UeS nAff = f)Nfmin_fminz is not a valid optimizer)callable
isinstancestr
startswithgetattrr   AttributeError
ValueError)	optimizeres     rO   _fit_determine_optimizerr     s    I:i#=#=##G,,	)II	M)4I 9  	M	{*CDE1L	Ms   
A 
A<(A77A<c                 4    U [         R                  " U 5      :H  $ rK   )r[   round)xs    rO   _isintegralr     s    rQ   c                     [         R                  " U 5      nUR                  [         R                  " U5      -
  n[         R                  " X   5      U4$ )a  
For a 1D array x, return a tuple containing the sum of the
finite values of x and the number of nonfinite values.

This is a utility function used when evaluating the negative
loglikelihood for a distribution and an array of samples.

Examples
--------
>>> import numpy as np
>>> from scipy.stats._distn_infrastructure import _sum_finite
>>> tot, nbad = _sum_finite(np.array([-2, -np.inf, 5, 1]))
>>> tot
4.0
>>> nbad
1
)r[   isfinitery   count_nonzerosum)r   finite_x	bad_counts      rO   _sum_finiter     s@    $ {{1~H 0 0 ::I66!+	))rQ   c                       \ rS rSrS r\S 5       r\R                  S 5       rS rS r	S r
S rSS
 jrS rS rSS jrS rS rS rS rSS jrS rSS jrSS jrS rSrg	)	rv_frozeni  c                     X l         X0l        UR                  " S0 UR                  5       D6U l        U R                  R
                  " U0 UD6u  n  nU R                  R                  " U6 u  U l        U l        g )Nr   )	ra   kwds	__class___updated_ctor_paramdist_parse_args_get_supportab)selfr   ra   r   shapes_s         rO   __init__rv_frozen.__init__  se    		 NN@T%=%=%?@	yy,,d;d;1//8rQ   c                 .    U R                   R                  $ rK   )r   _random_stater   s    rO   rz   rv_frozen.random_state  s    yy&&&rQ   c                 8    [        U5      U R                  l        g rK   )r	   r   r   r   seeds     rO   rz   r     s    "4T":		rQ   c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   r/   ra   r   r   r   s     rO   r/   rv_frozen.cdf  '    yy}}Q88dii88rQ   c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   r0   ra   r   r   s     rO   r0   rv_frozen.logcdf  )    yy;DII;;;rQ   c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   r3   ra   r   r   qs     rO   r3   rv_frozen.ppf  r   rQ   c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   r4   ra   r   r   s     rO   r4   rv_frozen.isf  r   rQ   Nc                     U R                   R                  5       nUR                  XS.5        U R                  R                  " U R
                  0 UD6$ )Nry   rz   )r   copyupdater   r,   ra   )r   ry   rz   r   s       rO   r,   rv_frozen.rvs  s=    yy~~T@Ayy}}dii0400rQ   c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   r1   ra   r   r   s     rO   r1   rv_frozen.sf  s'    yy||A7		7TYY77rQ   c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   r2   ra   r   r   s     rO   r2   rv_frozen.logsf  s'    yyq:499:		::rQ   c                     U R                   R                  5       nUR                  SU05        U R                  R                  " U R
                  0 UD6$ Nmoments)r   r   r   r   r   ra   )r   r   r   s      rO   r   rv_frozen.stats  s?    yy~~Y()yy		2T22rQ   c                 b    U R                   R                  " U R                  0 U R                  D6$ rK   )r   r=   ra   r   r   s    rO   r=   rv_frozen.median!  s$    yy8dii88rQ   c                 b    U R                   R                  " U R                  0 U R                  D6$ rK   )r   r:   ra   r   r   s    rO   r:   rv_frozen.mean$  s"    yy~~tyy6DII66rQ   c                 b    U R                   R                  " U R                  0 U R                  D6$ rK   )r   r<   ra   r   r   s    rO   r<   rv_frozen.var'  "    yy}}dii549955rQ   c                 b    U R                   R                  " U R                  0 U R                  D6$ rK   )r   r;   ra   r   r   s    rO   r;   rv_frozen.std*  r   rQ   c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   r7   ra   r   )r   orders     rO   r7   rv_frozen.moment-  s)    yy?		?TYY??rQ   c                 b    U R                   R                  " U R                  0 U R                  D6$ rK   )r   r5   ra   r   r   s    rO   r5   rv_frozen.entropy0  $    yy  $))9tyy99rQ   c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   r9   ra   r   )r   
confidences     rO   r9   rv_frozen.interval3  s)    yy!!*FtyyFDIIFFrQ   c           	      $   U R                   R                  " U R                  0 U R                  D6u  pgn[	        U R                   [
        5      (       a  U R                   R                  " XXrX440 UD6$ U R                   R                  " XXxX#U40 UD6$ rK   )r   r   ra   r   r   rH   r8   )	r   funclbubconditionalr   r   locscales	            rO   r8   rv_frozen.expect6  s    
 		--tyyFDIIFdii--99##DSbNNN99##DS$/9379 9rQ   c                 b    U R                   R                  " U R                  0 U R                  D6$ rK   )r   supportra   r   r   s    rO   r   rv_frozen.supportB  r   rQ   )r   ra   r   r   r   NN)mvrK   )NNNF)__name__
__module____qualname____firstlineno__r   propertyrz   setterr/   r0   r3   r4   r,   r1   r2   r   r=   r:   r<   r;   r7   r5   r9   r8   r   __static_attributes__r   rQ   rO   r   r     s    9 ' ' ; ;9<991
8;3
9766@:G
9:rQ   r   c                        \ rS rSrS rS rSrg)rv_discrete_frozeniF  c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   rE   ra   r   r   ks     rO   rE   rv_discrete_frozen.pmfH  r   rQ   c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   rF   ra   r   r   s     rO   rF   rv_discrete_frozen.logpmfK  r   rQ   r   N)r   r   r   r   rE   rF   r   r   rQ   rO   r   r   F      9<rQ   r   c                        \ rS rSrS rS rSrg)rv_continuous_frozeniO  c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   r-   ra   r   r   s     rO   r-   rv_continuous_frozen.pdfQ  r   rQ   c                 j    U R                   R                  " U/U R                  Q70 U R                  D6$ rK   )r   r.   ra   r   r   s     rO   r.   rv_continuous_frozen.logpdfT  r   rQ   r   N)r   r   r   r   r-   r.   r   r   rQ   rO   r   r   O  r   rQ   r   c           
         [         R                  " U6 n[        U[        [        -  5      (       d  U4n[         R
                  " U 5      (       a:  [         R                  " / UQU P76 Gt p U Vs/ s H  o3R                  5       PM     sn$ U R                  nU Vs/ s HJ  n[         R                  " U5      S:X  a  UO*[         R                  " U [         R                  " X45      5      PML     sn$ s  snf s  snf )a  Clean arguments to:

1. Ensure all arguments are iterable (arrays of dimension at least one
2. If cond != True and size > 1, ravel(args[i]) where ravel(condition) is
   True, in 1D.

Return list of processed arguments.

Examples
--------
>>> import numpy as np
>>> from scipy.stats._distn_infrastructure import argsreduce
>>> rng = np.random.default_rng()
>>> A = rng.random((4, 5))
>>> B = 2
>>> C = rng.random((1, 5))
>>> cond = np.ones(A.shape)
>>> [A1, B1, C1] = argsreduce(cond, A, B, C)
>>> A1.shape
(4, 5)
>>> B1.shape
(1,)
>>> C1.shape
(1, 5)
>>> cond[2,:] = 0
>>> [A1, B1, C1] = argsreduce(cond, A, B, C)
>>> A1.shape
(15,)
>>> B1.shape
(1,)
>>> C1.shape
(15,)

r   )r[   
atleast_1dr   listtuplers   broadcast_arraysrg   r   ry   extractbroadcast_to)condra   newargsr   ss        rO   
argsreducer  X  s    H mmT"G gu..*	vvd||,,<g<t<'./w		w//

A
   GGCLA%SD"//#"9:;    0
 s   ,C,AC1a  
def _parse_args(self, %(shape_arg_str)s %(locscale_in)s):
    return (%(shape_arg_str)s), %(locscale_out)s

def _parse_args_rvs(self, %(shape_arg_str)s %(locscale_in)s, size=None):
    return self._argcheck_rvs(%(shape_arg_str)s %(locscale_out)s, size=size)

def _parse_args_stats(self, %(shape_arg_str)s %(locscale_in)s, moments='mv'):
    return (%(shape_arg_str)s), %(locscale_out)s, moments
c                   t  ^  \ rS rSrSrS-U 4S jjr\S 5       r\R                  S 5       rS r	S r
S	 rS
 rS-S jr  S.S jrS rS r\R                  \l        S rS rS rS rS rS rS rSSS.S jrS rS rS rS rS rS rS rS r S  r!S! r"S" r#S# r$S$ r%S% r&S& r'S' r(S( r)S) r*S* r+S+ r,S,r-U =r.$ )/
rv_generici  zVClass which encapsulates common functionality between rv_discrete
and rv_continuous.

Nc                    > [         TU ]  5         [        U R                  5      nUR                  S L=(       d%    SUR
                  ;   =(       d    SUR                  ;   U l        [        U5      U l	        g r   )
superr   _getfullargspec_statsvarkwra   
kwonlyargs_stats_has_momentsr	   r   )r   r   sigr   s      rO   r   rv_generic.__init__  se     dkk*$'IIT$9 $A$-$9$A$-$? 	 05rQ   c                     U R                   $ )ab  Get or set the generator object for generating random variates.

If `random_state` is None (or `np.random`), the
`numpy.random.RandomState` singleton is used.
If `random_state` is an int, a new ``RandomState`` instance is used,
seeded with `random_state`.
If `random_state` is already a ``Generator`` or ``RandomState``
instance, that instance is used.

)r   r   s    rO   rz   rv_generic.random_state  s     !!!rQ   c                 $    [        U5      U l        g rK   )r	   r   r   s     rO   rz   r    s    /5rQ   c                      U R                   R                  U5        U R                  5         g ! [         a'    US   U l        US   U l        U R                  5          g f = fNr   r   )__dict__r   _attach_methodsr   _ctor_paramr   r   )r   states     rO   __setstate__rv_generic.__setstate__  sY    	MM  '
   " 	  %QxD!&qDMMO	s   +. .AAc                     [         e)zAttaches dynamically created methods to the rv_* instance.

This method must be overridden by subclasses, and must itself call
 _attach_argparser_methods. This method is called in __init__ in
 subclasses, and in __setstate__
)NotImplementedErrorr   s    rO   r!  rv_generic._attach_methods  s
     "!rQ   c           	          0 n[        U R                  U5        S H&  n[        X[        R                  " X   U 5      5        M(     g)z
Generates the argument-parsing functions dynamically and attaches
them to the instance.

Should be called from `_attach_methods`, typically in __init__ and
during unpickling (__setstate__)
r   _parse_args_stats_parse_args_rvsN)exec_parse_arg_templatesetattrtypes
MethodType)r   nsnames      rO   _attach_argparser_methods$rv_generic._attach_argparser_methods  s=     T%%r*KDD 0 04 @A LrQ   c                     U R                   (       a  [        U R                   [        5      (       d  [        S5      eU R                   R	                  SS5      R                  5       nU HP  n[        R                  " U5      (       a  [        S5      e[        R                  " SU5      (       a  MG  [        S5      e   O/ nU H  n[        U5      nUR                  SS n	U	(       d  M&  UR                  U	5        UR                  b  [        S	5      eUR                  b  [        S
5      eUR                   (       a  [        S5      eUR"                  c  M  [        S5      e   U(       a  US   nU H  n
X:w  d  M
  [        S5      e   O/ nU(       a  SR%                  U5      S-   OSn['        UUUS9n[(        U-  U l        U(       a  SR%                  U5      OSU l         [-        U S5      (       d  [/        U5      U l        gg)a`  Construct the parser string for the shape arguments.

This method should be called in __init__ of a class for each
distribution. It creates the `_parse_arg_template` attribute that is
then used by `_attach_argparser_methods` to dynamically create and
attach the `_parse_args`, `_parse_args_stats`, `_parse_args_rvs`
methods to the instance.

If self.shapes is a non-empty string, interprets it as a
comma-separated list of shape parameters.

Otherwise inspects the call signatures of `meths_to_inspect`
and constructs the argument-parsing functions from these.
In this case also sets `shapes` and `numargs`.
zshapes must be a string., z"keywords cannot be used as shapes.z^[_a-zA-Z][_a-zA-Z0-9]*$z'shapes must be valid python identifiersr   Nz+*args are not allowed w/out explicit shapesz,**kwds are not allowed w/out explicit shapesz1kwonly args are not allowed w/out explicit shapesz#defaults are not allowed for shapesr   z!Shape arguments are inconsistent., r*   )shape_arg_strlocscale_inlocscale_outnumargs)r   r   r   	TypeErrorreplacesplitkeyword	iskeywordSyntaxErrorrematchr  ra   appendvarargsr  r  defaultsjoindictparse_arg_templater.  hasattrlenr=  )r   meths_to_inspectr;  r<  r   fieldshapes_listmethshapes_argsra   item
shapes_strdcts                rO   _construct_argparserrv_generic._construct_argparser  s   $ ;;dkk3// :;;[[((c288:F$$U++%&JKKxx :EBB%AC C	   K(-d3"''+4&&t, #**6'IK K"((4'JL L"--'OQ Q"++7'(MNN% )( $Q (D~'(KLL (  28TYYv&-R
* , $6#; +1dii'ttY''v;DL (rQ   c           
         UR                  5       nU R                  =(       d    SUS'   U R                  =(       d    SUS'   Uc  Sn SR                  S U 5       5      nXCS
'   U R                  =(       d    SUS'   U R                  (       a  U R
                  S:X  a  US==   S-  ss'   U R                  (       a  SU R                   SU 3US'   OSUS'   U R                  c  S H  nX5   R                  SS5      X5'   M     [        S5       HX  nU R                  c!  U R                  R                  SS5      U l         [        R                  " U R                  U5      U l        MZ     U R                  R                  SS5      R                  SS5      U l        g! [         a    SR                  S	 U 5       5      n GN`f = f! [         a*  n[        SU R                   S[        U5       35      UeSnAff = f)z;Construct the instance docstring with string substitutions.distnamer3  r*   r   Nr   r9  c              3   (   #    U  H  oS  v   M
     g7f)z.3gNr   .0rb   s     rO   	<genexpr>,rv_generic._construct_doc.<locals>.<genexpr>>  s     A[cCy\[s   c              3   &   #    U  H  o v   M	     g 7frK   r   r[  s     rO   r]  r^  @  s     =#uXs   valsshapes_r   r7  z>>> z = set_vals_stmt)rB   rC   z-
%(shapes)s : array_like
    shape parametersrT   z%(shapes)s, z0Unable to construct docstring for distribution "z": z(, (z, )))r   r3  r   rI  r>  r=  r?  range__doc__r   	docformat	Exceptionrepr)r   docdictshapes_valstempdictr`  rS  r   r   s           rO   _construct_docrv_generic._construct_doc5  s   <<>992
![[.BK	>99A[AAD  "kk/R;;4<<1,Y3&;;*.t{{m3tf(EH_%(*H_%;;3!)!7!7Er"K 4 qA{{"#||33NBGS%//hG  ||++E37??sK;  	>99===D	>0  S !226))Da	!K LQRSSs*   F >&G"G ?G 
G7%G22G7c                 ~    Uc  SnSR                  U SU S3S[        S   S/5      U l        U R                  U5        g)	z7Construct instance docstring from the default template.NAr*   r8  z random variable.z

%(before_notes)s
r(   z
%(example)s)rI  
docheadersrf  rm  )r   longnamerj  discretes       rO   _construct_default_doc!rv_generic._construct_default_doc^  sQ     Hww8*AhZ7H I 8*W:M / 1 2 	G$rQ   c                 h    [        U [        5      (       a  [        U /UQ70 UD6$ [        U /UQ70 UD6$ )a@  Freeze the distribution for the given arguments.

Parameters
----------
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution.  Should include all
    the non-optional arguments, may include ``loc`` and ``scale``.

Returns
-------
rv_frozen : rv_frozen instance
    The frozen distribution.

)r   rG   r   r   r   ra   r   s      rO   freezerv_generic.freezeh  s;     dM**'<t<t<<%d:T:T::rQ   c                 &    U R                   " U0 UD6$ rK   )rx  rw  s      rO   __call__rv_generic.__call__|  s    {{D)D))rQ   c                     g)NNNNNr   rw  s      rO   r  rv_generic._stats  s    %rQ   c                     [         R                  " SS9   U R                  " U/UQ76 nS S S 5        U$ ! , (       d  f       W$ = f)Nignore)rs   )r[   errstategeneric_moment)r   rM   ra   r`  s       rO   _munprv_generic._munp  s;    [[X&&&q040D ' '&s	   3
Ac                 @   UR                  SS 5      n[        R                  " U6 nS nU Vs/ s H
  oe" U5      PM     nnUS   R                  nUS   R                  nUc  Un	O[        [        R                  " U5      5      n	U[        U	5      -
  n
U
S:  a
  SU
* -  U-   nOU
S:  a  SU
-  U	-   n	[        [        Xy5       VVs/ s H  u  pUS:H  =(       d    X:H  PM     snn5      nU(       d  [        SU SU	 SU 35      eUS S nUS   nUS	   nXUU	4$ s  snf s  snnf )
Nry   c                     U R                   S:  a=  U R                  S   S:X  a*  U S   n U R                   S:  a  U R                  S   S:X  a  M*  U $ r  )rt   r   )r   s    rO   squeeze_left.rv_generic._argcheck_rvs.<locals>.squeeze_left  sD    &&1*qaD &&1*qHrQ   r   )r   r   z;size does not match the broadcast shape of the parameters. r9  )getr[   r	  r   rt   r  r  rM  rs   zipr   )r   ra   kwargsry   	all_bcastr  r   bcast_shape
bcast_ndimsize_ndiffbcdimszdimokparam_bcast	loc_bcastscale_bcasts                    rO   _argcheck_rvsrv_generic._argcheck_rvs  s_    zz&$'''.		  /88i\!_i	8l((q\&&
<E"---.E SZ'19-+5KQYJ&E (+K(?A(?nu 1*..(?A B 004vRwbO P P  nbM	m{E99O 9:As   DD
c                 L    SnU H  n[        U[        U5      S:  5      nM     U$ )zDefault check for correct values on args and keywords.

Returns condition array of 1's where arguments are correct and
 0's where they are not.

r   r   )r   r   )r   ra   r  r   s       rO   	_argcheckrv_generic._argcheck  s-     CtgclQ&68D rQ   c                 2    U R                   U R                  4$ )au  Return the support of the (unscaled, unshifted) distribution.

*Must* be overridden by distributions which have support dependent
upon the shape parameters of the distribution.  Any such override
*must not* set or change any of the class members, as these members
are shared amongst all instances of the distribution.

Parameters
----------
arg1, arg2, ... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).

Returns
-------
a, b : numeric (float, or int or +/-np.inf)
    end-points of the distribution's support for the specified
    shape parameters.
r   r   )r   ra   r  s      rO   r   rv_generic._get_support  s    ( vvtvv~rQ   c                     U R                   " U6 u  p4[        R                  " SS9   X1:*  X:*  -  sS S S 5        $ ! , (       d  f       g = fNr  invalidr   r[   r  r   r   ra   r   r   s        rO   _support_maskrv_generic._support_mask  s8      $'[[*Fqv& +**	   	9
Ac                     U R                   " U6 u  p4[        R                  " SS9   X1:  X:  -  sS S S 5        $ ! , (       d  f       g = fr  r  r  s        rO   _open_support_maskrv_generic._open_support_mask   s8      $'[[*Eae$ +**r  r   c                J    UR                  US9nU R                  " U/UQ76 nU$ )Nry   )uniform_ppf)r   ry   rz   ra   UYs         rO   r   rv_generic._rvs  s/       d +IIa$rQ   c                     [         R                  " SS9   [        U R                  " U/UQ76 5      sS S S 5        $ ! , (       d  f       g = fNr  divide)r[   r  r   _cdfr   r   ra   s      rO   _logcdfrv_generic._logcdf  0    [[)tyy*T*+ *))	   ;
A	c                 .    SU R                   " U/UQ76 -
  $ NrS   r  r  s      rO   _sfrv_generic._sf  s    499Q&&&&rQ   c                     [         R                  " SS9   [        U R                  " U/UQ76 5      sS S S 5        $ ! , (       d  f       g = fr  )r[   r  r   r  r  s      rO   _logsfrv_generic._logsf  s0    [[)txx)D)* *))r  c                 (    U R                   " U/UQ76 $ rK   )_ppfvecr   r   ra   s      rO   r  rv_generic._ppf      ||A%%%rQ   c                 .    U R                   " SU-
  /UQ76 $ r  )r  r  s      rO   _isfrv_generic._isf  s    yyQ&&&rQ   c                    UR                  SS5      nUR                  SS5      nU R                  " U0 UD6u  ppg[        U R                  " U6 US:  5      n[        R
                  " U5      (       d  SU R                   S3n	[        U	5      e[        R
                  " US:H  5      (       a  U[        US5      -  $ Ub  U R                  n
[        U5      nOU R                  nU R                  " XUS.6nX-  U-   nUb  W
U l	        U(       aG  [        U [        5      (       d2  US	:X  a  [        U5      nU$ UR                  [        R                   5      nU$ )
a  Random variates of given type.

Parameters
----------
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    Location parameter (default=0).
scale : array_like, optional
    Scale parameter (default=1).
size : int or tuple of ints, optional
    Defining number of random variates (default is 1).
random_state : {None, int, `numpy.random.Generator`,
                `numpy.random.RandomState`}, optional

    If `random_state` is None (or `np.random`), the
    `numpy.random.RandomState` singleton is used.
    If `random_state` is an int, a new ``RandomState`` instance is
    used, seeded with `random_state`.
    If `random_state` is already a ``Generator`` or ``RandomState``
    instance, that instance is used.

Returns
-------
rvs : ndarray or scalar
    Random variates of given `size`.

rs  Nrz   r   zDomain error in arguments. The `scale` parameter must be positive for all distributions, and many distributions have restrictions on shape parameters. Please see the `scipy.stats.z` documentation for details.dr   r   )popr,  r   r  r[   rs   r3  r   r   r   r	   r   r   	rv_sampleintastypeint64)r   ra   r   rs  rndmr   r   ry   r  messagerandom_state_savedrz   r`  s                rO   r,   rv_generic.rvs#  sH   < 88J-xx-!%!5!5t!Dt!D54>>405A:?vvd||6 7;ii[ A44G
 W%%66%1*tD#&& !%!3!3-d3L--Lyy$E|c! !3D JtY77rz4y  {{288,rQ   c                 	   U R                   " U0 UD6u  ppE[        [        X445      u  p4[        [        [        U5      5      nU R                  " U6 US:  -  X3:H  -  n/ n[
        R                  " [        U5      U R                  S9n[
        R                  " U5      (       Ga  [        U/XU4-   Q76 n	U	S   U	S   U	SS pnU R                  (       a  U R                  " U	0 SU0D6u  ppOU R                  " U	6 u  ppSU;   aH  U
c  U R                  " S/U	Q76 n
UR                  5       n[        XX-  U-   5        UR!                  U5        S	U;   a  Uc  U R                  " S
/U	Q76 nU
c  U R                  " S/U	Q76 n
[
        R"                  " SS9   [
        R$                  " [
        R&                  " U
5      ) XS
-  -
  [
        R(                  5      nSSS5        UR                  5       n[        XX-  U-  5        UR!                  U5        SU;   a  Uc  U R                  " S/U	Q76 nU
c  U R                  " S/U	Q76 n
Uc7  U R                  " S
/U	Q76 n[
        R"                  " SS9   XU
-  -
  nSSS5        [
        R"                  " SS9   U
* U
-  SU-  -
  U
-  U-   nU[
        R*                  " US5      -  nSSS5        UR                  5       n[        XU5        UR!                  U5        SU;   Ga<  UGc  U R                  " S/U	Q76 nU
c  U R                  " S/U	Q76 n
Uc7  U R                  " S
/U	Q76 n[
        R"                  " SS9   XU
-  -
  nSSS5        Uc  SnOU[
        R*                  " US5      -  nUcB  U R                  " S/U	Q76 n[
        R"                  " SS9   U
* U
-  SU-  -
  U
-  U-   nSSS5        [
        R"                  " SS9   U
S
-  * SU-  -
  U
-  SU-  -
  U
-  U-   nUUS-  -  S-
  nSSS5        UR                  5       n[        XU5        UR!                  U5        O U Vs/ s H  nUR                  5       PM     nnU Vs/ s H  nUS   PM
     nn[-        U5      S:X  a  US   $ [        U5      $ ! , (       d  f       GN= f! , (       d  f       GN/= f! , (       d  f       GN= f! , (       d  f       GNo= f! , (       d  f       GN= f! , (       d  f       N= fs  snf s  snf )ah  Some statistics of the given RV.

Parameters
----------
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional (continuous RVs only)
    scale parameter (default=1)
moments : str, optional
    composed of letters ['mvsk'] defining which moments to compute:
    'm' = mean,
    'v' = variance,
    's' = (Fisher's) skew,
    'k' = (Fisher's) kurtosis.
    (default is 'mv')

Returns
-------
stats : sequence
    of requested moments.

r   
fill_valuer  r  Nr   mr   vrT   r  r  r  rU   rV   r   rW   rZ   rY   rX   r   )r+  mapr   r  r  r[   fullr   badvalueanyr  r  r  r  r   r   rF  r  wherer!   r    r\   rM  )r   ra   r   r   r   r   r  outputrB   goodargsrN   r]   r^   r_   out0mu2pmu3prc   mu4prd   r   r}   s                         rO   r   rv_generic.statsh  sy   4 %)$:$:D$ID$I!53,/
S$'(~~t$	2cjA''%+$--@ 66$<<!$=$s|*;=H#+B<"x}E&&"&++x #F1:G0D#FR #'++x"8g~:A11B||~d"*s"23d#g~;::a3(3Dz!ZZ5H5X6 hh}dUlBFFK 7||~d#+"56d#g~:::a3(3Dz!ZZ5H5{#zz!7h7[[:"&b.C ;X6 "s2v#~r1D8 288C#55 7 ||~d"%d#g~:::a3(3Dz!ZZ5H5{#zz!7h7[[:"&b.C ;z" !288C#55{#zz!7h7[[:$&38a#g#5";d"BC ;X6!#Q3"4qu<b@4G 38^c1 7 ||~d"%d#.56ggllngF6%+,Vc#b'V,v;!!9= k 76 ;:66 ;: ;:66 7,sU   AR&R
-R(
R:$S'S4S/S4
R
R%(
R7:
S	
S
S,c                    U R                   " U0 UD6u  pn[        [        X445      u  p4[        [        [        U5      5      nU R                  " U6 US:  -  X3:H  -  n[        [        U5      S5      n[        USU-
  U R                  5        [        XT/UQ76 nUS   nUSS n[        XeU R                  " U6 [        U5      -   5        US   $ )aN  Differential entropy of the RV.

Parameters
----------
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    Location parameter (default=0).
scale : array_like, optional  (continuous distributions only).
    Scale parameter (default=1).

Notes
-----
Entropy is defined base `e`:

>>> import numpy as np
>>> from scipy.stats._distn_infrastructure import rv_discrete
>>> drv = rv_discrete(values=((0, 1), (0.5, 0.5)))
>>> np.allclose(drv.entropy(), np.log(2.0))
True

r   r  r   Nr   )r   r  r   r  r  r   r   r   r  r  
vecentropyr   )	r   ra   r   r   r   cond0r  r  	goodscales	            rO   r5   rv_generic.entropy  s    0  ++T:T:53,/
S$'(%3szBuU|S)fqw/e2T2QK	AB<fT__h7#i.HIbzrQ   c           
         UnU R                   " U0 UD6u  pVn[        R                  " / UQUPUP76 nUGt pVn[        R                  " U R                  " U6 US:  5      n[        R                  " XS:H  5      n	[        R                  " XS:g  5      n
[        U/UQUPUP76 nUGt pVn[        U5      U:w  a  [        S5      eUS:  a  [        S5      eSu  ppUS:  a;  US:  a5  U R                  (       a  SSSS	S
S.U   0nO0 nU R                  " U0 UD6u  pp[        R                  " UR                  5      n[        XKXXR                  U5      US'   [        UR                  5      n[        UU) U R                   5        U	R#                  5       (       a   XvS:H     U-  UUS:H     -  n[        UU	U5        U
R#                  5       (       Ga  XX/nU Vs/ s H
  nUc  M  UPM     nn[%        S5       Vs/ s H  nUU   c  M  UPM     nn[#        U5      (       a'  [        US:g  /UQ76 nSnU H  nUU   UU'   US-  nM     Uu  pp[        US:g  /UQUPUPUP76 nUGt pVnn[        UR                  SS9nXv-  n[%        U5       H3  n[        UXXU R                  U5      nU['        UUSS9UU-  -  U-  -  nM5     UUU-  U-  -  nUXd-  -  n[        UU
U5        US   $ s  snf s  snf )a  non-central moment of distribution of specified order.

Parameters
----------
order : int, order >= 1
    Order of moment.
arg1, arg2, arg3,... : float
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

r   zMoment must be an integer.zMoment must be positive.r~     r   r  r  vsmvsk)r   rT   rU   rW   .rW   r   r  dtypeT)exactr   )r   r[   r	  r   r  r  r   r   r  r  r"   r   re   r  r   r   r  r  re  r   )r   r   ra   r   rM   r   r   r   i0i1i2rN   r]   r^   r_   mdictrb   resultres1momr   arrsidxjres2facr   valks                               rO   r7   rv_generic.moment  s     !--t<t<U""$9f$9c$95$9:"e^^DNNF3UQY?^^Bq)^^Bq)"2v2s2E2"e!HM9::E7880EA&&"$H$KL"kk6;U;OBRhhsyy!%aSb**fMC rxxfrc4==)6688?A%C1H5D&"d#6688B#C"4s!aAsD4#Ah=h#a&1hC=3xx!#(2T2A!!WCFFA  "OBRcQhAAAeASAD'+$V%#.D+C1X)!Rbdjj*02Q.sAv5<<  CFSL DCFND&"d#bz- 5=s   KK1
K!?K!c                 .    U R                   " S/UQ70 UD6$ )a  Median of the distribution.

Parameters
----------
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    Location parameter, Default is 0.
scale : array_like, optional
    Scale parameter, Default is 1.

Returns
-------
median : float
    The median of the distribution.

See Also
--------
rv_discrete.ppf
    Inverse of the CDF

      ?r3   rw  s      rO   r=   rv_generic.medianK  s    0 xx+d+d++rQ   c                     SUS'   U R                   " U0 UD6n[        U[        5      (       a  UR                  S:X  a  US   $ U$ )a~  Mean of the distribution.

Parameters
----------
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

Returns
-------
mean : float
    the mean of the distribution

r  r   r   r   r   r   r   rt   r   ra   r   ress       rO   r:   rv_generic.meane  E    & Yjj$'$'c7##Ar7N
rQ   c                     SUS'   U R                   " U0 UD6n[        U[        5      (       a  UR                  S:X  a  US   $ U$ )a  Variance of the distribution.

Parameters
----------
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

Returns
-------
var : float
    the variance of the distribution

r  r   r   r   r
  r  s       rO   r<   rv_generic.var~  r  rQ   c                 F    SUS'   [        U R                  " U0 UD65      nU$ )a  Standard deviation of the distribution.

Parameters
----------
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

Returns
-------
std : float
    standard deviation of the distribution

r  r   )r   r   r  s       rO   r;   rv_generic.std  s*    & Y4::t,t,-
rQ   c                     Un[        U5      n[        R                  " US:  US:  -  5      (       a  [        S5      eSU-
  S-  nSU-   S-  nU R                  " U/UQ70 UD6nU R                  " U/UQ70 UD6nXx4$ )a  Confidence interval with equal areas around the median.

Parameters
----------
confidence : array_like of float
    Probability that an rv will be drawn from the returned range.
    Each value should be in the range [0, 1].
arg1, arg2, ... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    location parameter, Default is 0.
scale : array_like, optional
    scale parameter, Default is 1.

Returns
-------
a, b : ndarray of float
    end-points of range that contain ``100 * alpha %`` of the rv's
    possible values.

Notes
-----
This is implemented as ``ppf([p_tail, 1-p_tail])``, where
``ppf`` is the inverse cumulative distribution function and
``p_tail = (1-confidence)/2``. Suppose ``[c, d]`` is the support of a
discrete distribution; then ``ppf([0, 1]) == (c-1, d)``. Therefore,
when ``confidence=1`` and the distribution is discrete, the left end
of the interval will be beyond the support of the distribution.
For discrete distributions, the interval will limit the probability
in each tail to be less than or equal to ``p_tail`` (usually
strictly less).

r   r   z'alpha must be between 0 and 1 inclusiverS   rT   )r   r[   r  r   r3   )	r   r   ra   r   alphaq1q2r   r   s	            rO   r9   rv_generic.interval  s    F 66519+,,FGG%i]%i]HHR'$'$'HHR'$'$'trQ   c                 x   U R                   " U0 UD6u  pn[        R                  " / UQUPUP76 nUSS US   US   pCnU R                  " U6 US:  -  nU R                  " U6 u  pxUR                  5       (       a  Xt-  U-   X-  U-   4$ UR                  S:X  a  U R                  U R                  4$ [        R                  " U5      R                  S5      [        R                  " U5      R                  S5      pXt-  U-   X-  U-   p[        U	SU-
  U R                  5        [        U
SU-
  U R                  5        X4$ )a  Support of the distribution.

Parameters
----------
arg1, arg2, ... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    location parameter, Default is 0.
scale : array_like, optional
    scale parameter, Default is 1.

Returns
-------
a, b : array_like
    end-points of the distribution's support.

Nr  r  r   r  r   )r   r[   r	  r  r   rs   rt   r  r   r  r   )r   ra   r  r   r   r  r  _a_bout_aout_bs              rO   r   rv_generic.support  s1   &  ++T<V<5""5D5#5u59d2hR5~~t$	2""D)88:::#RZ#%555YY!^==$--//B&&s+RZZ^-B-B3-GBzC'c)9ueQtVT]]+eQtVT]]+|rQ   c                 L   U R                  U5      u  p4nU R                  " U6 (       a  US::  a  [        $ [        U5      U-
  U-  n[	        U5      [        U5      -  n[        R                  " U R                  " U/UQ76 ) 5      (       a  [        $ U R                  " U/UQ76 U-   $ )zNegative loglikelihood function.
Notes
-----
This is ``-sum(log pdf(x, theta), axis=0)`` where `theta` are the
parameters (including loc and scale).
r   )
_unpack_loc_scaler  r    r   rM  r   r[   r  r  _nnlfr   thetar   r   r   ra   n_log_scales          rO   nnlfrv_generic.nnlf  s      11%8D~~t$
JQZ^u$!fs5z)664%%a/$//00Jzz!#d#k11rQ   c                 P    [         R                  " U R                  " U/UQ76 SS9* $ )Nr   axis)r[   r   _logpxfr  s      rO   r   rv_generic._nnlf  s$    t||A--A666rQ   c                    U R                   " U/UQ76 ) n[        R                  " USS9nUS:  a  [        U) U5      S   nU" U/UQ76 n[        R                  " U5      nU[        R
                  " U) SS9-  nUS:  a0  U[        [        5      -  S-  n[        R
                  " Xg   SS9* U-   $ [        R
                  " USS9* $ )Nr   r'  d   )r  r[   r   r  r   r   r   r#   )	r   r   ra   
log_fitfunr  n_badlogfffinite_logffpenaltys	            rO   _nlff_and_penaltyrv_generic._nlff_and_penalty  s    ##A---  Q/19E61%a(A1$t${{5)A..19c%j(3.GFF5.Q77'AAu1%%%rQ   c                     U R                  U5      u  p4nU R                  " U6 (       a  US::  a  [        $ [        X#-
  U-  5      n[	        U5      [        U5      -  nU R                  X%U R                  5      U-   $ )zPenalized negative loglikelihood function.
i.e., - sum (log pdf(x, theta), axis=0) + penalty
where theta are the parameters (including loc and scale)
r   )r  r  r    r   rM  r   r2  r)  r!  s          rO   _penalized_nnlfrv_generic._penalized_nnlf   sn    
  11%8D~~t$
JQUeO$!fs5z)%%at||<{JJrQ   c                    ^  T R                  U5      u  p4nT R                  " U6 (       a  US::  a  [        $ [        R                  " U5      U-
  U-  nU 4S jnT R                  X%U5      $ )zPenalized negative log product spacing function.
i.e., - sum (log (diff (cdf (x, theta))), axis=0) + penalty
where theta are the parameters (including loc and scale)
Follows reference [1] of scipy.stats.fit
r   c                   > [         R                  " U SS9u  pU R                  (       a  TR                  " U /UQ76 O/ nU R                  (       a  SUS   -
  S::  d5  [         R                  " S/US/45      n[         R                  " US/45      nO[         R                  " S/U45      nU[         R
                  " [         R                  " U5      U-  5      -  $ )NT)return_countsr   r  r   )r[   uniquery   r  concatenater   diff)r   ra   ljcdf_datar/   r   s        rO   log_psf,rv_generic._penalized_nlpsf.<locals>.log_psf7  s    IIat4EA./fftyy*T*"HFFq8B</14nnqc8aS%9:^^R!I.nnqc8_5 rwws|b0111rQ   )r  r  r    r[   sortr2  )r   r"  r   r   r   ra   r?  s   `      rO   _penalized_nlpsfrv_generic._penalized_nlpsf,  sb      11%8D~~t$
JWWQZ#u$
	2 %%aw77rQ   )rf  r"  r.  r   r  r=  r   rK   )NN
continuous)/r   r   r   r   rf  r   r   rz   r   r$  r!  r4  rV  rm  rt  rx  r{  r  r  r  r  r   r  r  r   r  r  r  r  r  r,   r   r5   r7   r=   r:   r<   r;   r9   r   r$  r   r2  r5  rB  r   __classcell__r   s   @rO   r  r    s    
6 " " 6 6"BO'b'LR /36B%;(*~~H
&E:T
,'
%
  $$ 	,'+&'
CJo!b#JKZ,422.,\!F2 7&
K8 8rQ   r  c                   R    \ rS rSrS\R
                  * \R
                  4S4S jrSrg)
_ShapeInfoiF  F)TTc                    Xl         X l        X0l        X@l        [	        U5      n[
        R                  " US   5      (       a5  US   (       d+  [
        R                  " US   [
        R                  5      US'   [
        R                  " US   5      (       a6  US   (       d,  [
        R                  " US   [
        R                  * 5      US'   X0l	        g r  )
r3  integrality	endpoints	inclusiver  r[   r   	nextafterr    domain)r   r3  rJ  rN  rL  s        rO   r   _ShapeInfo.__init__G  s    	&"f;;vay!!)A,VAY7F1I;;vay!!)A,VAY8F1IrQ   )rN  rK  rL  rJ  r3  N)r   r   r   r   r[   r    r   r   r   rQ   rO   rH  rH  F  s    ).7H'rQ   rH  c                    U Vs/ s H  o"U ;   d  M
  X R                  U5      4PM     nn[        U5      S:  a3  U VVs/ s H  u  p$UPM	     nnn[        SSR                  U5      -   5      eU(       a  US   S   $ S$ s  snf s  snnf )a  
Given names such as ``['f0', 'fa', 'fix_a']``, check that there is
at most one non-None value in `kwds` associated with those names.
Return that value, or None if none of the names occur in `kwds`.
As a side effect, all occurrences of those names in `kwds` are
removed.
r   zOfit method got multiple keyword arguments to specify the same fixed parameter: r9  r   N)r  rM  r   rI  )r   namesr3  r`  rb   repeateds         rO   _get_fixed_fit_valuerS  V  s     05Eut"T88D>"uDE
4y1}*./$YTD$/ >8,- . 	. 471:'4' F/s   	A=A=Bc                   .  ^  \ rS rSrSr   S-U 4S jjrS rS rS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S.S  jr!S.S! jr"S" r#S# r$S$ r%S% r&S& r'  S/S( jr(S) r)S'SS*.S+ jr*S,r+U =r,$ )0rG   ip  ar  A generic continuous random variable class meant for subclassing.

`rv_continuous` is a base class to construct specific distribution classes
and instances for continuous random variables. It cannot be used
directly as a distribution.

Parameters
----------
momtype : int, optional
    The type of generic moment calculation to use: 0 for pdf, 1 (default)
    for ppf.
a : float, optional
    Lower bound of the support of the distribution, default is minus
    infinity.
b : float, optional
    Upper bound of the support of the distribution, default is plus
    infinity.
xtol : float, optional
    The tolerance for fixed point calculation for generic ppf.
badvalue : float, optional
    The value in a result arrays that indicates a value that for which
    some argument restriction is violated, default is np.nan.
name : str, optional
    The name of the instance. This string is used to construct the default
    example for distributions.
longname : str, optional
    This string is used as part of the first line of the docstring returned
    when a subclass has no docstring of its own. Note: `longname` exists
    for backwards compatibility, do not use for new subclasses.
shapes : str, optional
    The shape of the distribution. For example ``"m, n"`` for a
    distribution that takes two integers as the two shape arguments for all
    its methods. If not provided, shape parameters will be inferred from
    the signature of the private methods, ``_pdf`` and ``_cdf`` of the
    instance.
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance then
    that instance is used.

Methods
-------
rvs
pdf
logpdf
cdf
logcdf
sf
logsf
ppf
isf
moment
stats
entropy
expect
median
mean
std
var
interval
__call__
fit
fit_loc_scale
nnlf
support

Notes
-----
Public methods of an instance of a distribution class (e.g., ``pdf``,
``cdf``) check their arguments and pass valid arguments to private,
computational methods (``_pdf``, ``_cdf``). For ``pdf(x)``, ``x`` is valid
if it is within the support of the distribution.
Whether a shape parameter is valid is decided by an ``_argcheck`` method
(which defaults to checking that its arguments are strictly positive.)

**Subclassing**

New random variables can be defined by subclassing the `rv_continuous` class
and re-defining at least the ``_pdf`` or the ``_cdf`` method (normalized
to location 0 and scale 1).

If positive argument checking is not correct for your RV
then you will also need to re-define the ``_argcheck`` method.

For most of the scipy.stats distributions, the support interval doesn't
depend on the shape parameters. ``x`` being in the support interval is
equivalent to ``self.a <= x <= self.b``.  If either of the endpoints of
the support do depend on the shape parameters, then
i) the distribution must implement the ``_get_support`` method; and
ii) those dependent endpoints must be omitted from the distribution's
call to the ``rv_continuous`` initializer.

Correct, but potentially slow defaults exist for the remaining
methods but for speed and/or accuracy you can over-ride::

  _logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf

The default method ``_rvs`` relies on the inverse of the cdf, ``_ppf``,
applied to a uniform random variate. In order to generate random variates
efficiently, either the default ``_ppf`` needs to be overwritten (e.g.
if the inverse cdf can expressed in an explicit form) or a sampling
method needs to be implemented in a custom ``_rvs`` method.

If possible, you should override ``_isf``, ``_sf`` or ``_logsf``.
The main reason would be to improve numerical accuracy: for example,
the survival function ``_sf`` is computed as ``1 - _cdf`` which can
result in loss of precision if ``_cdf(x)`` is close to one.

**Methods that can be overwritten by subclasses**
::

  _rvs
  _pdf
  _cdf
  _sf
  _ppf
  _isf
  _stats
  _munp
  _entropy
  _argcheck
  _get_support

There are additional (internal and private) generic methods that can
be useful for cross-checking and for debugging, but might work in all
cases when directly called.

A note on ``shapes``: subclasses need not specify them explicitly. In this
case, `shapes` will be automatically deduced from the signatures of the
overridden methods (`pdf`, `cdf` etc).
If, for some reason, you prefer to avoid relying on introspection, you can
specify ``shapes`` explicitly as an argument to the instance constructor.


**Frozen Distributions**

Normally, you must provide shape parameters (and, optionally, location and
scale parameters to each call of a method of a distribution.

Alternatively, the object may be called (as a function) to fix the shape,
location, and scale parameters returning a "frozen" continuous RV object:

rv = generic(<shape(s)>, loc=0, scale=1)
    `rv_frozen` object with the same methods but holding the given shape,
    location, and scale fixed

**Statistics**

Statistics are computed using numerical integration by default.
For speed you can redefine this using ``_stats``:

 - take shape parameters and return mu, mu2, g1, g2
 - If you can't compute one of these, return it as None
 - Can also be defined with a keyword argument ``moments``, which is a
   string composed of "m", "v", "s", and/or "k".
   Only the components appearing in string should be computed and
   returned in the order "m", "v", "s", or "k"  with missing values
   returned as None.

Alternatively, you can override ``_munp``, which takes ``n`` and shape
parameters and returns the n-th non-central moment of the distribution.

**Deepcopying / Pickling**

If a distribution or frozen distribution is deepcopied (pickled/unpickled,
etc.), any underlying random number generator is deepcopied with it. An
implication is that if a distribution relies on the singleton RandomState
before copying, it will rely on a copy of that random state after copying,
and ``np.random.seed`` will no longer control the state.

Examples
--------
To create a new Gaussian distribution, we would do the following:

>>> from scipy.stats import rv_continuous
>>> class gaussian_gen(rv_continuous):
...     "Gaussian distribution"
...     def _pdf(self, x):
...         return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
>>> gaussian = gaussian_gen(name='gaussian')

``scipy.stats`` distributions are *instances*, so here we subclass
`rv_continuous` and create an instance. With this, we now have
a fully functional distribution with all relevant methods automagically
generated by the framework.

Note that above we defined a standard normal distribution, with zero mean
and unit variance. Shifting and scaling of the distribution can be done
by using ``loc`` and ``scale`` parameters: ``gaussian.pdf(x, loc, scale)``
essentially computes ``y = (x - loc) / scale`` and
``gaussian._pdf(y) / scale``.

r   c
                   > [         TU ]  U	5        [        XX4XVUXS9	U l        Uc  [        nUc  SnXPl        X`l        X l        X0l        Uc  [        * U l        Uc  [        U l        X@l
        Xl        Xl        U R                  U R                  U R                  /SSS9  U R!                  5         Uc  US   S;   a  Sn
OS	n
X-   n["        R$                  R&                  S
:  ab  U R(                  c  U R+                  U[,        SS9  g [        [.        5      nU R1                  [,        UR3                  U R                  5      5        g g )N)	momtyper   r   xtolr  r3  rr  r   r   Distributionzloc=0, scale=1z
loc, scalerN  r;  r<  r   
aeiouAEIOUAn A rT   rD  rr  rj  rs  )r  r   rJ  r"  r   r  r3  r   r   r    rW  moment_typer   rV  _pdfr  r!  sysflagsr   rf  rt  rj  r   rm  r  )r   rV  r   r   rW  r  r3  rr  r   r   hstrrU  r   s               rO   r   rv_continuous.__init__6  sA    	  A8&
 H<!D 	9TDF9DF	"!!DIItyy3I.>/; 	" 	= 	Aw.({H99!||#++X4;5A , C 8n##GSWWTYY-?@ "rQ   c                     U R                   R                  5       n/ SQnU Vs/ s H  o1R                  US 5      PM       nU$ s  snf )N)r   r+  r,  _cdfvecr  r  r  r   r   r  r   rU  attrsattrs       rO   __getstate__rv_continuous.__getstate__h  sA    mm  "G)./t	/
 	0   Ac                    U R                  5         [        U R                  SS9U l        U R                  S-   U R                  l        [        U R                  SS9U l        [        U R                  SS9U l	        U R                  S-   U R                  l        U R                  S:X  a  [        U R                  SS9U l        O[        U R                  SS9U l        U R                  S-   U R                  l        g)zE
Attaches dynamically created methods to the rv_continuous instance.
r  otypesr   r   N)r4  r   _ppf_singler  r=  nin_entropyr  _cdf_singlerf  r_  _mom0_scr  _mom1_scr   s    rO   r!  rv_continuous._attach_methodsr  s    
 	&&( !!1!1#><<!+#DMM#> !1!1#><<!+q "+DMM#"FD"+DMM#"FD #',,"2rQ   c                     U R                   R                  5       nU R                  US'   U R                  US'   U R                  US'   U R
                  US'   U R                  US'   U R                  US'   U$ )Return the current version of _ctor_param, possibly updated by user.

Used by freezing.
Keep this in sync with the signature of __init__.
r   r   rW  r  r3  r   )r"  r   r   r   rW  r  r3  r   r   rU  s     rO   r   !rv_continuous._updated_ctor_param  sk     ##%66C66CiiF--JiiFH
rQ   c                 .    U R                   " U4U-   6 U-
  $ rK   )r/   )r   r   r   ra   s       rO   _ppf_to_solverv_continuous._ppf_to_solve  s    xx!t$Q&&rQ   c                    SnU R                   " U6 u  pE[        R                  " U5      (       aB  [        U* U5      nU R                  " XA/UQ76 S:  a  XC-  UpTU R                  " XA/UQ76 S:  a  M  [        R                  " U5      (       a@  [        X45      nU R                  " XQ/UQ76 S:  a  XUU-  pTU R                  " XQ/UQ76 S:  a  M  [        R                  " U R                  XEU4U-   U R                  S9$ )Ng      $@        )ra   rW  )	r   r[   r!   minr}  maxr   brentqrW  )r   r   ra   factorleftrights         rO   rq  rv_continuous._ppf_single  s    ''.88D>>w&D$$T4t4r9"mTe $$T4t4r9
 88E??%E$$U55:#V^e $$U55: t11#!dL 	LrQ   c                 2    X-  U R                   " U/UQ76 -  $ rK   r-   )r   r   r  ra   s       rO   _mom_integ0rv_continuous._mom_integ0  s    tdhhq(4(((rQ   c                 r    U R                   " U6 u  p4[        R                  " U R                  X4U4U-   S9S   $ Nra   r   )r   r   quadr  )r   r  ra   r  r  s        rO   ru  rv_continuous._mom0_sc  s@    ""D)~~d..$%49../1 	1rQ   c                 .    U R                   " U/UQ76 U-  $ rK   r  )r   r   r  ra   s       rO   _mom_integ1rv_continuous._mom_integ1  s    "T"Q&&rQ   c                 R    [         R                  " U R                  SSU4U-   S9S   $ )Nr   r   r  )r   r  r  )r   r  ra   s      rO   rv  rv_continuous._mom1_sc  s(    ~~d..1A49EaHHrQ   c                 0    [        U R                  USUSS9$ )Ngh㈵>r  )dxra   r   )r   r  r  s      rO   r`  rv_continuous._pdf  s    499aDt1EErQ   c                     U R                   " U/UQ76 n[        R                  " SS9   [        U5      sS S S 5        $ ! , (       d  f       g = fr  )r`  r[   r  r   )r   r   ra   ps       rO   _logpdfrv_continuous._logpdf  s4    IIa$[[)q6 *))s	   =
Ac                 (    U R                   " U/UQ76 $ rK   )r  r  s      rO   r)  rv_continuous._logpxf       ||A%%%rQ   c                 j    U R                   " U6 u  p4[        R                  " U R                  X1US9S   $ r  )r   r   r  r`  )r   r   ra   r  r  s        rO   rt  rv_continuous._cdf_single  s0    ""D)~~diiT:1==rQ   c                 (    U R                   " U/UQ76 $ rK   )rf  r  s      rO   r  rv_continuous._cdf  r  rQ   c                    ^  T R                   " S/UQ76 n[        R                  " SS9   [        X:  U4U-   U 4S jU 4S jS9sS S S 5        $ ! , (       d  f       g = f)Nr  r  r  c                 R   > [         R                  " TR                  " U /UQ76 5      $ rK   )r[   r   r  r   ra   r   s     rO   <lambda>'rv_continuous._logcdf.<locals>.<lambda>  s    		!8Kd8K1LrQ   c                 T   > [         R                  " TR                  " U /UQ76 * 5      $ rK   )r[   log1pr  r  s     rO   r  r    s    "((DHHQ<N<N;N2OrQ   ff2r  r[   r  r
   r   r   ra   r=   s   `   rO   r  rv_continuous._logcdf  sI    3&&[[)aj1$+ L!OQ *))   A
Ac                    ^  T R                   " S/UQ76 n[        R                  " SS9   [        X:  U4U-   U 4S jU 4S jS9sS S S 5        $ ! , (       d  f       g = f)Nr  r  r  c                 R   > [         R                  " TR                  " U /UQ76 5      $ rK   )r[   r   r  r  s     rO   r  &rv_continuous._logsf.<locals>.<lambda>  s    8JT8J1KrQ   c                 T   > [         R                  " TR                  " U /UQ76 * 5      $ rK   )r[   r  r  r  s     rO   r  r    s    "((DIIa<O$<O;O2PrQ   r  r  r  s   `   rO   r  rv_continuous._logsf  sI    3&&[[)aj1$+ K!PR *))r  c                    U R                   " U0 UD6u  p$n[        [        XU45      u  pn[        [        [        U5      5      n[        R
                  " UR                  [        R                  5      n[        R                  " X-
  U-  US9nU R                  " U6 US:  -  nU R                  " U/UQ76 US:  -  nXx-  n	[        [        U	5      U5      n
[        U
SU-
  [        R                  " U5      -   U R                  5        [        R                  " U	5      (       a9  [!        U	/U4U-   U4-   Q76 nUS   USS p[#        XU R$                  " U6 U-  5        U
R&                  S:X  a  U
S   $ U
$ )a  Probability density function at x of the given RV.

Parameters
----------
x : array_like
    quantiles
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

Returns
-------
pdf : ndarray
    Probability density function evaluated at x

r  r   r   r  Nr   )r   r  r   r  r[   promote_typesr  float64r  r  r   r   r   isnanr  r  r  r   r`  rt   r   r   ra   r   r   r   dtypr  cond1r  r  r  s               rO   r-   rv_continuous.pdf  sM   *  ++T:T:5Gae_5S$'(4JJd3%3""1,t,	:}uT{D)5"((1+-t}}=66$<<!$>1$t)UH*<>H&rlHSbM8&		8 4u <=;;!":rQ   c                    U R                   " U0 UD6u  p$n[        [        XU45      u  pn[        [        [        U5      5      n[        R
                  " UR                  [        R                  5      n[        R                  " X-
  U-  US9nU R                  " U6 US:  -  nU R                  " U/UQ76 US:  -  nXx-  n	[        [        U	5      U5      n
U
R                  [        * 5        [        U
SU-
  [        R                  " U5      -   U R                   5        [        R"                  " U	5      (       aB  [%        U	/U4U-   U4-   Q76 nUS   USS p['        XU R(                  " U6 [+        U5      -
  5        U
R,                  S:X  a  U
S   $ U
$ )a!  Log of the probability density function at x of the given RV.

This uses a more numerically accurate calculation if available.

Parameters
----------
x : array_like
    quantiles
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

Returns
-------
logpdf : array_like
    Log of the probability density function evaluated at x

r  r   r   r  Nr   )r   r  r   r  r[   r  r  r  r  r  r"   r   fillr    r   r  r  r  r  r   r  r   rt   r  s               rO   r.   rv_continuous.logpdf  s_   .  ++T:T:5Gae_5S$'(4JJd3%3""1,t,	:}uT{D)SD5"((1+-t}}=66$<<!$>1$t)UH*<>H&rlHSbM8&h 7#e* DE;;!":rQ   c                 2   U R                   " U0 UD6u  p$n[        [        XU45      u  pn[        [        [        U5      5      nU R                  " U6 u  pg[
        R                  " UR                  [
        R                  5      n[
        R                  " X-
  U-  US9nU R                  " U6 US:  -  n	U R                  " U/UQ76 US:  -  n
U[
        R                  " U5      :  U	-  nX-  n[        [        U5      U5      n[        USU	-
  [
        R                  " U5      -   U R                  5        [        XS5        [
        R                   " U5      (       a)  [#        U/U4U-   Q76 n[        XU R$                  " U6 5        UR&                  S:X  a  US   $ U$ )a  
Cumulative distribution function of the given RV.

Parameters
----------
x : array_like
    quantiles
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

Returns
-------
cdf : ndarray
    Cumulative distribution function evaluated at `x`

r  r   r   rS   r   )r   r  r   r  r   r[   r  r  r  r  r  r   r   r   r  r  r  r  r  rt   r   r   ra   r   r   r   r  r  r  r  r  cond2r  r  r  s                  rO   r/   rv_continuous.cdf6  sc   ,  ++T:T:5Gae_5S$'(""D)4JJd3%3''1D1UQY?bjjn$-}uT{D)fqw+T]];fS!66$<<!$51$t)5H&		8 45;;!":rQ   c                 >   U R                   " U0 UD6u  p$n[        [        XU45      u  pn[        [        [        U5      5      nU R                  " U6 u  pg[
        R                  " UR                  [
        R                  5      n[
        R                  " X-
  U-  US9nU R                  " U6 US:  -  n	U R                  " U/UQ76 US:  -  n
X:  U	-  nX-  n[        [        U5      U5      nUR                  [        * 5        [        USU	-
  X:H  -  [
        R                   " U5      -   U R"                  5        [        XS5        [
        R$                  " U5      (       a)  ['        U/U4U-   Q76 n[        XU R(                  " U6 5        UR*                  S:X  a  US   $ U$ )a  Log of the cumulative distribution function at x of the given RV.

Parameters
----------
x : array_like
    quantiles
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

Returns
-------
logcdf : array_like
    Log of the cumulative distribution function evaluated at x

r  r   r   r  r   )r   r  r   r  r   r[   r  r  r  r  r  r"   r   r  r    r   r  r  r  r  r  rt   r  s                  rO   r0   rv_continuous.logcdf`  sm   *  ++T:T:5Gae_5S$'(""D)4JJd3%3''1D1UQY?E!}uT{D)SDfqw0!<dmmLfS!66$<<!$51$t)5H&h 78;;!":rQ   c                    U R                   " U0 UD6u  p$n[        [        XU45      u  pn[        [        [        U5      5      nU R                  " U6 u  pg[
        R                  " UR                  [
        R                  5      n[
        R                  " X-
  U-  US9nU R                  " U6 US:  -  n	U R                  " U/UQ76 US:  -  n
XU:*  -  nX-  n[        [        U5      U5      n[        USU	-
  [
        R                  " U5      -   U R                  5        [        XS5        [
        R                   " U5      (       a)  [#        U/U4U-   Q76 n[        XU R$                  " U6 5        UR&                  S:X  a  US   $ U$ )a  Survival function (1 - `cdf`) at x of the given RV.

Parameters
----------
x : array_like
    quantiles
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

Returns
-------
sf : array_like
    Survival function evaluated at x

r  r   r   rS   r   )r   r  r   r  r   r[   r  r  r  r  r  r   r   r   r  r  r  r  r  rt   r  s                  rO   r1   rv_continuous.sf  sX   *  ++T:T:5Gae_5S$'(""D)4JJd3%3''1D1UQY?b!}uT{D)fqw+T]];fS!66$<<!$51$t)5H&( 34;;!":rQ   c                 4   U R                   " U0 UD6u  p$n[        [        XU45      u  pn[        [        [        U5      5      nU R                  " U6 u  pg[
        R                  " UR                  [
        R                  5      n[
        R                  " X-
  U-  US9nU R                  " U6 US:  -  n	U R                  " U/UQ76 US:  -  n
XU:*  -  nX-  n[        [        U5      U5      nUR                  [        * 5        [        USU	-
  [
        R                   " U5      -   U R"                  5        [        XS5        [
        R$                  " U5      (       a)  ['        U/U4U-   Q76 n[        XU R(                  " U6 5        UR*                  S:X  a  US   $ U$ )a  Log of the survival function of the given RV.

Returns the log of the "survival function," defined as (1 - `cdf`),
evaluated at `x`.

Parameters
----------
x : array_like
    quantiles
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

Returns
-------
logsf : ndarray
    Log of the survival function evaluated at `x`.

r  r   r   r  r   )r   r  r   r  r   r[   r  r  r  r  r  r"   r   r  r    r   r  r  r  r  r  rt   r  s                  rO   r2   rv_continuous.logsf  sf   0  ++T:T:5Gae_5S$'(""D)4JJd3%3''1D1UQY?b!}uT{D)SDfqw+T]];fS!66$<<!$51$t)5H&X 67;;!":rQ   c                    U R                   " U0 UD6u  p$n[        [        XU45      u  pn[        [        [        U5      5      nU R                  " U6 u  pgU R
                  " U6 US:  -  XD:H  -  nSU:  US:  -  n	XS:H  -  n
XS:H  -  nX-  n[        R                  " [        U5      U R                  S9nXe-  U-   nXu-  U-   n[        X[        X5      S   5        [        X[        X5      S   5        [        R                  " U5      (       aA  [        U/U4U-   XT4-   Q76 nUS   US   USS npE[        XU R                  " U6 U-  U-   5        UR                  S:X  a  US   $ U$ )a  Percent point function (inverse of `cdf`) at q of the given RV.

Parameters
----------
q : array_like
    lower tail probability
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

Returns
-------
x : array_like
    quantile corresponding to the lower tail probability q.

r   r   r  r  r  Nr   )r   r  r   r  r   r  r[   r  r   r  r   r  r  r  rt   r   r   ra   r   r   r   r  r  r  r  r  cond3r  r  lower_boundupper_boundr  s                    rO   r3   rv_continuous.ppf  v   *  ++T:T:5Gae_5S$'(""D)%3szBQ1q5!a a }t?j3&j3&fZ;A>?fZ;A>?66$<<!$B1$t)UL*@BH#+B<"x}3&		8 4u <s BC;;!":rQ   c                    U R                   " U0 UD6u  p$n[        [        XU45      u  pn[        [        [        U5      5      nU R                  " U6 u  pgU R
                  " U6 US:  -  XD:H  -  nSU:  US:  -  n	XS:H  -  n
XS:H  -  nX-  n[        R                  " [        U5      U R                  S9nXe-  U-   nXu-  U-   n[        X[        X5      S   5        [        X[        X5      S   5        [        R                  " U5      (       aA  [        U/U4U-   XT4-   Q76 nUS   US   USS npE[        XU R                  " U6 U-  U-   5        UR                  S:X  a  US   $ U$ )a  Inverse survival function (inverse of `sf`) at q of the given RV.

Parameters
----------
q : array_like
    upper tail probability
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    location parameter (default=0)
scale : array_like, optional
    scale parameter (default=1)

Returns
-------
x : ndarray or scalar
    Quantile corresponding to the upper tail probability q.

r   r   r  r  r  Nr   )r   r  r   r  r   r  r[   r  r   r  r   r  r  r  rt   r  s                    rO   r4   rv_continuous.isf	  r  rQ   c                 x     US   nUS   n[        US S 5      nX#U4$ ! [         a  n[        S5      UeS nAff = f)Nr  r  Not enough input arguments.r  
IndexErrorr   r   r"  r   r   ra   r   s         rO   r  rv_continuous._unpack_loc_scale:	  sY    	C)C"IEs$D 4  	C:;B	Cs    
949c           	         [        U[        5      (       a  UR                  " U R                  " U6 6 n[	        U5      [	        U5      -
  nUR
                  R                  u  pVU R                  " UR                  /UQ76 U R                  " UR                  /UQ76 U R                  " UR                  /UQ76 [        R                  " U R                  " XV/UQ76 5      /nOTU R                   " U/UQ76 ) n[        R"                  " U5      nUS:  a  [%        U) U5      S   nU R                  " U/UQ76 /n['        U V	s/ s H  n	[)        U	5      PM     sn	6 u  p[+        U
5      nU[+        U5      -  nU* U[,        -  S-  -   $ s  sn	f )z
Compute the penalized negative log-likelihood for the
"standardized" data (i.e. already shifted by loc and
scaled by scale) for the shape parameters in `args`.

`x` can be a 1D numpy array or a CensoredData instance.
r   r,  )r   r%   
_supportedr   rM  	_intervalTr  _uncensoredr  _leftr  _rightr[   r   
_delta_cdfr  r   r  r  r   r   r$   )r   r   ra   xsr.  r  r  termsr  termtotals
bad_countstotals                rO   _nnlf_and_penaltyrv_continuous._nnlf_and_penaltyC	  s\    a&&t00$78BFSW$E\\^^FB R^^3d3RXX--BII--tr556	E ''1D11E$$U+Eqyvq)!,\\!+d+,E "G;t#4"GHFZ v(3...	 #Hs   ;E?c                 X   U R                  U5      u  p4nU R                  " U6 (       a  US::  a  [        $ [        U[        5      (       a0  X#-
  U-  n[        U5      UR                  5       -
  [        U5      -  nOX#-
  U-  n[        U5      [        U5      -  nU R                  X%5      U-   $ )zPenalized negative loglikelihood function.

i.e., - sum (log pdf(x, theta), axis=0) + penalty
where theta are the parameters (including loc and scale)
r   )	r  r  r    r   r%   rM  num_censoredr   r  r!  s          rO   r5  rv_continuous._penalized_nnlfg	  s      11%8D~~t$
Ja&&E!Aq6ANN$44E
BKE!Aa&3u:-K%%a.<<rQ   c                 \    Uc  SU R                   -  nU R                  " U/UQ76 u  p4X#U4-   $ )z7Starting point for fit (shape arguments + loc + scale).)rS   )r=  _fit_loc_scale_support)r   rL   ra   r   r   s        rO   	_fitstartrv_continuous._fitstarty	  s9    <$,,&D00==
El""rQ   c                 Z  ^ ^^^^^^ / nT R                   (       ak  T R                   R                  SS5      R                  5       n[        U5       H2  u  pVS[	        U5      -   nUSU-   SU-   /n[        X(5      n	U	c  M.  XU'   M4     [        T5      m[        T5      m/ m[        TS-
  5       V
s/ s H  n
SU
-  PM
     sn
SS	/-   n/ n[        U5       HE  u  pXr;   a'  TR                  U
5        UR                  U5      TU
'   M1  UR                  TU
   5        MG     S
S1nUR                  SS
5      R                  5       nUS:X  a|  [        U5      S-   [        T5      -
  n[        R                  " SUS-   5      SS2[        R                  4   n[        R                  " USSS24   U-  [        U5      -  SS9mUU 4S jmO$US
:X  a  T R                   mO[#        SU SU 35      e[        T5      S:X  a  TnSmO)[        T5      T:X  a  [#        S5      eUU4S jmUUU4S jnUUTT4$ s  sn
f )zh
Return the (possibly reduced) function to optimize in order to find MLE
estimates for the .fit method.
r7  r8  r  fix_NrT   zf%dflocfscalemlemmmethodr   r'  c                 (   > TR                  XT5      $ rK   )_moment_error)r"  r   data_momentsr   s     rO   	objective-rv_continuous._reduce_func.<locals>.objective	  s    ))%LAArQ   zMethod 'z ' not available; must be one of r   z3All parameters fixed. There is nothing to optimize.c                 V   > Sn[        T5       H  nUT;  d  M  X   X'   US-  nM     U $ r  )re  )ra   r"  r   rM   Nargsfixedns       rO   restore+rv_continuous._reduce_func.<locals>.restore	  s8     uA"'(Q & rQ   c                 ,   > T" TS S  U 5      nT" X!5      $ rK   r   )r"  r   newthetara   r  r  s      rO   r   (rv_continuous._reduce_func.<locals>.func	  s    "47E2 --rQ   )r   r?  r@  	enumerater   rS  r  rM  re  rF  r  lowerr[   r   newaxisr   r5  r   )r   ra   r   rL   r   r   r  keyrQ  rb   rM   x0r'   r  n_params	exponentsr   r  r  r   r  r  s   ``               @@@@@rO   _reduce_funcrv_continuous._reduce_func	  s!    ;;[[((c288:F!&)CFlcAgvz2*47? #I * DzD	$)%!)$45$4q$458JJ&FA{a ((3-Q		$q'" ' $-(E*002T>6{QV4H1hqj11bjj=AI66$tQw-":3t9"D1MLB u_,,Ixx 0//6i9 : : v;!DG6{e# IK K	. 4$&&a 6s   .H(c                 
   U R                  U5      u  pEnU R                  " U6 (       a  US::  a  [        $ [        R                  " [        [        U5      5       Vs/ s H  nU R                  " US-   /UQ7XES.6PM     sn5      n[        R                  " [        R                  " U5      5      (       a  [        S5      eX8-
  [        R                  " [        R                  " U5      S5      -  S-  R                  5       $ s  snf )Nr   r   r   r   zqMethod of moments encountered a non-finite distribution moment and cannot continue. Consider trying method='MLE'.:0yE>rT   )r  r  r    r[   rr   re  rM  r7   r  r  r   maximumabsr   )	r   r"  r   r  r   r   ra   r   dist_momentss	            rO   r  rv_continuous._moment_error	  s    11%8D~~t$
Jxx*/L0A*B!D*BQ "&QqS!N4!NS!N*B!D E66"((<()) = > > -BFF<0$78:;<=@SU	C!Ds   #D c                    UR                  SS5      R                  5       n[        U[        5      nU(       a3  US:w  a  [	        S5      eUR                  5       S:X  a  UR                  nSn[        U5      nX`R                  :  a  [        S5      eU(       dX  [        R                  " U5      R                  5       n[        R                  " U5      R                  5       (       d  [	        S5      eS/S	-  nX`R                  :  d  S
U;   a  SU;   d  U R                  U5      nX'US -  nUR!                  S
US   5      nUR!                  SUS   5      n	X(U	4-  nU R#                  X#US9u  ppUR!                  S[$        R&                  5      n[)        U5      nU(       a  [        SU S35      eU" XU4SS9nU" X5      nUb  U" X.5      n[+        U5      nU R-                  U5      u  pn[        R                  " U R.                  " U6 5      (       a  U	S:  d  [1        S5      eUS:X  a&  [        R                  " U5      (       d  [1        S5      eU$ )ad  
Return estimates of shape (if applicable), location, and scale
parameters from data. The default estimation method is Maximum
Likelihood Estimation (MLE), but Method of Moments (MM)
is also available.

Starting estimates for the fit are given by input arguments;
for any arguments not provided with starting estimates,
``self._fitstart(data)`` is called to generate such.

One can hold some parameters fixed to specific values by passing in
keyword arguments ``f0``, ``f1``, ..., ``fn`` (for shape parameters)
and ``floc`` and ``fscale`` (for location and scale parameters,
respectively).

Parameters
----------
data : array_like or `CensoredData` instance
    Data to use in estimating the distribution parameters.
arg1, arg2, arg3,... : floats, optional
    Starting value(s) for any shape-characterizing arguments (those not
    provided will be determined by a call to ``_fitstart(data)``).
    No default value.
**kwds : floats, optional
    - `loc`: initial guess of the distribution's location parameter.
    - `scale`: initial guess of the distribution's scale parameter.

    Special keyword arguments are recognized as holding certain
    parameters fixed:

    - f0...fn : hold respective shape parameters fixed.
      Alternatively, shape parameters to fix can be specified by name.
      For example, if ``self.shapes == "a, b"``, ``fa`` and ``fix_a``
      are equivalent to ``f0``, and ``fb`` and ``fix_b`` are
      equivalent to ``f1``.

    - floc : hold location parameter fixed to specified value.

    - fscale : hold scale parameter fixed to specified value.

    - optimizer : The optimizer to use.  The optimizer must take
      ``func`` and starting position as the first two arguments,
      plus ``args`` (for extra arguments to pass to the
      function to be optimized) and ``disp``.
      The ``fit`` method calls the optimizer with ``disp=0`` to suppress output.
      The optimizer must return the estimated parameters.

    - method : The method to use. The default is "MLE" (Maximum
      Likelihood Estimate); "MM" (Method of Moments)
      is also available.

Raises
------
TypeError, ValueError
    If an input is invalid
`~scipy.stats.FitError`
    If fitting fails or the fit produced would be invalid

Returns
-------
parameter_tuple : tuple of floats
    Estimates for any shape parameters (if applicable), followed by
    those for location and scale. For most random variables, shape
    statistics will be returned, but there are exceptions (e.g.
    ``norm``).

Notes
-----
With ``method="MLE"`` (default), the fit is computed by minimizing
the negative log-likelihood function. A large, finite penalty
(rather than infinite negative log-likelihood) is applied for
observations beyond the support of the distribution.

With ``method="MM"``, the fit is computed by minimizing the L2 norm
of the relative errors between the first *k* raw (about zero) data
moments and the corresponding distribution moments, where *k* is the
number of non-fixed parameters.
More precisely, the objective function is::

    (((data_moments - dist_moments)
      / np.maximum(np.abs(data_moments), 1e-8))**2).sum()

where the constant ``1e-8`` avoids division by zero in case of
vanishing data moments. Typically, this error norm can be reduced to
zero.
Note that the standard method of moments can produce parameters for
which some data are outside the support of the fitted distribution;
this implementation does nothing to prevent this.

For either method,
the returned answer is not guaranteed to be globally optimal; it
may only be locally optimal, or the optimization may fail altogether.
If the data contain any of ``np.nan``, ``np.inf``, or ``-np.inf``,
the `fit` method will raise a ``RuntimeError``.

When passing a ``CensoredData`` instance to ``data``, the log-likelihood
function is defined as:

.. math::

    l(\pmb{\theta}; k) & = \sum
                            \log(f(k_u; \pmb{\theta}))
                        + \sum
                            \log(F(k_l; \pmb{\theta})) \\
                        & + \sum
                            \log(1 - F(k_r; \pmb{\theta})) \\
                        & + \sum
                            \log(F(k_{\text{high}, i}; \pmb{\theta})
                            - F(k_{\text{low}, i}; \pmb{\theta}))

where :math:`f` and :math:`F` are the pdf and cdf, respectively, of the
function being fitted, :math:`\pmb{\theta}` is the parameter vector,
:math:`u` are the indices of uncensored observations,
:math:`l` are the indices of left-censored observations,
:math:`r` are the indices of right-censored observations,
subscripts "low"/"high" denote endpoints of interval-censored observations, and
:math:`i` are the indices of interval-censored observations.

Examples
--------

Generate some data to fit: draw random variates from the `beta`
distribution

>>> import numpy as np
>>> from scipy.stats import beta
>>> a, b = 1., 2.
>>> rng = np.random.default_rng(172786373191770012695001057628748821561)
>>> x = beta.rvs(a, b, size=1000, random_state=rng)

Now we can fit all four parameters (``a``, ``b``, ``loc`` and
``scale``):

>>> a1, b1, loc1, scale1 = beta.fit(x)
>>> a1, b1, loc1, scale1
(1.0198945204435628, 1.9484708982737828, 4.372241314917588e-05, 0.9979078845964814)

The fit can be done also using a custom optimizer:

>>> from scipy.optimize import minimize
>>> def custom_optimizer(func, x0, args=(), disp=0):
...     res = minimize(func, x0, args, method="slsqp", options={"disp": disp})
...     if res.success:
...         return res.x
...     raise RuntimeError('optimization routine failed')
>>> a1, b1, loc1, scale1 = beta.fit(x, method="MLE", optimizer=custom_optimizer)
>>> a1, b1, loc1, scale1
(1.0198821087258905, 1.948484145914738, 4.3705304486881485e-05, 0.9979104663953395)

We can also use some prior knowledge about the dataset: let's keep
``loc`` and ``scale`` fixed:

>>> a1, b1, loc1, scale1 = beta.fit(x, floc=0, fscale=1)
>>> loc1, scale1
(0, 1)

We can also keep shape parameters fixed by using ``f``-keywords. To
keep the zero-th shape parameter ``a`` equal 1, use ``f0=1`` or,
equivalently, ``fa=1``:

>>> a1, b1, loc1, scale1 = beta.fit(x, fa=1, floc=0, fscale=1)
>>> a1
1

Not all distributions return estimates for the shape parameters.
``norm`` for example just returns estimates for location and scale:

>>> from scipy.stats import norm
>>> x = norm.rvs(a, b, size=1000, random_state=123)
>>> loc1, scale1 = norm.fit(x)
>>> loc1, scale1
(0.92087172783841631, 2.0015750750324668)
r  r  z,For censored data, the method must be "MLE".r   FzToo many input arguments.z$The data contains non-finite values.NrT   r   r   r  r  )rL   r   zUnknown arguments: .)ra   dispz\Optimization converged to parameters that are outside the range allowed by the distribution.r  zVOptimization failed: either a data moment or fitted distribution moment is non-finite.)r  r  r   r%   r   r  r  rM  r=  r>  r[   r   rg   r   rs   r  r  r  r   r   r   r  r  r  r&   )r   rL   ra   r   r  censoredNargstartr   r   r
  r   r  r   r`  objr   s                    rO   r6   rv_continuous.fit	  s8   \ (E*002dL1  ". / /  "a' '' 4y,,788
 ::d#))+D;;t$((** !GHHq<<$)0DNN4(E$rN"DhhueBi(%),e"&"3"3DT"3"J'HH[(--8	,Y7	1$q9:: a844&DT{!33D9Ft~~v.//EAI L M M T>;;s##  - . . rQ   c                 x   [        U[        5      (       a  UR                  5       nO[        R                  " U5      nU R
                  " U/UQ76 u  p4U R                  " U6   U R                  " U6 u  pVXVpX-
  n	U	S::  a  X44$ X7U-  -   n
X8U-  -   n[        R                  " U5      n[        R                  " U5      nX:  a  X:  a  X44$ X-
  nSnX-  nU	[        R                  :  a  X-
  U-
  nUSU-  -   U	-  nX44$ U[        R                  * :  a	  X-
  U-
  S4$ U[        R                  :  a	  X-
  U-   S4$ [        e)a  Estimate loc and scale parameters from data accounting for support.

Parameters
----------
data : array_like
    Data to fit.
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).

Returns
-------
Lhat : float
    Estimated location parameter for the data.
Shat : float
    Estimated scale parameter for the data.

r   g?rT   r   )r   r%   	_uncensorr[   r   fit_loc_scaler  r   r  r  r    RuntimeError)r   rL   ra   loc_hat	scale_hatr  r  r   r   support_widtha_hatb_hatdata_adata_b
data_width
rel_marginmargins                    rO   r  $rv_continuous._fit_loc_scale_support
  s^   & dL)) >>#D::d#D "//<t< 	""D)1 A%% i-'i-' >fn%% _

( 266!zV+G#a&j0MAI%% w;J&(!++ZJ&(!++rQ   c                    U R                   " U0 SS0D6u  p4[        U5      nUR                  5       nUR                  5       n[	        Xt-  5      n[
        R                  " SS9   XhU-  -
  n	SSS5        [
        R                  " W	5      (       d  Sn	[
        R                  " U5      (       a  SU:  d  SnX4$ ! , (       d  f       NQ= f)a  
Estimate loc and scale parameters from data using 1st and 2nd moments.

Parameters
----------
data : array_like
    Data to fit.
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).

Returns
-------
Lhat : float
    Estimated location parameter for the data.
Shat : float
    Estimated scale parameter for the data.

r   r   r  r  Nr   r   )r   r   r:   r<   r   r[   r  r   )
r   rL   ra   rN   r]   tmpmuhatmu2hatShatLhats
             rO   r   rv_continuous.fit_loc_scale  s    ( **d8y$&78dm
FL![[*7?D +{{4  DD!!q4xDz +*s   #B66
Cc                   ^ ^ UU 4S jnT R                   " T6 u  p4[        R                  " SS9   [        R                  " X#U5      S   nS S S 5        [        R
                  " W5      (       d  U$ T R                  " SS//TQ76 u  pg[        R                  " U5      (       a  UnOUn[        R                  " U5      (       a  Un	OUn	[        R                  " X)U5      S   $ ! , (       d  f       N= f)Nc                 @   > TR                   " U /TQ76 n[        U5      $ rK   )r`  r   )r   rb   ra   r   s     rO   integ%rv_continuous._entropy.<locals>.integ1  s     ))A%%C9rQ   r  )overr   绽|=gA?)r   r[   r  r   r  r  r3   r!   )
r   ra   r6  r  r  hlowuppupperr  s
   ``        rO   rs  rv_continuous._entropy0  s    	
 ""D)[[h'u"-a0A ( xx{{H xx
 3;d;HCxx||xx||>>%6q99! ('s   C  
C.r   c                 r  ^ ^^ UUS.mT R                   " U6   T R                  " U6 u  pTc  UU 4S jnOUUU 4S jnUc  X9U-  -   nUc  X:U-  -   nT R                  " XV//UQ70 TD6nUS   US   -
  nX(S'   Sn[        R                  " USU-
  /5      nUS   X-  -   nUT R
                  " U/UQ76 U-  -   u  nn[        R                  " XU40 UD6S   n[        R                  " UUU40 UD6S   n[        R                  " UUU40 UD6S   nUU-   U-   nU(       a  UU-  n[        R                  " U5      S   $ )	aY  Calculate expected value of a function with respect to the
distribution by numerical integration.

The expected value of a function ``f(x)`` with respect to a
distribution ``dist`` is defined as::

            ub
    E[f(x)] = Integral(f(x) * dist.pdf(x)),
            lb

where ``ub`` and ``lb`` are arguments and ``x`` has the ``dist.pdf(x)``
distribution. If the bounds ``lb`` and ``ub`` correspond to the
support of the distribution, e.g. ``[-inf, inf]`` in the default
case, then the integral is the unrestricted expectation of ``f(x)``.
Also, the function ``f(x)`` may be defined such that ``f(x)`` is ``0``
outside a finite interval in which case the expectation is
calculated within the finite range ``[lb, ub]``.

Parameters
----------
func : callable, optional
    Function for which integral is calculated. Takes only one argument.
    The default is the identity mapping f(x) = x.
args : tuple, optional
    Shape parameters of the distribution.
loc : float, optional
    Location parameter (default=0).
scale : float, optional
    Scale parameter (default=1).
lb, ub : scalar, optional
    Lower and upper bound for integration. Default is set to the
    support of the distribution.
conditional : bool, optional
    If True, the integral is corrected by the conditional probability
    of the integration interval.  The return value is the expectation
    of the function, conditional on being in the given interval.
    Default is False.

Additional keyword arguments are passed to the integration routine.

Returns
-------
expect : float
    The calculated expected value.

Notes
-----
The integration behavior of this function is inherited from
`scipy.integrate.quad`. Neither this function nor
`scipy.integrate.quad` can verify whether the integral exists or is
finite. For example ``cauchy(0).mean()`` returns ``np.nan`` and
``cauchy(0).expect()`` returns ``0.0``.

Likewise, the accuracy of results is not verified by the function.
`scipy.integrate.quad` is typically reliable for integrals that are
numerically favorable, but it is not guaranteed to converge
to a correct value for all possible intervals and integrands. This
function is provided for convenience; for critical applications,
check results against other integration methods.

The function is not vectorized.

Examples
--------

To understand the effect of the bounds of integration consider

>>> from scipy.stats import expon
>>> expon(1).expect(lambda x: 1, lb=0.0, ub=2.0)
0.6321205588285578

This is close to

>>> expon(1).cdf(2.0) - expon(1).cdf(0.0)
0.6321205588285577

If ``conditional=True``

>>> expon(1).expect(lambda x: 1, lb=0.0, ub=2.0, conditional=True)
1.0000000000000002

The slight deviation from 1 is due to numerical integration.

The integrand can be treated as a complex-valued function
by passing ``complex_func=True`` to `scipy.integrate.quad` .

>>> import numpy as np
>>> from scipy.stats import vonmises
>>> res = vonmises(loc=2, kappa=1).expect(lambda x: np.exp(1j*x),
...                                       complex_func=True)
>>> res
(-0.18576377217422957+0.40590124735052263j)

>>> np.angle(res)  # location of the (circular) distribution
2.0

r  c                 6   > U TR                   " U /UQ70 TD6-  $ rK   r  )r   ra   lockwdsr   s     rO   fun!rv_continuous.expect.<locals>.fun  s!    488A88888rQ   c                 B   > T" U 5      TR                   " U /UQ70 TD6-  $ rK   r  )r   ra   r   rA  r   s     rO   rB  rC    s%    Aw!!>d!>g!>>>rQ   r   r   ra   g?r   )r  r   r/   r[   rr   r  r   r  )r   r   ra   r   r   r   r   r   r   r  r  rB  
cdf_boundsinvfacr  inner_boundscdf_inner_boundscr  lbccddubr`  rA  s   ``                     @rO   r8   rv_continuous.expectI  sg   F !#""D)<9?:Ez!B:Ez!BXXrh999
AA.V xx% 01%a=6+@@TYY/7$7%??1 nnSa0403^^CA..q1nnS!R0403b3FNDxx~b!!rQ   c                     U R                  5       n[        SS[        R                  * [        R                  4S5      n[        SSS[        R                  4S5      nXU/-   nU$ )Nr   FFFr   r   _shape_inforH  r[   r    )r   
shape_infoloc_info
scale_info
param_infos        rO   _param_inforv_continuous._param_info  sZ    %%'
eUbffWbff,=~NBFF^L
Z"88
rQ   r  c          
         U R                   " U/UQ7X4S.6n[        R                  " US:  U R                  " U/UQ7X4S.6U R                  " U/UQ7X4S.6-
  U R                   " U/UQ7X4S.6U-
  5      nUR                  S:X  a  US   nU$ )a  
Compute CDF(x2) - CDF(x1).

Where x1 is greater than the median, compute SF(x1) - SF(x2),
otherwise compute CDF(x2) - CDF(x1).

This function is only useful if `dist.sf(x, ...)` has an implementation
that is numerically more accurate than `1 - dist.cdf(x, ...)`.
r  r  r   r   )r/   r[   r  r1   rt   )r   x1x2r   r   ra   cdf1r  s           rO   r  rv_continuous._delta_cdf  s     xx8T8s8
 $*772CC#C!WWRE$ECEF((2CC#CdJL ;;!BZFrQ   )rf  r"  r  r   r   r  r  r_  r3  r   r  rW  )	r   NNg+=NNNNNrK   )Nr   r   r   NNF)-r   r   r   r   rf  r   rk  r!  r   r}  rq  r  ru  r  rv  r`  r  r)  rt  r  r  r  r-   r.   r/   r0   r1   r2   r3   r4   r  r  r5  r  r  r  r6   r  r   rs  r8   rV  r  r   rE  rF  s   @rO   rG   rG   p  s   CJ 8=48#'0Ad3,'L*)1'IF
&>&QR%N(T(T(T'R+Z+Z+Z "/H=$#F'PCobENB:2 FJ E"N -.Q  rQ   c           	         ^ ^^ UUU 4S jnT R                   " T6 u  pE[        X4UT R                  " S/TQ76 T R                  5      $ )z,Non-central moment of discrete distribution.c                 Z   > [         R                  " U T5      TR                  " U /TQ76 -  $ rK   )r[   r\   _pmf)r   ra   rM   r   s    rO   rB  _drv2_moment.<locals>.fun  s&    xx1~		! 3d 333rQ   r  )r   _expectr  inc)r   rM   ra   rB  r  r  s   ```   rO   _drv2_momentrc    s?    4 %FB3B		# 5 5txx@@rQ   c                 p   U R                   " U6 u  p4UnUnSn[        U5      (       aF  [        [        SU-  S5      5      n XT:  a  SnO'U R                  " U/UQ76 nX:  a
  XW-  nUS-  nOOM-  SnSn[        U5      (       aF  [        [        SU-  S5      5      n Xc::  a  SnO8U R                  " U/UQ76 n	X:  a
  Xg-  nUS-  nOOM-  U R                  " U/UQ76 n	[        R                  " U5      (       d  [        R                  " U5      (       a  S	n
[        U
5      eS
n[        U5       H  nW	U:X  a  Us  $ X:X  a  Us  $ XVS-   ::  a  X:  a  Us  $ Us  $ [        Xe-   S-  5      nU R                  " U/UQ76 nX:  a  Xm:w  a  UnO[        S5      eUn	Mj  X:  a  X]:w  a  UnO[        S5      eUnM  Us  $    g )N
   r,  r   rS   rT   iir  zAArguments that bracket the requested quantile could not be found.i  rY   zupdating stopped, endless loop)
r   r!   floatr  r  r  r[   r!  re  r  )r   r   ra   r  r  r   r   stepqbqar  maxiterr   rI  qcs                  rO   _drv2_ppfsinglerl    s   %FB
A
ADQxx#c!eR.!w1$t$B		  DQxx#d1fc"#w1$t$B		  YYq 4 	xx{{bhhqkkU7## G7^!GHGH!8vc	NYYq 4 Fv"#CDDBfv"#CDDBH3 rQ   c            
          ^  \ rS rSrSrS\SSSSSSSS4
U 4S jjrS\SSSSSSSS4
U 4S jjrS	 rS
 r	S r
S rS rS rS rS rS rS rS rU 4S jrS rS rS rS rS rS rS rS rS r  S!S jrS rS rU =r $ )"rH   iF  a  A generic discrete random variable class meant for subclassing.

`rv_discrete` is a base class to construct specific distribution classes
and instances for discrete random variables. It can also be used
to construct an arbitrary distribution defined by a list of support
points and corresponding probabilities.

Parameters
----------
a : float, optional
    Lower bound of the support of the distribution, default: 0
b : float, optional
    Upper bound of the support of the distribution, default: plus infinity
moment_tol : float, optional
    The tolerance for the generic calculation of moments.
values : tuple of two array_like, optional
    ``(xk, pk)`` where ``xk`` are integers and ``pk`` are the non-zero
    probabilities between 0 and 1 with ``sum(pk) = 1``. ``xk``
    and ``pk`` must have the same shape, and ``xk`` must be unique.
inc : integer, optional
    Increment for the support of the distribution.
    Default is 1. (other values have not been tested)
badvalue : float, optional
    The value in a result arrays that indicates a value that for which
    some argument restriction is violated, default is np.nan.
name : str, optional
    The name of the instance. This string is used to construct the default
    example for distributions.
longname : str, optional
    This string is used as part of the first line of the docstring returned
    when a subclass has no docstring of its own. Note: `longname` exists
    for backwards compatibility, do not use for new subclasses.
shapes : str, optional
    The shape of the distribution. For example "m, n" for a distribution
    that takes two integers as the two shape arguments for all its methods
    If not provided, shape parameters will be inferred from
    the signatures of the private methods, ``_pmf`` and ``_cdf`` of
    the instance.
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance then
    that instance is used.

Methods
-------
rvs
pmf
logpmf
cdf
logcdf
sf
logsf
ppf
isf
moment
stats
entropy
expect
median
mean
std
var
interval
__call__
support

Notes
-----
This class is similar to `rv_continuous`. Whether a shape parameter is
valid is decided by an ``_argcheck`` method (which defaults to checking
that its arguments are strictly positive.)
The main differences are as follows.

- The support of the distribution is a set of integers.
- Instead of the probability density function, ``pdf`` (and the
  corresponding private ``_pdf``), this class defines the
  *probability mass function*, `pmf` (and the corresponding
  private ``_pmf``.)
- There is no ``scale`` parameter.
- The default implementations of methods (e.g. ``_cdf``) are not designed
  for distributions with support that is unbounded below (i.e.
  ``a=-np.inf``), so they must be overridden.

To create a new discrete distribution, we would do the following:

>>> from scipy.stats import rv_discrete
>>> class poisson_gen(rv_discrete):
...     "Poisson distribution"
...     def _pmf(self, k, mu):
...         return exp(-mu) * mu**k / factorial(k)

and create an instance::

>>> poisson = poisson_gen(name="poisson")

Note that above we defined the Poisson distribution in the standard form.
Shifting the distribution can be done by providing the ``loc`` parameter
to the methods of the instance. For example, ``poisson.pmf(x, mu, loc)``
delegates the work to ``poisson._pmf(x-loc, mu)``.

**Discrete distributions from a list of probabilities**

Alternatively, you can construct an arbitrary discrete rv defined
on a finite set of values ``xk`` with ``Prob{X=xk} = pk`` by using the
``values`` keyword argument to the `rv_discrete` constructor.

**Deepcopying / Pickling**

If a distribution or frozen distribution is deepcopied (pickled/unpickled,
etc.), any underlying random number generator is deepcopied with it. An
implication is that if a distribution relies on the singleton RandomState
before copying, it will rely on a copy of that random state after copying,
and ``np.random.seed`` will no longer control the state.

Examples
--------
Custom made discrete distribution:

>>> import numpy as np
>>> from scipy import stats
>>> xk = np.arange(7)
>>> pk = (0.1, 0.2, 0.3, 0.1, 0.1, 0.0, 0.2)
>>> custm = stats.rv_discrete(name='custm', values=(xk, pk))
>>>
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(1, 1)
>>> ax.plot(xk, custm.pmf(xk), 'ro', ms=12, mec='r')
>>> ax.vlines(xk, 0, custm.pmf(xk), colors='r', lw=4)
>>> plt.show()

Random number generation:

>>> R = custm.rvs(size=100)

r   Nr  r   c                 N   > Ub  [         TU ]  [        5      $ [         TU ]  U 5      $ rK   )r  __new__r  )clsr   r   r3  r  
moment_tolvaluesrb  rr  r   r   r   s              rO   ro  rv_discrete.__new__  s+     7?9-- 7?3''rQ   c                 P  > [         TU ]  U
5        [        XX4XVUXU
S9
U l        Uc  [        nX@l        Xl        X l        XPl        Xpl	        Xl
        Ub  [        S5      eU R                  U R                  U R                  /SSS9  U R                  5         U R!                  X85        g )N
r   r   r3  r  rq  rr  rb  rr  r   r   z.rv_discrete.__init__(..., values != None, ...)loc=0loc, 1rY  )r  r   rJ  r"  r   r  r   r   rq  rb  r   r   rV  r_  r  r!  _construct_docstrings)r   r   r   r3  r  rq  rr  rb  rr  r   r   r   s              rO   r   rv_discrete.__init__  s     	  4!c49
 H $MNN!!DIItyy3I.5/7 	" 	9 	""42rQ   c                     U R                   R                  5       n/ SQnU Vs/ s H  o1R                  US 5      PM       nU$ s  snf )N)r   r+  r,  rf  r  r  rg  rh  s       rO   rk  rv_discrete.__getstate__  s@    mm  "9)./t	/
 	0rm  c                    [        U R                  SS9U l        [        U R                  5      U l        U R                  5         [        [        SS9nU R                  S-   Ul        [        R                  " X5      U l        [        [        SS9nU R                  S-   Ul        [        R                  " X 5      U l        U R                  S-   U R                  l        g)zAAttaches dynamically created methods to the rv_discrete instance.r  ro  rT   r   N)r   rt  rf  rs  r  r4  rc  r=  rr  r0  r1  r  rl  r  )r   _vec_generic_moment_vppfs      rO   r!  rv_discrete._attach_methods  s     !1!1#>#DMM2 	&&( (SA"&,,"2#../BI /#6LL1$	''4  <<!+rQ   c                    Uc  SnXl         Uc  US   S;   a  SnOSnX1-   n[        R                  R                  S:  a  U R                  c  U R                  U[        SS9  O>[        [        5      nU R                  [        UR                  U R                   5      5        U R                  R                  S	S
5      U l        g g )NrX  r   rZ  r\  r]  rT   rs  r^  zE
    scale : array_like, optional
        scale parameter (default=1)r*   )r3  ra  rb  r   rf  rt  docdict_discreterJ  r   rm  r  r?  )r   r3  rr  rc  rU  s        rO   rx  !rv_discrete._construct_docstrings  s    <!D	 Aw.({H99!||#++X4D5? , A <(##$4cggdii6HI  <<//@ACEDL "rQ   c                    U R                   R                  5       nU R                  US'   U R                  US'   U R                  US'   U R
                  US'   U R                  US'   U R                  US'   U R                  US'   U$ )ry  r   r   r  rq  rb  r3  r   )	r"  r   r   r   r  rq  rb  r3  r   rz  s     rO   r   rv_discrete._updated_ctor_param5  sy     ##%66C66C--J OOLXXE
iiFH
rQ   c                     [        U5      U:H  $ rK   )r   r   r   ra   s      rO   _nonzerorv_discrete._nonzeroE  s    Qx1}rQ   c                 V    U R                   " U/UQ76 U R                   " US-
  /UQ76 -
  $ )Nr   r  r  s      rO   r_  rv_discrete._pmfH  s-    yy"T"TYYqs%:T%:::rQ   c                     [         R                  " SS9   [        U R                  " U/UQ76 5      sS S S 5        $ ! , (       d  f       g = fr  )r[   r  r   r_  r  s      rO   _logpmfrv_discrete._logpmfK  r  r  c                 (    U R                   " U/UQ76 $ rK   )r  r  s      rO   r)  rv_discrete._logpxfO  r  rQ   c                 r     US   nSn[        US S 5      nX#U4$ ! [         a  n[        S5      UeS nAff = f)Nr  r   r  r  r  s         rO   r  rv_discrete._unpack_loc_scaleU  sU    	C)CEs$D 4  	C:;B	Cs    
616c                     U R                   " U6 u  p4[        [        U5      US-   5      n[        R                  " U R
                  " U/UQ76 SS9$ )Nr   r   r'  )r   r   r  r[   r   r_  )r   r   ra   r  r  r  s         rO   rt  rv_discrete._cdf_single^  sG    ""D)3r7AaC vvdii)D)22rQ   c                 x    [        U5      R                  [        R                  5      nU R                  " U/UQ76 $ rK   )r   r  r[   r  rf  )r   r   ra   r   s       rO   r  rv_discrete._cdfc  s,    !HOOBJJ'||A%%%rQ   c                 .   > SUS'   [         TU ]  " U0 UD6$ )a  Random variates of given type.

Parameters
----------
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    Location parameter (default=0).
size : int or tuple of ints, optional
    Defining number of random variates (Default is 1). Note that `size`
    has to be given as keyword, not as positional argument.
random_state : {None, int, `numpy.random.Generator`,
                `numpy.random.RandomState`}, optional

    If `random_state` is None (or `np.random`), the
    `numpy.random.RandomState` singleton is used.
    If `random_state` is an int, a new ``RandomState`` instance is
    used, seeded with `random_state`.
    If `random_state` is already a ``Generator`` or ``RandomState``
    instance, that instance is used.

Returns
-------
rvs : ndarray or scalar
    Random variates of given `size`.

Trs  )r  r,   )r   ra   r  r   s      rO   r,   rv_discrete.rvsi  s#    : "zw{D+F++rQ   c           	         U R                   " U0 UD6u  p$n[        [        X45      u  p[        [        [        U5      5      nU R                  " U6 u  pg[        X-
  5      nU R
                  " U6 nX:  X:*  -  n	[        U [        5      (       d  XR                  " U/UQ76 -  n	X-  n
[        [        U
5      S5      n[        USU-
  [        R                  " U5      -   U R                  5        [        R                  " U
5      (       a?  [!        U
/U4U-   Q76 n[        X[        R"                  " U R$                  " U6 SS5      5        UR&                  S:X  a  US   $ U$ )a  Probability mass function at k of the given RV.

Parameters
----------
k : array_like
    Quantiles.
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information)
loc : array_like, optional
    Location parameter (default=0).

Returns
-------
pmf : array_like
    Probability mass function evaluated at k

r  r   r   r   )r   r  r   r  r   r  r   r  r  r   r   r   r[   r  r  r  r  clipr_  rt   r   r   ra   r   r   r   r  r  r  r  r  r  r  s                rO   rE   rv_discrete.pmf  s/   & ''661Wqh'S$'(""D)AEN%QW%$	**MM!3d33E}uT{C(fqw"((1+-t}}=66$<<!$51$t)5H&		8(<a CD;;!":rQ   c                    U R                   " U0 UD6u  p$n[        [        X45      u  p[        [        [        U5      5      nU R                  " U6 u  pg[        X-
  5      nU R
                  " U6 nX:  X:*  -  n	[        U [        5      (       d  XR                  " U/UQ76 -  n	X-  n
[        [        U
5      S5      nUR                  [        * 5        [        USU-
  [        R                  " U5      -   U R                   5        [        R"                  " U
5      (       a)  [%        U
/U4U-   Q76 n[        XU R&                  " U6 5        UR(                  S:X  a  US   $ U$ )a  Log of the probability mass function at k of the given RV.

Parameters
----------
k : array_like
    Quantiles.
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    Location parameter. Default is 0.

Returns
-------
logpmf : array_like
    Log of the probability mass function evaluated at k.

r  r   r   r   )r   r  r   r  r   r  r   r  r  r"   r   r  r    r   r[   r  r  r  r  r  rt   r  s                rO   rF   rv_discrete.logpmf  s0   & ''661Wqh'S$'(""D)AEN%QW%$	**MM!3d33E}uT{C(SDfqw"((1+-t}}=66$<<!$51$t)5H&h 78;;!":rQ   c           	         U R                   " U0 UD6u  p$n[        [        X45      u  p[        [        [        U5      5      nU R                  " U6 u  pg[        X-
  5      nU R
                  " U6 nX:  X:  -  n	X:  n
[        R                  " U5      nX-  [        R                  " U5      -  n[        [        U5      S5      n[        XX:H  -  S5        [        XX:H  -  S5        [        USU-
  [        R                  " U5      -   U R                  5        [        R                  " U5      (       a?  [        U/U4U-   Q76 n[        X[        R                   " U R"                  " U6 SS5      5        UR$                  S:X  a  US   $ U$ )a  Cumulative distribution function of the given RV.

Parameters
----------
k : array_like, int
    Quantiles.
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    Location parameter (default=0).

Returns
-------
cdf : ndarray
    Cumulative distribution function evaluated at `k`.

r  rS   r  r   r   r   )r   r  r   r  r   r  r[   isneginfr   r   r   r   r  r  r  r  r  r  rt   )r   r   ra   r   r   r   r  r  r  r  r  r  r  r  r  s                  rO   r/   rv_discrete.cdf  sO   & ''661Wqh'S$'(""D)AEN%QV$A}r{{1~-uT{C(fU^,c2fU^,c2fqw"((1+-t}}=66$<<!$51$t)5H&		8(<a CD;;!":rQ   c                    U R                   " U0 UD6u  p$n[        [        X45      u  p[        [        [        U5      5      nU R                  " U6 u  pg[        X-
  5      nU R
                  " U6 nX:  X:  -  n	X:  n
X-  n[        [        U5      S5      nUR                  [        * 5        [        USU-
  [        R                  " U5      -   U R                  5        [        XX:H  -  S5        [        R                  " U5      (       a)  [        U/U4U-   Q76 n[        XU R                   " U6 5        UR"                  S:X  a  US   $ U$ )a  Log of the cumulative distribution function at k of the given RV.

Parameters
----------
k : array_like, int
    Quantiles.
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    Location parameter (default=0).

Returns
-------
logcdf : array_like
    Log of the cumulative distribution function evaluated at k.

r  r   r  r   r   )r   r  r   r  r   r  r"   r   r  r    r   r[   r  r  r  r  r  rt   r   r   ra   r   r   r   r  r  r  r  r  r  r  r  s                 rO   r0   rv_discrete.logcdf   s%   & ''661Wqh'S$'(""D)AEN%QV$}uT{C(SDfqw"((1+-t}}=fU^,c266$<<!$51$t)5H&h 78;;!":rQ   c           	         U R                   " U0 UD6u  p$n[        [        X45      u  p[        [        [        U5      5      nU R                  " U6 u  pg[        X-
  5      nU R
                  " U6 nX:  X:  -  n	X:  [        R                  " U5      -  U-  n
X-  [        R                  " U5      -  n[        [        U5      S5      n[        USU-
  [        R                  " U5      -   U R                  5        [        XS5        [        R                  " U5      (       a?  [        U/U4U-   Q76 n[        X[        R                   " U R"                  " U6 SS5      5        UR$                  S:X  a  US   $ U$ )a  Survival function (1 - `cdf`) at k of the given RV.

Parameters
----------
k : array_like
    Quantiles.
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    Location parameter (default=0).

Returns
-------
sf : array_like
    Survival function evaluated at k.

r  r   rS   r   r   )r   r  r   r  r   r  r[   r  r   r   r   r   r  r  r  r  r  r  rt   r  s                 rO   r1   rv_discrete.sf(  s<   & ''661Wqh'S$'(""D)AEN%QV$&BKKN*e3}r{{1~-uT{C(fqw"((1+-t}}=fS!66$<<!$51$t)5H&((;Q BC;;!":rQ   c                    U R                   " U0 UD6u  p$n[        [        X45      u  p[        [        [        U5      5      nU R                  " U6 u  pg[        X-
  5      nU R
                  " U6 nX:  X:  -  n	X:  U-  n
X-  n[        [        U5      S5      nUR                  [        * 5        [        USU-
  [        R                  " U5      -   U R                  5        [        XS5        [        R                  " U5      (       a)  [        U/U4U-   Q76 n[        XU R                   " U6 5        UR"                  S:X  a  US   $ U$ )a  Log of the survival function of the given RV.

Returns the log of the "survival function," defined as 1 - `cdf`,
evaluated at `k`.

Parameters
----------
k : array_like
    Quantiles.
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    Location parameter (default=0).

Returns
-------
logsf : ndarray
    Log of the survival function evaluated at `k`.

r  r   r  r   r   )r   r  r   r  r   r  r"   r   r  r    r   r[   r  r  r  r  r  rt   r  s                 rO   r2   rv_discrete.logsfN  s#   , ''661Wqh'S$'(""D)AEN%QV$5 }uT{C(SDfqw"((1+-t}}=fS!66$<<!$51$t)5H&X 67;;!":rQ   c                 t   U R                   " U0 UD6u  p$n[        [        X45      u  p[        [        [        U5      5      nU R                  " U6 u  pgU R
                  " U6 XD:H  -  nUS:  US:  -  n	US:H  U-  n
X-  n[        R                  " [        U5      U R                  SS9n[        XS:H  X:H  -  US-
  U-   5        [        XXt-   5        [        R                  " U5      (       a9  [        U/U4U-   U4-   Q76 nUS   USS p[        XU R                  " U6 U-   5        UR                  S:X  a  US   $ U$ )a  Percent point function (inverse of `cdf`) at q of the given RV.

Parameters
----------
q : array_like
    Lower tail probability.
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    Location parameter (default=0).

Returns
-------
k : array_like
    Quantile corresponding to the lower tail probability, q.

r   r   r  r  r  r  Nr   )r   r  r   r  r   r  r[   r  r   r  r   r  r  r  rt   )r   r   ra   r   r   r   r  r  r  r  r  r  r  r  s                 rO   r3   rv_discrete.ppfx  s<   & ''661Wqh'S$'(""D)%4Q1q5!a5 }tcJfAv-r!tcz:fRX&66$<<!$<1$t)SF*:<H$RL(3B-&		8 4s :;;;!":rQ   c                    U R                   " U0 UD6u  p$n[        [        X45      u  p[        [        [        U5      5      nU R                  " U6 u  pgU R
                  " U6 XD:H  -  nUS:  US:  -  n	US:H  U-  n
US:H  U-  nX-  n[        R                  " [        U5      U R                  SS9nUS-
  U-   nXt-   n[        XX:H  -  U5        [        XX:H  -  U5        [        R                  " U5      (       a:  [        U/U4U-   U4-   Q76 nUS   USS nn[        XU R                  " U6 U-   5        UR                  S:X  a  US   $ U$ )a  Inverse survival function (inverse of `sf`) at q of the given RV.

Parameters
----------
q : array_like
    Upper tail probability.
arg1, arg2, arg3,... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).
loc : array_like, optional
    Location parameter (default=0).

Returns
-------
k : ndarray or scalar
    Quantile corresponding to the upper tail probability, q.

r   r   r  r  r  Nr   )r   r  r   r  r   r  r[   r  r   r  r   r  r  r  rt   )r   r   ra   r   r   r   r  r  r  r  r  r  r  r  r  r  r  s                    rO   r4   rv_discrete.isf  s]   & ''661Wqh'S$'(""D)%4Q1q5!a5 a5 } tcJ1fslhfT\*K8fT\*K8 66$<<!$<1$t)SF*:<H$RL(3B-C&		8 4s :;;;!":rQ   c           	         ^ ^ [        T S5      (       a   [        R                  " T R                  5      $ T R                  " T6 u  p#[        UU 4S jX#T R                  " S/TQ76 T R                  5      $ )Npkc                 <   > [        TR                  " U /TQ76 5      $ rK   )r   r_  r  s    rO   r  &rv_discrete._entropy.<locals>.<lambda>  s    T$))A*=*=%>rQ   r  )rL  r   r5   r  r   ra  r  rb  )r   ra   r  r  s   ``  rO   rs  rv_discrete._entropy  s`    4==))&&-FB>499S#84#8$((D DrQ   c
           
        ^ ^^^ T R                   " T6 u  m  n
Tc	  UUU 4S jnO	UUUU 4S jnT R                  " T6 u  pUc  UnOUT-
  nUc  UnOUT-
  nU(       a+  T R                  " US-
  /TQ76 T R                  " U/TQ76 -
  nOSn[        T [        5      (       a  T R                  XU5      nX-  $ T R                  " S/TQ76 n[        XUUT R                  XxU	5      nX-  $ )a  
Calculate expected value of a function with respect to the distribution
for discrete distribution by numerical summation.

Parameters
----------
func : callable, optional
    Function for which the expectation value is calculated.
    Takes only one argument.
    The default is the identity mapping f(k) = k.
args : tuple, optional
    Shape parameters of the distribution.
loc : float, optional
    Location parameter.
    Default is 0.
lb, ub : int, optional
    Lower and upper bound for the summation, default is set to the
    support of the distribution, inclusive (``lb <= k <= ub``).
conditional : bool, optional
    If true then the expectation is corrected by the conditional
    probability of the summation interval. The return value is the
    expectation of the function, `func`, conditional on being in
    the given interval (k such that ``lb <= k <= ub``).
    Default is False.
maxcount : int, optional
    Maximal number of terms to evaluate (to avoid an endless loop for
    an infinite sum). Default is 1000.
tolerance : float, optional
    Absolute tolerance for the summation. Default is 1e-10.
chunksize : int, optional
    Iterate over the support of a distributions in chunks of this size.
    Default is 32.

Returns
-------
expect : float
    Expected value.

Notes
-----
For heavy-tailed distributions, the expected value may or
may not exist,
depending on the function, `func`. If it does exist, but the
sum converges
slowly, the accuracy of the result may be rather low. For instance, for
``zipf(4)``, accuracy for mean, variance in example is only 1e-5.
increasing `maxcount` and/or `chunksize` may improve the result,
but may also make zipf very slow.

The function is not vectorized.

c                 6   > U T-   TR                   " U /TQ76 -  $ rK   r_  )r   ra   r   r   s    rO   rB  rv_discrete.expect.<locals>.fun  s     #tyy2T222rQ   c                 B   > T" U T-   5      TR                   " U /TQ76 -  $ rK   r  )r   ra   r   r   r   s    rO   rB  r    s$    AcE{499Q#6#666rQ   r   rS   r  )r   r   r1   r   r  ra  r  rb  )r   r   ra   r   r   r   r   maxcount	tolerance	chunksizer   rB  r  r  rF  r  r
  s   ````             rO   r8   rv_discrete.expect  s    p %%t,
a<3 37 7 ""D):BcB:BcBWWRT)D)DGGB,>,>>FFdI&&,,s+C< YYs"T"cr2txxiP|rQ   c                     U R                  5       n[        SS[        R                  * [        R                  4S5      nX/-   nU$ )Nr   TrO  rP  )r   rR  rS  rU  s       rO   rV  rv_discrete._param_info5  s?    %%'
eTRVVGRVV+<nM*,
rQ   )rf  rf  r"  r  r   r   r  r  rb  rq  r3  r   r  )	Nr   r   NNF  r9      )!r   r   r   r   rf  r    ro  r   rk  r!  rx  r   r  r_  r  r)  r  rt  r  r,   rE   rF   r/   r0   r1   r2   r3   r4   rs  r8   rV  r   rE  rF  s   @rO   rH   rH   F  s    IT CdT!d$	( ct 1t43>,,E8 ;,& 3
&,@$L%N(T&P$L(T&P.`D =ALN[z rQ   c                    X!-
  U::  a8  [         R                  " XS-   U5      nU " U5      n	[         R                  " U	5      $ X1:  a  UnX2:  a  UnSu  p[        X2S-   XtS9 Hq  nXR                  -  n
[         R                  " U " U5      5      nX-  n[        U5      XlR                  -  :  a    O'X:  d  MU  [        R                  " S[        SS9  Us  $    [        US-
  US-
  Xt* S9 Hq  nXR                  -  n
[         R                  " U " U5      5      nX-  n[        U5      XlR                  -  :  a    U$ X:  d  MV  [        R                  " S[        SS9    U$    U$ )z4Helper for computing the expectation value of `fun`.r   )r   r  )r  rb  zexpect(): sum did not convergerU   )
stacklevel)	r[   r   r   _iter_chunkedry   r  warningswarnRuntimeWarning)rB  r   r   r
  rb  r  r  r  suppr`  counttotr   deltas                 rO   ra  ra  <  sO    	IyyT3'4yvvd| 
w	wJE2!tyBs1vu:	FF**MM:(Q8J C 2a4AEs1vu:	FF** J MM:(Q8J F JrQ   c              #   ^  #    US:X  a  [        S5      eUS::  a  [        SU S35      eUS:  a  SOSn[        X#-  5      n[        R                  " U 5      nXa-
  U-  S:  aK  [	        U[        Xa-
  5      5      nXt-  n[        R
                  " XfU-   U5      n	Xh-  nU	v   Xa-
  U-  S:  a  MJ  gg7f)ab  Iterate from x0 to x1 in chunks of chunksize and steps inc.

x0 must be finite, x1 need not be. In the latter case, the iterator is
infinite.
Handles both x0 < x1 and x0 > x1. In the latter case, iterates downwards
(make sure to set inc < 0.)

>>> from scipy.stats._distn_infrastructure import _iter_chunked
>>> [x for x in _iter_chunked(2, 5, inc=2)]
[array([2, 4])]
>>> [x for x in _iter_chunked(2, 11, inc=2)]
[array([2, 4, 6, 8]), array([10])]
>>> [x for x in _iter_chunked(2, -5, inc=-2)]
[array([ 2,  0, -2, -4])]
>>> [x for x in _iter_chunked(2, -9, inc=-2)]
[array([ 2,  0, -2, -4]), array([-6, -8])]

r   zCannot increment by zero.z!Chunk size must be positive; got r  r   r  N)r   r  r[   r   r  r   )
r
  rY  r  rb  r  stepsizer   r  rg  r  s
             rO   r  r  g  s     & ax455A~<YKqIJJ1W"A9?#H
A6S.1
Hc!&k*yyyHc*		
 6S.1
s   B'B-+B-c            
          ^  \ rS rSrSrS\SSSSSSSS4
U 4S jjrS rS	 rS
 r	S r
S rS rSS jrS rS rS rSrU =r$ )r  i  zA 'sample' discrete distribution defined by the support and values.

The ctor ignores most of the arguments, only needs the `values` argument.
r   Nr  r   c                   > [         [        U ]  U
5        Uc  [        S5      e[	        XX4XVUXU
S9
U l        Uc  [        nX@l        XPl        Xpl	        Xl
        U R                  U l        Uu  p[        R                  " U5      [        R                  " U5      :w  a  [        S5      e[        R                  " US5      R!                  5       (       a  [        S5      e[        R"                  " [        R$                  " U5      S5      (       d  [        S5      e['        [)        [        R*                  " U5      5      5      [        R,                  " U5      :X  d  [        S5      e[        R.                  " [        R*                  " U5      5      n[        R0                  " [        R*                  " U5      US	5      U l        [        R0                  " [        R*                  " U5      US	5      U l        U R2                  S	   U l        U R2                  S
   U l        [        R:                  " U R4                  S	S9U l        SU l
        U R?                  U R@                  /SSS9  U RC                  5         U RE                  X85        g )Nz(rv_sample.__init__(..., values=None,...)ru  z#xk and pk must have the same shape.r  z(All elements of pk must be non-negative.r   z The sum of provided pk is not 1.z$xk may not contain duplicate values.r   r  r'  r8  rv  rw  rY  )#r  rH   r   r   rJ  r"  r   r  rq  rb  r   rs  r  r[   r   lessr  allcloser   rM  setrg   ry   argsorttakexkr  r   r   cumsumqvalsrV  r_  r!  rx  )r   r   r   r3  r  rq  rr  rb  rr  r   r   r  r  indxr   s                 rO   r   rv_sample.__init__  s    	k4)$/>GHH  4!c49
 H $--88B<288B<'BCC772s!!GHH{{266":q))?@@3rxx|$%4CDDzz"((2,'''"((2,a0''"((2,a0YYtwwQ/
!!DII;.5/7 	" 	9
 	""42rQ   c                     U R                   R                  5       n/ SQnU Vs/ s H  o1R                  US 5      PM       nU$ s  snf )Nr*  rg  rh  s       rO   rk  rv_sample.__getstate__  sA    mm  " H)./t	/
 	0rm  c                 $    U R                  5         g)z/Attaches dynamically created argparser methods.N)r4  r   s    rO   r!  rv_sample._attach_methods  s    &&(rQ   c                 2    U R                   U R                  4$ )aN  Return the support of the (unscaled, unshifted) distribution.

Parameters
----------
arg1, arg2, ... : array_like
    The shape parameter(s) for the distribution (see docstring of the
    instance object for more information).

Returns
-------
a, b : numeric (float, or int or +/-np.inf)
    end-points of the distribution's support.
r  )r   ra   s     rO   r   rv_sample._get_support  s     vvtvv~rQ   c           
          [         R                  " U R                   Vs/ s H  o!U:H  PM	     snU R                   Vs/ s H  n[         R                  " X15      S   PM     snS5      $ s  snf s  snf rp   )r[   selectr  r  r	  )r   r   r   r  s       rO   r_  rv_sample._pmf  sZ    yy$''2'Qq&'2@DH1"--a3A6H!M 	M2Hs
   A(#A-
c                     [         R                  " US S 2S 4   U R                  5      u  p#[         R                  " X2:  SS9S-
  nU R                  U   $ )Nr  r'  r   )r[   r	  r  r   r  )r   r   xxxxkr  s        rO   r  rv_sample._cdf  sH    %%a4j$'':yy+a/zz$rQ   c                     [         R                  " US   U R                  5      u  p#[        X2:  SS9nU R                  U   $ )N).Nr  r'  )r[   r	  r  r   r  )r   r   qqsqqr  s        rO   r  rv_sample._ppf  s:    %%a	lDJJ?cib)wwt}rQ   c                     UR                  US9nUc+  [        R                  " USS9nU R                  U5      S   nU$ U R                  U5      nU$ )Nr  r   )ndminr   )r  r[   rr   r  )r   ry   rz   r  r  s        rO   r   rv_sample._rvs  sX       d +<!$A		!QA  		!ArQ   c                 B    [         R                  " U R                  5      $ rK   )r   r5   r  r   s    rO   rs  rv_sample._entropy  s    }}TWW%%rQ   c                     [        U5      n[        R                  " U R                  U[        R                  S4   -  U R
                  -  SS9$ )N.r   r'  )r   r[   r   r  r  r  )r   rM   s     rO   r  rv_sample.generic_moment   s;    AJvvdggqS11DGG;!DDrQ   c                     U R                   X R                   :*  U R                   U:*  -     nU" U5      n[        R                  " U5      $ rK   )r  r[   r   )r   rB  r   r   ra   r   r  r`  s           rO   ra  rv_sample._expect  s:    wwgg$''R-894yvvd|rQ   )r"  r   r   r  rb  rq  r  r  r   r  r  r   )r   r   r   r   rf  r    r   rk  r!  r   r_  r  r  r   rs  r  ra  r   rE  rF  s   @rO   r  r    s`    
 ct 1t433j) M 

	&E rQ   r  c                     / n/ n[        U SSS2   USSS2   SS9 HN  u  pEXT:  d  XEs=:X  a  S:X  a'  O  O$UR                  U5        UR                  S5        M=  UR                  S5        MP     [        USSS2   5      [        USSS2   5      4$ )a  
This is a utility function used by `_rvs()` in the class geninvgauss_gen.
It compares the tuple argshape to the tuple size.

Parameters
----------
argshape : tuple of integers
    Shape of the arguments.
size : tuple of integers or integer
    Size argument of rvs().

Returns
-------
The function returns two tuples, scalar_shape and bc.

scalar_shape : tuple
    Shape to which the 1-d array of random variates returned by
    _rvs_scalar() is converted when it is copied into the
    output array of _rvs().

bc : tuple of booleans
    bc is an tuple the same length as size. bc[j] is True if the data
    associated with that index is generated in one call of _rvs_scalar().

Nr  r   )	fillvalueTF)r   rF  r  )argshapery   scalar_shapebcargdimsizedims         rO   rq   rq     s    4 L	B&x"~tDbDz124 6Q 6(IIdOIIe4 dd#$eBttHo55rQ   c                 
   / n/ nU  Hw  u  pEUR                  S5      (       a  M  UR                  S5      (       a!  [        XQ5      (       a  UR                  U5        [	        XQ5      (       d  Mf  UR                  U5        My     X#4$ )a;  Collect names of statistical distributions and their generators.

Parameters
----------
namespace_pairs : sequence
    A snapshot of (name, value) pairs in the namespace of a module.
rv_base_class : class
    The base class of random variable generator classes in a module.

Returns
-------
distn_names : list of strings
    Names of the statistical distributions.
distn_gen_names : list of strings
    Names of the generators of the statistical distributions.
    Note that these are not simply the names of the statistical
    distributions, with a _gen suffix added.

r   _gen)r   endswith
issubclassrF  r   )namespace_pairsrv_base_classdistn_namesdistn_gen_namesr3  values         rO   get_distribution_namesr  1  sw    ( KO&??3==  Z%E%E""4(e++t$ ' ''rQ   rK   )r  r9  r  )rW   r   ){scipy._lib._utilr   r  ra  rA  rD  r0  r  	itertoolsr   
scipy._libr   _distr_paramsr   r   r	   r
   scipy.specialr   r   scipyr   r   scipy._lib._finite_differencesr   r   numpyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r[   
_constantsr#   r$   _censored_datar%   scipy.stats._warnings_errorsr&   rq  _doc_rvs_doc_pdf_doc_logpdf_doc_pmf_doc_logpmf_doc_cdf_doc_logcdf_doc_sf
_doc_logsf_doc_ppf_doc_isf_doc_moment
_doc_stats_doc_entropy_doc_fit_doc_expect_doc_expect_discrete_doc_median	_doc_mean_doc_var_doc_std_doc_intervalrI  _doc_allmethods_doc_default_longsummary_doc_default_frozen_note_doc_default_example_doc_default_locscale_doc_default_doc_default_before_notesrj  r   r  _doc_disc_methodsr  r?  _doc_disc_methods_err_varnamer  _doc_default_discrete_example_doc_default_discrete_locscale_doc_default_discdirr   r-  rP   re   rj   rm   r   r   r   r   r   r   r   r  rK  r  rH  rS  rG   rc  rl  rH   ra  r  r  rq   r  )r  r  s   00rO   <module>r0     ss  
 G 
  	   !  1 ; $
   7 + + + + +  ' ( 1
 4-68


 	 '':i0(H&+w%x;%|X&$h-I J  . `  ww0',. /
 GG%=%4%6 7 	8	8 k 
8	
 k 	' Z 
8 
8 Z | 
8 k k   I!" 
8#$ !+*#-(5> <<> "  (  1  7  C,S199+rJS  !A (C,S199&&IS )   U    X ''<MN<MS+C0<MNO!+I!6!H  ":"B"B]#$    ":  )! X"  <  "@  GG%5m%D%5l%C%E F #<   GG-m<-l;-l;-i8: ;  0   u6u!W 5Au6C# 7#@"#L
*0R: R:j< <<9 <5 p	 g8 g8T  (4}J }B,AEXs* sl <A(V!H} }@#6L(yx Ob 7s   <MM"1M"