
    -i̐                    \   S SK r S SKJrJr  S SK J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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$  \%" 5       r&S r'/ SQr(Sr)Sr* " S S\5      r+ " S S\+5      r, " S S\,5      r- " S S\,5      r. " S S\5      r/ " S S\/5      r0 " S S 5      r1S! r2S" r3S# r4S$ r5S% r6SS& jr7S' r8S( r9S) r:S*S+.S, jr;S- r<S. r= " S/ S0\"5      r> " S1 S2\>5      r? " S3 S4\>5      r@0 S5S6_S7S8_S9S:_S;S<_S=S>_S?S@_SASB_SCSD_SESF_SGSH_SISJ_SKSL_SMSN_SOSP_SQSR_SSST_SUSV_0 SWSX_SYSZ_S[S\_S]S^_S_S`_SaSb_ScSd_SeSf_SgSh_SiSj_SkSl_SmSn_SoSp_SqSr_SsSt_SuSv_SwSx_E0 SySz_S{S|_S}S~_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_ESS0ErAS rBS rCS rDS rES rFS rGS rH " S S\?5      rI " S S\I5      rJ\R                  * \R                  4S jrK " S S\I5      rL " S S\I5      rMS rN " S S\"5      rO " S S\I5      rP " S S\I5      rQS rRS rSS rTg)    N)ABCabstractmethod)cached_property)inf)
xp_promote)
_rng_spawn_RichResult)ClassDocNumpyDocString)specialstats)	_log1mexp)tanhsinhnsum)_bracket_root_bracket_minimum)_chandrupatla_chandrupatla_minimize)_ProbabilityDistribution)qmcc                 :    [        U 5      [        L =(       d    U S L $ N)typeobjectxs    [/var/www/html/venv/lib/python3.13/site-packages/scipy/stats/_distribution_infrastructure.py_isnullr      s    7f)T	)    )make_distributionMixtureorder_statistictruncateabsexplogskip_allno_cachec                       \ rS rSrSr\R                  S\R                  * S\R                  S\R                  * S0r\	S 5       r
\	S 5       r\	S	 5       r\	S
 5       rSrg)_Domain   aD  Representation of the applicable domain of a parameter or variable.

A `_Domain` object is responsible for storing information about the
domain of a parameter or variable, determining whether a value is within
the domain (`contains`), and providing a text/mathematical representation
of itself (`__str__`). Because the domain of a parameter/variable can have
a complicated relationship with other parameters and variables of a
distribution, `_Domain` itself does not try to represent all possibilities;
in fact, it has no implementation and is meant for subclassing.

Attributes
----------
symbols : dict
    A map from special numerical values to symbols for use in `__str__`

Methods
-------
contains(x)
    Determine whether the argument is contained within the domain (True)
    or not (False). Used for input validation.
get_numerical_endpoints()
    Gets the numerical values of the domain endpoints, which may have been
    defined symbolically or through a callable.
__str__()
    Returns a text representation of the domain (e.g. ``[0, b)``).
    Used for generating documentation.

\infty-\inftyz\piz-\pic                     [        5       er   NotImplementedErrorselfr   s     r   contains_Domain.contains       !##r   c                     [        5       er   r/   )r2   ns     r   draw_Domain.draw   r5   r   c                     [        5       er   r/   r1   s     r   get_numerical_endpoints_Domain.get_numerical_endpoints   r5   r   c                     [        5       er   r/   r2   s    r   __str___Domain.__str__   r5   r    N)__name__
__module____qualname____firstlineno____doc__npr   pisymbolsr   r3   r8   r;   r?   __static_attributes__rA   r   r   r*   r*      s    8 vvy266':ruufruufgVG$ $ $ $ $ $ $ $r   r*   c                   Z   ^  \ rS rSrSr\* \4S4U 4S jjrS rS rS
S jr	S
S jr
S	rU =r$ )	_Interval   a  Representation of an interval defined by two endpoints.

Each endpoint may be a finite scalar, positive or negative infinity, or
be given by a single parameter. The domain may include the endpoints or
not.

This class still does not provide an implementation of the __str__ method,
so it is meant for subclassing (e.g. a subclass for domains on the real
line).

Attributes
----------
symbols : dict
    Inherited. A map from special values to symbols for use in `__str__`.
endpoints : 2-tuple of float(s) and/or str(s) and/or callable(s).
    A tuple with two values. Each may be either a float (the numerical
    value of the endpoints of the domain), a string (the name of the
    parameters that will define the endpoint), or a callable taking the
    parameters used to define the endpoints of the domain as keyword only
    arguments and returning a numerical value for the endpoint.
inclusive : 2-tuple of bools
    A tuple with two boolean values; each indicates whether the
    corresponding endpoint is included within the domain or not.

Methods
-------
define_parameters(*parameters)
    Records any parameters used to define the endpoints of the domain
get_numerical_endpoints(parameter_values)
    Gets the numerical values of the domain endpoints, which may have been
    defined symbolically or through a callable.
contains(item, parameter_values)
    Determines whether the argument is contained within the domain
draw(size, rng, proportions, parameter_values)
    Draws random values based on the domain.

)FFc                    > [         TU ]  R                  5       U l        Uu  p4[        R                  " U5      S   [        R                  " U5      S   4U l        X l        g NrA   )superrI   copyrG   asarray	endpoints	inclusive)r2   rS   rT   ab	__class__s        r   __init___Interval.__init__  sI    w++-Ar*BJJqM",=="r   c                     U Vs0 s H  o"R                   UR                  _M     nnU R                  R                  U5        gs  snf )a  Records any parameters used to define the endpoints of the domain.

Adds the keyword name of each parameter and its text representation
to the  `symbols` attribute as key:value pairs.
For instance, a parameter may be passed into to a distribution's
initializer using the keyword `log_a`, and the corresponding
string representation may be '\log(a)'. To form the text
representation of the domain for use in documentation, the
_Domain object needs to map from the keyword name used in the code
to the string representation.

Returns None, but updates the `symbols` attribute.

Parameters
----------
*parameters : _Parameter objects
    Parameters that may define the endpoints of the domain.

N)namesymbolrI   update)r2   
parametersparamnew_symbolss       r   define_parameters_Interval.define_parameters  s<    ( >HHZEzz5<</ZHK( Is    Ac                    U R                   u  p# [        U5      (       a	  U" S0 UD6nO%[        R                  " UR	                  X"5      5      n[        U5      (       a	  U" S0 UD6nO&[        R                  " UR	                  X35      5      n [        X#S[        S9u  p#X#4$ ! [
         a!  nSU R                   S3n[        U5      UeSnAff = f)a  Get the numerical values of the domain endpoints.

Domain endpoints may be defined symbolically or through a callable.
This returns numerical values of the endpoints given numerical values for
any variables.

Parameters
----------
parameter_values : dict
    A dictionary that maps between string variable names and numerical
    values of parameters, which may define the endpoints.

Returns
-------
a, b : ndarray
    Numerical values of the endpoints

zThe endpoints of the distribution are defined by parameters, but their values were not provided. When using a private method of zA, pass all required distribution parameters as keyword arguments.NT)force_floatingxprA   )rS   callablerG   rR   get	TypeErrorrW   r   )r2   parameter_valuesrU   rV   emessages         r   r;   !_Interval.get_numerical_endpoints1  s    & ~~	,{{)()JJ/33A9:{{)()JJ/33A9: !t;t  	,448NN3C D$$G
 G$!+	,s   AB! '%B! !
C+CCc                     U=(       d    0 nU R                  U5      u  p4U R                  u  pVU(       a  X:  OX:  nU(       a  X:*  OX:  nXx-  $ )af  Determine whether the argument is contained within the domain.

Parameters
----------
item : ndarray
    The argument
parameter_values : dict
    A dictionary that maps between string variable names and numerical
    values of parameters, which may define the endpoints.

Returns
-------
out : bool
    True if `item` is within the domain; False otherwise.

)r;   rT   )	r2   itemri   rU   rV   left_inclusiveright_inclusivein_leftin_rights	            r   r3   _Interval.contains`  sS    " ,1r ++,<=*...'-$)48 /49TX!!r   c                   ^ [         R                  R                  T5      mU4S jn[        U [        5      (       a  TR
                  OUnUR                  5       UR                  5       p[         R                  " U	5      [         R                  " U
5      -  nSX'   SX'   U4U-   nUS:X  a	  U" XUS9nU$ US:X  a5  Un[         R                  " U5      nTR                  US9S:  nX=U'   XMU) '   U$ US:X  a.  X" SS	US9-
  nX" SS	US9-   nTR                  US9S:  nX   X'   U$ US
:X  a%  [         R                  " U[         R                  5      nW$ )a  Draw random values from the domain.

Parameters
----------
n : int
    The number of values to be drawn from the domain.
type_ : str
    A string indicating whether the values are

    - strictly within the domain ('in'),
    - at one of the two endpoints ('on'),
    - strictly outside the domain ('out'), or
    - NaN ('nan').
min, max : ndarray
    The endpoints of the domain.
squeezed_based_shape : tuple of ints
    See _RealParameter.draw.
rng : np.Generator
    The Generator used for drawing random values.

c                  0   > TR                   " U 0 UDSS0D6$ )NendpointT)integers)argskwargsrngs     r   ints_Interval.draw.<locals>.ints  s    #,,*V*VQU*V#Vr   r      in)sizeon      ?out   nan)rG   randomdefault_rng
isinstance_RealIntervaluniformrQ   isnanonesfullr   )r2   r7   type_minmaxsqueezed_base_shaperz   r{   r   min_nnmax_nnishapez
z_on_shapezrs         `         r   r8   _Interval.draw  sW   , ii##C(V!+D-!@!@#++d SXXZHHVrxx//		**D=U3A$ ! d]J
#A


"S(AaDqbE  e^AE22A'!QU33B


"S(A5AD
  e^rvv&Ar   )rS   rT   rI   r   )rB   rC   rD   rE   rF   r   rX   ra   r;   r3   r8   rJ   __classcell__rW   s   @r   rL   rL      s6    $J $'$ #).-^ "D6 6r   rL   c                   $    \ rS rSrSrS rS rSrg)r   i  a  Represents a simply-connected subset of the real line; i.e., an interval

Completes the implementation of the `_Interval` class for intervals
on the real line.

Methods
-------
define_parameters(*parameters)
    (Inherited) Records any parameters used to define the endpoints of the
    domain.
get_numerical_endpoints(parameter_values)
    (Inherited) Gets the numerical values of the domain endpoints, which
    may have been defined symbolically.
contains(item, parameter_values)
    (Inherited) Determines whether the argument is contained within the
    domain
__str__()
    Returns a string representation of the domain, e.g. "[a, b)".
c                     U R                   u  pU R                  US5      U R                  US5      p!U R                  u  p4U(       a  SOSnU(       a  SOSnU U SU U 3$ )Nf1f2[(]), )rS   _get_endpoint_strrT   )r2   rU   rV   ro   rp   leftrights          r   r?   _RealInterval.__str__  se    ~~%%a.0F0Fq$0O1*...'$s#&Cs"QCw''r   c                    [        U5      (       a  UR                  b  UR                  $ [        R                  " U5      R                  R                  5       nU Vs/ s H8  oDR                  [        R                  R                  :X  d  M,  UR                  PM:     nnU SSR                  U5       S3$ U R                  R                  X 5      $ s  snf )Nr   ,r   )rf   rF   inspect	signaturer^   valueskind	ParameterKEYWORD_ONLYr[   joinrI   rg   )r2   rv   funcnameparamsps        r   r   _RealInterval._get_endpoint_str  s    H+'''&&x0;;BBDF & &1&&G4E4E4R4R*R   Zq&!1 2!44||J88	s   +CCrA   N)rB   rC   rD   rE   rF   r?   r   rJ   rA   r   r   r   r     s    ((	9r   r   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )_IntegerIntervali  a  Represents an interval of integers

Completes the implementation of the `_Interval` class for simple
domains on the integers.

Methods
-------
define_parameters(*parameters)
    (Inherited) Records any parameters used to define the endpoints of the
    domain.
get_numerical_endpoints(parameter_values)
    (Inherited) Gets the numerical values of the domain endpoints, which
    may have been defined symbolically.
contains(item, parameter_values)
    (Overridden) Determines whether the argument is contained within the
    domain
draw(n, type_, min, max, squeezed_base_shape, rng=None)
    (Inherited) Draws random values based on the domain.
__str__()
    Returns a string representation of the domain, e.g. "{a, a+1, ..., b-1, b}".

c                 \   > [         TU ]  X5      nU[        R                  " U5      :H  nX4-  $ r   )rP   r3   rG   round)r2   rn   ri   super_containsintegralrW   s        r   r3   _IntegerInterval.contains  s-    )$ABHHTN*((r   c           	      ,   U R                   u  pU R                  R                  X5      nU R                  R                  X"5      n[        U[        5      [        U[        5      pCU(       a  US:H  O[
        R                  " U5      nU(       a  US:H  O[
        R                  " U5      nU(       a  U S3OUS-    nU(       a  U S3OUS-
   nU(       dM  U(       dF  X!-
  n	U	S:X  a  SU SU SU SU S	3	$ U	S
:X  a  SU SU SU S	3$ U	S:X  a	  SU SU S	3$ U	S:X  a  SU S	3$ U(       d%  U(       a  U(       a  U S3OUS
-    n
SU SU SU
 S3$ U(       a%  U(       d  U(       a  U S3OUS
-
   nSU SU SU S3$ U(       a  U(       a  gSU SU SU SU S	3	$ )Nr-   r,   z + 1r}   z - 1   z\{r   z\}   r   z + 2z, ...\}z - 2z\{..., -2, -1, 0, 1, 2, ...\}z, ..., )rS   rI   rg   r   strrG   isinf)r2   rU   rV   a_strb_stra_infb_infap1bm1gapap2bm2s               r   r?   _IntegerInterval.__str__  s   ~~LLQ"LLQ"!!S):a+=u#(Zbhhqk"'YRXXa[ "4j!a%!4j!a%U%CaxaS3%r#b488axaS3%r!D11axaS1#T**axaS~% %QCt*a!eWC!Bse2cU)44 %QCt*a!eWC!Bse2cU)44U4aS3%wse2aS55r   rA   r   )	rB   rC   rD   rE   rF   r3   r?   rJ   r   r   s   @r   r   r     s    ,)
%6 %6r   r   c                   V    \ rS rSrSrSSS.S jrS rSSSSSS.S	 jjr\S
 5       r	Sr
g)
_Parameteri)  a0  Representation of a distribution parameter or variable.

A `_Parameter` object is responsible for storing information about a
parameter or variable, providing input validation/standardization of
values passed for that parameter, providing a text/mathematical
representation of the parameter for the documentation (`__str__`), and
drawing random values of itself for testing and benchmarking. It does
not provide a complete implementation of this functionality and is meant
for subclassing.

Attributes
----------
name : str
    The keyword used to pass numerical values of the parameter into the
    initializer of the distribution
symbol : str
    The text representation of the variable in the documentation. May
    include LaTeX.
domain : _Domain
    The domain of the parameter for which the distribution is valid.
typical : 2-tuple of floats or strings (consider making a _Domain)
    Defines the endpoints of a typical range of values of the parameter.
    Used for sampling.

Methods
-------
__str__():
    Returns a string description of the variable for use in documentation,
    including the keyword used to represent it in code, the symbol used to
    represent it mathemtatically, and a description of the valid domain.
draw(size, *, rng, domain, proportions)
    Draws random values of the parameter. Proportions of values within
    the valid domain, on the endpoints of the domain, outside the domain,
    and having value NaN are specified by `proportions`.
validate(x):
    Validates and standardizes the argument for use as numerical values
    of the parameter.

N)r\   typicalc                    Xl         U=(       d    UU l        X l        Ub&  [        U[        5      (       d  UR                  U5      nU=(       d    UU l        g r   )r[   r\   domainr   r*   rW   r   )r2   r[   r   r\   r   s        r   rX   _Parameter.__init__Q  sE    	nz'7'C'C&&w/G(&r   c                 h    SU R                    SU R                   S[        U R                  5       S3$ )z@String representation of the parameter for use in documentation.`z` for :math:`z \in )r[   r\   r   r   r>   s    r   r?   _Parameter.__str__Y  s/    499+]4;;-vc$++>N=OqQQr   r   )rz   regionproportionsri   c          	      F   U=(       d    0 nU R                   nUc  SOUnU[        R                  " U5      -  nUR                  U5      u  p[        R                  " X5      u  pUR
                  n
[        R                  " X5      n[        R                  " U5      n[        R                  " U
5      nU(       a  [        X-  5      OSn[        R                  R                  U5      nUR                  X5      u  nnnnS[        U5      [        U
5      -
  -  U
-   n[        R                  " [        R                  " U5      S:H  5      S   n[        [!        [        U5      5      5      n[        R                  " U5      U   n[        R                  " UR#                  5       5      n[        R                  " U	R#                  5       5      nUR
                  nUS:X  a  U R$                  nUR                  U5      u  p[        R                  " X5      u  p[        R                  " UR#                  5       5      n[        R                  " U	R#                  5       5      nUR'                  USUUUUS9nOUR'                  USUUUUS9nUR'                  USUUUUS9nUR'                  US	UUUUS9nUR'                  US
UUUUS9n [        R(                  " UUUU 4SS9n!UR+                  U!SS9n![        R,                  " U![        U5      U-   5      n![        R.                  " U!UU5      n!U!$ )a  Draw random values of the parameter for use in testing.

Parameters
----------
size : tuple of ints
    The shape of the array of valid values to be drawn.
rng : np.Generator
    The Generator used for drawing random values.
region : str
    The region of the `_Parameter` from which to draw. Default is
    "domain" (the *full* domain); alternative is "typical". An
    enhancement would give a way to interpolate between the two.
proportions : tuple of numbers
    A tuple of four non-negative numbers that indicate the expected
    relative proportion of elements that:

    - are strictly within the domain,
    - are at one of the two endpoints,
    - are strictly outside the domain, and
    - are NaN,

    respectively. Default is (1, 0, 0, 0). The number of elements in
    each category is drawn from the multinomial distribution with
    `np.prod(size)` as the number of trials and `proportions` as the
    event probabilities. The values in `proportions` are automatically
    normalized to sum to 1.
parameter_values : dict
    Map between the names of parameters (that define the endpoints of
    `typical`) and numerical values (arrays).

)r}   r   r   r   r   r}   r}   r   r~   rz   r   r   r   axis)r   rG   sumr;   broadcast_arraysr   broadcast_shapesprodintr   r   multinomiallenwhererR   tuplerangesqueezer   r8   concatenatepermutedreshapemoveaxis)"r2   r   rz   r   r   ri   r   pvalsrU   rV   
base_shapeextended_shape
n_extendedn_baser7   n_inn_onn_outn_nanbase_shape_paddedbase_singletonsnew_base_singletonsshape_expansionr   r   r   r   min_heremax_herez_inz_onz_outz_nanr   s"                                     r   r8   _Parameter.draw]  s   B ,1r&1&9l{bff[11--.>?""1(WW
,,T>WW^,
$(2C
#$ii##C(#&??1#< dE5 "3~#6Z#HI)*((2::.?#@!#CDQG#E#o*>$?@**^4_E jj%jj%!iiYllG223CDDA&&q,DAzz!))+.Hzz!))+.H<<dHh@S$'   )D ;;tT35Hc;RD{{4sC1D#{NE5#s4GSQ{{5%c3FC{PNND$u5A>LLL#JJq%03FFGKK.@r   c                     [        5       er   r/   )r2   arrs     r   validate_Parameter.validate  r5   r   )r   r[   r\   r   r   )rB   rC   rD   rE   rF   rX   r?   r8   r   r   rJ   rA   r   r   r   r   )  sD    &N 04T )RiT("iV $ $r   r   c                       \ rS rSrSrS rSrg)_RealParameteri  zRepresents a real-valued parameter.

Implements the remaining methods of _Parameter for real parameters.
All attributes are inherited.

c                 *   [         R                  " U5      nSnUR                  [         R                  :X  d  UR                  [         R                  :X  a  GOUR                  [         R
                  :X  d  UR                  [         R                  :X  a$  [         R                  " U[         R                  S9nO[         R                  " UR                  [         R                  5      (       a  Os[         R                  " UR                  [         R                  5      (       a$  [         R                  " U[         R                  S9nOSU R                   S3n[        U5      eU R                  R                  X5      nUb  XS-  OUnUS   UR                  U4$ )a  Input validation/standardization of numerical values of a parameter.

Checks whether elements of the argument `arr` are reals, ensuring that
the dtype reflects this. Also produces a logical array that indicates
which elements meet the requirements.

Parameters
----------
arr : ndarray
    The argument array to be validated and standardized.
parameter_values : dict
    Map of parameter names to parameter value arrays.

Returns
-------
arr : ndarray
    The argument array that has been validated and standardized
    (converted to an appropriate dtype, if necessary).
dtype : NumPy dtype
    The appropriate floating point dtype of the parameter.
valid : boolean ndarray
    Logical array indicating which elements are valid (True) and
    which are not (False). The arrays of all distribution parameters
    will be broadcasted, and elements for which any parameter value
    does not meet the requirements will be replaced with NaN.

NdtypezParameter `z` must be of real dtype.rA   )rG   rR   r  float64float32int32int64
issubdtypefloatingintegerr[   rh   r   r3   )r2   r   ri   valid_dtyperk   valids         r   r   _RealParameter.validate  s   8 jjo 99

"cii2::&=YY"(("cii288&;**S

3C]]399bkk22]]399bjj11**S

3C#DII;.FGGG$$$$S;'2'>#E2w		5((r   rA   N)rB   rC   rD   rE   rF   r   rJ   rA   r   r   r  r    s    0)r   r  c                   F    \ rS rSrSrS rS rS rS rS r	S r
SS
 jrSrg	)_Parameterizationi  au  Represents a parameterization of a distribution.

Distributions can have multiple parameterizations. A `_Parameterization`
object is responsible for recording the parameters used by the
parameterization, checking whether keyword arguments passed to the
distribution match the parameterization, and performing input validation
of the numerical values of these parameters.

Attributes
----------
parameters : dict
    String names (of keyword arguments) and the corresponding _Parameters.

Methods
-------
__len__()
    Returns the number of parameters in the parameterization.
__str__()
    Returns a string representation of the parameterization.
copy
    Returns a copy of the parameterization. This is needed for transformed
    distributions that add parameters to the parameterization.
matches(parameters)
    Checks whether the keyword arguments match the parameterization.
validation(parameter_values)
    Input validation / standardization of parameterization. Validates the
    numerical values of all parameters.
draw(sizes, rng, proportions)
    Draw random values of all parameters of the parameterization for use
    in testing.
c                 R    U Vs0 s H  o"R                   U_M     snU l        g s  snf r   )r[   r^   )r2   r^   r_   s      r   rX   _Parameterization.__init__'  s"    :DE*::u,*EEs   $c                 ,    [        U R                  5      $ r   )r   r^   r>   s    r   __len___Parameterization.__len__*  s    4??##r   c                 B    [        U R                  R                  5       6 $ r   )r  r^   r   r>   s    r   rQ   _Parameterization.copy-  s     $//"8"8":;;r   c                 N    U[        U R                  R                  5       5      :H  $ )aC  Checks whether the keyword arguments match the parameterization.

Parameters
----------
parameters : set
    Set of names of parameters passed into the distribution as keyword
    arguments.

Returns
-------
out : bool
    True if the keyword arguments names match the names of the
    parameters of this parameterization.
)setr^   keysr2   r^   s     r   matches_Parameterization.matches0  s!     S!5!5!7888r   c                 8   Sn[        5       nUR                  5        HA  u  pEU R                  U   nUR                  XQ5      u  pWnUR	                  U5        X(-  nXQU'   MC     [        U5      S:X  a  WR                  O[        R                  " [        U5      6 nX'4$ )a  Input validation / standardization of parameterization.

Parameters
----------
parameter_values : dict
    The keyword arguments passed as parameter values to the
    distribution.

Returns
-------
all_valid : ndarray
    Logical array indicating the elements of the broadcasted arrays
    for which all parameter values are valid.
dtype : dtype
    The common dtype of the parameter arrays. This will determine
    the dtype of the output of distribution methods.
Tr}   )
r  itemsr^   r   addr   r  rG   result_typelist)	r2   ri   	all_validdtypesr[   r   	parameterr  r  s	            r   
validation_Parameterization.validationA  s    $ 	)//1ID-I ) 2 23 ICJJu!)I%(T" 2 ![!^		f1Nr   c                     U R                   R                  5        VVs/ s H  u  p[        U5      PM     nnnSR                  U5      $ s  snnf )z8Returns a string representation of the parameterization.r   )r^   r!  r   r   )r2   r[   r_   messagess       r   r?   _Parameterization.__str___  s@    26//2G2G2IJ2I;4CJ2IJyy"" Ks   A	Nc           	      2   0 nUb.  [        U5      (       a  [        R                  " US   5      (       d  U/[        U R                  5      -  n[	        XR                  R                  5       5       H#  u  pgUR                  XbUUUS9XWR                  '   M%     U$ )a  Draw random values of all parameters for use in testing.

Parameters
----------
sizes : iterable of shape tuples
    The size of the array to be generated for each parameter in the
    parameterization. Note that the order of sizes is arbitary; the
    size of the array generated for a specific parameter is not
    controlled individually as written.
rng : NumPy Generator
    The generator used to draw random values.
proportions : tuple
    A tuple of four non-negative numbers that indicate the expected
    relative proportion of elements that are within the parameter's
    domain, are on the boundary of the parameter's domain, are outside
    the parameter's domain, and have value NaN. For more information,
    see the `draw` method of the _Parameter subclasses.
domain : str
    The domain of the `_Parameter` from which to draw. Default is
    "domain" (the *full* domain); alternative is "typical".

Returns
-------
parameter_values : dict (string: array)
    A dictionary of parameter name/value pairs.
r   )rz   r   ri   r   )r   rG   iterabler^   zipr   r8   r[   )r2   sizesrz   r   r   ri   r   r_   s           r   r8   _Parameterization.drawd  s    < =E

"++eAh2G2GGC00Euoo&<&<&>?KD+0::;!1 ,6 ,ZZ( @  r   )r^   )NNNr   )rB   rC   rD   rE   rF   rX   r  rQ   r  r(  r?   r8   rJ   rA   r   r   r  r    s+    >F$<9" <#
* r   r  c           	      >  ^ ^^^^^^^ SS[         R                  * S4[         R                  * S4S.m[        * [        * 4S[        * [        * 4S[        * S4S[        * 4SSS.m1 Skm1 SkmS	S
1mSS1m1 Skm[        R                  " T 5      UUUU UUUU4S j5       nU$ )Nr   r}   r   )icdficcdfilogcdfilogccdf)r   r   )r}   r   )logpdfpdflogpmfpmf_logcdf1	_logccdf1_cdf1_ccdf1>   r9  r;  r8  r:  >   r4  r5  r6  r7  r>  r?  r<  r=  c                  
  > U R                   [        :X  a  T%" X/UQ70 UD6$ T%R                  n[        R                  " U5      nU R
                  nU R                  n[        U [        5      nU=(       a    US;   nUR                  U:w  a5  [        R                  " UR                  U5      n[        R                  " XS9nUR                  U:X  d8   [        R                  " UR                  U5      n[        R                  " X5      nT$R!                  X@R#                  5       5      u  pU R$                  R&                  R(                  u  pUT(;   a  U(       d  U(       a  X:  OX:*  nUT(;   a  U(       a  X:  OX:  nUU-  nUR                  S:X  a  UO[        R*                  " U5      nSnUT&;   a5  X:H  nX:H  nUU-  nUR                  S:X  a  UO[        R*                  " U5      nSnU(       aG  UT';   aA  U[        R,                  " U5      :g  nUR                  S:X  a  UO[        R*                  " U5      nU(       a(  [        R.                  " XSS	9n[        R0                  UU'   [        R                  " T%" X/UQ70 UD65      nSnUR                  U:w  a"  [        R                  " XPR
                  5      nSnUR                  U:w  a>  [        R                  " UU R                  5      nU=(       d    U=(       d    U=(       d    UnU(       a  [        R.                  " UUSS	9nU(       a6  US
;   a  [        R2                  * OSnUUW[        R4                  " U5      ) -  '   U(       a=  T)R!                  U[        R0                  [        R0                  45      u  nnUUU'   UUU'   U(       a  U R#                  5       u  nnUR                  U:w  aT  [        R.                  " [        R                  " UU5      SS9n[        R.                  " [        R                  " UU5      SS9nUR7                  S5      (       a  UW   OUW   n UR7                  S5      (       a  UW   OUW   n!U(       d  U UU'   U!UU'   UT";   a  [        R8                  " USS5      nUS   $ UT#;   a$  UR:                  n[        R8                  " US S5      nUS   $ ! [         a.  n	SU R                  R                   SU S3n
[        U
5      U	eS n	A	ff = f)N>   r>  r?  r<  r=  r  zThe argument provided to `.zJ` cannot be be broadcast to the same shape as the distribution parameters.rA   FTr  rQ   >   r8  r:  r   rQ   ccdf              ?)validation_policy	_SKIP_ALLrB   rG   rR   _dtype_shaper   DiscreteDistributionr  r#  r   r   broadcast_to
ValueErrorrW   rg   support	_variabler   rT   anyfloorarrayr   r   r   endswithclipreal)*r2   r   rx   ry   method_namer  r   discretekeep_low_endpointrj   rk   lowhighleft_inc	right_incmask_low	mask_highmask_invalidany_invalidany_endpointmask_low_endpointmask_high_endpointmask_endpointany_non_integralmask_non_integralresres_needs_copyzeroreplace_lowreplace_highrU   rV   replace_low_endpointreplace_high_endpointrT  clip_logrS   freplace_exactreplace_non_integralreplace_strictreplacementss*                                     r   filtered"_set_invalid_nan.<locals>.filtered  s   !!Y.T.t.v..jjJJqMd$89$ P 9P *P 77eNN177E2E

1*A ww%	1++AGGU;OOA- MM+||~>	 #nn33== +~ =(( G./h 	"-"?IQX) 	 9,'3'9'9R'?|FF<0 	
 -'!""#).1CCM-:-@-@B-FM!#!6 
 !';;!"bhhqk!15F5L5LPR5R 1%'VV,=%> 
 d3A ffAlOjj44T4V45 99NN5++6E!N99//#t{{3C, B B!-B1A  ((3e$7C )-AABFF7qD6:C!RXXc]N23   rvvrvv.>? &K'CM)C	N <<>DAqww%HHR__Q6TBHHR__Q6TB )4(<(<V(D(D#$() ! *5)=)=f)E)E$%)* " %)=%&&;C"# $''#r2&C
 2w	 H$((C''#tR(C2wG  101H1H0I} %<<  !)q01s   7S 
S=)S88S=)rG   r   	functoolswraps)	ro  rt  rT  rn  rS   rp  rq  rr  rs  s	   ` @@@@@@@r   _set_invalid_nanrx    s    "  & ffWaLwlDI #tcTl6 #tcTl6"%q	SD	#v7L 8N<MXDK(H=__Q} } }~ Or   c                 F   ^  [         R                  " T 5      U 4S j5       nU$ )Nc                 f  > U R                   [        :X  a  T" U /UQ70 UD6$ T" U /UQ70 UD6nUc  [        U R                  5      e[        R
                  " U5      nSnUR                  nXPR                  :w  a"  [        R                  " XPR                  5      nSnUR                  U R                  :w  a5  [        R                  " X0R                  5      nU=(       d    U R                  nU(       a  UR                  USS9nU R                  (       a  [        R                  X0R                  '   US   $ )NFTrB  rA   )rG  rH  r0   _not_implementedrG   rR   r  rI  r#  r   rJ  rL  _any_invalidastyper   _invalid)r2   rx   ry   rg  
needs_copyr  ro  s         r   rt  +_set_invalid_nan_property.<locals>.filtered;  s    !!Y.T+D+F++&t&v&;%d&;&;<<jjo
		KKNN5++6EJ99#//#{{3C#8t'8'8J**5t*4C "$C2wr   rv  rw  )ro  rt  s   ` r   _set_invalid_nan_propertyr  2  s'     __Q > Or   c                 N   ^  [         R                  " T 5      S S.U 4S jj5       nU$ )Nmethodc                  > TR                   nU=(       d    U R                  R                  US 5      n[        U5      (       a  OaUb(  US:X  a  SOUnUR	                  SU5      n[        X5      nO6T" U /UQ7SU0UD6nUS:w  a"  U R                  [        :w  a  XR                  U'    U" U0 UD6$ ! [         a  n[        U R                  5      UeS nAff = f)Nzlog/explogexpdispatchr  _sample_dispatch)rB   _method_cacherg   rf   replacegetattrcache_policy	_NO_CACHEKeyErrorr0   r{  )r2   r  rx   ry   	func_namerV  rj   ro  s          r   wrapped_dispatch.<locals>.wrappedp  s    JJ	B4--11)TBF!'9!4X&F#++J?KT/Ft<d<6<V<F..43D3D	3Q06""9-	D4*6** 	D%d&;&;<!C	Ds   &B. .
C8CCr  ro  r  s   ` r   	_dispatchr  ^  s,    $ __Q$( D D& Nr   c                 F   ^  [         R                  " T 5      U 4S j5       nU$ )Nc                   > TR                   nU R                  5       u  pg[        R                  " XXg5      u  ppg[        R                  " UR
                  UR
                  U R                  5      nUR                  USS9UR                  USS9p!X!:  n	X)   X   sX'   X)'   X:  n
Xj   X'   X&:  n
Xj   X*'   X:  n
Xz   X'   X':  n
Xz   X*'   T" XU/UQ70 UD6nUS;   a  [        R                  " USS5      nO[        R                  " US S5      n[        R                  " U5      nUS:X  a  X==   S-  ss'   US   $ US:X  a  X==   S	-  ss'   X==   S
-  ss'   US   $ US:X  aU  [        R                  " U	5      (       a  [        R                  " US-   5      OUnX   [        R                  S-  -   X'   US   $ [        [        R                  " S5      X   5      R                  X'   US   $ )NTrC  >   _cdf2_ccdf2rE  rF  r        r  g       @_logcdf2                              ?r   rA   )rB   rN  rG   r   r#  r  rI  r}  rT  rR   rP  rH   _logexpxmexpyr&   rU  )r2   r   yrx   ry   r  rY  rZ  r  i_swapr   rg  ro  s               r   r  '_cdf2_input_validation.<locals>.wrapped  s   JJ	LLN	--aC>cqww=xxDx)188E8+E1
  y!)	19GvGvHwHw,T,V, ++''#r2&C''#tR(C jjoK3K 2w ("K2KK2K 2w *$*,&&.."**S2X&cC+b0CK
 2w (q	3;?DDCK2wr   r  r  s   ` r   _cdf2_input_validationr    s(    $ __Q- -^ Nr   c                     [         R                  " U R                  [         R                  5      (       a   [         R                  " U R                  5      $ [         R
                  " U 5      $ r   )rG   r  r  inexactfinfoiinfor   s    r   _fiinfor    s<    	}}QWWbjj))xx  xx{r   c                    ^ ^^ U=(       d    / nU=(       d    0 n[        UR                  5       5      m[        U5      mU UU4S jn[        U5      [        UR	                  5       5      -   nX14$ )Nc                 N   > T" U /US T Q70 [        [        TUTS  5      5      D6$ r   )dictr/  )r   rx   ro  n_argsnamess     r   r  _kwargs2args.<locals>.wrapped  s0    FT'6]Fd3ud67m+D&EFFr   )r$  r  r   r   r   )ro  rx   ry   r  r  r  s   `   @@r   _kwargs2argsr    sY     :2D\rFEYFG ;v}}//D=r   c                 
   [         R                  " [         R                  " U5      5      n[         R                  " U5      (       aP  [         R                  " UR                  5       5      n[         R                  " UR                  5      R                  X'   [         R                  " X5      u  p[         R                  " [        R                  " X[         R                  S-  -   /SS95      nX:H  n[         R                  * X2'   U$ )zCompute the log of the difference of the exponentials of two arguments.

Avoids over/underflow, but does not prevent loss of precision otherwise.
r  r   r   )rG   isneginfrU  rP  rR   rQ   r  r  r   r   r   	logsumexprH   r   )r   r  r   rg  s       r   r  r    s     	BGGAJA	vvayyJJqvvx xx $$q$DA
**W&&RUU2X:Q?
@C	
AffWCFJr   c                    [         R                  " U S5      n[         R                  " U5      n[         R                  " U 5      [         R                  " U5      -  nX   X$'   X   X4'   [         R                  " U 5      [         R                  " U5      ) -  nX   X$'   X   S-   X4'   [         R                  " U5      [         R                  " U 5      ) -  nX   S-
  X$'   X   X4'   X#4$ )Nr  r}   )rG   	full_like	ones_likeisfinite)xminxmaxrU   rV   r   s        r   _guess_bracketr    s    
T4 A
TA
DBKK--A7AD7AD
DR[[...A7AD7Q;AD
DR[[...A7Q;AD7AD4Kr   c                 h   U R                   n[        R                  " U 5      n [        R                  " U 5      R	                  U R
                  5      n[        R                  " U 5      nUn[        R                  " US-  5      S:  nXE   [        R                  S-  -   XE'   UR                  U5      S   $ )a  Standardizes the (complex) logarithm of a real number.

The logarithm of a real number may be represented by a complex number with
imaginary part that is a multiple of pi*1j. Even multiples correspond with
a positive real and odd multiples correspond with a negative real.

Given a logarithm of a real number `x`, this function returns an equivalent
representation in a standard form: the log of a positive real has imaginary
part `0` and the log of a negative real has imaginary part `pi`.

r  r   rA   )
r   rG   
atleast_1drU  r}  r  imagr%   rH   r   )r   r   rU  complexr  negatives         r   _log_real_standardizer    s     GGE
aA771:QWW%DggajGAvvgbj!C'H+
*AK99UBr   Tinclude_examplesc                   [        [        R                  5      nUR                  S5        U(       d  UR                  S5        [	        U 5      n[	        [
        5      nU Ha  nUS;   a  XE   X5'   M  US;   a  M  US:X  a  X5   R                  [        U 5      5        M=  US:X  a  [        U 5      /X5'   MS  X5==   XE   -  ss'   Mc     [        U5      $ )NindexExamples>   Methods
Attributes>   SummaryzExtended Summary)
r  r   sectionsremover
   UnivariateDistributionappend_generate_domain_support_generate_exampler   )dist_familyr  fieldsdocsuperdocfields         r   _combine_docsr  %  s    (()F
MM'j!
;
C./H--!CJk!((J6{CDj +K89CJJ(/)J  s8Or   c                    [        U R                  5      nSU R                  R                   S3nUS:X  a  SnOoUS:X  a  S[	        U R                  S   5       S3nOLSS	S
SS.U   nU R                   Vs/ s H  nS[	        U5       3PM     nnSR                  U5      nSU SU S3nSR                  UR                  S5       Vs/ s H  owR                  5       PM     snSS  5      nX#-   $ s  snf s  snf )Nz
for :math:`x \in z`.
r   z@
        This class accepts no distribution parameters.
        r}   z:
        This class accepts one parameterization:
        z
.
        twothreefourfive)r   r      r   z- 
z
        This class accepts z parameterizations:

        	
        )r   _parameterizationsrO  r   r   r   splitlstrip)r  n_parameterizationsr   rN  numberr   parameterizationslines           r   r  r  ;  s2   k<<=#K$9$9$@$@#AFFa 
	!		[++A.	/0 1	
 w6f=! );;=; 01r#a&]; 	 = II&78"8 $		 	
 ii7==3FG3F43FGKLG= Hs   4C-C2c           
         U R                  S5      nS/U-  n[        R                  R                  S5      nSnU R	                  X#US9n[        R                  R                  S5      nU R
                  nU(       a  [        UR                  U   R                  5      nU Vs/ s H  n[        [        XV5      S5      PM     nn[        Xx5       VV	s/ s H  u  piU SU	 3PM     n
nn	W SS	R                  U
5       S
3nS	R                  UR                   Vs/ s H  nSU 3PM
     sn5      nU " S0 [        [        Xx5      5      D6nOU S3nUnSn[        UR                  U5      S5      n[        UR                  SU-  5      S5      nSU SU SUR!                  5        S3nU(       a-  USW S[#        UR                  R%                  5       5       S3-  nUSU SU SUR'                  U5      UR)                  U5      4 S3-  n[+        U [,        5      (       a  SU S3nUU-  nUSUR/                  5       UR1                  5       UR3                  5       4 SUR5                  5       UR7                  5       4 SUR9                  5       UR;                  5       4 S3-  n[+        U [,        5      (       a  US-  nOUSUR=                  5        S3-  nUS [?        URA                  S!S"95       S#3-  nS$R                  URC                  S$5       Vs/ s H  nURE                  5       PM     snS%S  5      nU$ s  snf s  sn	nf s  snf s  snf )&Nr   rA   l   j? )rz   i_parameterizationl   l r   =r   r   r   zX.z()g{Gz?a  
    To use the distribution class, it must be instantiated using keyword
    parameters corresponding with one of the accepted parameterizations.

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy import stats
    >>> from scipy.stats import z
    >>> X = a  

    For convenience, the ``plot`` method can be used to visualize the density
    and other functions of the distribution.

    >>> X.plot()
    >>> plt.show()

    The support of the underlying distribution is available using the ``support``
    method.

    >>> X.support()
    z
    z
        The numerical values of parameters associated with all parameterizations
        are available as attributes.

        >>> r  zj
    To evaluate the probability density/mass function of the underlying distribution
    at argument ``x=z``:

    >>> x = z 
    >>> X.pdf(x), X.pmf(x)
    z

    The cumulative distribution function, its complement, and the logarithm
    of these functions are evaluated similarly.

    >>> np.allclose(np.exp(X.logccdf(x)), 1 - X.cdf(x))
    True
    a  
    The inverse of these functions with respect to the argument ``x`` is also
    available.

    >>> logp = np.log(1 - X.ccdf(x))
    >>> np.allclose(X.ilogcdf(logp), x)
    True

    Note that distribution functions and their logarithms also have two-argument
    versions for working with the probability mass between two arguments. The
    result tends to be more accurate than the naive implementation because it avoids
    subtractive cancellation.

    >>> y = zO
    >>> np.allclose(X.ccdf(x, y), 1 - (X.cdf(y) - X.cdf(x)))
    True
        z
    There are methods for computing measures of central tendency,
    dispersion, higher moments, and entropy.

    >>> X.mean(), X.median(), X.mode()
    z3

    >>> X.variance(), X.standard_deviation()
    z)

    >>> X.skewness(), X.kurtosis()
    z

    >>> np.allclose(X.moment(order=6, kind='standardized'),
    ...             X.moment(order=6, kind='central') / X.variance()**3)
    True
    zK
    >>> np.allclose(np.exp(X.logentropy()), X.entropy())
    True
        z!
        >>> X.entropy()
        z
    Pseudo-random samples can be drawn from
    the underlying distribution using ``sample``.

    >>> X.sample(shape=(4,))
    )r  r   z  # may vary
    r  r}   )#_num_parametersrG   r   r   _drawrB   r$  r  r^   r   r  r/  r   _parametersr  r4  rN  r   r   r9  r;  
issubclassContinuousDistributionmeanmedianmodevariancestandard_deviationskewnesskurtosisentropyreprsampler  r  )r  n_parametersshapesrz   r   distr[   parameter_namesri   valuename_valuesinstantiationr_   
attributesXr   r   r  exampleexample_continuousr  s                        r   r  r  X  s   ..q1LTL F
))


0C	AVCD
))



+CDt66q9DDE+-+ ?CE'$"5q9+ 	 - ?=?= .9T$q(= 	 ?&$))K"8!9;YY$:J:JK:J"UG:JKL
G$s?EFG&AaffQiAaffQUmQA! "& 'O  YY[M )G.   L 		q}}##%	&' (	 	  C C UU1XquuQx  G" +566" C 	" 	%% 
 VVXqxxz1668#$ % ZZ\1''))* + ZZ\1::<  ! G& +566  	
 	 		
 	 	
  
 
!(((
  ! G ii7==3FG3F43FGKLGNy-?  Ll Hs   !L3L8L>Mc                      \ rS rSrSrSr/ r\SSS.S jrSS.S jr	S	 r
S
 rS rS rS rS rS r\S 5       r\R&                  S 5       r\S 5       r\R&                  S 5       r\S 5       r\R&                  S 5       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%\&  SS& j5       r'\&S' 5       r(\&SS( j5       r)  SS* jr*SSSS+.S, jr+S- r,S. r-S/ r.\/SS0.S1 j5       r0\1SS2 j5       r2S3 r3S4 r4S5 r5S6 r6\/SS0.S7 j5       r7\1SS8 j5       r8S9 r9S: r:S; r;\/SS0.S< j5       r<\1SS= j5       r=S> r>S? r?\/SS0.S@ j5       r@\1SSA j5       rASB rBSSC jrCSS0.SD jrDSS0.SE jrESS0.SF jrFSS0.SG jrGSSHSI.SJ jrH\ISS0.SK j5       rJ\1SS0.SL j5       rKSM rLSN rM\ISS0.SO j5       rN\1SS0.SP j5       rOSQ rPSR rQ\ISS0.SS j5       rR\1SS0.ST j5       rSSU rTSV rU\ISS0.SW j5       rV\1SS0.SX j5       rWSY rXSZ rYSSS0.S[ jjrZ\[S\ 5       r\\1SS0.S] j5       r]S^ r^S_ r_S` r`Sa raSb rb\ISS0.Sc j5       rc\1SS0.Sd j5       rdSe reSf rfSg rgSh rhSi riSSS0.Sj jjrj\[Sk 5       rk\1SS0.Sl j5       rlSm rmSn rnSo roSp rpSq rq\ISr 5       rr\1SS0.Ss j5       rsSt rtSu ruSv rvSw rwSx rxSSS0.Sy jjry\[Sz 5       rz\1SS0.S{ j5       r{S| r|S} r}\ISS0.S~ j5       r~\1SS j5       rS rS rS rS rS rSSS0.S jjr\[S 5       r\1SS0.S j5       rS rS r\IS 5       r\1SS j5       rS rS rS rS rS r\ISS0.S j5       r\1SS j5       rS rS rS r\ISS0.S j5       r\1SS j5       rS rS rS rS r\ISS0.S j5       r\1SS j5       rS rS rS r\ISS0.S j5       r\1SS j5       rS rS rS rS rSSSS.S jjr\1S 5       rS rS rS r\S 5       r\S 5       r\S 5       rS r\/SSS0.S jj5       rSSS0.S jjrS rS rS rS rSSS0.S jjrS rS rS rS rS rSSS0.S jjrS rS rS rS rS rS rS rSSS)S.S jjrS rSSSS.S jjrSrg)r  i  a)  Class that represents a continuous statistical distribution.

Parameters
----------
tol : positive float, optional
    The desired relative tolerance of calculations. Left unspecified,
    calculations may be faster; when provided, calculations may be
    more likely to meet the desired accuracy.
validation_policy : {None, "skip_all"}
    Specifies the level of input validation to perform. Left unspecified,
    input validation is performed to ensure appropriate behavior in edge
    case (e.g. parameters out of domain, argument outside of distribution
    support, etc.) and improve consistency of output dtype, shape, etc.
    Pass ``'skip_all'`` to avoid the computational overhead of these
    checks when rough edges are acceptable.
cache_policy : {None, "no_cache"}
    Specifies the extent to which intermediate results are cached. Left
    unspecified, intermediate results of some calculations (e.g. distribution
    support, moments, etc.) are cached to improve performance of future
    calculations. Pass ``'no_cache'`` to reduce memory reserved by the class
    instance.

Attributes
----------
All parameters are available as attributes.

Methods
-------
support

plot

sample

moment

mean
median
mode

variance
standard_deviation

skewness
kurtosis

pdf
logpdf

cdf
icdf
ccdf
iccdf

logcdf
ilogcdf
logccdf
ilogccdf

entropy
logentropy

See Also
--------
:ref:`rv_infrastructure` : Tutorial

Notes
-----
The following abbreviations are used throughout the documentation.

- PDF: probability density function
- CDF: cumulative distribution function
- CCDF: complementary CDF
- entropy: differential entropy
- log-*F*: logarithm of *F* (e.g. log-CDF)
- inverse *F*: inverse function of *F* (e.g. inverse CDF)

The API documentation is written to describe the API, not to serve as
a statistical reference. Effort is made to be correct at the level
required to use the functionality, not to be mathematically rigorous.
For example, continuity and differentiability may be implicitly assumed.
For precise mathematical definitions, consult your preferred mathematical
text.

r}   N)tolrG  r  c                   Xl         X l        X0l        SU R                  R                   S3U l        0 U l        [        UR                  5       5       VVs0 s H  u  pVUc  M
  XV_M     nnnU R                  " S0 UD6  g s  snnf )Nr   z` does not provide an accurate implementation of the required method. Consider leaving `method` and `tol` unspecified to use another implementation.rA   )
r  rG  r  rW   rB   r{  _original_parameterssortedr!  _update_parameters)r2   r  rG  r  r^   keyvals          r   rX   UnivariateDistribution.__init__=  s    !2(''( )L L 	
 %'! Z--/0E0 $,347 ch0 	 E-*-Es   	A>"A>rG  c          	         U R                   R                  5       =p4UR                  " S	0 UD6  Sn[        R                  " S5      U l        SU l        [        5       U l        SU l	        SU l
        [        R                  U l        U=(       d    U R                  [        :X  a  U R                  " S	0 UD6nO[!        U R"                  5      (       d9  U(       a1  SU R$                  R&                   S[)        U5       S3n[+        U5      eOoU R-                  U5      nU R/                  U5      u  p7pU R1                  XS5      u  p:pU R                  " S	0 UD6nXl        Xl        Xpl        Xl
        Xl	        Xl        U R3                  5         X0l        XPl        X@l         U R4                  R9                  5        HD  n[;        U R$                  U5      (       a  M   [=        U R$                  U[?        U4S j5      5        MF     g)
a  Update the numerical values of distribution parameters.

Parameters
----------
**params : array_like
    Desired numerical values of the distribution parameters. Any or all
    of the parameters initially used to instantiate the distribution
    may be modified. Parameters used in alternative parameterizations
    are not accepted.

validation_policy : str
    To be documented. See Question 3 at the top.
NFr   r}   The `zB` distribution family does not accept parameters, but parameters `z` were provided.c                 B    U R                   U   R                  5       S   $ rO   )r  rQ   )self_name_s     r   <lambda>;UnivariateDistribution._update_parameters.<locals>.<lambda>  s    383D3DU3K3P3P3RSU3Vr   rA   ) r  rQ   r]   rG   rR   r~  r|  r   rJ  _ndim_sizer  rI  rG  rH  _process_parametersr   r  rW   rB   r  rM  _identify_parameterization
_broadcast	_validatereset_cacher  _parameterizationr  hasattrsetattrproperty)r2   rG  r   r^   original_parametersparameterizationrk   r   r   ndiminvalidr`  r  r[   s                 r   r  )UnivariateDistribution._update_parametersP  s    ,0+D+D+I+I+KK
#F#

5)!g

jj7!7!7IE11?J?JT,,--"4>>#:#:"; <"://?A !))	 0  $>>zJ,0OOJ,G)Jt/< 4J11?J?J#M +KJJK%!1$7!$$))+Dt~~t,,DNND(t 4W +X Y	 ,r   c                 X    0 U l         0 U l        0 U l        SU l        0 U l        SU l        g)zClear all cached values.

To improve the speed of some calculations, the distribution's support
and moments are cached.

This function is called automatically whenever the distribution
parameters are updated.

N)_moment_raw_cache_moment_central_cache_moment_standardized_cache_support_cacher  _constant_cacher>   s    r   r  "UnivariateDistribution.reset_cache  s4     "$%'"*,'"#r   c                 &   [        U5      nU R                   H  nUR                  U5      (       d  M    U$    U(       d  SU R                  R                   S3nO.U R                  U5      nSU SU R                  R                   S3n[        U5      e)Nr  zB` distribution family requires parameters, but none were provided.zThe provided parameters `z4` do not match a supported parameterization of the `z` distribution family.)r  r  r  rW   rB   _get_parameter_strrM  )r2   r^   parameter_names_setr  rk   r  s         r   r  1UnivariateDistribution._identify_parameterization  s     "*o $ 7 7''(;<<   !8 '"4>>#:#:"; <' ' #'"9"9*"E66G H#~~6677MO W%%r   c                 j   UR                  5        Vs/ s H  n[        R                  " U5      PM     nn[        S U 5       5      n[	        U5      S:X  a,  XS   R
                  US   R                  US   R                  4$  [        R                  " U6 n[        [        UR                  5       U5      5      US   R
                  US   R                  US   R                  4$ s  snf ! [         a?  nU R                  U5      nSU SU R                  R                   S3n[        U5      UeS nAff = f)Nc              3   8   #    U  H  oR                   v   M     g 7fr   r  ).0r'  s     r   	<genexpr>4UnivariateDistribution._broadcast.<locals>.<genexpr>  s     O9   r}   r   zThe parameters `z` provided to the `z<` distribution family cannot be broadcast to the same shape.)r   rG   rR   r  r   r   r   r  r   rM  r)  rW   rB   r  r/  r  )r2   r^   r'  parameter_valsparameter_shapesrj   r  rk   s           r   r  !UnivariateDistribution._broadcast  sO     ,6+<+<+>@+>i **Y/+> 	 @OOO A%q 1 7 7"1%**N1,=,B,BD D	-00.AN S*N;<q!''q!&&q!&&( 	(@  	-"55jAO)/): ;>>223 4@@G W%1,	-s    C$C) )
D23:D--D2c                    UR                  U5      u  p4U) nUR                  S:X  a  UO[        R                  " U5      nU(       a8  U H2  n[        R                  " X'   5      X''   [        R
                  X'   U'   M4     X%Xd4$ rO   )r(  r   rG   rP  rQ   r   )r2   r  r^   r  r  r  r`  parameter_names           r   r   UnivariateDistribution._validate  sy     (22:>&!("!4g"&&/",-/WW..0
*68ff
*73 #-
 K66r   c                     U$ )a  Process and cache distribution parameters for reuse.

This is intended to be overridden by subclasses. It allows distribution
authors to pre-process parameters for re-use. For instance, when a user
parameterizes a LogUniform distribution with `a` and `b`, it makes
sense to calculate `log(a)` and `log(b)` because these values will be
used in almost all distribution methods. The dictionary returned by
this method is passed to all private methods that calculate functions
of the distribution.
rA   r2   r   s     r   r  *UnivariateDistribution._process_parameters  s	     r   c                 H    SSR                  UR                  5       5       S3$ )N{r   })r   r  r  s     r   r)  )UnivariateDistribution._get_parameter_str  s"    DIIjoo/0144r   c                     U R                   R                  5       U l         [        [        U R                   5      5       H-  nU R                   U   R                  5       U R                   U'   M/     g r   )r  rQ   r   r   )r2   r   s     r   _copy_parameterization-UnivariateDistribution._copy_parameterization  sW    "&"9"9">">"@s42234A)-)@)@)C)H)H)JD##A& 5r   c                     U R                   $ )zpositive float:
The desired relative tolerance of calculations. Left unspecified,
calculations may be faster; when provided, calculations may be
more likely to meet the desired accuracy.
)_tolr>   s    r   r  UnivariateDistribution.tol  s     yyr   c                 P   [        U5      (       a  Xl        g [        R                  " U5      nUR                  S:w  d:  US:  a4  [        R
                  " UR                  [        R                  5      (       d%  SU R                  R                   S3n[        U5      eUS   U l        g )NrA   r   zAttribute `tol` of `z)` must be a positive float, if specified.)r   rC  rG   rR   r   r  r  r  rW   rB   rM  )r2   r  rk   s      r   r  rD  (  s    3<<IjjoIIO37MM#))R[[99-dnn.E.E-F G< <GW%%G	r   c                     U R                   $ )a9  {None, "no_cache"}:
Specifies the extent to which intermediate results are cached. Left
unspecified, intermediate results of some calculations (e.g. distribution
support, moments, etc.) are cached to improve performance of future
calculations. Pass ``'no_cache'`` to reduce memory reserved by the class
instance.
)_cache_policyr>   s    r   r  #UnivariateDistribution.cache_policy6  s     !!!r   c                     Ub  [        U5      R                  5       OS nS S1nX;  a(  SU R                  R                   SU S3n[	        U5      eXl        g )Nr(   zAttribute `cache_policy` of `` must be one of , if specified.)r   lowerrW   rB   rM  rG  )r2   r  cache_policiesrk   s       r   r  rH  A  sf    4@4Ls<(..0RV
+-6t~~7N7N6O P))7(8IGW%%)r   c                     U R                   $ )a  {None, "skip_all"}:
Specifies the level of input validation to perform. Left unspecified,
input validation is performed to ensure appropriate behavior in edge
case (e.g. parameters out of domain, argument outside of distribution
support, etc.) and improve consistency of output dtype, shape, etc.
Use ``'skip_all'`` to avoid the computational overhead of these
checks when rough edges are acceptable.
)_validation_policyr>   s    r   rG  (UnivariateDistribution.validation_policyK  s     &&&r   c                     Ub  [        U5      R                  5       OS nS S1nX;  a(  SU R                  R                   SU S3n[	        U5      eXl        g )Nr'   z"Attribute `validation_policy` of `rJ  rK  )r   rL  rW   rB   rM  rO  )r2   rG  iv_policiesrk   s       r   rG  rP  W  sn     !2 = !!2399;CG 	Z(/;DNN<S<S;T U))4_FGW%%"3r   c           
         U R                   R                  n[        U R                  R	                  5       5      n/ n[
        R                  " SS9   U VVs/ s H  u  pEU S[        U5       3PM     nnnSSS5        SR                  W5       nUR                  U5        U SSR                  U5       S3$ s  snnf ! , (       d  f       NN= f)zReturns a string representation of the distribution.

Includes the name of the distribution family, the names of the
parameters and the `repr` of each of their values.



   	thresholdr  Nr   r   r   )
rW   rB   r$  r  r!  rG   printoptionsr  r   r  r2   
class_namer^   infor\   r  str_parameterss          r   __repr__UnivariateDistribution.__repr__d  s     ^^,,
$3399;<
__r*MWXZMF$u+7ZNX + IIn56N#Qtyy/q11 Y +*   B=B72B=7B==
Cc           
         U R                   R                  n[        U R                  R	                  5       5      n/ n[
        R                  " SS9   U VVs/ s H  u  pEU S[        U5       3PM     nnnS S S 5        SR                  W5       nUR                  U5        U SSR                  U5       S3$ s  snnf ! , (       d  f       NN= f)NrT  rU  r  r   r   r   )
rW   rB   r$  r  r!  rG   rW  r   r   r  rX  s          r   r?   UnivariateDistribution.__str__u  s    ^^,,
$3399;<
__r*LVWJ=6#e*6JNW + IIn56N#Qtyy/q11 X +*r^  c                     [        XS9$ N)locShiftedScaledDistributionr2   rc  s     r   __add__UnivariateDistribution.__add__  s    (77r   c                     [        X* S9$ rb  rd  rf  s     r   __sub__UnivariateDistribution.__sub__  s    (488r   c                     [        XS9$ )Nscalerd  r2   rn  s     r   __mul__UnivariateDistribution.__mul__  s    (;;r   c                     [        U SU-  S9$ )Nr}   rm  rd  ro  s     r   __truediv__"UnivariateDistribution.__truediv__  s    (QuW==r   c                   ^ [         R                  " T5      (       a  TS::  d  T[        T5      :w  a  Sn[        U5      e[         R                  " SS9   S[        U 5       S[        T5       3nS[        U 5       S[        T5       3nS S S 5        TS-  S:X  a  [        U 5      OU n[        U4S jWWU4S	 jU4S
 jS9n[        U40 UDSS0D6$ ! , (       d  f       NM= f)Nr   zrRaising a random variable to the power of an argument is only implemented when the argument is a positive integer.rT  rU  r   z)**r   c                    > U T-  $ r   rA   uothers    r   r  0UnivariateDistribution.__pow__.<locals>.<lambda>  s	    Er   c                 j   > [         R                  " U 5      [         R                  " U 5      ST-  -  -  $ Nr}   )rG   signr$   rw  s    r   r  rz    s#    bffQi!e).D!Dr   c                 N   > ST-  [         R                  " U 5      ST-  S-
  -  -  $ r|  )rG   r$   rw  s    r   r  rz    s#    !E'BFF1I%!,D"Dr   grepr_patternstr_patternhdh
increasingT)
rG   isscalarr   r0   rW  r  r   r$   r   MonotonicTransformedDistribution)r2   ry  rk   r  r  r  funcss    `     r   __pow__UnivariateDistribution.__pow__  s    {{5!!UaZ5CJ3FNG%g.. __r*tDzl#d5k];Lc$i[CJ<8K + aCIT)!,DDF
 0LULtLL +*s   5C
Cc                 $    U R                  U5      $ r   )rg  r2   ry  s     r   __radd__UnivariateDistribution.__radd__      ||E""r   c                 @    U R                  5       R                  U5      $ r   )__neg__rg  r  s     r   __rsub__UnivariateDistribution.__rsub__  s    ||~%%e,,r   c                 $    U R                  U5      $ r   )rp  r  s     r   __rmul__UnivariateDistribution.__rmul__  r  r   c           
         U R                  5       u  p#[        R                  " SS9   [        S [	        U5       S[	        U 5       S3[        U5       S[        U 5       S3S S S9nS S S 5        [        R                  " US	:  5      (       d  [        R                  " US	:*  5      (       a  [        U 40 WDS
S0D6nOSn[        U5      e[        R                  " US:H  5      (       a  U$ XQ-  $ ! , (       d  f       N= f)NrT  rU  c                     SU -  $ r|  rA   rx  s    r   r  5UnivariateDistribution.__rtruediv__.<locals>.<lambda>      QUr   z/(r   c                     SU -  $ r|  rA   r  s    r   r  r    r  r   c                     SU S-  -  $ )Nr}   r   rA   r  s    r   r  r    s    Q!Vr   r  r   r  FzjDivision by a random variable is only implemented when the support is either non-negative or non-positive.r}   )	rN  rG   rW  r  r  r   allr  r0   )r2   ry  rU   rV   r  r   rk   s          r   __rtruediv__#UnivariateDistribution.__rtruediv__  s    ||~__r*?)-eRT
|1&E(+E
|2c$i[%B*/CEE +
 66!q&>>RVVAF^^24S5SUSCRG%g..66%1*J; +*s   AC..
C<c                   ^ [         R                  " SS9   [        U4S jU4S jU4S j[        T5       S[        U 5       S3[	        T5       S[	        U 5       S3S9nS S S 5        [         R
                  " T5      (       a  TS	::  d  TS
:X  a  Sn[        U5      eTS
:  a  [        U 40 WDSS0D6$ [        U 40 WDSS0D6$ ! , (       d  f       Nh= f)NrT  rU  c                    > TU -  $ r   rA   rw  s    r   r  1UnivariateDistribution.__rpow__.<locals>.<lambda>  s	    UAXr   c                 ^   > [         R                  " U 5      [         R                  " T5      -  $ r   rG   r&   rw  s    r   r  r    s    RVVAY%>r   c                 d   > S[         R                  " U [         R                  " T5      -  5      -  $ r|  )rG   r$   r&   rw  s    r   r  r    s     a"&&RVVE]1B*C&Cr   z**(r   )r  r  r  r  r  r   r}   z~Raising an argument to the power of a random variable is only implemented when the argument is a positive scalar other than 1.r  TF)rG   rW  r  r  r   r  r0   r  )r2   ry  r  rk   s    `  r   __rpow__UnivariateDistribution.__rpow__  s    __r*->C)-eSdA&F(+E
|3s4yk%C	FE + {{5!!UaZ5A:G &g..193DSESdSS3DTETeTT! +*s   A
C
Cc                     U S-  $ )Nr  rA   r>   s    r   r  UnivariateDistribution.__neg__  s    byr   c                     [        U 5      $ r   FoldedDistributionr>   s    r   __abs__UnivariateDistribution.__abs__  s    !$''r   c                    U R                   [        :X  a  U$ [        R                  " XR                  S9S   nSU R
                  R                   S3n [        UR                  5       5      nUS:  d  XQ:w  a  [        U5      eSU R
                  R                   S[        U5       S3nUR                  5       U;  a  [        U5      eU$ ! [         a  n[        U5      UeS nAff = f)	Nr  rA   zArgument `order` of `z,.moment` must be a finite, positive integer.r   zArgument `kind` of `z.moment` must be one of rA  )rG  rH  rG   rR   rI  rW   rB   r   rn   	ExceptionrM  r  rL  )r2   orderr   kindsrk   	order_intrj   s          r   _validate_order_kind+UnivariateDistribution._validate_order_kind  s    
 !!Y.L

54R8*4>>+B+B*C D9 9	-ejjl+I a<9-W%%)$..*A*A)B C%%(ZL3::<u$W%%  	-W%1,	-s   C	 	
C$CC$c                     [         R                  " U5      nUR                  U R                  :w  a  UR	                  U R                  5      nUS   $ rO   )rG   rR   r  rI  r}  r1   s     r   _preserve_type%UnivariateDistribution._preserve_type  s:    JJqM77dkk!%Aur   c                 2   [         R                  R                  U5      n[        U R                  5      S:X  a  U " 5       $ Uc.  U R                  5       nUR                  S[        SUS-
  5      SS9nU R                  U   nUR                  XUSS9nU " S0 UD6$ )zuDraw a specific (fully-defined) distribution from the family.

See _Parameterization.draw for documentation details.
r   r}   T)rv   r   )r   r   rA   )	rG   r   r   r   r  _num_parameterizationsrw   r   r8   )clsr0  rz   r  r   r7   r  r^   s           r   r  UnivariateDistribution._draw  s     ii##C(s%%&!+5L%**,A!$aQA!N112DE%**5;2; + =
 Z  r   c                 ,    [        U R                  5      $ r   )r   r  )r  s    r   r  -UnivariateDistribution._num_parameterizations  s     3))**r   c                 `    U R                  5       (       d  S$ [        U R                  U   5      $ Nr   )r  r   r  )r  r  s     r   r  &UnivariateDistribution._num_parameters  s5     3355 	F//0BCD	Fr   Fc                 h   Uc  U R                   " S0 UD6OUu  pg[        R                  " Xg5      u  pgUR                  (       d)  [        R                  " UR
                  U R                  S9$ Uc  / OUnUc  0 OUn[        XUS9u  p[        R                  " U6 n[        U R                  5      (       a  S OU R                  n	[        U [        5      (       a  [        XXsXYS9n
U
R                  $ [        XXsU[        U	S9S9R                   n
[        R"                  " U
5      n
U(       a'  [        R$                  " UR'                  5       S   5      O[        R(                  n[        R*                  " XR
                  5      nU(       a  [        R,                  * OSXU:  '   [        R.                  X'   U
S   $ )	Nr  rx   ry   )rx   r&   rtol)r  )rx   r&   
tolerancesr}   r   rA   )_supportrG   r   r   emptyr   rI  r  r   r  r   r  	_tanhsinhr   r   r  r   rR   r   popitemTrue_rL  r   r   )r2   	integrandlimitsrx   r   r&   rU   rV   ro  r  rg  conds               r   _quadrature"UnivariateDistribution._quadrature  sJ    +1.t}}&v&f""1(vv88AGG4;;77\rt~6yFC""D)txx((tdhh d233A!CCC<<qQstOSSC**S/C 5;288FNN,Q/0D??41D&)BFF7qCQLCIr7Nr   )boundsr   xatolc          	      *  ^ Uc  U R                   " S0 UD6OUu  pgUc  0 OUn[        R                  " X&U5      u  p&nUR                  (       dV  [	        5       n[        R
                  " UR                  U R                  S9n	XU	sUl        Ul	        Ul
        XsUl        Ul        U4S jn
[        X/US9u  pUR                  n[        R                  " Xg5      u  pg[        Xg5      u  pUR!                  U5      nUR!                  U5      nUR!                  U5      nUR!                  U5      n[#        XXX|S9n[%        U R&                  5      (       a  S OU R&                  nUc  S OUn[)        UUSSS9n[+        U4UR                  UR                  US.UD6$ )	Nr  c                    > T" U 40 UD6U-
  $ r   rA   )r   _pry   ro  s      r   r   1UnivariateDistribution._solve_bounded.<locals>.f2J  s    Q>&>B&&r   r  xl0xr0r  r  rx   r   )xrtolr  fatolfrtolrU   rV   rx   rA   )r  rG   r   r   r	   r  r   rI  xlr   xrflfrr  r  r  r   r   r   r  r  r   )r2   ro  r   r  r   r  r  r  rg  r  r   f3rx   r   r  r  r  r  s    `                r   _solve_bounded%UnivariateDistribution._solve_bounded<  sa    17T]],V,F
~6++AT:vv-CHHQWWDKK8E$)%!CFCE36"NCFCF	'  V< 

]]4.
!$-||E"||E"kk% kk% BS$R  ))txx5U!1E
RM366SVV$M*MMr   c                 X    [        U R                  US 5      n[        [        US 5      nX#L$ r   )r  rW   r  )r2   rV  r  super_methods       r   
_overrides!UnivariateDistribution._overridese  s.     d;5{DI))r   c                    U R                   b  U R                   $ U R                  " S0 U R                  D6u  pUR                  U R                  :w  a   [
        R                  " XR                  5      nUR                  U R                  :w  a   [
        R                  " X R                  5      nU R                  (       a  [
        R                  " U5      R                  5       [
        R                  " U5      R                  5       p![
        R                  [
        R                  sXR                  '   X R                  '   US   US   p!X4nU R                  [        :w  a  X0l         U$ rO   )r%  r  r  r   rJ  rG   rL  r|  rR   rQ   r   r~  r  r  )r2   rU   rV   rN  s       r   rN  UnivariateDistribution.support  s    
 *&&&}}0t//077dkk!;;/A77dkk!;;/A::a=%%'A););)=q13.Amma.R5!B%q&	)")r   c                    U R                   R                  R                  U5      u  p#[        U5      (       ax  [	        UR                  5       5      nUS   R                  nUR                  U:w  a  [        R                  " X%5      OUnUR                  U:w  a  [        R                  " X55      OUnU R                  U5      U R                  U5      4$ r  )
rO  r   r;   r   r$  r   r   rG   rL  r  )r2   r   rU   rV   valsr   s         r   r  UnivariateDistribution._support  s    ~~$$<<VDv;;(DGMME-.WW-=)1A-.WW-=)1A""1%t':':1'===r   r  c                D    U R                   " SSU0U R                  D6S-   $ )Nr  r  rA   )_logentropy_dispatchr  r2   r  s     r   
logentropy!UnivariateDistribution.logentropy  s&    ((KK$:J:JKbPPr   c                     U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_logentropy_formula_entropy_formula)r  r  _logentropy_logexp_safe_logentropy_quadraturer2   r  r   s      r   r  +UnivariateDistribution._logentropy_dispatch  sZ    ??011--F
 	 __/0011F  00Fr   c                 ,    [        U R                  5      er   r0   r{  r9  s     r   r  *UnivariateDistribution._logentropy_formula      !$"7"788r   c                 j    [         R                  " U R                  " S0 UD6S-   5      n[        U5      $ )Nr  rA   )rG   r&   _entropy_dispatchr  )r2   r   rg  s      r   _logentropy_logexp)UnivariateDistribution._logentropy_logexp  s.    ffT++5f5b89$S))r   c                 T   U R                   " S0 UD6n[        R                  " UR                  5      n[        R                  " U5      (       aQ  UR                  5        VVs0 s H
  u  pEXEU   _M     nnn[        R                  " U5      nU R                  " S0 UD6X#'   US   $ s  snnf rO   )r   rG   r   rU  rP  r!  rR   r  )r2   r   r   maskr  r  params_masks          r   r  .UnivariateDistribution._logentropy_logexp_safe  s    %%//xx!66$<<9?HXS34y=KH**S/C33BkBCI2w Is   !B$c                 n   ^  U 4S jnT R                  X!SS9n[        U[        R                  S-  -   5      $ )Nc                 b   > TR                   " U 40 UD6nU[        R                  " SU-   5      -   $ Nr  )_logpxf_dispatchrG   r&   )r   r   logpxfr2   s      r   logintegrandCUnivariateDistribution._logentropy_quadrature.<locals>.logintegrand  s0    **177FBFF2f9---r   Tr   r&   r  )r  r  rG   rH   )r2   r   r  rg  s   `   r   r  -UnivariateDistribution._logentropy_quadrature  s6    	. |E$S2558^44r   c                >    U R                   " SSU0U R                  D6$ Nr  rA   )r  r  r  s     r   r  UnivariateDistribution.entropy  s!    %%HVHt7G7GHHr   c                     U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  nU$ )Nr  r  )r  r  _entropy_logexp_entropy_quadraturer  s      r   r  (UnivariateDistribution._entropy_dispatch  sZ    ??-..**F
 	 __233))F  --Fr   c                 ,    [        U R                  5      er   r  r9  s     r   r  'UnivariateDistribution._entropy_formula	  r  r   c           	      v    [         R                  " [         R                  " U R                  " S0 UD65      5      $ rO   )rG   rU  r%   r  r9  s     r   r  &UnivariateDistribution._entropy_logexp
	  s(    wwrvvd77A&ABCCr   c                 0   ^  U 4S jnT R                  X!S9* $ )Nc                    > TR                   " U 40 UD6nTR                  " U 40 UD6n[        R                  " U5      nUS:g  nX%   X5   -  XE'   U$ r  )_pxf_dispatchr	  rG   rR   )r   r   pxfr
  tempr   r2   s         r   r  =UnivariateDistribution._entropy_quadrature.<locals>.integrand	  sX    $$Q1&1C**177F::c?DAfVY&DGKr   r   r  )r2   r   r  s   `  r   r  *UnivariateDistribution._entropy_quadrature	  s!    	    :::r   c                >    U R                   " SSU0U R                  D6$ r  )_median_dispatchr  r  s     r   r  UnivariateDistribution.median	  s!    $$GFGd6F6FGGr   c                 f    U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_median_formula)r  r'  _median_icdfr  s      r   r$  'UnivariateDistribution._median_dispatch	  s6    ??,--))F  &&Fr   c                 ,    [        U R                  5      er   r  r9  s     r   r'  &UnivariateDistribution._median_formula#	  r  r   c                 &    U R                   " S0 UD6$ )N)r   _icdf_dispatchr9  s     r   r(  #UnivariateDistribution._median_icdf&	  s    ""1&11r   c                >    U R                   " SSU0U R                  D6$ r  )_mode_dispatchr  r  s     r   r  UnivariateDistribution.mode)	  s!    ""E&ED4D4DEEr   c                 f    U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_mode_formula)r  r4  _mode_optimizationr  s      r   r1  %UnivariateDistribution._mode_dispatch-	  s7     ???++''F  ,,Fr   c                 ,    [        U R                  5      er   r  r9  s     r   r4  $UnivariateDistribution._mode_formula7	  r  r   c           	      <  ^  T R                   (       d)  [        R                  " T R                  T R                  S9$ T R
                  " S0 UD6u  p4T R                  " S0 UD6n[        U 4S jSUS9u  pg[        XeX4US9n[        XhR                  UR                  UR                  XqS9n	[        R                  " U	R                  5      n
UR                  S:H  nXR                   UR"                  :*  -  nXR$                  UR"                  :  -  nX<   X'   XM   X'   U
S   $ )Nr  c                 ,   > TR                   " U 40 UD6* $ r   r  )r   r   r2   s     r   r  ;UnivariateDistribution._mode_optimization.<locals>.<lambda>A	  s    D4F4Fq4SF4S3Sr   rA   r  )r  r  rx   )rx   r  r  )r  rG   r  rJ  rI  r  r$  r  r   r   r  xmr  rR   r   statusr  fmr  )r2   r  r   rU   rV   mro  rx   res_brg  r  mode_at_boundarymode_at_leftmode_at_rights   `             r   r5  )UnivariateDistribution._mode_optimization:	  s    zz88DKKt{{;;}}&v&!!+F+S$&v7 ADA$Q%((EHH*.=zz#%%  <<2-'88uxx+?@(HHuxx,?@_.Bxr   c                $    U R                  SSUS9$ )Nr}   rawr   r  momentr  s     r   r  UnivariateDistribution.meanN	  s    {{15{88r   c                $    U R                  SSUS9$ )Nr   centralrH  rI  r  s     r   r  UnivariateDistribution.varianceQ	  s    {{19V{<<r   c                H    [         R                  " U R                  US95      $ Nr  )rG   sqrtr  r  s     r   r  )UnivariateDistribution.standard_deviationT	  s    wwt}}F}344r   c                $    U R                  SSUS9$ )Nr   standardizedrH  rI  r  s     r   r  UnivariateDistribution.skewnessW	  s    {{1>&{AAr   
non-excess)r  
conventionc                    SS1nSU R                   R                   SU S3nUR                  5       nX#;  a  [        U5      eU R	                  SSUS9nUS:X  a  US	-
  $ U$ )
NrV  excesszParameter `convention` of `z.kurtosis` must be one of rA  r  rT  rH  r   )rW   rB   rL  rM  rJ  )r2   r  rW  conventionsrk   ks         r   r  UnivariateDistribution.kurtosisZ	  s{    #X.01H1H0I J%%0M4%%'
(W%%KKvK>"h.q1u5A5r   c               @    U R                   " U4SU0U R                  D6$ Nr  )_logpdf_dispatchr  r2   r   r  s      r   r8  UnivariateDistribution.logpdf	  #    $$QJvJ9I9IJJr   c                    U R                  S5      (       a  U R                  nU$ [        U R                  5      (       a  U R                  nU$ )N_logpdf_formula)r  rd  r   r  _logpdf_logexpr2   r   r  r   s       r   r_  'UnivariateDistribution._logpdf_dispatch	  E    ??,--))F  TXX((Fr   c                 ,    [        U R                  5      er   r  r2   r   r   s      r   rd  &UnivariateDistribution._logpdf_formula	  r  r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rG   r&   _pdf_dispatchrj  s      r   re  %UnivariateDistribution._logpdf_logexp	  !    vvd((5f566r   c               @    U R                   " U4SU0U R                  D6$ r^  )rm  r  r`  s      r   r9  UnivariateDistribution.pdf	  #    !!!GFGd6F6FGGr   c                f    U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_pdf_formula)r  rt  _pdf_logexprf  s       r   rm  $UnivariateDistribution._pdf_dispatch	  5    ??>**&&F  %%Fr   c                 ,    [        U R                  5      er   r  rj  s      r   rt  #UnivariateDistribution._pdf_formula	  r  r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rG   r%   r_  rj  s      r   ru  "UnivariateDistribution._pdf_logexp	  !    vvd++A8899r   c               @    U R                   " U4SU0U R                  D6$ r^  )_logpmf_dispatchr  r`  s      r   r:  UnivariateDistribution.logpmf	  rb  r   c                    U R                  S5      (       a  U R                  nU$ [        U R                  5      (       a  U R                  nU$ )N_logpmf_formula)r  r  r   r  _logpmf_logexprf  s       r   r~  'UnivariateDistribution._logpmf_dispatch	  rh  r   c                 ,    [        U R                  5      er   r  rj  s      r   r  &UnivariateDistribution._logpmf_formula	  r  r   c                     [         R                  " SS9   [         R                  " U R                  " U40 UD65      sS S S 5        $ ! , (       d  f       g = f)Nignoredivide)rG   errstater&   _pmf_dispatchrj  s      r   r  %UnivariateDistribution._logpmf_logexp	  s6    [[)66$,,Q9&9: *))s   'A
Ac               @    U R                   " U4SU0U R                  D6$ r^  )r  r  r`  s      r   r;  UnivariateDistribution.pmf	  rr  r   c                f    U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_pmf_formula)r  r  _pmf_logexprf  s       r   r  $UnivariateDistribution._pmf_dispatch	  rw  r   c                 ,    [        U R                  5      er   r  rj  s      r   r  #UnivariateDistribution._pmf_formula	  r  r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rG   r%   r~  rj  s      r   r  "UnivariateDistribution._pmf_logexp	  r|  r   c               F    Uc  U R                  XS9$ U R                  XUS9$ rP  )r<  r  r2   r   r  r  s       r   logcdfUnivariateDistribution.logcdf	  s+    9===22==f=55r   c                    U R                   " X4SU0U R                  D6n[        R                  " UR                  [        R
                  5      (       d  US-   $ U$ )Nr  r  )_logcdf2_dispatchr  rG   r  r  complexfloating)r2   r   r  r  r   s        r   r  UnivariateDistribution._logcdf2	  sL    $$QM&MD<L<LM!#syy":L:L!M!MbVSVVr   c                N   U R                  S5      (       a  U R                  nU$ U R                  S5      (       d  U R                  S5      (       a  U R                  nU$ U R                  S5      (       d  U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_logcdf2_formula_logcdf_formula_logccdf_formula_cdf_formula_ccdf_formula)r  r  _logcdf2_subtraction_logcdf2_logexp_safe_logcdf2_quadraturer2   r   r  r  r   s        r   r  (UnivariateDistribution._logcdf2_dispatch	  s     ??-..**F  oo/00!344..F  oon--11..F  --Fr   c                 ,    [        U R                  5      er   r  r2   r   r  r   s       r   r  'UnivariateDistribution._logcdf2_formula	  r  r   c                 H   X:  n[         R                  " X5      [         R                  " X5      p!U R                  " U40 UD6nU R                  " U40 UD6nU R                  " U40 UD6nU R                  " U40 UD6nUS:  US:  -  n	US:  US:  -  n
X-  ) n[        Xe5      n[        Xx5      U
   X'   [         R                  " XX5      U   n[        U5      X'   X==   [         R                  S-  -  ss'   [         R                  " U5      (       a  US   $ UR                  S   $ )Nr  r  rA   )rG   minimummaximum_logcdf_dispatch_logccdf_dispatchr  	logaddexpr   rH   rP  rU  )r2   r   r  r   	flip_signlogcdf_xlogcdf_y	logccdf_x	logccdf_y	case_left
case_rightcase_centrallog_masslog_tails                 r   r  +UnivariateDistribution._logcdf2_subtraction	  s   E	zz!A!11((5f5((5f5**177	**177	]x"}5	"nR8
"/0 4,YB:N<<4\B!*8!4ruurz)!vvi00x|GhmmB6GGr   c                     U R                   " X40 UD6n[        R                  " X:  5      (       a  US-   OUn[        R                  " U5      $ r  )_cdf2_dispatchrG   rP  r&   )r2   r   r  r   express        r   _logcdf2_logexp&UnivariateDistribution._logcdf2_logexp
  s>    $$Q4V4 "qu"6vvf~r   c           	         U R                   " X40 UD6n[        R                  " UR                  5      n[        R                  " U5      (       av  UR                  5        VVs0 s H)  u  pgU[        R                  " XuR                  5      U   _M+     nnn[        R                  " U5      nU R                  " X   X%   40 UD6XE'   US   $ s  snnf rO   )
r  rG   r   rU  rP  r!  rL  r   rR   r  )	r2   r   r  r   r   r  r  r  r  s	            r   r  +UnivariateDistribution._logcdf2_logexp_safe
  s    ""1262xx!66$<<+1<<>;+9xs ZZ @ FF+9  ;**S/C00!'Q[QCI2w	;s   "0C
c                 @    U R                  U R                  X4SUS9nU$ )NT)r  r&   r   )r  r	  )r2   r   r  r   logress        r   r  *UnivariateDistribution._logcdf2_quadrature
  s-    !!$"7"7&*6 " ;r   c                @    U R                   " U4SU0U R                  D6$ r^  )r  r  r`  s      r   r<  UnivariateDistribution._logcdf1
  rb  r   c                    U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  nU$ )Nr  r  r  )r  r  _logcdf_complement_logcdf_logexp_safe_logcdf_quadraturerf  s       r   r  'UnivariateDistribution._logcdf_dispatch
  s}    ??,--))F  __/00,,F
 	 __^,,--F  ,,Fr   c                 ,    [        U R                  5      er   r  rj  s      r   r  &UnivariateDistribution._logcdf_formula%
  r  r   c                 :    [        U R                  " U40 UD65      $ r   )r   r  rj  s      r   r  )UnivariateDistribution._logcdf_complement(
  s    //<V<==r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rG   r&   _cdf_dispatchrj  s      r   _logcdf_logexp%UnivariateDistribution._logcdf_logexp+
  ro  r   c           	         U R                   " U40 UD6n[        R                  " U5      n[        R                  " U5      (       as  UR	                  5        VVs0 s H)  u  pVU[        R
                  " XdR                  5      U   _M+     nnn[        R                  " U5      nU R                  " X   40 UD6X4'   US   $ s  snnf rO   )	r  rG   r   rP  r!  rL  r   rR   r  r2   r   r   r   r  r  r  r  s           r   r  *UnivariateDistribution._logcdf_logexp_safe.
  s    !!!.v.xx}66$<<+1<<>;+9xs rsJJ?EE+9  ;**S/C//G;GCI2w	;   0B=c                 d    U R                   " S0 UD6u  p4U R                  U R                  X14USS9$ NT)r  r   r&   rA   r  r  r	  r2   r   r   rU   _s        r   r  )UnivariateDistribution._logcdf_quadrature8
  >    }}&v& 5 5qf'-4   9 	9r   c               F    Uc  U R                  XS9$ U R                  XUS9$ rP  )r>  r  r  s       r   cdfUnivariateDistribution.cdf=
  s+    9::a://::a6:22r   c                @    U R                   " X4SU0U R                  D6$ r^  )r  r  r  s       r   r  UnivariateDistribution._cdf2C
  s#    ""1KK$:J:JKKr   c                N   U R                  S5      (       a  U R                  nU$ U R                  S5      (       d  U R                  S5      (       a  U R                  nU$ U R                  S5      (       d  U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_cdf2_formular  r  r  r  )r  r  _cdf2_logexp_cdf2_subtraction_safe_cdf2_quadraturer  s        r   r  %UnivariateDistribution._cdf2_dispatchG
  s     ???++''F  oo/00!344&&F
 	 __^,,0P0P00F  **Fr   c                 ,    [        U R                  5      er   r  r  s       r   r  $UnivariateDistribution._cdf2_formulaU
  r  r   c           	      x    [         R                  " [         R                  " U R                  " X40 UD65      5      $ r   )rG   rU  r%   r  r  s       r   r  #UnivariateDistribution._cdf2_logexpX
  s*    wwrvvd44QDVDEFFr   c                     U R                   " U40 UD6nU R                   " U40 UD6nU R                  " U40 UD6nU R                  " U40 UD6nUS:  US:  -  n[        R                  " XU-
  XT-
  5      $ Nr   )r  _ccdf_dispatchrG   r   )	r2   r   r  r   cdf_xcdf_yccdf_xccdf_yr   s	            r   _cdf2_subtraction(UnivariateDistribution._cdf2_subtraction[
  s     ""1//""1//$$Q1&1$$Q1&1c\fsl+xx&=%+66r   c           	         U R                   " U40 UD6nU R                   " U40 UD6nU R                  " U40 UD6nU R                  " U40 UD6nUS:  US:  -  n[        R                  " XU-
  XT-
  5      n	[        R                  " U R
                  5      R                  n
[        U R                  5      (       d  U R                  O[        R                  " U
5      n[        R                  " XE5      n[        R                  " Xg5      n[        R                  " [        R                  " XU5      5      n[        R                  " X-  5      U:  n[        R                  " U5      (       ax  UR                  5        VVs0 s H+  u  nnU[        R                  " UUR                   5      U   _M-     nnn[        R"                  " U	5      n	U R$                  " X   X/   40 UD6X'   U	S   $ s  snnf )Nr   rA   )r  r  rG   r   r  rI  epsr   r  rQ  r  spacingr$   rP  r!  rL  r   rR   r  )r2   r   r  r   r  r  r  r  r   r   r  r  cdf_maxccdf_maxr  r  r  r  r  s                      r   r  -UnivariateDistribution._cdf2_subtraction_safef
  s   ""1//""1//$$Q1&1$$Q1&1c\fsl+hhq-5hht{{#''%dhh//dhhRWWS\**U*::f-**RXXa7;<vvci 7*66$<<+1<<>;+9xsC TZZ @ FF+9  ;**S/C--agqwN+NCI2w	;s   :2G$c                 :    U R                  U R                  X4US9$ )Nr  r   )r  r  r  s       r   r  'UnivariateDistribution._cdf2_quadrature}
  s"     2 2A6&QQr   c                @    U R                   " U4SU0U R                  D6$ r^  )r  r  r`  s      r   r>  UnivariateDistribution._cdf1
  rr  r   c                    U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  nU$ )Nr  r  r  )r  r  _cdf_logexp_cdf_complement_safe_cdf_quadraturerf  s       r   r  $UnivariateDistribution._cdf_dispatch
  s|    ??>**&&F  __.//%%F
 	 ___--..F  ))Fr   c                 ,    [        U R                  5      er   r  rj  s      r   r  #UnivariateDistribution._cdf_formula
  r  r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rG   r%   r  rj  s      r   r  "UnivariateDistribution._cdf_logexp
  r|  r   c                 .    SU R                   " U40 UD6-
  $ r|  )r  rj  s      r   _cdf_complement&UnivariateDistribution._cdf_complement
  s    4&&q3F333r   c           	      f   U R                   " U40 UD6nSU-
  n[        R                  " U R                  5      R                  n[        U R                  5      (       d  U R                  O[        R                  " U5      nXd-  [        R                  " U5      :  n[        R                  " U5      (       as  UR                  5        VV	s0 s H)  u  pU[        R                  " XR                  5      U   _M+     n
nn	[        R                  " U5      nU R                  " X   /U
Q76 XG'   US   $ s  sn	nf Nr}   rA   )r  rG   r  rI  r  r   r  rQ  r  rP  r!  rL  r   rR   r  )r2   r   r   rD  r   r  r  r  r  r  r  s              r   r  +UnivariateDistribution._cdf_complement_safe
  s    ""1//$hhht{{#''%dhh//dhhRWWS\y2::d++66$<<+1<<>;+9xs ZZ @ FF+9  ;**S/C,,QWC{CCI2w	;   0D-c                 b    U R                   " S0 UD6u  p4U R                  U R                  X14US9$ Nr  rA   r  r  r  r  s        r   r  &UnivariateDistribution._cdf_quadrature
  <    }}&v& 2 2A6'-   / 	/r   c               F    Uc  U R                  XS9$ U R                  XUS9$ rP  )r=  	_logccdf2r  s       r   logccdfUnivariateDistribution.logccdf
  s+    9>>!>33>>!v>66r   c                @    U R                   " X4SU0U R                  D6$ r^  )_logccdf2_dispatchr  r  s       r   r   UnivariateDistribution._logccdf2
  s#    &&qOFOd>N>NOOr   c                f    U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_logccdf2_formula)r  r"  _logccdf2_additionr  s        r   r  )UnivariateDistribution._logccdf2_dispatch
  s8     ??.//++F  ,,Fr   c                 ,    [        U R                  5      er   r  r  s       r   r"  (UnivariateDistribution._logccdf2_formula
  r  r   c                 z    U R                   " U40 UD6nU R                  " U40 UD6n[        R                  " XE/SS9$ )Nr   r   )r  r  r   r  )r2   r   r  r   r  r  s         r   r#  )UnivariateDistribution._logccdf2_addition
  sB    ((5f5**177	  (!6Q??r   c                @    U R                   " U4SU0U R                  D6$ r^  )r  r  r`  s      r   r=   UnivariateDistribution._logccdf1
  s#    %%aKK$:J:JKKr   c                     U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  nU$ )Nr  r  r  )r  r  _logccdf_complement_logccdf_logexp_safe_logccdf_quadraturerf  s       r   r  (UnivariateDistribution._logccdf_dispatch
  s}    ??-..**F  __.//--F
 	 ___--..F  --Fr   c                 ,    [        U R                  5      er   r  rj  s      r   r  'UnivariateDistribution._logccdf_formula
  r  r   c                 :    [        U R                  " U40 UD65      $ r   )r   r  rj  s      r   r,  *UnivariateDistribution._logccdf_complement
  s    ..q;F;<<r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rG   r&   r  rj  s      r   _logccdf_logexp&UnivariateDistribution._logccdf_logexp
  s!    vvd))!6v677r   c           	         U R                   " U40 UD6n[        R                  " U5      n[        R                  " U5      (       as  UR	                  5        VVs0 s H)  u  pVU[        R
                  " XdR                  5      U   _M+     nnn[        R                  " U5      nU R                  " X   40 UD6X4'   US   $ s  snnf rO   )	r5  rG   r   rP  r!  rL  r   rR   r.  r  s           r   r-  +UnivariateDistribution._logccdf_logexp_safe
  s    ""1//xx}66$<<+1<<>;+9xs ZZ @ FF+9  ;**S/C00HKHCI2w	;r  c                 d    U R                   " S0 UD6u  p4U R                  U R                  X4USS9$ r  r  r2   r   r   r  rV   s        r   r.  *UnivariateDistribution._logccdf_quadrature
  r  r   c               F    Uc  U R                  XS9$ U R                  XUS9$ rP  )r?  r  r  s       r   rD  UnivariateDistribution.ccdf
  s+    9;;q;00;;qF;33r   c                @    U R                   " X4SU0U R                  D6$ r^  )_ccdf2_dispatchr  r  s       r   r  UnivariateDistribution._ccdf2
  s#    ##ALL4;K;KLLr   c                f    U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_ccdf2_formula)r  rB  _ccdf2_additionr  s        r   r?  &UnivariateDistribution._ccdf2_dispatch
  s6    ??+,,((F  ))Fr   c                 ,    [        U R                  5      er   r  r  s       r   rB  %UnivariateDistribution._ccdf2_formula  r  r   c                 V    U R                   " U40 UD6nU R                  " U40 UD6nXE-   $ r   )r  r  )r2   r   r  r   r  r  s         r   rC  &UnivariateDistribution._ccdf2_addition  s4    ""1//$$Q1&1~r   c                @    U R                   " U4SU0U R                  D6$ r^  )r  r  r`  s      r   r?  UnivariateDistribution._ccdf1
  #    ""1HVHt7G7GHHr   c                     U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  nU$ )Nr  r  r  )r  r  _ccdf_logexp_ccdf_complement_safe_ccdf_quadraturerf  s       r   r  %UnivariateDistribution._ccdf_dispatch  s|    ???++''F  __/00&&F
 	 __^,,//F  **Fr   c                 ,    [        U R                  5      er   r  rj  s      r   r  $UnivariateDistribution._ccdf_formula  r  r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rG   r%   r  rj  s      r   rM  #UnivariateDistribution._ccdf_logexp  s!    vvd,,Q9&9::r   c                 .    SU R                   " U40 UD6-
  $ r|  )r  rj  s      r   _ccdf_complement'UnivariateDistribution._ccdf_complement   s    4%%a26222r   c           	      f   U R                   " U40 UD6nSU-
  n[        R                  " U R                  5      R                  n[        U R                  5      (       d  U R                  O[        R                  " U5      nXd-  [        R                  " U5      :  n[        R                  " U5      (       as  UR                  5        VV	s0 s H)  u  pU[        R                  " XR                  5      U   _M+     n
nn	[        R                  " U5      nU R                  " X   40 U
D6XG'   US   $ s  sn	nf r  )r  rG   r  rI  r  r   r  rQ  r  rP  r!  rL  r   rR   rO  )r2   r   r   r  r   r  r  r  r  r  r  s              r   rN  ,UnivariateDistribution._ccdf_complement_safe#  s      -f-#ghht{{#''%dhh//dhhRWWS\y2::c?*66$<<+1<<>;+9xs ZZ @ FF+9  ;**S/C--agEECI2w	;r  c                 b    U R                   " S0 UD6u  p4U R                  U R                  X4US9$ r  r  r:  s        r   rO  'UnivariateDistribution._ccdf_quadrature0  r  r   c               @    U R                   " U4SU0U R                  D6$ r^  )_ilogcdf_dispatchr  r2   logpr  s      r   r6  UnivariateDistribution.ilogcdf7  s#    %%dN6NT=M=MNNr   c                     U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_ilogcdf_formula_ilogccdf_formula)r  rb  _ilogcdf_complement_ilogcdf_inversionrf  s       r   r]  (UnivariateDistribution._ilogcdf_dispatch;  sZ    ??-..**F
 	 __011--F  ,,Fr   c                 ,    [        U R                  5      er   r  rj  s      r   rb  'UnivariateDistribution._ilogcdf_formulaE  r  r   c                 :    U R                   " [        U5      40 UD6$ r   )_ilogccdf_dispatchr   rj  s      r   rd  *UnivariateDistribution._ilogcdf_complementH  s    &&y|>v>>r   c                 6    U R                  U R                  XS9$ Nr   )_solve_bounded_continuousr  rj  s      r   re  )UnivariateDistribution._ilogcdf_inversionK  s    --d.C.CQ-VVr   c               @    U R                   " U4SU0U R                  D6$ r^  )r.  r  r2   r   r  s      r   r4  UnivariateDistribution.icdfN  rK  r   c                     U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_icdf_formula_iccdf_formula)r  rt  _icdf_complement_safe_icdf_inversionrf  s       r   r.  %UnivariateDistribution._icdf_dispatchR  sY    ???++''F
 	 __-..//F  ))Fr   c                 ,    [        U R                  5      er   r  rj  s      r   rt  $UnivariateDistribution._icdf_formula\  r  r   c                 .    U R                   " SU-
  40 UD6$ r|  )_iccdf_dispatchrj  s      r   _icdf_complement'UnivariateDistribution._icdf_complement_  s    ##AE4V44r   c           	      b   U R                   " U40 UD6n[        R                  " U R                  5      R                  n[        U R                  5      (       d  U R                  O[        R                  " U5      nXQ-  [        R                  " SU-
  5      :  n[        R                  " U5      (       as  UR                  5        VVs0 s H)  u  pxU[        R                  " XR                  5      U   _M+     n	nn[        R                  " U5      nU R                  " X   /U	Q76 X6'   US   $ s  snnf r  )r}  rG   r  rI  r  r   r  rQ  r  rP  r!  rL  r   rR   rw  
r2   r   r   r   r  r  r  r  r  r  s
             r   rv  ,UnivariateDistribution._icdf_complement_safeb  s    ##A00hht{{#''%dhh//dhhRWWS\wAE**66$<<+1<<>;+9xs ZZ @ FF+9  ;**S/C,,QWC{CCI2w	;   0D+c                 6    U R                  U R                  XS9$ rm  )rn  r  rj  s      r   rw  &UnivariateDistribution._icdf_inversionn  s    --d.@.@!-SSr   c               @    U R                   " U4SU0U R                  D6$ r^  )rj  r  r^  s      r   r7  UnivariateDistribution.ilogccdfq  s#    &&tOFOd>N>NOOr   c                     U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  nU$ )Nrc  rb  )r  rc  _ilogccdf_complement_ilogccdf_inversionrf  s       r   rj  )UnivariateDistribution._ilogccdf_dispatchu  sZ    ??.//++F
 	 __/00..F  --Fr   c                 ,    [        U R                  5      er   r  rj  s      r   rc  (UnivariateDistribution._ilogccdf_formula  r  r   c                 :    U R                   " [        U5      40 UD6$ r   )r]  r   rj  s      r   r  +UnivariateDistribution._ilogccdf_complement  s    %%il=f==r   c                 6    U R                  U R                  XS9$ rm  )rn  r  rj  s      r   r  *UnivariateDistribution._ilogccdf_inversion  s    --d.D.Da-WWr   c               @    U R                   " U4SU0U R                  D6$ r^  )r|  r  rq  s      r   r5  UnivariateDistribution.iccdf  s#    ##AIfI8H8HIIr   c                     U R                  S5      (       a  U R                  nU$ U R                  S5      (       a  U R                  nU$ U R                  nU$ )Nru  rt  )r  ru  _iccdf_complement_safe_iccdf_inversionrf  s       r   r|  &UnivariateDistribution._iccdf_dispatch  sY    ??+,,((F
 	 ___--00F  **Fr   c                 ,    [        U R                  5      er   r  rj  s      r   ru  %UnivariateDistribution._iccdf_formula  r  r   c                 .    U R                   " SU-
  40 UD6$ r|  r-  rj  s      r   _iccdf_complement(UnivariateDistribution._iccdf_complement  s    ""1q53F33r   c           	      b   U R                   " U40 UD6n[        R                  " U R                  5      R                  n[        U R                  5      (       d  U R                  O[        R                  " U5      nXQ-  [        R                  " SU-
  5      :  n[        R                  " U5      (       as  UR                  5        VVs0 s H)  u  pxU[        R                  " XR                  5      U   _M+     n	nn[        R                  " U5      nU R                  " X   /U	Q76 X6'   US   $ s  snnf r  )r  rG   r  rI  r  r   r  rQ  r  rP  r!  rL  r   rR   r  r  s
             r   r  -UnivariateDistribution._iccdf_complement_safe  s    $$Q1&1hht{{#''%dhh//dhhRWWS\wAE**66$<<+1<<>;+9xs ZZ @ FF+9  ;**S/C--agDDCI2w	;r  c                 6    U R                  U R                  XS9$ rm  )rn  r  rj  s      r   r  'UnivariateDistribution._iccdf_inversion  s    --d.A.A1-TTr   r  rz   c                b   [         R                  " U5      (       d  U4O
[        U5      nX@R                  -   n[	        U[
        R                  5      (       d  [         R                  R                  U5      OUnU R                  " U4X#S.U R                  D6nUR                  U R                  SS9$ )Nr  FrC  )rG   r.  r   rJ  r   r   	QMCEnginer   r   r  r  r}  rI  )r2   r   r  rz   sample_shape
full_shaperg  s          r   r  UnivariateDistribution.sample  s     (*{{5'9'9xuU|!KK/
0:30N0Nbii##C(TW##J 8v 8&*&6&68 zz$++Ez22r   c                    U R                  S5      (       a-  [        U[        R                  5      (       d  U R                  nU$ U R
                  nU$ )N_sample_formula)r  r   r   r  r  _sample_inverse_transform)r2   r  r  rz   r   s        r   r  'UnivariateDistribution._sample_dispatch  sH     ??,--jcmm6T6T))F  33Fr   c                ,    [        U R                  5      er   r  )r2   r  rz   r   s       r   r  &UnivariateDistribution._sample_formula  r  r   c                    [        U[        R                  5      (       a  U R                  " U4SU0UD6nOUR	                  XR
                  S9nU R                  " U40 UD6$ )Nqrng)r   r  )r   r   r  _qmc_uniformr   rI  r.  )r2   r  rz   r   r   s        r   r  0UnivariateDistribution._sample_inverse_transform  sW    c3==))''
GGGGjjjjDG""75f55r   c                   US [        U5      [        U R                  5      -
   nU(       a  US   OSn[        R                  " U(       a  USS  OU5      n[	        UR
                  U5      nUR                  n[        SUR                  UR                  S9n	[        U[        R                  5      (       a  UR                  U	S'   / n
U HL  nU" SSU0U	D6nUR                  U5      nUR                  U(       a  UOS5      S   nU
R!                  U5        MN     U
(       a,  ["        R$                  " ["        R&                  " U
5      SS5      O["        R(                  " / 5      nUR                  U5      $ )Nr   r}   )dscrambleoptimizationbitsseedrA   r  )r   rJ  mathr   r   rz   rW   r  r  _optimizationr   r   Sobolr  r   r   r  rG   r   stackrR   )r2   r  r  r   r  n_low_discrepancyn_independentrngs
qrng_classry   uniformsrz   r   s                r   r  #UnivariateDistribution._qmc_uniform  s+    ""C3z?3t{{3C#CD/;LO		L*QR.jQ
 $((M2^^
DMM@R@RSdCII&&!YYF6N C131&1Dkk"34Goo<&7RPQSTGOOG$	  =E"++bhhx0"a8"**UW.z**r   c                 
    1 Sk$ )N>   cacheformulageneral	normalize	transform
quadraturerA   r>   s    r   _moment_methods&UnivariateDistribution._moment_methods(  s    6 	6r   c                 (    U R                  5       S   $ r  
_constantsr>   s    r   _zeroUnivariateDistribution._zero-       ##r   c                 (    U R                  5       S   $ r|  r  r>   s    r   _oneUnivariateDistribution._one1  r  r   c                     U R                   b  U R                   $ U R                  SS/5      nU R                  [        :w  a  Xl         U$ Nr   r}   )r&  r  r  r  )r2   	constantss     r   r  !UnivariateDistribution._constants5  sH    +'''''A/		)#, r   c                    U R                   U R                  U R                  S.nU R                  XU5      nXB   nU" XS9$ )NrG  rM  rT  r  )_moment_raw_moment_central_moment_standardizedr  r2   r  r   r  r  moment_kinds         r   rJ  UnivariateDistribution.moment@  sJ    (( 00!%!:!:< ))%u=k500r   c                d    Uc  U R                   OU1nU R                  " U4SU0U R                  D6$ )z)Raw distribution moment about the origin.methods)r  _moment_raw_dispatchr  r2   r  r  r  s       r   r  "UnivariateDistribution._moment_rawI  s8    
 +1.$&&vh((TT4CSCSTTr   c                   S nSU;   a  U R                   R                  US 5      nUc  SU;   a  U R                  " U40 UD6nUc  SU;   a  US:  a  U R                  " U40 UD6nUc  SU;   a  U R                  " U40 UD6nUc%  SU;   a  U R
                  " U4SU R                  0UD6nUc%  SU;   a  U R                  " U4SU R                  0UD6nUb"  U R                  [        :w  a  X@R                   U'   U$ )	Nr  r  r  r}   r  r  centerquadrature_icdf)
r"  rg   _moment_raw_formula_moment_raw_transform_moment_raw_general_moment_from_pxfr  _moment_integrate_icdfr  r  r2   r  r  r   rJ  s        r   r  +UnivariateDistribution._moment_raw_dispatchQ  s   g++//t<F>i72--e>v>F>kW4//@@F>i72--e>v>F>lg5**5NNvNF>/7:00TtzzTVTF$"3"3y"@,2""5)r   c                     g r   rA   r2   r  r   s      r   r  *UnivariateDistribution._moment_raw_formulak      r   c                 (   / n[        [        U5      S-   5       H1  n1 SknU R                  " SXES.UD6nUc    g UR                  U5        M3     1 SknU R                  " U R
                  4SU0UD6nUc  g U R                  XXR                  5      n	U	$ )Nr}   >   r  r  r  r  r  r  >   r  r  r  r  rA   )r   r   _moment_central_dispatchr  r  r  _moment_transform_centerr  )
r2   r  r   central_momentsr   r  moment_imean_methodsr  rJ  s
             r   r  ,UnivariateDistribution._moment_raw_transformn  s    s5zA~&ABG44X1XQWXH""8, ' :((SLSFS<..utZZXr   c                 *    US:X  a  U R                   $ S $ r  )r  r  s      r   r  *UnivariateDistribution._moment_raw_general  s     "QJtyy0D0r   c                d    Uc  U R                   OU1nU R                  " U4SU0U R                  D6$ )z#Distribution moment about the mean.r  )r  r  r  r  s       r   r  &UnivariateDistribution._moment_central  s6    *0.$&&vh,,UXGXtGWGWXXr   c                   S nSU;   a  U R                   R                  US 5      nUc  SU;   a  U R                  " U40 UD6nUc  SU;   a  U R                  " U40 UD6nUc  SU;   a  US:  a  U R                  " U40 UD6nUc  SU;   a  U R
                  " U40 UD6nUcF  SU;   a@  U R                  " U R                  40 UDSU R                  0D6nU R                  " U4S	U0UD6nUcF  S
U;   a@  U R                  " U R                  40 UDSU R                  0D6nU R                  " U4S	U0UD6nUb"  U R                  [        :w  a  X@R                   U'   U$ )Nr  r  r  r  r   r  r  r  r  r  )r#  rg   _moment_central_formula_moment_central_transform_moment_central_normalize_moment_central_generalr  r  r  r  r  r  r  )r2   r  r  r   rJ  r  s         r   r  /UnivariateDistribution._moment_central_dispatch  s   g//33E4@F>i7211%B6BF>kW433EDVDF>kW433EDVDF>i7211%B6BF>lg5,,TYY K& K595I5IKD**5HHHF>/7:,,TYY K& K595I5IKD00NtNvNF$"3"3y"@06&&u-r   c                     g r   rA   r  s      r   r  .UnivariateDistribution._moment_central_formula  r  r   c                 2   / n[        [        U5      S-   5       H1  n1 SknU R                  " SXES.UD6nUc    g UR                  U5        M3     U R                  nU R                  " U R
                  4SU0UD6nU R                  XU R                  U5      n	U	$ )Nr}   >   r  r  r  r  r  rA   )r   r   r  r  r  r  r  r  )
r2   r  r   raw_momentsr   r  r  r  r  rJ  s
             r   r  0UnivariateDistribution._moment_central_transform  s    s5zA~&A5G00TqTVTHx( ' ++((SLSFS..u4::tTr   c                     1 SknU R                   " U40 UDSU0D6nUc  g U R                  " SSU R                  0UD6nXEUS-  -  -  $ )N>   r  r  r  r  r   r   )_moment_standardized_dispatchr  r  )r2   r  r   r  standard_momentvars         r   r   0UnivariateDistribution._moment_central_normalize  sc    1<<U Nf NELN"++Vt7K7KVvVU1W~--r   c                 X    U R                   U R                  S.nUR                  US 5      $ )Nr3  r  r  rg   )r2   r  r   general_central_momentss       r   r  .UnivariateDistribution._moment_central_general  s(    &*iiDJJ"?&**5$77r   c                d    Uc  U R                   OU1nU R                  " U4SU0U R                  D6$ )z!Standardized distribution moment.r  )r  r
  r  r  s       r   r  +UnivariateDistribution._moment_standardized  sC    *0.$&&vh11% F F484D4DF 	Fr   c                |   S nSU;   a  U R                   R                  US 5      nUc  SU;   a  U R                  " U40 UD6nUc  SU;   a  U R                  " US40 UD6nUc  SU;   a  U R                  " U40 UD6nUc  SU;   a  U R                  " US40 UD6nUb"  U R
                  [        :w  a  X@R                   U'   U$ )Nr  r  r  Fr  T)r$  rg   _moment_standardized_formula_moment_standardized_normalize_moment_standardized_generalr  r  r  s        r   r
  4UnivariateDistribution._moment_standardized_dispatch  s    g4488EF>i7266uGGF>kW488PPF>i7266uGGF>kW488OOF$"3"3y"@5;++E2r   c                     g r   rA   r  s      r   r  3UnivariateDistribution._moment_standardized_formula  r  r   c                     U(       a  S1O1 SknU R                   " U40 UDSU0D6nUc  g U R                   " SSU R                  0UD6nXVUS-  -  -  $ )Nr  >   r  r  r  r  r   r	  )r  r  )r2   r  use_quadraturer   r  central_momentr  s          r   r  5UnivariateDistribution._moment_standardized_normalize  st    %3L>9 	66u H H?FH!++ 6t7K7K 6.46E!Gn,,r   c                 n    U R                   U R                  U R                   S.nUR                  US 5      $ )N)r   r}   r   r  )r2   r  r   general_standard_momentss       r   r  3UnivariateDistribution._moment_standardized_general  s.    '+yyTZZDII#N '++E488r   c                 4   ^  U 4S jnT R                  XAU4US9$ )Nc                 >   > TR                   " U 40 UD6nX@U-
  U-  -  $ r   r;  )r   r  r  r   r  r2   s        r   r  :UnivariateDistribution._moment_from_pxf.<locals>.integrand  s*    $$Q1&1C&5(((r   )rx   r   r!  r2   r  r  r   r  s   `    r   r  'UnivariateDistribution._moment_from_pxf  s$    	) 	OOr   c                 6   ^  U 4S jnT R                  USX4US9$ )Nc                 8   > TR                   " U 40 UD6n X-
  U-  $ r   r-  )r   r  r  r   r2   s       r   r  @UnivariateDistribution._moment_integrate_icdf.<locals>.integrand  s%    ##A00AHu$$r   )rE  rF  )r  rx   r   r!  r%  s   `    r   r  -UnivariateDistribution._moment_integrate_icdf  s/    	% 	(&+_V   E 	Er   c                    [         R                  " X4/UQ76 tp4nUn[         R                  " US-   5      R                  S/S/UR                  -  -   5      nU R                  U5      n[        R                  " XV5      n[         R                  " SS9   [         R                  " Xr-  X4-
  XV-
  -  -  SS9nS S S 5        U$ ! , (       d  f       W$ = f)Nr}   r  r  )r  r   r   )
rG   r   aranger   r  r  r   binomr  r   )	r2   r  	moment_asrU   rV   r7   r   
n_choose_imoment_bs	            r   r  /UnivariateDistribution._moment_transform_center  s    ..q@i@yIIacN""B4AFF
?3"]]1(
[[*vvj2AC13<?aHH + +*s   "B==
C)	logcenterrT  c                0   Ub  USL a8  U R                   " U R                  [        R                  * 40 U R                  D6nOS nUc  UOUnU R                   " X40 U R                  D6nU(       a(  U R                   " SU40 U R                  D6nXVUS-  -  -
  nU$ )NTr   )_logmoment_quadr  rG   r   r  )r2   r  r2  rT  logmeanrg  logvars          r   
_logmoment!UnivariateDistribution._logmoment  s     4**499rvvgRAQAQRGG(0Gi	""5Ht7G7GH))!WI8H8HIF%'**C
r   c                 6   ^  U 4S jnT R                  XAU4USS9$ )Nc                 z   > TR                   " U 40 UD6nXA[        [        R                  " U S-   5      U5      -  -   $ r  )r	  r  rG   r&   )r   r  r2  r   r8  r2   s        r   r  <UnivariateDistribution._logmoment_quad.<locals>.logintegrand!  s9    **177FM"&&R.)$LLLLr   T)rx   r   r&   r!  )r2   r  r2  r   r  s   `    r   r4  &UnivariateDistribution._logmoment_quad   s/    	M 93E'-4   9 	9r   )taxc          
          [        U [        5      n1 Skn1 SknUR                  U5      nUR                  1 Sk5      n	U(       a  SOSn
Uc  U
OUnU R                  nXpUc  SOUS   nU R	                  5       u  nn[
        R                  " [
        R                  " U5      5      (       a  SOS	nUc  UOUS
   n[
        R                  " [
        R                  " U5      5      (       a  S
OSnUc  UOUS   n[
        R                  " UU/5      nU(       a  USS2[
        R                  4   OUnSU R                  R                   SU 3nX;  a  [        U5      eSU R                  R                   SU	 3nX;  a  [        U5      eSU R                  R                   SU	 3nX;  a  [        U5      eSU R                  R                   S3nU R                  (       a  [        U5      eSnUS
:  a  [        U5      e SSKJn  Uc  UR#                  5       OUnX;   a  UO[%        U SU-   5      " U5      nSU R                  R                   SSU-    SU SU S3	n[
        R                  " [
        R                  " U5      5      (       d  [        U5      eU(       an  X;   ai  [
        R&                  " [
        R(                  " US   5      [
        R*                  " US
   5      S
-   5      nU(       a  USS2[
        R                  4   OUnOk[
        R,                  " SS
S5      nU(       a  USS2[
        R                  4   OUnUS   US
   US   -
  U-  -   nU(       a  [
        R.                  " U5      OUnX;   a  UO[%        X5      " U5      nX;   a  UO[%        X5      " U5      n[
        R0                  " UR2                  [
        R4                  " UR2                  5      5      u  p[7        X5       H  u  nnU(       aB  X;   a=  US:X  a7  UR9                  UU[
        R:                  " S
UR<                  S   -  5      S9  MO  U(       a9  X;   a4  Un[
        R>                  " UUS   S
-   /45      nURA                  UUSS9  M  URC                  UU5        M     URE                  SU S35        URG                  SU S35        URI                  [K        U 5      5        [M        U RN                  5      (       a  / n U RP                  RR                  n![U        U!5      n"U" V#s/ s H&  n#[
        RV                  " U RN                  U#   5      PM(     n$n#[7        U$6  HX  n%[7        U"U%5       V&V's/ s H  u  n&n'SU!U&   RX                   S U'S! 3PM     n(n&n'U R[                  S"R]                  U(5      5        MZ     UR_                  U 5        U$ ! [          a+  nSU R                  R                   S3n[!        U5      UeSnAff = fs  sn#f s  sn'n&f )#a  Plot a function of the distribution.

Convenience function for quick visualization of the distribution
underlying the random variable.

Parameters
----------
x, y : str, optional
    String indicating the quantities to be used as the abscissa and
    ordinate (horizontal and vertical coordinates), respectively.
    Defaults are ``'x'`` (the domain of the random variable) and either
    ``'pdf'`` (the probability density function) (continuous) or
    ``'pdf'`` (the probability density function) (discrete).
    Valid values are:
    'x', 'pdf', 'pmf', 'cdf', 'ccdf', 'icdf', 'iccdf', 'logpdf', 'logpmf',
    'logcdf', 'logccdf', 'ilogcdf', 'ilogccdf'.
t : 3-tuple of (str, float, float), optional
    Tuple indicating the limits within which the quantities are plotted.
    The default is ``('cdf', 0.0005, 0.9995)`` if the domain is infinite,
    indicating that the central 99.9% of the distribution is to be shown;
    otherwise, endpoints of the support are used where they are finite.
    Valid values are:
    'x', 'cdf', 'ccdf', 'icdf', 'iccdf', 'logcdf', 'logccdf',
    'ilogcdf', 'ilogccdf'.
ax : `matplotlib.axes`, optional
    Axes on which to generate the plot. If not provided, use the
    current axes.

Returns
-------
ax : `matplotlib.axes`
    Axes on which the plot was generated.
    The plot can be customized by manipulating this object.

Examples
--------
Instantiate a distribution with the desired parameters:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy import stats
>>> X = stats.Normal(mu=1., sigma=2.)

Plot the PDF over the central 99.9% of the distribution.
Compare against a histogram of a random sample.

>>> ax = X.plot()
>>> sample = X.sample(10000)
>>> ax.hist(sample, density=True, bins=50, alpha=0.5)
>>> plt.show()

Plot ``logpdf(x)`` as a function of ``x`` in the left tail,
where the log of the CDF is between -10 and ``np.log(0.5)``.

>>> X.plot('x', 'logpdf', t=('logcdf', -10, np.log(0.5)))
>>> plt.show()

Plot the PDF of the normal distribution as a function of the
CDF for various values of the scale parameter.

>>> X = stats.Normal(mu=0., sigma=[0.5, 1., 2])
>>> X.plot('cdf', 'pdf')
>>> plt.show()

>   r   r4  r5  r6  r7  >   r  rD  r  r  >   r9  r;  r8  r:  r;  r9  Nr  r   gMb@?r}   gCl?r   zArgument `t` of `z.plot` "must be one of zArgument `x` of `zArgument `y` of `r   z.plot` was called on a random variable with at least one invalid shape parameters. When a parameter is invalid, no plot can be shown.z^To use `plot`, distribution parameters must be scalars or arrays with one or fewer dimensions.z'`matplotlib` must be installed to use `z.plot`.r   z/.plot` received invalid input for `t`: calling r   z) produced rA  i,  )alphar  )baseline$z$ = z.4gr   )0r   rK  unionr  rN  rG   r  r  rR   newaxisrW   rB   rM  r|  matplotlib.pyplotpyplotModuleNotFoundErrorgcar  r,  r   r   linspacer   r   T
atleast_2dr/  barrQ  r   r   stairsplot
set_xlabel
set_ylabel	set_titler   r   r  r  r^   r$  r  r\   r  r   legend))r2   r   r  r=  r>  rW  t_is_quantilet_is_probabilityvalid_tvalid_xy	y_defaultr  x_namey_namet_namerU   rV   tliml_defaulttlimltlimr_defaulttlimrtlimrk   pltexcqlimqgridxiyir   edgeslabelr^   param_namespnameparam_arrays
param_valsr[   r  assignmentss)                                            r   rN  UnivariateDistribution.plot2  sv   ` d$89E?%%&67MM"DE%E5	Izz)1||~1VVBKKN33!"!VVBKKN33!"!zz5%.)&*tArzzM" 't~~'>'>&? @%%,I/ W%%&t~~'>'>&? @%%-J0!W%%&t~~'>'>&? @%%-J0!W%% t~~../ 0C C W%%E!8W%%	8+
 *SWWY" .tGD#f*4Md4St~~../ 0!&j\4&D6Dvvbkk$'((W%% /		"&&a/266$q'?Q+>?A$(!RZZ- aA;;q!S)D*.42::&DDQ47T!W,44A'QA (Agd.CA.F(Agd.CA.F ""133acc(:;!iFBF3%r2RWWQqwwqz\%:;f5RVAXJ'78		&%$	7B   	&m$
&m$
SY t  E//::Jz*K)46)4 MM$*:*:5*AB)4  6!<0
03K0LN0L94 "#:d#3#:#:";4CyI0L  NTYY{34 1 IIe	u # 	8>>2237<G%g.C7	8d6Ns$   :V= -W5 #W:=
W2&W--W2)r|  rG  r&  rI  r~  r  r#  r"  r$  r  r{  r  r  r  r  rJ  r  r%  rC  rO  r  r  rG  )NNNN)r   )NNNFr   rA   r}   rG  r   )r   N)rB   rC   rD   rE   rF   __array_priority__r  _nullrX   r  r  r  r  r  r  r)  r@  r  r  setterr  rG  r\  r?   rg  rj  rp  rs  r  r  r  r  r  r  r  r  r  r  classmethodr  r  r  r  r  r  rN  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r$  r'  r(  r  r1  r4  r5  r  r  r  r  r  rx  r8  r_  rd  re  r9  rm  rt  ru  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  r  r  r  r  r  r  r>  r  r  r  r  r  r  r  r  r  r"  r#  r=  r  r  r,  r5  r-  r.  rD  r  r?  rB  rC  r?  r  r  rM  rV  rN  rO  r6  r]  rb  rd  re  r4  r.  rt  r}  rv  rw  r7  rj  rc  r  r  r5  r|  ru  r  r  r  r  r  r  r  r  r   r  r  r  r  rJ  r  r  r  r  r  r  r  r  r  r   r  r  r
  r  r  r  r  r  r  r7  r4  rN  rJ   rA   r   r   r  r    s&   Tj  $t$ .& 7; JYX$* >!(F7&5K   	ZZ  " " * * 	' 	' 4 42"289<>M(#-#$U&(8 <@! !$ + + F F 8<%*@ .2$d %NR*T4	> #' Q Q  9*5  $ I I  9D; # H H  92 ! F F  9( " 9 "& = ,0 5 "& B "&, 6Z %) K K ,0  97 "& H H )-  9: %) K K ,0  9; "& H H )-  9:
6T 6 W W 04  9H"

 $( K K ,0 	 	9>79
3$ 3 L L -1  9G	7.R H H )- 	 	9:4/
7d 7 P P 15  9@
 %) L L 	 	9=89
44 4 M M .2  9 I I 	 	9;3/ )- O O  9?W #' I I  95
T *. P P  9>X $( J J  94
UB	34 	3  96+B 6 6 $ $ $ $	 1D 1 1UT U4&1
Y Y
B .8Fd F.	-9PEt% 9$}t } }r   r  c                   Z   ^  \ rS rSrU 4S jrS rS rSS.S jrSS.S jrSS	 jr	S
r
U =r$ )r  i  c                 0   > US;   a  g[         TU ]  U5      $ )N>   r  r  TrP   r  r2   rV  rW   s     r   r  !ContinuousDistribution._overrides      ==w!+..r   c                 .    [         R                  " U5      $ r   )rG   
zeros_likerj  s      r   r  #ContinuousDistribution._pmf_formula  s    }}Qr   c                 N    [         R                  " U[         R                  * 5      $ r   )rG   r  r   rj  s      r   r  &ContinuousDistribution._logpmf_formula  s    ||Aw''r   Nr  c                ,    U R                   " U4SU0UD6$ r^  )rm  rf  s       r   r  $ContinuousDistribution._pxf_dispatch      !!!=F=f==r   c                ,    U R                   " U4SU0UD6$ r^  )r_  rf  s       r   r	  'ContinuousDistribution._logpxf_dispatch      $$Q@v@@@r   c                 6    U R                  XX4S9R                  $ )Nr   r  )r  r   )r2   funcr   r   r  s        r   rn  0ContinuousDistribution._solve_bounded_continuous!  s    ""46"GIIIr   rA   r   )rB   rC   rD   rE   r  r  r  r  r	  rn  rJ   r   r   s   @r   r  r    s3    /
 ( *. > -1 AJ Jr   r  c                      ^  \ rS rSrU 4S jrS rS rSS.S jrSS.S jrU 4S	 jr	U 4S
 jr
U 4S j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 rU 4S jrS rSrU =r$ )rK  i%  c                 0   > US;   a  g[         TU ]  U5      $ )N>   rt  rd  Trw  rx  s     r   r  DiscreteDistribution._overrides&  rz  r   c                 D   U(       aP  [        [        UR                  5       5      5      n[        R                  " U5      [        R                  " U5      -  nO[        R                  " U5      n[        R
                  " U[        R                  [        R                  5      $ r   nextiterr   rG   r   r   r   r   r2   r   r   r   
nan_results        r   rd  $DiscreteDistribution._logpdf_formula+  \    T&--/*+A!rxx{2J!Jxx
BFFBFF33r   c                 D   U(       aP  [        [        UR                  5       5      5      n[        R                  " U5      [        R                  " U5      -  nO[        R                  " U5      n[        R
                  " U[        R                  [        R                  5      $ r   r  r  s        r   rt  !DiscreteDistribution._pdf_formula3  r  r   Nr  c                ,    U R                   " U4SU0UD6$ r^  )r  rf  s       r   r  "DiscreteDistribution._pxf_dispatch;  r  r   c                ,    U R                   " U4SU0UD6$ r^  )r~  rf  s       r   r	  %DiscreteDistribution._logpxf_dispatch>  r  r   c                 N   > [         TU ]  " [        R                  " U5      40 UD6$ r   )rP   r  rG   rQ  r2   r   r   rW   s      r   r  $DiscreteDistribution._cdf_quadratureA  s     w&rxx{=f==r   c                 N   > [         TU ]  " [        R                  " U5      40 UD6$ r   )rP   r  rG   rQ  r  s      r   r  'DiscreteDistribution._logcdf_quadratureD  s     w)"((1+@@@r   c                 T   > [         TU ]  " [        R                  " US-   5      40 UD6$ r|  )rP   rO  rG   rQ  r  s      r   rO  %DiscreteDistribution._ccdf_quadratureG  s$    w'QB6BBr   c                 T   > [         TU ]  " [        R                  " US-   5      40 UD6$ r|  )rP   r.  rG   rQ  r  s      r   r.  (DiscreteDistribution._logccdf_quadratureJ  s$    w*288AE?EfEEr   c                    [        S5      eNzUTwo argument cdf functions are currently only supported for continuous distributions.r/   r  s       r   r  DiscreteDistribution._cdf2M      !() 	)r   c                    [        S5      er  r/   r  s       r   r  DiscreteDistribution._ccdf2R  r  r   c                    [        S5      er  r/   r  s       r   r  DiscreteDistribution._logcdf2W  r  r   c                    [        S5      er  r/   r  s       r   r  DiscreteDistribution._logccdf2\  r  r   c                    U R                  XUSS9n[        R                  " [        R                  " UR                  5      5      nUR
                  S:H  n[        R                  " UR                  U   5      Xg'   U R                  " S0 UD6u  p[        R                  " X(U	5      u  p(n	U" U" U40 UD6U5      nX   Xg'   U$ )N?r  r   rA   )	r  rG   rR   rQ  r  funr   r  r   )
r2   r  r   r   comprg  r   r  r  r  s
             r   _solve_bounded_discrete,DiscreteDistribution._solve_bounded_discretea  s    !!$&!DJJrxx'( ww!|((355;']],V,
++AT:D((!,*r   c                    U R                  X!XCS9nU" U40 UD6n[        R                  " U" Xa5      XUS-   5      n[        R                  U[        R                  " U5      [        R                  " U5      -  '   US   $ )N)r   r  rF  rA   )r  rG   r   r   r   )r2   r   r  r  r   r   ro  rg  s           r   _base_discrete_inversion-DiscreteDistribution._base_discrete_inversionq  sn     (((KfhhtAz1#g. *,BHHQK"((1+%&2wr   c                 Z    U R                   " XR                  [        R                  40 UD6$ r   )r  r  rG   greater_equalrj  s      r   rw  $DiscreteDistribution._icdf_inversion  s1    ,,Q0B0B-/-=-=IAGI 	Ir   c                 Z    U R                   " XR                  [        R                  40 UD6$ r   )r  r  rG   r  rj  s      r   re  'DiscreteDistribution._ilogcdf_inversion  s1    ,,Q0E0E-/-=-=IAGI 	Ir   c                 Z    U R                   " XR                  [        R                  40 UD6$ r   )r  r  rG   
less_equalrj  s      r   r  %DiscreteDistribution._iccdf_inversion  s/    ,,Q0C0C-/]]F>DF 	Fr   c                 Z    U R                   " XR                  [        R                  40 UD6$ r   )r  r  rG   r  rj  s      r   r  (DiscreteDistribution._ilogccdf_inversion  s/    ,,Q0F0F-/]]F>DF 	Fr   c                   > [         T
U ]  " SSS0UD6nU R                  5       u  p4[        R                  " U5      [        R
                  " U5      pe[        R                  " U5      n[        R                  " U[        R                  " SXr-
  5      -   X45      n[        R                  " XXU/5      n[        R                  " U R                  " U40 UD6SS9n	[        R                  " XX/5      $ )Nr  r   r}   r   r   rA   )rP   r5  rN  rG   rQ  ceilr   rT  copysignr  argmaxr  choose)r2   r   r   rY  rZ  r  r  nearestxoidxrW   s             r   r5  'DiscreteDistribution._mode_optimization  s     G&;S;F;LLN	!bggajB((1+ WWWr{{1gk::CFHHbb\"ii**177a@yy2l++r   c                 0   ^  U 4S jnT R                  X!SS9$ )Nc                    > TR                   " U 40 UD6n[        R                  " [        R                  " U5      U[        R                  " U* 5      -   [        R
                  * 5      $ r   )r~  rG   r   r  r&   r   )r   r   r:  r2   s      r   r  ADiscreteDistribution._logentropy_quadrature.<locals>.logintegrand  sK    **177F 88BKK/"&&&/1IBFF7SSr   Tr  r!  )r2   r   r  s   `  r   r  +DiscreteDistribution._logentropy_quadrature  s!    	T FFr   rA   )rB   rC   rD   rE   r  rd  rt  r  r	  r  r  rO  r.  r  r  r  r  r  r  rw  re  r  r  r5  r  rJ   r   r   s   @r   rK  rK  %  s    /
44 *. > -1 A>ACF)
)
)
)
 *IIFF,(	G 	Gr   rK  argusARGUS	betaprime	BetaPrimechi2
ChiSquaredcrystalballCrystalBalldgammaDoubleGammadweibullDoubleWeibullexponExponential	exponnormExponentiallyModifiedNormal	exponweibExponentialWeibullexponpowExponentialPowerfatiguelifeFatigueLife
foldcauchyFoldedCauchyfoldnormFoldedNormalgenlogisticGeneralizedLogisticgennormGeneralizedNormal	genparetoGeneralizedParetogenexponGeneralizedExponential
genextremeGeneralizedExtremeValue
gausshyperGaussHypergeometricgengammaGeneralizedGammagenhalflogisticGeneralizedHalfLogisticgeninvgaussGeneralizedInverseGaussiangumbel_rGumbelgumbel_lReflectedGumbel
halfcauchy
HalfCauchyhalflogisticHalfLogistichalfnorm
HalfNormalhalfgennormHalfGeneralizedNormal	hypsecantHyperbolicSecantinvgammaInverseGammmainvgaussInverseGaussian
invweibullInverseWeibull	irwinhall	IrwinHall	jf_skew_tJonesFaddySkewT	johnsonsb	JohnsonSB	johnsonsu	JohnsonSUksone
KSOneSidedkstwo
KSTwoSided	kstwobignKSTwoSidedAsymptoticlaplace_asymmetricLaplaceAsymmetriclevy_lLevyLeftlevy_stable
LevyStableloggammaExpGamma
loglaplace
LogLaplacelognorm	LogNormal
loguniform
LogUniformncx2NoncentralChiSquarednctNoncentralTnormNormalnorminvgaussNormalInverseGaussianpowerlawPowerLaw	powernormPowerNormalrdistRrel_breitwignerRelativisticBreitWignerrecipinvgaussReciprocalInverseGaussian
reciprocalsemicircularSemiCircular
skewcauchy
SkewCauchyskewnorm
SkewNormalstudentized_rangeStudentizedRanger=  StudentT	trapezoidTrapezoidaltriang
Triangular
truncexponTruncatedExponential	truncnormTruncatedNormaltruncparetoTruncatedParetotruncweibull_minTruncatedWeibulltukeylambdaTukeyLambdavonmises_lineVonMisesLineweibull_minWeibullweibull_maxReflectedWeibull
wrapcauchyWrappedCauchyLine	betabinomBetaBinomial
betanbinomBetaNegativeBinomialdlaplaceLaplaceDiscretegeom	Geometric	hypergeomHypergeometriclogserLogarithmicSeriesnbinomNegativeBinomialnchypergeom_fisherNoncentralHypergeometricFishernchypergeom_wallenius!NoncentralHypergeometricWallenius
nhypergeomNegativeHypergeometricpoisson_binomPoissonBinomialrandintUniformDiscrete	yulesimon	YuleSimonzipfZetac                    U [         R                  [         R                  [         R                  [         R                  [         R
                  [         R                  1;   a  [        SU R                   S35      e[        U [         R                  [         R                  -  5      (       a  [        U 5      $ [        U SS5      S:  a  [        U 5      $ Sn[        U5      e)a|#  Generate a `UnivariateDistribution` class from a compatible object

The argument may be an instance of `rv_continuous` or an instance of
another class that satisfies the interface described below.

The returned value is a `ContinuousDistribution` subclass if the input is an
instance of `rv_continuous` or a `DiscreteDistribution` subclass if the input
is an instance of `rv_discrete`. Like any subclass of `UnivariateDistribution`,
it must be instantiated (i.e. by passing all shape parameters as keyword
arguments) before use. Once instantiated, the resulting object will have the
same interface as any other instance of `UnivariateDistribution`; e.g.,
`scipy.stats.Normal`, `scipy.stats.Binomial`.

.. note::

    `make_distribution` does not work perfectly with all instances of
    `rv_continuous`. Known failures include `levy_stable`, `vonmises`,
    `hypergeom`, 'nchypergeom_fisher', 'nchypergeom_wallenius', and
    `poisson_binom`. Some methods of some distributions will not support
    array shape parameters.

Parameters
----------
dist : `rv_continuous`
    Instance of `rv_continuous`, `rv_discrete`, or an instance of any class with
    the following attributes:

    __make_distribution_version__ : str
        A string containing the version number of SciPy in which this interface
        is defined. The preferred interface may change in future SciPy versions,
        in which case support for an old interface version may be deprecated
        and eventually removed.
    parameters : dict or tuple
        If a dictionary, each key is the name of a parameter,
        and the corresponding value is either a dictionary or tuple.
        If the value is a dictionary, it may have the following items, with default
        values used for entries which aren't present.

        endpoints : tuple, default: (-inf, inf)
            A tuple defining the lower and upper endpoints of the domain of the
            parameter; allowable values are floats, the name (string) of another
            parameter, or a callable taking parameters as keyword only
            arguments and returning the numerical value of an endpoint for
            given parameter values.

        inclusive : tuple of bool, default: (False, False)
            A tuple specifying whether the endpoints are included within the domain
            of the parameter.

        typical : tuple, default: ``endpoints``
            Defining endpoints of a typical range of values of a parameter. Can be
            used for sampling parameter values for testing. Behaves like the
            ``endpoints`` tuple above, and should define a subinterval of the
            domain given by ``endpoints``.

        A tuple value ``(a, b)`` associated to a key in the ``parameters``
        dictionary is equivalent to ``{endpoints: (a, b)}``.

        Custom distributions with multiple parameterizations can be defined by
        having the ``parameters`` attribute be a tuple of dictionaries with
        the structure described above. In this case, ``dist``'s class must also
        define a method ``process_parameters`` to map between the different
        parameterizations. It must take all parameters from all parameterizations
        as optional keyword arguments and return a dictionary mapping parameters to
        values, filling in values from other parameterizations using values from
        the supplied parameterization. See example.

    support : dict or tuple
        A dictionary describing the support of the distribution or a tuple
        describing the endpoints of the support. This behaves identically to
        the values of the parameters dict described above, except that the key
        ``typical`` is ignored.

    The class **must** also define a ``pdf`` method and **may** define methods
    ``logentropy``, ``entropy``, ``median``, ``mode``, ``logpdf``,
    ``logcdf``, ``cdf``, ``logccdf``, ``ccdf``,
    ``ilogcdf``, ``icdf``, ``ilogccdf``, ``iccdf``,
    ``moment``, and ``sample``.
    If defined, these methods must accept the parameters of the distribution as
    keyword arguments and also accept any positional-only arguments accepted by
    the corresponding method of `ContinuousDistribution`.
    When multiple parameterizations are defined, these methods must accept
    all parameters from all parameterizations. The ``moment`` method
    must accept the ``order`` and ``kind`` arguments by position or keyword, but
    may return ``None`` if a formula is not available for the arguments; in this
    case, the infrastructure will fall back to a default implementation. The
    ``sample`` method must accept ``shape`` by position or keyword, but contrary
    to the public method of the same name, the argument it receives will be the
    *full* shape of the output array - that is, the shape passed to the public
    method prepended to the broadcasted shape of random variable parameters.

Returns
-------
CustomDistribution : `UnivariateDistribution`
    A subclass of `UnivariateDistribution` corresponding with `dist`. The
    initializer requires all shape parameters to be passed as keyword arguments
    (using the same names as the instance of `rv_continuous`/`rv_discrete`).

Notes
-----
The documentation of `UnivariateDistribution` is not rendered. See below for
an example of how to instantiate the class (i.e. pass all shape parameters of
`dist` to the initializer as keyword arguments). Documentation of all methods
is identical to that of `scipy.stats.Normal`. Use ``help`` on the returned
class or its methods for more information.

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

Create a `ContinuousDistribution` from `scipy.stats.loguniform`.

>>> LogUniform = stats.make_distribution(stats.loguniform)
>>> X = LogUniform(a=1.0, b=3.0)
>>> np.isclose((X + 0.25).median(), stats.loguniform.ppf(0.5, 1, 3, loc=0.25))
np.True_
>>> X.plot()
>>> sample = X.sample(10000, rng=np.random.default_rng())
>>> plt.hist(sample, density=True, bins=30)
>>> plt.legend(('pdf', 'histogram'))
>>> plt.show()

Create a custom distribution.

>>> class MyLogUniform:
...     @property
...     def __make_distribution_version__(self):
...         return "1.16.0"
...
...     @property
...     def parameters(self):
...         return {'a': {'endpoints': (0, np.inf),
...                       'inclusive': (False, False)},
...                 'b': {'endpoints': ('a', np.inf),
...                       'inclusive': (False, False)}}
...
...     @property
...     def support(self):
...         return {'endpoints': ('a', 'b'), 'inclusive': (True, True)}
...
...     def pdf(self, x, a, b):
...         return 1 / (x * (np.log(b)- np.log(a)))
>>>
>>> MyLogUniform = stats.make_distribution(MyLogUniform())
>>> Y = MyLogUniform(a=1.0, b=3.0)
>>> np.isclose(Y.cdf(2.), X.cdf(2.))
np.True_

Create a custom distribution with variable support.

>>> class MyUniformCube:
...     @property
...     def __make_distribution_version__(self):
...         return "1.16.0"
...
...     @property
...     def parameters(self):
...         return {"a": (-np.inf, np.inf),
...                 "b": {'endpoints':('a', np.inf), 'inclusive':(True, False)}}
...
...     @property
...     def support(self):
...         def left(*, a, b):
...             return a**3
...
...         def right(*, a, b):
...             return b**3
...         return (left, right)
...
...     def pdf(self, x, *, a, b):
...         return 1 / (3*(b - a)*np.cbrt(x)**2)
...
...     def cdf(self, x, *, a, b):
...         return (np.cbrt(x) - a) / (b - a)
>>>
>>> MyUniformCube = stats.make_distribution(MyUniformCube())
>>> X = MyUniformCube(a=-2, b=2)
>>> Y = stats.Uniform(a=-2, b=2)**3
>>> X.support()
(-8.0, 8.0)
>>> np.isclose(X.cdf(2.1), Y.cdf(2.1))
np.True_

Create a custom distribution with multiple parameterizations. Here we create a
custom version of the beta distribution that has an alternative parameterization
in terms of the mean ``mu`` and a dispersion parameter ``nu``.

>>> class MyBeta:
...     @property
...     def __make_distribution_version__(self):
...         return "1.16.0"
...
...     @property
...     def parameters(self):
...         return ({"a": (0, np.inf), "b": (0, np.inf)},
...                 {"mu": (0, 1), "nu": (0, np.inf)})
...
...     def process_parameters(self, a=None, b=None, mu=None, nu=None):
...         if a is not None and b is not None:
...             nu = a + b
...             mu = a / nu
...         else:
...             a = mu * nu
...             b = nu - a
...         return dict(a=a, b=b, mu=mu, nu=nu)
...
...     @property
...     def support(self):
...         return {'endpoints': (0, 1)}
...
...     def pdf(self, x, a, b, mu, nu):
...         return special._ufuncs._beta_pdf(x, a, b)
...
...     def cdf(self, x, a, b, mu, nu):
...         return special.betainc(a, b, x)
>>>
>>> MyBeta = stats.make_distribution(MyBeta())
>>> X = MyBeta(a=2.0, b=2.0)
>>> Y = MyBeta(mu=0.5, nu=4.0)
>>> np.isclose(X.pdf(0.3), Y.pdf(0.3))
np.True_

r   z` is not supported.__make_distribution_version__z0.0.0z1.16.0zThe argument must be an instance of `rv_continuous`, `rv_discrete`, or an instance of a class with attribute `__make_distribution_version__ >= 1.16`.)r   r   vonmisesrd  rj  rl  rp  r0   r[   r   rv_continuousrv_discrete_make_distribution_rv_genericr  _make_distribution_customrM  )r  rk   s     r   r    r      s    F !!5>>5??((%*E*E##% % "Adii[0C"DEE$++e.?.??@@,T22	6	@H	L(..> !!r   c                   ^ ^^^^ / m/ n[        T ST R                  T R                  45      nT R                  5        Ha  n[	        UR
                  UR                  S9n[        UR                  US9nTR                  U5        UR                  UR                  5        Mc     [        R                  T R                  T R                  R                  5       5      m[        T [        R                  5      (       a  [        R                  [         smnO[        R"                  [$        smnU U4S jnU" S5      (       a  U 4S jnU 4S jn	X4n
OUn
[	        U
SS9n[        S	US
S9m " UUU4S jSU5      nS/S S.U 4S jjjnU 4S jnU 4S jnU 4S jnU 4S jnSSSSSSSSSSSSS .nS!S"S#10nUR'                  5        Hm  u  nnT R                  U;   a  UUT R                     ;   a  M+  [        T R(                  US 5      n[        TUS 5      nUULd  MV  [+        UU[        T U5      5        Mo     U" S$5      (       a  Xl        U" S%5      (       a  Xl        U" S&5      (       a!  UUl        U" S$5      (       d  Xl        UUl        [5        US'S(9R7                  5       nS)T R                   S*U S+3S,T S+3S-U 3/nS.R9                  U5      Ul        U$ )0Nr  rS   rT   r   c                 L   > [        TR                  U S 5      [        TU S 5      L$ r   )r  rW   )rV  r  	old_classs    r   r  1_make_distribution_rv_generic.<locals>._overrides  s)    T:y+t<= 	>r   _get_supportc                  ^   > TR                   " S0 U D6u  p[        R                  " U5      S   $ rO   r  rG   rR   )ri   rU   r  r  s      r   r   +_make_distribution_rv_generic.<locals>.left  ,    $$8'78DA::a=$$r   c                  ^   > TR                   " S0 U D6u  p[        R                  " U5      S   $ rO   r  )ri   r  rV   r  s      r   r   ,_make_distribution_rv_generic.<locals>.right   r  r   TTr   )r  r}   r   r   c                   b   >^  \ rS rSr Y(       a  \"  Y6 /O/ r YrU U4S jrU U4S jrSr	U =r
$ )9_make_distribution_rv_generic.<locals>.CustomDistributioni+  c                 D   > [         TU ]  5       nUR                  ST5      $ NCustomDistributionrP   r\  r  r2   srW   repr_strs     r   r\  B_make_distribution_rv_generic.<locals>.CustomDistribution.__repr__0  "     "A9918<<r   c                 D   > [         TU ]  5       nUR                  ST5      $ r  rP   r?   r  r  s     r   r?   A_make_distribution_rv_generic.<locals>.CustomDistribution.__str__4  !    !A9918<<r   rA   )rB   rC   rD   rE   r  r  rO  r\  r?   rJ   r   )rW   _x_paramr^   r  s   @r   r  r  +  s-    BL0*=>#% 			=	= 	=r   r  r   c                ,   > TR                   " SXS.UD6$ )N)r   random_staterA   )_rvs)r2   r  rz   ry   r  s       r   r  6_make_distribution_rv_generic.<locals>._sample_formula8  s    yyEjEfEEr   c                 <   > TR                   " [        U5      40 UD6$ r   )_munpr   r2   r  ry   r  s      r   r  :_make_distribution_rv_generic.<locals>._moment_raw_formula;  s    zz#e*///r   c                 <   > US:w  a  g TR                   " S0 UD6S   $ )Nr}   r   rA   _statsr  s      r   _moment_raw_formula_1<_make_distribution_rv_generic.<locals>._moment_raw_formula_1>  $    A:{{$V$Q''r   c                 <   > US:w  a  g TR                   " S0 UD6S   $ )Nr   r}   rA   r  r  s      r   r  >_make_distribution_rv_generic.<locals>._moment_central_formulaC  r  r   c                   > US:X  a7  TR                   (       a  SUS'   TR                  " S0 UD6[        US-
  5         $ US:X  aA  TR                   (       a  SUS'   TR                  " S0 UD6[        US-
  5         nUc  U$ US-   $ g )Nr   r  momentsr}   r  r[  rA   )_stats_has_momentsr  r   )r2   r  ry   r[  r  s       r   _moment_standard_formula?_make_distribution_rv_generic.<locals>._moment_standard_formulaH  s    A:&&$'y!;;((UQY88aZ&&$'y!%f%c%!)n5A	1,q1u,r   rd  rt  r  r  r  r  r  r  rt  ru  r  r'  )_logpdf_pdf_logpmf_pmf_logcdf_cdf_logsf_sf_ppf_isf_entropy_medianr0  r  r  r  r  r  Fr  z#This class represents `scipy.stats.z` as a subclass of `z`.z(The `repr`/`str` of class instances is `'The PDF of the distribution is defined r  ro  )r  rU   rV   _shape_infor   rS   rT   r  r[   r  _distribution_namesrg   
capitalizer   r   r{  r  r|  rK  r!  rW   r  r  r  r  r  r  r  r   rF   )r  r  rN  
shape_infor   r_   	new_classr  r   r   rS   
_x_supportr  r  r  r  r  r  r  skip_override
old_method
new_methodr  r  support_etcdocsr  r  r^   r  s   `                         @@@@r   r}  r}    s   JEdJ(89G&&(
)=)='1';';=zv>% Z__% ) #&&tyy$))2F2F2HIH$++,,$224J	9$002F	9> .!!	%	% M		lKJc*gFH= =Y =FD F F0(
(
 ,%+%+%+%&'-+-G $eV_5M")--/
J99%*dii8P*PT:y*d;%&
GD*4MN #2 '1D.&-<*(:R7'""5J29P6 2UKRRTK
-dii[ 9;b	
28*B?
1+?	D #'))D/r   c                 b    [        U [        5      (       a  SU 0OU nUR                  SS 5      nX4$ )NrS   r   )r   r   pop)rZ  domain_infor   s      r   _get_domain_infor    s3    )3D%)@)@;%dKooi.Gr   c           	        ^ ^^^ [        T R                  [        5      (       a  T R                  OT R                  4n/ mU Hq  n/ nUR                  5        H8  u  pE[	        U5      u  pg[        S0 UD6n[        XHUS9n	UR                  U	5        M:     TR                  U(       a  [        U6 O/ 5        Ms     [	        T R                  5      u  pj[        S0 UD6n[        SUS9mT R                  R                  m " UUU4S jS[        5      n1 SknU H2  n[        T U5      (       d  M  SU S3n[        X[        T U5      5        M4     [        T S	5      (       a'  U 4S
 jnU 4S jnU 4S jnUUl        UUl        UUl        [        T S5      (       a  [        US[        T S5      5        ['        USS9R)                  5       nST S3SU 3/nSR+                  U5      Ul        U$ )Nr  r   r  c                   F   >^  \ rS rSr Yr YrU U4S jrU U4S jrSrU =r	$ )5_make_distribution_custom.<locals>.CustomDistributioni  c                 D   > [         TU ]  5       nUR                  ST5      $ r  r  r  s     r   r\  >_make_distribution_custom.<locals>.CustomDistribution.__repr__  r  r   c                 D   > [         TU ]  5       nUR                  ST5      $ r  r  r  s     r   r?   =_make_distribution_custom.<locals>.CustomDistribution.__str__  r  r   rA   )
rB   rC   rD   rE   r  rO  r\  r?   rJ   r   )rW   r  r  r  s   @r   r  r    s    .		=	= 	=r   r  >   r  r9  rD  cdf2r4  r  ccdf2r5  r  r8  r  r  r  r6  r  logcdf2r7  logccdf2r  r  _formularJ  c                 .   > TR                   " U4SS0UD6$ )Nr   rG  rI  r  s      r   r  6_make_distribution_custom.<locals>._moment_raw_formula  s    ;;u;5;F;;r   c                 .   > TR                   " U4SS0UD6$ )Nr   rM  rI  r  s      r   r  :_make_distribution_custom.<locals>._moment_central_formula  s    ;;u?9???r   c                 .   > TR                   " U4SS0UD6$ )Nr   rT  rI  r  s      r   r  ?_make_distribution_custom.<locals>._moment_standardized_formula  s    ;;uD>DVDDr   process_parametersr  Fr  zThis class represents `z,` as a subclass of `ContinuousDistribution`.r  r  rA   )r   r^   r   r!  r  r   r  r  r  rN  rW   rB   r  r  r  r  r  r  r  r  r  r   rF   )r  dist_parametersr  r^   r[   rZ  r  r   r   r_   r  r  r  r  r  r  r  r  r  r  r  r  r  r  s   `                    @@@r   r~  r~    s   %doou==DOOCV  + 
*002JD#3D#9 K"1[1F"4HEe$	 3
 	  :!2J!?SUV , &dll3NK--Jc*5H~~&&H
= 
=3 
=7G 4  VHH-J&GD&4IJ	  tX	<	@	E 2E.5L2:V7t)**!D./	
   2UKRRTK
!( ,$ 	$
1+?D
 #'))D/r   c                    ^  U 4S jnU$ )Nc                  > TR                   n[        U R                  U5      n	U R                  XU5      n
U R                  X#U5      nU	" X/UQ70 UD6nU	" X/UQ70 UD6n[        R
                  " [        R                  " X\U5      5      S   $ rO   )rB   r  _dist
_transformrG   real_if_closer   )r2   r   r  rc  rn  r}  rx   ry   rn   ro  xtytfxyfyxr  s                 r   r  8_shift_scale_distribution_function_2arg.<locals>.wrapped  s    }}DJJ% __QU+__QU+((((((C 89"==r   rA   )r  r  s   ` r   '_shift_scale_distribution_function_2argr    s    > Nr   c                 &   ^ ^ SSSSS.mUU 4S jnU$ )Nr  r  r  r  )r  r  r  r  c                  > TR                   n[        U R                  U5      n[        U R                  TU   5      n	U R                  XU5      n
U" U
/UQ70 UD6nU	" U
/UQ70 UD6n[        R
                  " XKU5      S   $ rO   )rB   r  r  r  rG   r   )r2   r   rc  rn  r}  rx   ry   rn   ro  cfr  fxcfxcitemr  s                r   r  3_shift_scale_distribution_function.<locals>.wrapped   s    }}DJJ%TZZt- __QU+r#D#F#%d%f%xx#&r**r   rA   r  r  r  s   ` @r   "_shift_scale_distribution_functionr    s"    !4."4.0E+ Nr   c                 &   ^ ^ SSSSS.mUU 4S jnU$ )Nrj  r|  r]  r.  )r]  r.  rj  r|  c                  > TR                   n[        U R                  U5      n[        U R                  TU   5      n	U R                  U" U/UQ70 UD6X#5      n
U R                  U	" U/UQ70 UD6X#5      n[        R
                  " XJU5      S   $ rO   )rB   r  r  _itransformrG   r   )r2   r   rc  rn  r}  rx   ry   rn   ro  r  r  r  r  r  s               r   r  ._shift_scale_inverse_function.<locals>.wrapped  s    }}DJJ%TZZt- q4T4V4cAr!5d5f5sBxx#&r**r   rA   r  s   ` @r   _shift_scale_inverse_functionr    s"    "60#6 02E
+ Nr   c                   f   ^  \ rS rSrU 4S jrU 4S jrU 4S jrSS.U 4S jjrS rS	 r	S
 r
SrU =r$ )TransformedDistributioni#  c                p  > [        U[        5      (       d  Sn[        U5      eU R                  5         UR                  U l        Xl        UR                  (       a  UR                  R                  n[        U5      nU R                  (       d#  U R                  R                  [        5       5        U R                   Hf  nUR                  UR                  5      (       a(  SU SU R                  R                   S3n[        U5      eUR                  R!                  U5        Mh     ["        TU ]H  " U0 UD6  g )Nz@Transformations are currently only supported for continuous RVs.z!One or more of the parameters of z% has the same name as a parameter of z;. Name collisions create ambiguities and are not supported.)r   r  r0   r@  rO  r  r  r^   r  r  r  r  intersectionrW   rB   rM  r]   rP   rX   )	r2   r  rx   ry   rk   r  
set_paramsr  rW   s	           r   rX    TransformedDistribution.__init__$  s   !344XG%g..##%
11<<O_-J**''../@/BC$($;$; **+;+F+FGG!B1# FB"&.."9"9!: ;K KG %W-- ++22?C %< 	$)&)r   c                 f   > U R                   R                  U5      =(       d    [        TU ]  U5      $ r   )r  r  rP   rx  s     r   r  "TransformedDistribution._overrides;  s,    

%%k2 37%k2	4r   c                 V   > U R                   R                  5         [        TU ]  5         g r   )r  r  rP   )r2   rW   s    r   r  #TransformedDistribution.reset_cache?  s    

 r   Nr	  c                   > 0 nUR                  U R                  R                  5        UR                  U5        [        TU ]  " SSU0UD6  g )NrG  rA   )r]   r  r  rP   r  )r2   rG  r   r^   rW   s       r   r  *TransformedDistribution._update_parametersC  sF    

 	$**99:&!"U5FU*Ur   c                 :    U R                   R                  " S0 UD6$ rO   )r  r  r9  s     r   r  +TransformedDistribution._process_parametersN  s    zz--777r   c                     [        5       er   r/   r>   s    r   r\   TransformedDistribution.__repr__Q      !##r   c                     [        5       er   r/   r>   s    r   r?   TransformedDistribution.__str__T  r  r   )r  rO  )rB   rC   rD   rE   rX   r  r  r  r  r\  r?   rJ   r   r   s   @r   r  r  #  s7    *.4 7; 	V 	V8$$ $r   r  c                   ,  ^  \ rS rSrSr\" \* S4SS9r\" SS\SS	9r	\" S\4S
S9r
\" SS\
SS	9r\" \	\5      \" \	5      \" \5      /r\R                  * \R                  S.U 4S jjrSS jrS rS rS rS rS rS rS rS rS rS rS rS rSrU =r$ )TruncatedDistributioniX  zTruncated distribution.ub)TFr  lbb_l)皙?g?r\   r   r   )FTb_u)g?r  r  r  c               0   > [         TU ]  " U/UQ7X#S.UD6$ )Nr  rP   rX   )r2   r  r  r  rx   ry   rW   s         r   rX   TruncatedDistribution.__init__k  s"    wADARA&AAr   c           
         Ub  UO([         R                  " U[         R                  * 5      S   nUb  UO'[         R                  " U[         R                  5      S   nU R                  R                  " S0 UD6nU R
                  " SXS.UD6u  pVU R                  R                  " XV40 UD6nUR                  [        XXVUS95        U$ )NrA   r  )r  r  _a_blogmass)	rG   r  r   r  r  r  r  r]   r  )r2   r  r  r   r^   rU   rV   r  s           r   r  )TruncatedDistribution._process_parametersn  s    >Rr||B'@'D>Rr||B'?'CZZ33=f=
}}88Z8**..qBzB$"IJr   c                     U R                   R                  " S0 UD6u  pE[        R                  " XA5      [        R                  " XR5      4$ rO   )r  r  rG   r  r  )r2   r  r  r   rU   rV   s         r   r  TruncatedDistribution._supportw  s8    zz"",V,zz! "**Q"333r   c                     gNFrA   r2   rV  s     r   r   TruncatedDistribution._overrides{  s    r   c                J    U R                   R                  " U/UQ70 UD6n	X-
  $ r   )r  r_  )
r2   r   r  r  r  r  r  rx   r   r8  s
             r   r_  &TruncatedDistribution._logpdf_dispatch~  s)    ,,Q@@@r   c                J    U R                   R                  " XA/UQ70 UD6n	X-
  $ r   r  r  )
r2   r   r  r  r  r  r  rx   r   r  s
             r   r  &TruncatedDistribution._logcdf_dispatch  s)    --bEdEfEr   c                J    U R                   R                  " X/UQ70 UD6n	X-
  $ r   r)  )
r2   r   r  r  r  r  r  rx   r   r  s
             r   r  'TruncatedDistribution._logccdf_dispatch  s)    **..qFtFvF  r   c                J    U R                   R                  " X/UQ70 U	D6n
X-
  $ r   r)  )r2   r   r  r  r  r  r  r  rx   r   r  s              r   r  'TruncatedDistribution._logcdf2_dispatch  s)    **..qEdEfE  r   c                    U R                   R                  " U/UQ70 UD6n	[        R                  " XU-   5      n
U R                   R                  " U
/UQ70 UD6$ r   )r  r  rG   r  r]  )r2   r_  r  r  r  r  r  rx   r   log_Falogp_adjusteds              r   r]  'TruncatedDistribution._ilogcdf_dispatch  sQ    ,,RA$A&AVG^<zz++MKDKFKKr   c                    U R                   R                  " U/UQ70 UD6n	[        R                  " XU-   5      n
U R                   R                  " U
/UQ70 UD6$ r   )r  r  rG   r  rj  )r2   r_  r  r  r  r  r  rx   r   log_cFbr1  s              r   rj  (TruncatedDistribution._ilogccdf_dispatch  sQ    **..rCDCFCWWn=zz,,]LTLVLLr   c                    U R                   R                  " U/UQ70 UD6n	X[        R                  " U5      -  -   n
U R                   R                  " U
/UQ70 UD6$ r   )r  r  rG   r%   r.  )r2   r   r  r  r  r  r  rx   r   Fa
p_adjusteds              r   r.  $TruncatedDistribution._icdf_dispatch  sT    ZZ%%b:4:6:BFF7O++
zz((EdEfEEr   c                    U R                   R                  " U/UQ70 UD6n	X[        R                  " U5      -  -   n
U R                   R                  " U
/UQ70 UD6$ r   )r  r  rG   r%   r|  )r2   r   r  r  r  r  r  rx   r   cFbr8  s              r   r|  %TruncatedDistribution._iccdf_dispatch  sT    jj''<T<V<RVVG_,,
zz))*FtFvFFr   c           	          [         R                  " SS9   S[        U R                  5       S[        U R                  5       S[        U R
                  5       S3sS S S 5        $ ! , (       d  f       g = fNrT  rU  z	truncate(z, lb=z, ub=r   )rG   rW  r  r  r  r  r>   s    r   r\  TruncatedDistribution.__repr__  sR    __r*TZZ 01 2tww-d477m_A? +**   AA$$
A2c           	          [         R                  " SS9   S[        U R                  5       S[        U R                  5       S[        U R
                  5       S3sS S S 5        $ ! , (       d  f       g = fr>  )rG   rW  r   r  r  r  r>   s    r   r?   TruncatedDistribution.__str__  sQ    __r*DJJ0 1dgg,uS\N!= +**r@  rA   NN)rB   rC   rD   rE   rF   r   r   
_lb_domainr  	_lb_param
_ub_domain	_ub_paramr  r  rG   rX   r  r  r  r_  r  r  r  r]  rj  r.  r|  r\  r?   rJ   r   r   s   @r   r  r  X  s    ! 3$OJtF'1:GI $NJtF)3ZII ,IyA+I6+I68 )+w266 B B4  
!!L
M
F
G
@
> >r   r  c                     [        XUS9$ )a  Truncate the support of a random variable.

Given a random variable `X`, `truncate` returns a random variable with
support truncated to the interval between `lb` and `ub`. The underlying
probability density function is normalized accordingly.

Parameters
----------
X : `ContinuousDistribution`
    The random variable to be truncated.
lb, ub : float array-like
    The lower and upper truncation points, respectively. Must be
    broadcastable with one another and the shape of `X`.

Returns
-------
X : `ContinuousDistribution`
    The truncated random variable.

References
----------
.. [1] "Truncated Distribution". *Wikipedia*.
       https://en.wikipedia.org/wiki/Truncated_distribution

Examples
--------
Compare against `scipy.stats.truncnorm`, which truncates a standard normal,
*then* shifts and scales it.

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy import stats
>>> loc, scale, lb, ub = 1, 2, -2, 2
>>> X = stats.truncnorm(lb, ub, loc, scale)
>>> Y = scale * stats.truncate(stats.Normal(), lb, ub) + loc
>>> x = np.linspace(-3, 5, 300)
>>> plt.plot(x, X.pdf(x), '-', label='X')
>>> plt.plot(x, Y.pdf(x), '--', label='Y')
>>> plt.xlabel('x')
>>> plt.ylabel('PDF')
>>> plt.title('Truncated, then Shifted/Scaled Normal')
>>> plt.legend()
>>> plt.show()

However, suppose we wish to shift and scale a normal random variable,
then truncate its support to given values. This is straightforward with
`truncate`.

>>> Z = stats.truncate(scale * stats.Normal() + loc, lb, ub)
>>> Z.plot()
>>> plt.show()

Furthermore, `truncate` can be applied to any random variable:

>>> Rayleigh = stats.make_distribution(stats.rayleigh)
>>> W = stats.truncate(Rayleigh(), lb=0.5, ub=3)
>>> W.plot()
>>> plt.show()

r  )r  )r  r  r  s      r   r#   r#     s    z !b11r   c                   H   \ rS rSrSr\" \* \4SS9r\" SS\SS9r	\" \* \4SS9r
\" S	S
\
SS9r\" \	\5      \" \	5      \" \5      /rS3S 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S.S j5       r\SS.S j5       r \SS.S  j5       r!\SS.S! j5       r"\#SS.S" j5       r$\#SS.S# j5       r%\#SS.S$ j5       r&\#SS.S% j5       r'\(SS.S& j5       r)\(SS.S' j5       r*\(SS.S( j5       r+\(SS.S) j5       r,S* r-S+ r.S, r/S- r0S. r1S/ r2S0 r3S1 r4S2r5g)4re  i  z8Distribution with a standard shift/scale transformation.r  r  rc  z\mur}   r   r  rn  z\sigma)r  rT  Nc                     Ub  UO[         R                  " U5      S   nUb  UO[         R                  " U5      S   nUS:  nU R                  R                  " S0 UD6nUR                  [        XUS95        U$ )NrA   r   rc  rn  r}  )rG   r|  r  r  r  r]   r  )r2   rc  rn  r   r}  r^   s         r   r  -ShiftedScaledDistribution._process_parameters  sp    _c"--*>r*B*S0A"0EqyZZ33=f=
$3$?@r   c                     X-
  U-  $ r   rA   r2   r   rc  rn  ry   s        r   r  $ShiftedScaledDistribution._transform  s    r   c                     X-  U-   $ r   rA   rO  s        r   r  %ShiftedScaledDistribution._itransform  s    y3r   c                     U R                   R                  " S0 UD6u  pVU R                  XQU5      U R                  XaU5      pe[        R                  " X5U5      S   [        R                  " X6U5      S   4$ rO   )r  r  r  rG   r   )r2   rc  rn  r}  r   rU   rV   s          r   r  "ShiftedScaledDistribution._support  sg    zz"",V,.0@0@0O1xx#B'$1)=b)AAAr   c                 \   [         R                  " SS9   [        U R                  5       S[        U R                  5       3nU R
                  R                  (       d-  U R
                  S:  a  US[        U R
                  * 5       3-  nO[         R                  " U R
                  S:g  5      (       dD  [         R                  " U R
                  R                  U R                  R                  5      (       d  US[        U R
                  5       3-  nS S S 5        U$ ! , (       d  f       W$ = fNrT  rU  *r   z - z + )
rG   rW  r  rn  r  rc  r  rP  can_castr  r2   results     r   r\  "ShiftedScaledDistribution.__repr__  s    __r*djj)*!D,<+=>F88==TXX\CdhhY011&&Q''TXX^^TZZ5E5EFF CTXX/00 +  +*    C=D
D+c                 \   [         R                  " SS9   [        U R                  5       S[        U R                  5       3nU R
                  R                  (       d-  U R
                  S:  a  US[        U R
                  * 5       3-  nO[         R                  " U R
                  S:g  5      (       dD  [         R                  " U R
                  R                  U R                  R                  5      (       d  US[        U R
                  5       3-  nS S S 5        U$ ! , (       d  f       W$ = frV  )
rG   rW  r   rn  r  rc  r  rP  rX  r  rY  s     r   r?   !ShiftedScaledDistribution.__str__  s    __r*TZZ)3tzz?*;<F88==TXX\CTXXI/00&&Q''TXX^^TZZ5E5EFF CDHH// +  +* r\  c                    U R                   R                  " U0 UD6[        R                  " [        R                  " U5      5      -   $ r   )r  r  rG   r&   r$   )r2   rc  rn  r}  rx   r   s         r   r  +ShiftedScaledDistribution._entropy_dispatch6  s7    

,,d=f=&&'( 	)r   c                   U R                   R                  " U0 UD6n[        R                  " [        R                  " [        R                  " U5      5      S-   5      n[
        R                  " [        R                  " Xg5      SS9$ )Nr  r   r   )r  r  rG   r&   r$   r   r  r   )r2   rc  rn  r}  rx   r   lH0llss           r   r  .ShiftedScaledDistribution._logentropy_dispatch:  s]    jj--t>v>ffRVVBFF5M*2-.  !4!4S!>QGGr   c                b    U R                   R                  " SSU0UD6nU R                  XbU5      $ r  )r  r$  r  r2   r  rc  rn  r}  r   rG  s          r   r$  *ShiftedScaledDistribution._median_dispatch?  s1    jj))BB6B%00r   c                b    U R                   R                  " SSU0UD6nU R                  XbU5      $ r  )r  r1  r  rf  s          r   r1  (ShiftedScaledDistribution._mode_dispatchC  s1    jj''@v@@%00r   c                    U R                  XU5      nU R                  R                  " U/UQ70 UD6nU[        R                  " [        R
                  " U5      5      -
  $ r   )r  r  r_  rG   r&   r$   )r2   r   rc  rn  r}  rx   r   r8  s           r   r_  *ShiftedScaledDistribution._logpdf_dispatchG  L    OOAE*,,Q@@@rvve}---r   c                    U R                  XU5      nU R                  R                  " U/UQ70 UD6nU[        R                  " U5      -  $ r   )r  r  rm  rG   r$   )r2   r   rc  rn  r}  rx   r   r9  s           r   rm  'ShiftedScaledDistribution._pdf_dispatchL  C    OOAE*jj&&q:4:6:RVVE]""r   c                    U R                  XU5      nU R                  R                  " U/UQ70 UD6nU[        R                  " [        R
                  " U5      5      -
  $ r   )r  r  r~  rG   r&   r$   )r2   r   rc  rn  r}  rx   r   r:  s           r   r~  *ShiftedScaledDistribution._logpmf_dispatchQ  rl  r   c                    U R                  XU5      nU R                  R                  " U/UQ70 UD6nU[        R                  " U5      -  $ r   )r  r  r  rG   r$   )r2   r   rc  rn  r}  rx   r   r;  s           r   r  'ShiftedScaledDistribution._pmf_dispatchV  ro  r   c                    U R                  XU5      nU R                  R                  " U/UQ70 UD6nU[        R                  " [        R
                  " U5      5      -
  $ r   )r  r  r	  rG   r&   r$   )r2   r   rc  rn  r}  rx   r   r
  s           r   r	  *ShiftedScaledDistribution._logpxf_dispatch[  rl  r   c                    U R                  XU5      nU R                  R                  " U/UQ70 UD6nU[        R                  " U5      -  $ r   )r  r  r  rG   r$   )r2   r   rc  rn  r}  rx   r   r  s           r   r  'ShiftedScaledDistribution._pxf_dispatch`  ro  r   r  c                    g r   rA   rf  s       r   r  *ShiftedScaledDistribution._logcdf_dispatchf      r   c                    g r   rA   rf  s       r   r  'ShiftedScaledDistribution._cdf_dispatchj  rz  r   c                    g r   rA   rf  s       r   r  +ShiftedScaledDistribution._logccdf_dispatchn  rz  r   c                    g r   rA   rf  s       r   r  (ShiftedScaledDistribution._ccdf_dispatchr  rz  r   c                    g r   rA   r  s        r   r  +ShiftedScaledDistribution._logcdf2_dispatchv  rz  r   c                    g r   rA   r  s        r   r  (ShiftedScaledDistribution._cdf2_dispatchz  rz  r   c                    g r   rA   r  s        r   r  ,ShiftedScaledDistribution._logccdf2_dispatch~  rz  r   c                    g r   rA   r  s        r   r?  )ShiftedScaledDistribution._ccdf2_dispatch  rz  r   c                    g r   rA   rf  s       r   r]  +ShiftedScaledDistribution._ilogcdf_dispatch  rz  r   c                    g r   rA   rf  s       r   r.  (ShiftedScaledDistribution._icdf_dispatch  rz  r   c                    g r   rA   rf  s       r   rj  ,ShiftedScaledDistribution._ilogccdf_dispatch  rz  r   c                    g r   rA   rf  s       r   r|  )ShiftedScaledDistribution._iccdf_dispatch  rz  r   c                    U R                   R                  " U4SU0UD6nUc  S $ U[        R                  " U5      U-  -  $ Nr  )r  r
  rG   r}  r2   r  rc  rn  r}  r  r   rg  s           r   r
  7ShiftedScaledDistribution._moment_standardized_dispatch  sJ    zz77.".&,.{tCbggene.C(CCr   c                X    U R                   R                  " U4SU0UD6nUc  S $ XsU-  -  $ r  )r  r  r  s           r   r  2ShiftedScaledDistribution._moment_central_dispatch  s?    zz22.".&,.{t:Ul(::r   c                   / nUn[        [        U5      S-   5       HR  n	X:  a  U R                  OUnU R                  R                  " U	4SU0UD6n
U
c    g XU	-  -  nUR                  U5        MT     U R                  XX R                  5      $ )Nr}   r  )r   r   r  r  r  r  r  r  )r2   r  rc  rn  r}  r  r   r  methods_highest_orderr   rG  r  s               r   r  .ShiftedScaledDistribution._moment_raw_dispatch  s     's5zA~&A/0yt++1 **11!OWOOC{AX~Hx( ' ,,ZZ1 	1r   c                l    U R                   R                  " U4XbS.UD6nU R                  " U4X4US.UD6$ )Nr  rL  )r  r  r  )	r2   r  rz   rc  rn  r}  r  r   rvss	            r   r  *ShiftedScaledDistribution._sample_dispatch  s>    jj))*WVWPVWOOOOr   c                 Z    [        U R                  U R                  U-   U R                  S9$ N)rc  rn  re  r  rc  rn  rf  s     r   rg  !ShiftedScaledDistribution.__add__  &    (C/3zz; 	;r   c                 Z    [        U R                  U R                  U-
  U R                  S9$ r  r  rf  s     r   rj  !ShiftedScaledDistribution.__sub__  r  r   c                 `    [        U R                  U R                  U-  U R                  U-  S9$ r  r  ro  s     r   rp  !ShiftedScaledDistribution.__mul__  /    (-1XX-=/3zzE/AC 	Cr   c                 `    [        U R                  U R                  U-  U R                  U-  S9$ r  r  ro  s     r   rs  %ShiftedScaledDistribution.__truediv__  r  r   rA   rC  )6rB   rC   rD   rE   rF   r   r   _loc_domainr  
_loc_param_scale_domain_scale_paramr  r  r  r  r  r  r\  r?   r  r  r$  r1  r_  rm  r~  r  r	  r  r  r  r  r  r  r  r  r  r  r?  r  r]  r.  rj  r|  r
  r  r  r  rg  rj  rp  rs  rJ   rA   r   r   re  re    s	   BC4+NKf'2FDJ "cT3K<PM!'))6	KL ,JE+J7+L9;B

2)H
11.
#
.
#
.
# (,0  ( ()-  ( (-1  ( (*.  ( -04  - --1  - -15  - -.2  - #-1  # #*.  # #.2  # #+/  #D;1 P
;;C
Cr   re  c                      ^  \ rS rSrSr\" SSS9r\" S\SS9r\" S	\	R                  4SS9r\" S
\SS9r\R                  \5        \" \\5      /rU 4S jrS rSS jrS rS rS rS rS rS rS rS rS rSrU =r$ )OrderStatisticDistributioni  a  Probability distribution of an order statistic

An instance of this class represents a random variable that follows the
distribution underlying the :math:`r^{\text{th}}` order statistic of a
sample of :math:`n` observations of a random variable :math:`X`.

Parameters
----------
dist : `ContinuousDistribution`
    The random variable :math:`X`
n : array_like
    The (integer) sample size :math:`n`
r : array_like
    The (integer) rank of the order statistic :math:`r`


Notes
-----
If we make :math:`n` observations of a continuous random variable
:math:`X` and sort them in increasing order
:math:`X_{(1)}, \dots, X_{(r)}, \dots, X_{(n)}`,
:math:`X_{(r)}` is known as the :math:`r^{\text{th}}` order statistic.

If the PDF, CDF, and CCDF underlying math:`X` are denoted :math:`f`,
:math:`F`, and :math:`F'`, respectively, then the PDF underlying
math:`X_{(r)}` is given by:

.. math::

    f_r(x) = \frac{n!}{(r-1)! (n-r)!} f(x) F(x)^{r-1} F'(x)^{n - r}

The CDF and other methods of the distribution underlying :math:`X_{(r)}`
are calculated using the fact that :math:`X = F^{-1}(U)`, where :math:`U` is
a standard uniform random variable, and that the order statistics of
observations of `U` follow a beta distribution, :math:`B(r, n - r + 1)`.

References
----------
.. [1] Order statistic. *Wikipedia*. https://en.wikipedia.org/wiki/Order_statistic

Examples
--------
Suppose we are interested in order statistics of samples of size five drawn
from the standard normal distribution. Plot the PDF underlying the fourth
order statistic and compare with a normalized histogram from simulation.

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy import stats
>>> from scipy.stats._distribution_infrastructure import OrderStatisticDistribution
>>>
>>> X = stats.Normal()
>>> data = X.sample(shape=(10000, 5))
>>> ranks = np.sort(data, axis=1)
>>> Y = OrderStatisticDistribution(X, r=4, n=5)
>>>
>>> ax = plt.gca()
>>> Y.plot(ax=ax)
>>> ax.hist(ranks[:, 3], density=True, bins=30)
>>> plt.show()

)r}   r7   r  r  rrJ  r  r}   r7   )r}   r  c               2   > [         TU ]  " U/UQ7X#S.UD6  g )Nr  r7   r  )r2   r  r  r7   rx   ry   rW   s         r   rX   #OrderStatisticDistribution.__init__  s    999&9r   c                :    U R                   R                  " U0 UD6$ r   )r  r  )r2   r  r7   rx   ry   s        r   r  #OrderStatisticDistribution._support  s    zz""D3F33r   c                 n    U R                   R                  " S0 UD6nUR                  [        XS95        U$ )Nr  rA   )r  r  r]   r  )r2   r  r7   r   r^   s        r   r  .OrderStatisticDistribution._process_parameters  s1    ZZ33=f=
$.)r   c                     US;   $ )N>   r  rt  r  rt  ru  rd  rA   r$  s     r   r  %OrderStatisticDistribution._overrides!  s     B B 	Br   c                    [         R                  " X#U-
  S-   5      nU R                  R                  " U40 UD6nU R                  R                  " UR
                  40 UD6nU R                  R                  " UR
                  40 UD6n[        R                  " US-
  S:H  [        R                  " U5      -  SUS-
  U-  5      n	[        R                  " X2-
  S:H  [        R                  " U5      -  SX2-
  U-  5      n
Xi-   U
-   U-
  $ )Nr}   r   )
r   betalnr  r_  r  rU  r  rG   r   r  )r2   r   r  r7   ry   
log_factorlog_fXlog_FXlog_cFX
rm1_log_FXnmr_log_cFXs              r   rd  *OrderStatisticDistribution._logpdf_formula&  s    ^^A1uqy1
,,Q9&9 ,,QVV>v>**..qvv@@ XXq1uzR[[-@@!ac6\R
hh
bkk'.BBAW}U"[0:==r   c                    [         R                  " X#U-
  S-   5      nU R                  R                  " U40 UD6nU R                  R                  " U40 UD6nU R                  R
                  " U40 UD6nXgUS-
  -  -  XU-
  -  -  U-  $ r|  )r   betar  rm  r  r  )	r2   r   r  r7   ry   factorfXFXcFXs	            r   rt  'OrderStatisticDistribution._pdf_formula4  s    aQ+ZZ%%a262ZZ%%a262jj''4V41I~c
*V33r   c                 v    U R                   R                  " U40 UD6n[        R                  " X#U-
  S-   U5      $ r|  )r  r  r   betaincr2   r   r  r7   ry   x_s         r   r  'OrderStatisticDistribution._cdf_formula<  s4    ZZ%%a262qA#a%,,r   c                 v    U R                   R                  " U40 UD6n[        R                  " X#U-
  S-   U5      $ r|  )r  r  r   betainccr  s         r   r  (OrderStatisticDistribution._ccdf_formula@  s6    ZZ%%a262Q3q5"--r   c                 v    [         R                  " X#U-
  S-   U5      nU R                  R                  " U40 UD6$ r|  )r   
betaincinvr  r.  r2   r   r  r7   ry   p_s         r   rt  (OrderStatisticDistribution._icdf_formulaD  s6    Q3q5!,zz((6v66r   c                 v    [         R                  " X#U-
  S-   U5      nU R                  R                  " U40 UD6$ r|  )r   betainccinvr  r.  r  s         r   ru  )OrderStatisticDistribution._iccdf_formulaH  s6      aCE1-zz((6v66r   c           	          [         R                  " SS9   S[        U R                  5       S[        U R                  5       S[        U R
                  5       S3sS S S 5        $ ! , (       d  f       g = fNrT  rU  zorder_statistic(z, r=z, n=r   )rG   rW  r  r  r  r7   r>   s    r   r\  #OrderStatisticDistribution.__repr__L  sS    __r*&tDJJ'7&8T$&&\N Kdffa) +**r@  c           	          [         R                  " SS9   S[        U R                  5       S[        U R                  5       S[        U R
                  5       S3sS S S 5        $ ! , (       d  f       g = fr  )rG   rW  r   r  r  r7   r>   s    r   r?   "OrderStatisticDistribution.__str__Q  sR    __r*&s4::&7tCK= ITVVQ( +**r@  rA   rC  )rB   rC   rD   rE   rF   r   	_r_domainr  _r_paramrG   r   	_n_domain_n_paramra   r  r  rX   r  r  r  rd  rt  r  r  rt  ru  r\  r?   rJ   r   r   s   @r   r  r    s    =B LIIc)VDHBFF|LIc)VDH)+Hh?@:4
B
>4-.77*
) )r   r  c               f   [         R                  " U5      [         R                  " U5      p![         R                  " U[         R                  " U5      :g  US:  -  5      (       d8  [         R                  " U[         R                  " U5      :g  US:  -  5      (       a  Sn[	        U5      e[        XUS9$ )a  Probability distribution of an order statistic

Returns a random variable that follows the distribution underlying the
:math:`r^{\text{th}}` order statistic of a sample of :math:`n`
observations of a random variable :math:`X`.

Parameters
----------
X : `ContinuousDistribution`
    The random variable :math:`X`
r : array_like
    The (positive integer) rank of the order statistic :math:`r`
n : array_like
    The (positive integer) sample size :math:`n`

Returns
-------
Y : `ContinuousDistribution`
    A random variable that follows the distribution of the prescribed
    order statistic.

Notes
-----
If we make :math:`n` observations of a continuous random variable
:math:`X` and sort them in increasing order
:math:`X_{(1)}, \dots, X_{(r)}, \dots, X_{(n)}`,
:math:`X_{(r)}` is known as the :math:`r^{\text{th}}` order statistic.

If the PDF, CDF, and CCDF underlying math:`X` are denoted :math:`f`,
:math:`F`, and :math:`F'`, respectively, then the PDF underlying
math:`X_{(r)}` is given by:

.. math::

    f_r(x) = \frac{n!}{(r-1)! (n-r)!} f(x) F(x)^{r-1} F'(x)^{n - r}

The CDF and other methods of the distribution underlying :math:`X_{(r)}`
are calculated using the fact that :math:`X = F^{-1}(U)`, where :math:`U` is
a standard uniform random variable, and that the order statistics of
observations of `U` follow a beta distribution, :math:`B(r, n - r + 1)`.

References
----------
.. [1] Order statistic. *Wikipedia*. https://en.wikipedia.org/wiki/Order_statistic

Examples
--------
Suppose we are interested in order statistics of samples of size five drawn
from the standard normal distribution. Plot the PDF underlying each
order statistic and compare with a normalized histogram from simulation.

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy import stats
>>>
>>> X = stats.Normal()
>>> data = X.sample(shape=(10000, 5))
>>> sorted = np.sort(data, axis=1)
>>> Y = stats.order_statistic(X, r=[1, 2, 3, 4, 5], n=5)
>>>
>>> ax = plt.gca()
>>> colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
>>> for i in range(5):
...     y = sorted[:, i]
...     ax.hist(y, density=True, bins=30, alpha=0.1, color=colors[i])
>>> Y.plot(ax=ax)
>>> plt.show()

r   z0`r` and `n` must contain only positive integers.r  )rG   rR   rP  rQ  rM  r  )r  r  r7   rk   s       r   r"   r"   W  s    L ::a="**Q-q	vvqBHHQKAE*++rvvqBHHQK7GAPQE6R/S/SD!!%a22r   c                      \ rS rSrSrS rSS.S jr\S 5       r\S 5       r	S	 r
S
 rS rS rS rSS.S jrSS.S jrSS.S jrSS.S jrSS.S jrSS.S jrSS.S jrSS.S jrSS.S jrS.SS.S jjrS rS rS rSS.S jrSS.S jrSS.S jrSS.S jrS/SS.S  jjr S/SS.S! jjr!S/SS.S" jjr"S/SS.S# jjr#S$ r$SS.S% jr%SS.S& jr&SS.S' jr'SS.S( jr(S0SSS).S* jjr)S+ r*S, r+S-r,g)1r!   i  a  Representation of a mixture distribution.

A mixture distribution is the distribution of a random variable
defined in the following way: first, a random variable is selected
from `components` according to the probabilities given by `weights`, then
the selected random variable is realized.

Parameters
----------
components : sequence of `ContinuousDistribution`
    The underlying instances of `ContinuousDistribution`.
    All must have scalar shape parameters (if any); e.g., the `pdf` evaluated
    at a scalar argument must return a scalar.
weights : sequence of floats, optional
    The corresponding probabilities of selecting each random variable.
    Must be non-negative and sum to one. The default behavior is to weight
    all components equally.

Attributes
----------
components : sequence of `ContinuousDistribution`
    The underlying instances of `ContinuousDistribution`.
weights : ndarray
    The corresponding probabilities of selecting each random variable.

Methods
-------
support

sample

moment

mean
median
mode

variance
standard_deviation

skewness
kurtosis

pdf
logpdf

cdf
icdf
ccdf
iccdf

logcdf
ilogcdf
logccdf
ilogccdf

entropy

Notes
-----
The following abbreviations are used throughout the documentation.

- PDF: probability density function
- CDF: cumulative distribution function
- CCDF: complementary CDF
- entropy: differential entropy
- log-*F*: logarithm of *F* (e.g. log-CDF)
- inverse *F*: inverse function of *F* (e.g. inverse CDF)

References
----------
.. [1] Mixture distribution, *Wikipedia*,
       https://en.wikipedia.org/wiki/Mixture_distribution


Examples
--------
A mixture of normal distributions:

>>> import numpy as np
>>> from scipy import stats
>>> import matplotlib.pyplot as plt
>>> X1 = stats.Normal(mu=-2, sigma=1)
>>> X2 = stats.Normal(mu=2, sigma=1)
>>> mixture = stats.Mixture([X1, X2], weights=[0.4, 0.6])
>>> print(f'mean: {mixture.mean():.2f}, '
...       f'median: {mixture.median():.2f}, '
...       f'mode: {mixture.mode():.2f}')
mean: 0.40, median: 1.04, mode: 2.00
>>> x = np.linspace(-10, 10, 300)
>>> plt.plot(x, mixture.pdf(x))
>>> plt.title('PDF of normal distribution mixture')
>>> plt.show()

c                    [        U5      S:X  a  Sn[        U5      eU HB  n[        U[        5      (       d  Sn[        U5      eUR                  S:X  a  M7  Sn[        U5      e   Uc  X4$ [
        R                  " U5      nUR                  [        U5      4:w  a  Sn[        U5      e[
        R                  " UR                  [
        R                  5      (       d  Sn[        U5      e[
        R                  " [
        R                  " U5      S5      (       d  S	n[        U5      e[
        R                  " US:  5      (       d  S
n[        U5      eX4$ )Nr   z7`components` must contain at least one random variable.zMEach element of `components` must be an instance of `ContinuousDistribution`.rA   z5All elements of `components` must have scalar shapes.z5`components` and `weights` must have the same length.z)`weights` must have floating point dtype.rF  z`weights` must sum to 1.0.z#All `weights` must be non-negative.)r   rM  r   r  rJ  rG   rR   r   r  r  r  iscloser   r  )r2   
componentsweightsrk   r  s        r   _input_validationMixture._input_validation  s%   z?aPGW%%C c#9::7 ))::#Q ))  ?&&**W%==S_..MGW%%}}W]]BJJ77AGW%%zz"&&/3//2GW%%vvgl##;GW%%""r   N)r  c                "   U R                  X5      u  p[        U5      n[        R                  " S U 5       6 n[        R                  " S U 5       6 U l        XAsU l        U l        Uc  [        R                  " USU-  US9OUU l	        S U l
        g )Nc              3   8   #    U  H  oR                   v   M     g 7fr   )rI  r.  r  s     r   r/  #Mixture.__init__.<locals>.<genexpr>0  s      Bzzr1  c              3   8   #    U  H  oR                   v   M     g 7fr   )rJ  r  s     r   r/  r  1  s     +M*3JJ*r1  r}   r  )r  r   rG   r#  r   rJ  rI  _componentsr   _weightsrG  )r2   r  r  r7   r  s        r   rX   Mixture.__init__-  s    "44ZI

O Bz BC))+M*+MN(-%T%8?1Q3e4W!%r   c                 ,    [        U R                  5      $ r   )r$  r  r>   s    r   r  Mixture.components6  s    D$$%%r   c                 6    U R                   R                  5       $ r   )r  rQ   r>   s    r   r  Mixture.weights:  s    }}!!##r   c                 "   U Vs/ s H  n[         R                  " U5      PM     nn[         R                  " U R                  /S U 5       Q76 n[         R                  " U R
                  /S U 5       Q76 n[         R                  " XQUS9$ s  snf )Nc              3   8   #    U  H  oR                   v   M     g 7fr   r  r.  args     r   r/   Mixture._full.<locals>.<genexpr>@  s     -H4Cii4r1  c              3   8   #    U  H  oR                   v   M     g 7fr   r  r  s     r   r/  r  A  s     2M99r1  r  )rG   rR   r#  rI  r   rJ  r   )r2   r  rx   r  r  r   s         r   _fullMixture._full>  sp    +/04C

340t{{I-H4-HI##DKKN2M2MNwwu// 1s    Bc                     U R                   " S/UQ76 n[        U R                  U R                  5       H  u  pEU[	        XA5      " U6 U-  -  nM     US   $ Nr   rA   )r  r/  r  r  r  )r2   r  rx   r   r  weights         r   _sumMixture._sumD  sU    jj"T"t//?KC73$d+f44C @2wr   c                    U R                   " [        R                  * /UQ76 n[        U R                  [        R
                  " U R                  5      5       H*  u  pE[        R                  " U[        XA5      " U6 U-   US9  M,     US   $ )N)r   rA   )	r  rG   r   r/  r  r&   r  r  r  )r2   r  rx   r   r  
log_weights         r   _logsumMixture._logsumJ  sj    jj"&&(4("4#3#3RVVDMM5JKOCLLgc/6CM  L2wr   c                 H   U R                  [        R                  5      nU R                  [        R                  * 5      nU R                   HQ  n[        R                  " XR                  5       S   5      n[        R                  " X#R                  5       S   5      nMS     X4$ r  )r  rG   r   r  r  rN  r  )r2   rU   rV   r  s       r   rN  Mixture.supportP  ss    JJrvvJJw##C

1kkmA./A

1kkmA./A $ tr   c                      Ub  [        S5      eg )Nz/`method` not implemented for this distribution.r/   r  s     r   _raise_if_methodMixture._raise_if_methodX  s    %&WXX r   r  c                   ^  T R                  U5        U 4S jn[        U/T R                  5       Q7SS06R                  n[	        U[
        R                  S-  -   5      $ )Nc                    > TR                  U R                  5      [        R                  " TR                  U R                  5      S-   5      -   $ r  )r8  rU  rG   r&   r   r2   s    r   log_integrand)Mixture.logentropy.<locals>.log_integrand^  s8    
 ;;qvv&AFF0Cb0H)IIIr   r&   Tr  )r
  r  rN  r   r  rG   rH   )r2   r  r  rg  s   `   r   r  Mixture.logentropy\  sP    f%	J AADAJJ$S2558^44r   c                v   ^  T R                  U5        [        U 4S j/T R                  5       Q76 R                  $ )Nc                 L   > TR                  U 5      * TR                  U 5      -  $ r   )r9  r8  r  s    r   r  !Mixture.entropy.<locals>.<lambda>j  s    DHHQK<$++a.#@r   )r
  r  rN  r   r  s   ` r   r  Mixture.entropyh  s4    f%@ *,,.**2(	3r   c                   ^  T R                  U5        T R                  5       u  p#U 4S jn[        USX#S9n[        XER                  UR
                  UR                  5      nUR                  $ )Nc                 (   > TR                  U 5      * $ r   )r9  r  s    r   ro  Mixture.mode.<locals>.fp  s    $((1+%r   rF  )r  r  )r
  rN  r   r   r  r=  r  r   )r2   r  rU   rV   ro  rg  s   `     r   r  Mixture.modem  sR    f%||~%q"15$Q?uur   c                F    U R                  U5        U R                  S5      $ r  )r
  r4  r  s     r   r  Mixture.medianu  s    f%yy~r   c                F    U R                  U5        U R                  S5      $ )Nr  r
  r  r  s     r   r  Mixture.meany  s    f%yy  r   c                F    U R                  U5        U R                  S5      $ )Nr   )r
  r  r  s     r   r  Mixture.variance}  s!    f%##A&&r   c                J    U R                  U5        U R                  5       S-  $ r  )r
  r  r  s     r   r  Mixture.standard_deviation  s!    f%}}##r   c                F    U R                  U5        U R                  S5      $ )Nr   r
  r  r  s     r   r  Mixture.skewness  !    f%((++r   c                F    U R                  U5        U R                  S5      $ )Nr  r$  r  s     r   r  Mixture.kurtosis  r&  r   c                    U R                  U5        U R                  U R                  U R                  S.n[        R                  XX$5      nXB   nU" U5      $ )Nr  )r
  r  r  r  r  r  r  s         r   rJ  Mixture.moment  sX    f%(( 00!%!:!:< ';;DUk5!!r   c                     U R                  S5      n[        U R                  U R                  5       H  u  p4X#R	                  USS9U-  -  nM     US   $ )Nr   rG  r   rA   )r  r/  r  r  rJ  )r2   r  r   r  r   s        r   r  Mixture._moment_raw  sP    jjmt//?KC::e%:0699C @2wr   c           	      j   [        U5      nU R                  S5      n[        U R                  U R                  5       Hj  u  p4[        US-   5       Vs/ s H  nUR                  USS9PM     nnUR                  5       U R                  5       pvUR                  WXVU5      nX(U-  -  nMl     US   $ s  snf )Nr   r}   rM  r,  rA   )	r   r  r/  r  r  r   rJ  r  r  )	r2   r  r   r  r   r.  rU   rV   rJ  s	            r   r  Mixture._moment_central  s    E
jjmt//?KC&+EAI&68&6U E	:&6  888:tyy{q11%qIFF?"C @ 2w8s   B0c                 L    U R                  U5      U R                  5       U-  -  $ r   )r  r  )r2   r  s     r   r  Mixture._moment_standardized  s&    ##E*T-D-D-F-MMMr   c               H    U R                  U5        U R                  SU5      $ )Nr9  r  r`  s      r   r9  Mixture.pdf  !    f%yy""r   c               H    U R                  U5        U R                  SU5      $ )Nr8  r
  r  r`  s      r   r8  Mixture.logpdf  !    f%||Ha((r   c               H    U R                  U5        U R                  SU5      $ )Nr;  r  r`  s      r   r;  Mixture.pmf  r4  r   c               H    U R                  U5        U R                  SU5      $ )Nr:  r6  r`  s      r   r:  Mixture.logpmf  r8  r   c               \    U R                  U5        Uc  U4OX4nU R                  " S/UQ76 $ Nr  r  r2   r   r  r  rx   s        r   r  Mixture.cdf  s3    f%ytqfyy&&&r   c               \    U R                  U5        Uc  U4OX4nU R                  " S/UQ76 $ Nr  r6  r?  s        r   r  Mixture.logcdf  s3    f%ytqf||H,t,,r   c               \    U R                  U5        Uc  U4OX4nU R                  " S/UQ76 $ NrD  r  r?  s        r   rD  Mixture.ccdf  s3    f%ytqfyy'$''r   c               \    U R                  U5        Uc  U4OX4nU R                  " S/UQ76 $ Nr  r6  r?  s        r   r  Mixture.logccdf  s3    f%ytqf||I---r   c           	         ^ U R                  5       u  p4[        U T5      mU4S jn[        X45      u  pg[        XVXsXB4S9n[	        XXR
                  UR                  U4S9R                  $ )Nc                    > T" U 5      U-
  $ r   rA   )r   r   r  s     r   r  !Mixture._invert.<locals>.<lambda>  s    Q!r   r  r  )rN  r  r  r   r   r  r  r   )	r2   r  r   r  r  ro  r  r  rg  s	    `       r   _invertMixture._invert  s\    \\^
dC #!$-ACDQQ&&CFF!>@@@r   c               H    U R                  U5        U R                  SU5      $ r>  r
  rM  rq  s      r   r4  Mixture.icdf  s!    f%||E1%%r   c               H    U R                  U5        U R                  SU5      $ rE  rP  rq  s      r   r5  Mixture.iccdf  s!    f%||FA&&r   c               H    U R                  U5        U R                  SU5      $ rB  rP  rq  s      r   r6  Mixture.ilogcdf  r8  r   c               H    U R                  U5        U R                  SU5      $ rH  rP  rq  s      r   r7  Mixture.ilogccdf  s!    f%||Iq))r   )rz   r  c          	         U R                  U5        [        R                  R                  U5      n[        R                  " [        R
                  " U5      5      nUR                  X@R                  5      n[        XPR                  5       VVs/ s H  u  pgUR                  XbS9PM     nnn[        R                  " UR                  [        R                  " U5      5      U5      nUS   $ s  snnf )N)r   rz   rA   )r
  rG   r   r   r   r  r   r  r/  r  r  r   r   r   )	r2   r   rz   r  r   nsr7   r  r   s	            r   r  Mixture.sample  s    f%ii##C(wwr}}U+,__T==18;B@P@P8QR8QfaSZZaZ)8QRJJs||BNN1$56>u Ss   C+c                    SnUS-  n[         R                  " SS9   U R                   H  nUS[        U5       S3-  nM     US-  nUS[        U R                  5       S3-  nS S S 5        US	-  nU$ ! , (       d  f       N= f
Nz	Mixture(
z    [
rT  rU  z        z,
z    ],
z    weights=r   )rG   rW  r  r  r  r2   rZ  	components      r   r\  Mixture.__repr__  s    )__r*!__	HT)_$5S99 -j FT$,,%7$8<<F	 +
 	# +*   AA22
B c                    SnUS-  n[         R                  " SS9   U R                   H  nUS[        U5       S3-  nM     US-  nUS[        U R                  5       S3-  nS S S 5        US	-  nU$ ! , (       d  f       N= fr\  )rG   rW  r  r   r  r]  s      r   r?   Mixture.__str__  s    )__r*!__	HS^$4C88 -j FS%6$7s;;F	 +
 	# +*r`  )r  rI  rJ  r  rG  rp  r   ro  )-rB   rC   rD   rE   rF   r  rX   r  r  r  r  r  r  rN  r
  r  r  r  r  r  r  r  r  r  rJ  r  r  r  r9  r8  r;  r:  r  r  rD  r  rM  r4  r5  r6  r7  r  r\  r?   rJ   rA   r   r   r!   r!     so   ^D$#L /3 & & & $ $0Y $( 
5 !% 3
 "   $  " ! "& ' ,0 $ "& , "& ,"D "	N #' # &* ) #' # &* )'$ '
-T -
(4 (
.d .
A $( & %) ' '+ ) (, *d4 		r   r!   c                      ^  \ rS rSrSrSSSS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U =r$ )r  i  a  Distribution underlying a strictly monotonic function of a random variable

Given a random variable :math:`X`; a strictly monotonic function
:math:`g(u)`, its inverse :math:`h(u) = g^{-1}(u)`, and the derivative magnitude
:math: `|h'(u)| = \left| \frac{dh(u)}{du} \right|`, define the distribution
underlying the random variable :math:`Y = g(X)`.

Parameters
----------
X : `ContinuousDistribution`
    The random variable :math:`X`.
g, h, dh : callable
    Elementwise functions representing the mathematical functions
    :math:`g(u)`, :math:`h(u)`, and :math:`|h'(u)|`
logdh : callable, optional
    Elementwise function representing :math:`\log(h'(u))`.
    The default is ``lambda u: np.log(dh(u))``, but providing
    a custom implementation may avoid over/underflow.
increasing : bool, optional
    Whether the function is strictly increasing (True, default)
    or strictly decreasing (False).
repr_pattern : str, optional
    A string pattern for determining the __repr__. The __repr__
    for X will be substituted into the position where `***` appears.
    For example:
        ``"exp(***)"`` for the repr of an exponentially transformed
        distribution
    The default is ``f"{g.__name__}(***)"``.
str_pattern : str, optional
    A string pattern for determining `__str__`. The `__str__`
    for X will be substituted into the position where `***` appears.
    For example:
        ``"exp(***)"`` for the repr of an exponentially transformed
        distribution
    The default is the value `repr_pattern` takes.
NT)logdhr  r  r  c               `  >^ [         TU ]  " U/U	Q70 U
D6  X l        X0l        TU l        Ub  UOU4S jU l        U(       a  U R                  R                  U l        U R                  R                  U l
        U R                  R                  U l        U R                  R                  U l        U R                  R                  U l        U R                  R"                  U l        U R                  R&                  U l        U R                  R*                  U l        OU R                  R                  U l        U R                  R                  U l
        U R                  R                  U l        U R                  R                  U l        U R                  R"                  U l        U R                  R                  U l        U R                  R*                  U l        U R                  R&                  U l        X`l        U=(       d    UR0                   S3U l        U=(       d    U R2                  U l        g )Nc                 <   > [         R                  " T" U 5      5      $ r   r  )rx  r  s    r   r  ;MonotonicTransformedDistribution.__init__.<locals>.<lambda>4  s    bffRUmr   z(***))rP   rX   _g_h_dh_logdhr  r  _xdfr  _cxdfr.  _ixdfr|  _icxdfr  _logxdfr  _logcxdfr]  _ilogxdfrj  	_ilogcxdf_increasingrB   _repr_pattern_str_pattern)r2   r  r  r  r  rd  r  r  r  rx   ry   rW   s       `      r   rX   )MonotonicTransformedDistribution.__init__,  s    	,T,V, % 1u3 	

00DI22DJ22DJ**44DK::66DL JJ88DM JJ88DM!ZZ::DN

11DI11DJ33DJ**33DK::77DL JJ77DM JJ99DM!ZZ99DN%)A

|5-A'=4+=+=r   c                     [         R                  " SS9   U R                  R                  S[	        U R
                  5      5      sS S S 5        $ ! , (       d  f       g = fNrT  rU  z***)rG   rW  ru  r  r  r  r>   s    r   r\  )MonotonicTransformedDistribution.__repr__K  s9    __r*%%--eT$**5EF +**   /A
Ac                     [         R                  " SS9   U R                  R                  S[	        U R
                  5      5      sS S S 5        $ ! , (       d  f       g = fry  )rG   rW  rv  r  r   r  r>   s    r   r?   (MonotonicTransformedDistribution.__str__O  s8    __r*$$,,UC

OD +**r{  c                     gr#  rA   r$  s     r   r  +MonotonicTransformedDistribution._overridesS      r   c                    U R                   R                  " S0 UD6u  p#[        R                  " US:H  [        R                  " SUR
                  S9U5      n[        R                  " SS9   U R                  (       a+  U R                  U5      U R                  U5      4sS S S 5        $ U R                  U5      U R                  U5      4sS S S 5        $ ! , (       d  f       g = f)Nr   z-0r  r  r  rA   )	r  r  rG   r   rR   r  r  rt  rh  )r2   r   rU   rV   s       r   r  )MonotonicTransformedDistribution._supportW  s    zz"",V,HHQT2::d!'':A>[[)wwqz4771:- *) wwqz4771:-	 *))s   +3C(!C
C!c                     U R                   R                  " U R                  U5      /UQ70 UD6U R                  U5      -   $ r   )r  r_  ri  rk  r2   r   rx   r   s       r   r_  1MonotonicTransformedDistribution._logpdf_dispatcha  s7    zz**4771:GGG$++VW.XXr   c                     U R                   R                  " U R                  U5      /UQ70 UD6U R                  U5      -  $ r   )r  rm  ri  rj  r  s       r   rm  .MonotonicTransformedDistribution._pdf_dispatchd  s7    zz''
DTDVDtxxPQ{RRr   c                 L    U R                   " U R                  U5      /UQ70 UD6$ r   )rp  ri  r  s       r   r  1MonotonicTransformedDistribution._logcdf_dispatchg  s#    ||DGGAJ8888r   c                 L    U R                   " U R                  U5      /UQ70 UD6$ r   )rl  ri  r  s       r   r  .MonotonicTransformedDistribution._cdf_dispatchj  s#    yy5d5f55r   c                 L    U R                   " U R                  U5      /UQ70 UD6$ r   )rq  ri  r  s       r   r  2MonotonicTransformedDistribution._logccdf_dispatchm  s#    }}TWWQZ9$9&99r   c                 L    U R                   " U R                  U5      /UQ70 UD6$ r   )rm  ri  r  s       r   r  /MonotonicTransformedDistribution._ccdf_dispatchp  s#    zz$''!*6t6v66r   c                 L    U R                  U R                  " U/UQ70 UD65      $ r   )rh  rr  r2   r   rx   r   s       r   r]  2MonotonicTransformedDistribution._ilogcdf_dispatchs  s$    wwt}}Q88899r   c                 L    U R                  U R                  " U/UQ70 UD65      $ r   )rh  rn  r  s       r   r.  /MonotonicTransformedDistribution._icdf_dispatchv  s$    wwtzz!5d5f566r   c                 L    U R                  U R                  " U/UQ70 UD65      $ r   )rh  rs  r  s       r   rj  3MonotonicTransformedDistribution._ilogccdf_dispatchy  s$    wwt~~a9$9&9::r   c                 L    U R                  U R                  " U/UQ70 UD65      $ r   )rh  ro  r  s       r   r|  0MonotonicTransformedDistribution._iccdf_dispatch|  s$    wwt{{16t6v677r   c                b    U R                   R                  " U4X#S.UD6nU R                  U5      $ Nr  )r  r  rh  r2   r  r  rz   r   r  s         r   r  1MonotonicTransformedDistribution._sample_dispatch  s/    jj))*WVWPVWwws|r   )rm  rj  rh  ri  ro  rs  rr  rt  rn  rq  rk  rp  ru  rv  rl  )rB   rC   rD   rE   rF   rX   r\  r?   r  r  r_  rm  r  r  r  r  r]  r.  rj  r|  r  rJ   r   r   s   @r   r  r    st    #J 59 t!> >>GE.YS96:7:7;8 r   r  c                      ^  \ rS rSrSrU 4S jrS rS rSS.S jrSS.S	 jr	SS.S
 jr
SS.S jrSS.S jrSS.S jrS rS rS rSrU =r$ )r  i  aZ  Distribution underlying the absolute value of a random variable

Given a random variable :math:`X`; define the distribution
underlying the random variable :math:`Y = |X|`.

Parameters
----------
X : `ContinuousDistribution`
    The random variable :math:`X`.

Returns
-------
Y : `ContinuousDistribution`
    The random variable :math:`Y = |X|`

c                   > [         TU ]  " U/UQ70 UD6  SU R                  R                  R                  S   4U R                  R                  l        g )NTr}   )rP   rX   rO  r   rT   )r2   r  rx   ry   rW   s       r   rX   FoldedDistribution.__init__  sI    ,T,V,
 ,01F1F1P1PQR1S*T'r   c                     gr#  rA   r$  s     r   r  FoldedDistribution._overrides  r  r   c                 H   U R                   R                  " S0 UD6u  p#[        R                  " U5      [        R                  " U5      pT[        R                  " XE5      [        R
                  " XE5      pTUS:  US:  -  n[        R                  " U5      nSXF'   US   US   4$ r  )r  r  rG   r$   r  r  rR   )r2   r   rU   rV   a_b_r   s          r   r  FoldedDistribution._support  s    zz"",V,BFF1IBB#RZZ%7BUq1uZZ^"vr"v~r   Nr  c                   [         R                  " U5      nU R                  R                  " U/UQ7SU0UD6nU R                  R                  " U* /UQ7SU0UD6n[         R                  " U5      n[         R                  " U5      nU R                  R
                  " S0 UD6u  px[         R                  * Xa* U:  '   [         R                  * XQU:  '   [         R                  " Xe/5      n	[        R                  " U	SS9$ )Nr  r   r   rA   )
rG   r$   r  r_  rR   r  r   r  r   r  )
r2   r   r  rx   r   r   r   rU   rV   logpdfss
             r   r_  #FoldedDistribution._logpdf_dispatch  s    FF1I

++ANNVNvNzz**A2NNVNvNzz$

5!zz"",V,wR!Vw!e((D=)  q11r   c                r   [         R                  " U5      nU R                  R                  " U/UQ7SU0UD6nU R                  R                  " U* /UQ7SU0UD6n[         R                  " U5      n[         R                  " U5      nU R                  R
                  " S0 UD6u  pxSXa* U:  '   SXQU:  '   Xe-   $ )Nr  r   rA   )rG   r$   r  rm  rR   r  )	r2   r   r  rx   r   r   r   rU   rV   s	            r   rm   FoldedDistribution._pdf_dispatch  s    FF1I

((KTK&KFKzz''KTK&KFKzz$

5!zz"",V,R!V!e|r   c                   [         R                  " U5      nU R                  R                  " S0 UD6u  pV[         R                  " U* U5      n[         R
                  " X5      nU R                  R                  " Xx/UQ7SU0UD6R                  $ r  )rG   r$   r  r  r  r  r  rU  	r2   r   r  rx   r   rU   rV   r  r  s	            r   r  #FoldedDistribution._logcdf_dispatch  sr    FF1Izz"",V,ZZAZZzz++BSTS&SFSXXXr   c                   [         R                  " U5      nU R                  R                  " S0 UD6u  pV[         R                  " U* U5      n[         R
                  " X5      nU R                  R                  " Xx/UQ70 UD6$ rO   )rG   r$   r  r  r  r  r  r  s	            r   r   FoldedDistribution._cdf_dispatch  sg    FF1Izz"",V,ZZAZZzz((A$A&AAr   c                   [         R                  " U5      nU R                  R                  " S0 UD6u  pV[         R                  " U* U5      n[         R
                  " X5      nU R                  R                  " Xx/UQ7SU0UD6R                  $ r  )rG   r$   r  r  r  r  r  rU  r  s	            r   r  $FoldedDistribution._logccdf_dispatch  s|    FF1Izz"",V,ZZAZZzz,,R 7d 76 7/577;t	<r   c                
   [         R                  " U5      nU R                  R                  " S0 UD6u  pV[         R                  " U* U5      n[         R
                  " X5      nU R                  R                  " Xx/UQ7SU0UD6$ r  )rG   r$   r  r  r  r  r?  r  s	            r   r  !FoldedDistribution._ccdf_dispatch  sl    FF1Izz"",V,ZZAZZzz))"Q4QQ&QQr   c                l    U R                   R                  " U4X#S.UD6n[        R                  " U5      $ r  )r  r  rG   r$   r  s         r   r  #FoldedDistribution._sample_dispatch  s/    jj))*WVWPVWvvc{r   c                     [         R                  " SS9   S[        U R                  5       S3sS S S 5        $ ! , (       d  f       g = fNrT  rU  zabs(r   )rG   rW  r  r  r>   s    r   r\  FoldedDistribution.__repr__  s0    __r*$tzz*+1- +**	   8
Ac                     [         R                  " SS9   S[        U R                  5       S3sS S S 5        $ ! , (       d  f       g = fr  )rG   rW  r   r  r>   s    r   r?   FoldedDistribution.__str__  s/    __r*#djj/*!, +**r  rA   )rB   rC   rD   rE   rF   rX   r  r  r_  rm  r  r  r  r  r  r\  r?   rJ   r   r   s   @r   r  r    sk    &U 15 
2 .2 	 15 Y .2 B 26 < /3 R.- -r   r  c                    [        U 5      $ )a  Absolute value of a random variable

Parameters
----------
X : `ContinuousDistribution`
    The random variable :math:`X`.

Returns
-------
Y : `ContinuousDistribution`
    A random variable :math:`Y = |X|`.

Examples
--------
Suppose we have a normally distributed random variable :math:`X`:

>>> import numpy as np
>>> from scipy import stats
>>> X = stats.Normal()

We wish to have a random variable :math:`Y` distributed according to
the folded normal distribution; that is, a random variable :math:`|X|`.

>>> Y = stats.abs(X)

The PDF of the distribution in the left half plane is "folded" over to
the right half plane. Because the normal PDF is symmetric, the resulting
PDF is zero for negative arguments and doubled for positive arguments.

>>> import matplotlib.pyplot as plt
>>> x = np.linspace(0, 5, 300)
>>> ax = plt.gca()
>>> Y.plot(x='x', y='pdf', t=('x', -1, 5), ax=ax)
>>> plt.plot(x, 2 * X.pdf(x), '--')
>>> plt.legend(('PDF of `Y`', 'Doubled PDF of `X`'))
>>> plt.show()

r  r  s    r   r$   r$     s    N a  r   c                X    [        U [        R                  [        R                  S S S9$ )aP  Natural exponential of a random variable

Parameters
----------
X : `ContinuousDistribution`
    The random variable :math:`X`.

Returns
-------
Y : `ContinuousDistribution`
    A random variable :math:`Y = \exp(X)`.

Examples
--------
Suppose we have a normally distributed random variable :math:`X`:

>>> import numpy as np
>>> from scipy import stats
>>> X = stats.Normal()

We wish to have a lognormally distributed random variable :math:`Y`,
a random variable whose natural logarithm is :math:`X`.
If :math:`X` is to be the natural logarithm of :math:`Y`, then we
must take :math:`Y` to be the natural exponential of :math:`X`.

>>> Y = stats.exp(X)

To demonstrate that ``X`` represents the logarithm of ``Y``,
we plot a normalized histogram of the logarithm of observations of
``Y`` against the PDF underlying ``X``.

>>> import matplotlib.pyplot as plt
>>> rng = np.random.default_rng(435383595582522)
>>> y = Y.sample(shape=10000, rng=rng)
>>> ax = plt.gca()
>>> ax.hist(np.log(y), bins=50, density=True)
>>> X.plot(ax=ax)
>>> plt.legend(('PDF of `X`', 'histogram of `log(y)`'))
>>> plt.show()

c                     SU -  $ r|  rA   r  s    r   r  exp.<locals>.<lambda>B  s    PQTUPUr   c                 0    [         R                  " U 5      * $ r   r  r  s    r   r  r  C  s    RVVAYJr   r  r  r  rd  )r  rG   r%   r&   r  s    r   r%   r%     s'    T ,A266o2FH Hr   c                    [         R                  " U R                  5       S   S:  5      (       a  Sn[        U5      e[	        U [         R
                  [         R                  [         R                  S S9$ )a  Natural logarithm of a non-negative random variable

Parameters
----------
X : `ContinuousDistribution`
    The random variable :math:`X` with positive support.

Returns
-------
Y : `ContinuousDistribution`
    A random variable :math:`Y = \exp(X)`.

Examples
--------
Suppose we have a gamma distributed random variable :math:`X`:

>>> import numpy as np
>>> from scipy import stats
>>> Gamma = stats.make_distribution(stats.gamma)
>>> X = Gamma(a=1.0)

We wish to have a exp-gamma distributed random variable :math:`Y`,
a random variable whose natural exponential is :math:`X`.
If :math:`X` is to be the natural exponential of :math:`Y`, then we
must take :math:`Y` to be the natural logarithm of :math:`X`.

>>> Y = stats.log(X)

To demonstrate that ``X`` represents the exponential of ``Y``,
we plot a normalized histogram of the exponential of observations of
``Y`` against the PDF underlying ``X``.

>>> import matplotlib.pyplot as plt
>>> rng = np.random.default_rng(435383595582522)
>>> y = Y.sample(shape=10000, rng=rng)
>>> ax = plt.gca()
>>> ax.hist(np.exp(y), bins=50, density=True)
>>> X.plot(ax=ax)
>>> plt.legend(('PDF of `X`', 'histogram of `exp(y)`'))
>>> plt.show()

r   zXThe logarithm of a random variable is only implemented when the support is non-negative.c                     U $ r   rA   r  s    r   r  log.<locals>.<lambda>v  s    Ar   r  )rG   rP  rN  r0   r  r&   r%   )r  rk   s     r   r&   r&   F  sY    V 
vvaiik!nq !!.!'**+A266bff2=? ?r   rC  )Urv  abcr   r   r   r   r  numpyrG   r   scipy._lib._array_apir   scipy._lib._utilr   r	   scipy._lib._docscraper
   r   scipyr   r   scipy.special._ufuncsr   scipy.integrater   r  r   scipy.optimize._bracketr   r   scipy.optimize._chandrupatlar   r   %scipy.stats._probability_distributionr   scipy.statsr   r   rr  r   __all__rH  r  r*   rL   r   r   r   r  r  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  rK  r  r    r}  r  r~  r  r  r  r  r  r#   re  r  r"   r!   r  r  r$   r%   r&   rA   r   r   <module>r     s    # %     , 4 :   + 7 C N J  	*, 		h-$c -$`J JZ'9I '9TA6y A6Ha$ a$H7)Z 7)tG  G T^B)X&RBJ,&& , 48 ,:GTM 5 M ZAJ3 J,NG1 NGdYWY Y L	Y
 =Y mY Y ]Y .Y %Y "Y =Y .Y Y (Y  "!Y" $#Y$ (%Y& +'Y( ')Y* "+Y, 0-Y. //Y0 1Y2 !3Y4 ,5Y6 N7Y8 9Y: *;Y< #=Y> ?Y@ !AYB "CYD EYF "GYH IYJ KYL \MYN \OYP 'QYR -SYT jUYV <WYX 
YYZ ,[Y\ {]Y^ ,_Y` "aYb 
=cYd HeYf +gYh 
iYj kYl SmYn 0oYp 0qYr ,sYt NuYv ,wYx yYz +{Y| }Y~ Y@ lAYB (CYD "EYF $GYH *IYJ =KYL ^MYN 9OYP %QYR %SYV WYX (YYZ ![Y\ K]Y^ !_Y` !aYb  cYd :eYf @gYh *iYj &kYl  mYn oYp FqY zp"d~B Nz *(2$4 2$jS>3 S>l FF7rvv =2@YC 7 YCxJ)!8 J)ZJ3Z_& _D{'> {|g-0 g-T'!T+H\0?r   