
    (ph                       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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  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      r* " S S5      r+S r,S  r-S! r.S" r/S# r0SS$ jr1S% r2S& r3S' r4S( r5S)S*.S+ jr6S, r7S- r8 " S. S/\5      r90 S0S1_S2S3_S4S5_S6S7_S8S9_S:S;_S<S=_S>S?_S@SA_SBSC_SDSE_SFSG_SHSI_SJSK_SLSM_SNSO_SPSQ_0 SRSS_STSU_SVSW_SXSY_SZS[_S\S]_S^S__S`Sa_SbSc_SdSe_SfSg_ShSi_SjSk_SlSm_SnSo_SpSq_SrSs_E0 StSu_SvSw_SxSy_SzS{_S|S}_S~S_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SSSSS.Er:S r;S r<S r=S r> " S S\95      r? " S S\?5      r@\R                  * \R                  4S jrA " S S\?5      rB " S S\?5      rCS rD " S S\5      rE " S S\?5      rF " S S\?5      rGS rHS rIS rJg)    N)ABCabstractmethod)cached_property)inf)
_lazywhere
_rng_spawn)ClassDocNumpyDocString)specialstats)tanhsinh)_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   a.  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.
__str__()
    Returns a text representation of the domain (e.g. ``[0, b)``).
    Used for generating documentation.

z\inftyz-\inftyz\piz-\pic                     [        5       er   NotImplementedErrorselfr   s     r   contains_Domain.contains       !##r   c                     [        5       er   r*   )r-   ns     r   draw_Domain.draw   r0   r   c                     [        5       er   r*   r,   s     r   get_numerical_endpoints_Domain.get_numerical_endpoints   r0   r   c                     [        5       er   r*   r-   s    r   __str___Domain.__str__   r0   r    N)__name__
__module____qualname____firstlineno____doc__npr   pisymbolsr   r.   r3   r6   r:   __static_attributes__r<   r   r   r'   r'      s    8 vvy266':ruufruufgVG$ $ $ $ $ $ $ $r   r'   c                   P   ^  \ 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r
U =r$ )
_SimpleDomain   a  Representation of a simply-connected domain 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)
    A tuple with two values. Each may be either a float (the numerical
    value of the endpoints of the domain) or a string (the name of the
    parameters that will define 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.
contains(item, parameter_values)
    Determines whether the argument is contained within 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 Nr<   )superrD   copyrB   asarray	endpoints	inclusive)r-   rN   rO   ab	__class__s        r   __init___SimpleDomain.__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symbolrD   update)r-   
parametersparamnew_symbolss       r   define_parameters_SimpleDomain.define_parameters  s<    ( >HHZEzz5<</ZHK( Is    Ac                    U R                   u  p# [        R                  " UR                  X"5      5      n[        R                  " UR                  X35      5      n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. 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.N)rN   rB   rM   get	TypeErrorrR   )r-   parameter_valuesrP   rQ   emessages         r   r6   %_SimpleDomain.get_numerical_endpoints*  s    & ~~
		,

+//56A

+//56A t  	,448NN3C D$$G
 G$!+	,s   A
A 
B'BB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.

)r6   rO   )	r-   itemra   rP   rQ   left_inclusiveright_inclusivein_leftin_rights	            r   r.   _SimpleDomain.containsO  sS    " ,1r ++,<=*...'-$)48 /49TX!!r   )rN   rO   rD   r   )r=   r>   r?   r@   rA   r   rS   r\   r6   r.   rE   __classcell__rR   s   @r   rG   rG      s0     B $'$ #).#J "  "r   rG   c                   (    \ rS rSrSrS rSS jrSrg)_RealDomainir  a  Represents a simply-connected subset of the real line; i.e., an interval

Completes the implementation of the `_SimpleDomain` class for simple
domains 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)".
draw(size, rng, proportions, parameter_values)
    Draws random values based on the domain. Proportions of values within
    the domain, on the endpoints of the domain, outside the domain,
    and having value NaN are specified by `proportions`.

c                     U R                   u  pU R                  u  p4U(       a  SOSnU R                  R                  X 5      nU(       a  SOSnU R                  R                  X" 5      nU U SU U 3$ )N[(]), )rN   rO   rD   r_   )r-   rP   rQ   rg   rh   leftrights          r   r:   _RealDomain.__str__  sp    ~~*...'$s#LLQ#'&CLLQ#'s"QCw''r   Nc                 x   [         R                  R                  U5      nUR                  5       UR                  5       p[         R                  " U5      [         R                  " U5      -  n	SXy'   SX'   U4U-   n
US:X  a  UR                  XxU
S9nU$ US:X  a5  U
n[         R                  " U5      nUR                  US9S:  n	X;U	'   XKU	) '   U$ US:X  a<  XvR                  U
S9-
  nXR                  U
S9-   nU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.

r      in)sizeon      ?outnan)	rB   randomdefault_rngrL   isnanuniformonesfullr   )r-   r2   type_minmaxsqueezed_base_shaperngmin_nnmax_nnishapez
z_on_shapezrs                 r   r3   _RealDomain.draw  sB   , ii##C( SXXZHHVrxx//		**D=F7A& # d]J
#A


"S(AaDqbE  e^%00A++5+11B


"S(A5AD
  e^rvv&Ar   r<   r   )r=   r>   r?   r@   rA   r:   r3   rE   r<   r   r   ro   ro   r  s    2	(4r   ro   c                       \ rS rSrSrS rSrg)_IntegerDomaini  zRepresentation of a domain of consecutive integers.

Completes the implementation of the `_SimpleDomain` class for domains
composed of consecutive integer values.

To be completed when needed.
c                     [         er   r*   r9   s    r   rS   _IntegerDomain.__init__  s    !!r   r<   N)r=   r>   r?   r@   rA   rS   rE   r<   r   r   r   r     s    "r   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)rW   typicalc                    Xl         U=(       d    UU l        X l        Ub   [        U[        5      (       d  [        U5      nU=(       d    UU l        g r   )rV   rW   domain
isinstancer'   ro   r   )r-   rV   r   rW   r   s        r   rS   _Parameter.__init__  s?    	nz'7'C'C!'*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 )rV   rW   strr   r9   s    r   r:   _Parameter.__str__
  s/    499+]4;;-vc$++>N=OqQQr   r   )r   regionproportionsra   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).

)rz   r   r   r   r   rz   rz   r   r{   r   r}   r   r   axis)r   rB   sumr6   broadcast_arraysr   broadcast_shapesprodintr   r   multinomiallenwhererM   tuplerangesqueezer   r3   concatenatepermutedreshapemoveaxis)"r-   r|   r   r   r   ra   r   pvalsrP   rQ   
base_shapeextended_shape
n_extendedn_baser2   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   r3   _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*   )r-   arrs     r   validate_Parameter.validatey  r0   r   )r   rV   rW   r   r   )r=   r>   r?   r@   rA   rS   r:   r3   r   r   rE   r<   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.r<   )rB   rM   r   float64float32int32int64
issubdtypefloatingintegerrV   r`   r   r.   )r-   r   ra   valid_dtyperc   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   r<   N)r=   r>   r?   r@   rA   r   rE   r<   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   )rV   rY   )r-   rY   rZ   s      r   rS   _Parameterization.__init__  s"    :DE*::u,*EEs   $c                 ,    [        U R                  5      $ r   )r   rY   r9   s    r   __len___Parameterization.__len__  s    4??##r   c                 B    [        U R                  R                  5       6 $ r   )r   rY   valuesr9   s    r   rL   _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.
)setrY   keysr-   rY   s     r   matches_Parameterization.matches  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.
Trz   )
r   itemsrY   r   addr   r   rB   result_typelist)	r-   ra   	all_validdtypesrV   r   	parameterr   r   s	            r   
validation_Parameterization.validation  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.ru   )rY   r   r   join)r-   rV   rZ   messagess       r   r:   _Parameterization.__str__  s@    26//2G2G2IJ2I;4CJ2IJyy"" Ks   A	Nc           	      ,   0 n[        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   )r   r   ra   r   )r   rB   iterablerY   zipr   r3   rV   )r-   sizesr   r   r   ra   r|   rZ   s           r   r3   _Parameterization.draw  s    < 5zzU1X!6!6GC00Euoo&<&<&>?KD+0::;!1 ,6 ,ZZ( @  r   )rY   )NNNr   )r=   r>   r?   r@   rA   rS   r   rL   r   r   r:   r3   rE   r<   r   r   r   r     s+    >F$<9" <#
* r   r   c                   ^ ^^^^^^ SS[         R                  * S4[         R                  * S4S.m[        * [        * 4S[        * S4S[        * 4SSS.mSS1m1 S	kmS
S1mSS1m[        R                  " T 5      UUUU UUU4S j5       nU$ )Nr   rz   r   )icdficcdfilogcdfilogccdf)r   r   )rz   r   )logpdfpdf_logcdf1	_logccdf1_cdf1_ccdf1r
  r	  >   r  r  r  r  r  r  r  r  c                 x  > 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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(       a  X:  OX:*  nUT";   a  U(       a  X:  OX:  nX-  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U(       a'  [        R(                  " XSS9n[        R*                  X'   [        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  a5  [        R                  " UU R                  5      nU=(       d    U=(       d    UnU(       a  [        R(                  " UUSS9nU(       a=  T#R                  U[        R*                  [        R*                  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R-                  S
5      (       a  UW   OUW   nUR-                  S
5      (       a  UW   OUW   nUUU'   UUU'   UT;   a  [        R.                  " USS5      nUS   $ UT;   a$  UR0                  n[        R.                  " 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)Nr   zThe argument provided to `.zJ` cannot be be broadcast to the same shape as the distribution parameters.r<   FTr   rL   rL   ccdf              ?)validation_policy	_SKIP_ALLr=   rB   rM   _dtype_shaper   r   r   r   broadcast_to
ValueErrorrR   r_   support	_variabler   rO   anyarrayr   endswithclipreal)$r-   r   argskwargsmethod_namer   r   rb   rc   lowhighleft_inc	right_incmask_low	mask_highmask_invalidany_invalidany_endpointmask_low_endpointmask_high_endpointmask_endpointresres_needs_copyreplace_lowreplace_highrP   rQ   replace_low_endpointreplace_high_endpointr!  clip_logrN   freplace_exactreplace_strictreplacementss$                                r   filtered"_set_invalid_nan.<locals>.filtered\  s   !!Y.T.t.v..jjJJqM 77eNN177E2E

1*A ww%	1++AGGU;OOA- MM+||~>	 #nn33== +~ =(AG 	"-"?IQX) 	 ,'3'9'9R'?|FF<0 	
 -'!""#).1CCM-:-@-@B-FM!#!6 
 d3A ffAOjj44T4V45 99NN5++6E!N99//#t{{3C+J{JlN((3e$7C   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!"&;C"# $''#r2&C
 2w	 H$((C''#tR(C2wg  101H1H0I} %<<  !)q01s   27P 
P9)P44P9)rB   r   	functoolswraps)r9  r=  r!  r8  rN   r:  r;  r<  s   ` @@@@@@r   _set_invalid_nanrA  B  s       & ffWaLwlDI #tcTl6"%q	SD	#v7L X&N<MXDK(H__Qj j jX 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   $ )NFTr  r<   )r  r  r+   _not_implementedrB   rM   r   r  r   r   r  r  _any_invalidastyper   _invalid)r-   r#  r$  r2  
needs_copyr   r9  s         r   r=  +_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   r?  r@  )r9  r=  s   ` r   _set_invalid_nan_propertyrK    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dispatchrN  _sample_dispatch)r=   _method_cacher_   callablereplacegetattrcache_policy	_NO_CACHEKeyErrorr+   rD  )r-   rN  r#  r$  	func_namer%  rb   r9  s          r   wrapped_dispatch.<locals>.wrapped
  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rJ  r9  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   $ )NTr  >   _cdf2_ccdf2r  r  ra        rb  g       @_logcdf2                              ?   r<   )r=   r  rB   r   r   r   r  rF  r!  rM   r  rC   _logexpxmexpyr#   r"  )r-   r   yr#  r$  rZ  r&  r'  r   i_swapr   r2  r9  s               r   r[  '_cdf2_input_validation.<locals>.wrapped3  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   rJ  r]  s   ` r   _cdf2_input_validationrm  !  s(    $ __Q- -^ Nr   c                     [         R                  " U R                  [         R                  5      (       a   [         R                  " U R                  5      $ [         R
                  " U 5      $ r   )rB   r   r   inexactfinfoiinfor   s    r   _fiinforr  f  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   r#  r9  n_argsnamess     r   r[  _kwargs2args.<locals>.wrapped{  s0    FT'6]Fd3ud67m+D&EFFr   )r   r   r   r   )r9  r#  r$  r[  rv  rw  s   `   @@r   _kwargs2argsry  m  sY     :2D\rFEYFG :V]]_--D=r   c                 2    S nS n[        U S:  U 4XS9S   $ )ah  Compute the log of the complement of the exponential.

This function is equivalent to::

    log1mexp(x) = np.log(1-np.exp(x))

but avoids loss of precision when ``np.exp(x)`` is nearly 0 or 1.

Parameters
----------
x : array_like
    Input array.

Returns
-------
y : ndarray
    An array of the same shape as `x`.

Examples
--------
>>> import numpy as np
>>> from scipy.stats._distribution_infrastructure import _log1mexp
>>> x = 1e-300  # log of a number very close to 1
>>> _log1mexp(x)  # log of the complement of a number very close to 1
-690.7755278982137
>>> # np.log1p(-np.exp(x))  # -inf; emits warning

c                 X    [         R                  " [         R                  " U 5      * 5      $ r   )rB   log1pr"   r   s    r   f1_log1mexp.<locals>.f1  s    xx
##r   c           	          [         R                  " SS9   [         R                  " [         R                  " [        R
                  " U S-   5      * 5      5      sS S S 5        $ ! , (       d  f       g = f)Nignoredividerf  )rB   errstater"  r#   r   expm1r   s    r   f2_log1mexp.<locals>.f2  s?    [[)772667==R#8"89: *))s   AA!!
A/rd  )r9  r  r<   )r   )r   r}  r  s      r   	_log1mexpr    s(    :$;
 a"fqdb044r   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.
rg  r   r   )rB   isneginfr"  r  rM   rL   rp  r   r   r   r   	logsumexprC   r   )r   rj  r   r2  s       r   ri  ri    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$ )Nrc  rz   )rB   	full_like	ones_likeisfinite)xminxmaxrP   rQ   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`.

rg  r~   r<   )
r   rB   
atleast_1dr"  rF  r   imagr"   rC   r   )r   r   r"  complexrj  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	   ContinuousDistribution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.
        rz   z:
        This class accepts one parameterization:
        z
.
        twothreefourfive)rh           z- 
z
        This class accepts z parameterizations:

        	
        )r   _parameterizationsr  r   r   r   splitlstrip)r  n_parameterizationsr   r  numberpparameterizationslines           r   r  r    s2   k<<=";#8#8#?#?"@DF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       SU SUR)                  5       UR+                  5       UR-                  5       4 SUR/                  5       UR1                  5       4 SUR3                  5       UR5                  5       4 S[7        UR9                  SS95       S3-  nSR                  UR;                  S5       Vs/ s H  nUR=                  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   r<   l   j? )r   i_parameterizationl   l rh  =rr   ru   rt   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  ze
    To evaluate the probability density function of the underlying distribution
    at argument ``x=z``:

    >>> x = z
    >>> X.pdf(x)
    a  

    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

    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 = z
    >>> np.allclose(X.ccdf(x, y), 1 - (X.cdf(y) - X.cdf(x)))
    True

    There are methods for computing measures of central tendency,
    dispersion, higher moments, and entropy.

    >>> X.mean(), X.median(), X.mode()
    z2
    >>> X.variance(), X.standard_deviation()
    z(
    >>> X.skewness(), X.kurtosis()
    aR  
    >>> np.allclose(X.moment(order=6, kind='standardized'),
    ...             X.moment(order=6, kind='central') / X.variance()**3)
    True
    >>> np.allclose(np.exp(X.logentropy()), X.entropy())
    True

    Pseudo-random samples can be drawn from
    the underlying distribution using ``sample``.

    >>> X.sample(shape=(4,))
    )r  r   z  # may vary
    r  rz   )_num_parametersrB   r   r   _drawr=   r   r  rY   roundrV  r   r   _parametersru  r  r  r   r   r
  meanmedianmodevariancestandard_deviationskewnesskurtosisreprsampler  r  )r  n_parametersshapesr   r   distrV   parameter_namesra   valuename_valuesinstantiationrZ   
attributesXr  r   rj  exampler  s                       r   r  r    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 UU1XJ ( C  VVXqxxz1668#$ %ZZ\1''))* +ZZ\1::<  ! 
!(((
  !c2 2Gj ii7==3FG3F43FGKLGNK-?  L~ Hs   !KKK!Kc                   0   \ 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, 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 rBSC 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 rQSSS0.SS jjrR\SST 5       rT\1SS0.SU j5       rUSV rVSW rWSX rXSY rYSZ rZ\ISS0.S[ j5       r[\1SS0.S\ j5       r\S] r]S^ r^S_ r_S` r`Sa raSSS0.Sb jjrb\SSc 5       rc\1SS0.Sd j5       rdSe reSf rfSg rgSh rhSi ri\ISj 5       rj\1SS0.Sk j5       rkSl rlSm rmSn rnSo roSp rpSSS0.Sq jjrq\SSr 5       rr\1SS0.Ss j5       rsSt rtSu ru\ISS0.Sv j5       rv\1SSw j5       rwSx rxSy rySz rzS{ r{S| r|SSS0.S} jjr}\SS~ 5       r~\1SS0.S j5       rS 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 rSSS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.

rz   N)tolr  rW  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.r<   )
r  r  rW  rR   r=   rD  _original_parameterssortedr   _update_parameters)r-   r  r  rW  rY   keyvals          r   rS   ContinuousDistribution.__init__  s    !2(''( )L L 	
 %'! Z--/0E0 $,347 ch0 	 E-*-Es   	A>"A>r  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   rz   The `zB` distribution family does not accept parameters, but parameters `z` were provided.c                 B    U R                   U   R                  5       S   $ rJ   )r  rL   )self_name_s     r   <lambda>;ContinuousDistribution._update_parameters.<locals>.<lambda>E  s    383D3DU3K3P3P3RSU3Vr   r<   ) r  rL   rX   rB   rM   rG  rE  r   r  _ndim_sizer   r  r  r  _process_parametersr   r  rR   r=   r   r  _identify_parameterization
_broadcast	_validatereset_cacher  _parameterizationr   hasattrsetattrproperty)r-   r  paramsrY   original_parametersparameterizationrc   r   r|   ndiminvalidr-  r   rV   s                 r   r  )ContinuousDistribution._update_parameters  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_cacherS  _constant_cacher9   s    r   r  "ContinuousDistribution.reset_cacheH  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   rR   r=   _get_parameter_strr  )r-   rY   parameter_names_setr  rc   r  s         r   r  1ContinuousDistribution._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>4ContinuousDistribution._broadcast.<locals>.<genexpr>  s     O9   rz   r   zThe parameters `z` provided to the `z<` distribution family cannot be broadcast to the same shape.)r   rB   rM   r   r   r   r|   r  r   r  r  rR   r=   ru  r   r   )r-   rY   r   parameter_valsparameter_shapesrb   r  rc   s           r   r  !ContinuousDistribution._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$ rJ   )r   r   rB   r  rL   r   )r-   r  rY   r   r   r  r-  parameter_names           r   r   ContinuousDistribution._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.
r<   r-   r  s     r   r  *ContinuousDistribution._process_parameters  s	     r   c                 H    SSR                  UR                  5       5       S3$ )N{ru   })r   r   r   s     r   r  )ContinuousDistribution._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  rL   r   r   )r-   r   s     r   _copy_parameterization-ContinuousDistribution._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.
)_tolr9   s    r   r  ContinuousDistribution.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 )Nr<   r   zAttribute `tol` of `z)` must be a positive float, if specified.)r   r  rB   rM   r   r   r   r   rR   r=   r  )r-   r  rc   s      r   r  r    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_policyr9   s    r   rW  #ContinuousDistribution.cache_policy  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   lowerrR   r=   r  r!  )r-   rW  cache_policiesrc   s       r   rW  r"    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_policyr9   s    r   r  (ContinuousDistribution.validation_policy  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 `r$  r%  )r   r&  rR   r=   r  r)  )r-   r  iv_policiesrc   s       r   r  r*    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  Nru   rr   rt   )
rR   r=   r   r  r   rB   printoptionsr  r   r  r-   
class_namerY   inforW   r  str_parameterss          r   __repr__ContinuousDistribution.__repr__  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)Nr.  r/  r  ru   rr   rt   )
rR   r=   r   r  r   rB   r1  r   r   r  r2  s          r   r:   ContinuousDistribution.__str__!  s    ^^,,
$3399;<
__r*LVWJ=6#e*6JNW + IIn56N#Qtyy/q11 X +*r8  c                     [        XS9$ N)locShiftedScaledDistributionr-   r=  s     r   __add__ContinuousDistribution.__add__+  s    (77r   c                     [        X* S9$ r<  r>  r@  s     r   __sub__ContinuousDistribution.__sub__.  s    (488r   c                     [        XS9$ )Nscaler>  r-   rH  s     r   __mul__ContinuousDistribution.__mul__1  s    (;;r   c                     [        U SU-  S9$ )Nrz   rG  r>  rI  s     r   __truediv__"ContinuousDistribution.__truediv__4  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.r.  r/  rr   z)**rh  c                    > U T-  $ r   r<   uothers    r   r  0ContinuousDistribution.__pow__.<locals>.<lambda>D  s	    Er   c                 j   > [         R                  " U 5      [         R                  " U 5      ST-  -  -  $ Nrz   )rB   signr!   rQ  s    r   r  rT  F  s#    bffQi!e).D!Dr   c                 N   > ST-  [         R                  " U 5      ST-  S-
  -  -  $ rV  )rB   r!   rQ  s    r   r  rT  G  s#    !E'BFF1I%!,D"Dr   grepr_patternstr_patternhdh
increasingT)
rB   isscalarr   r+   r1  r  r   r!   ru   MonotonicTransformedDistribution)r-   rS  rc   r[  r\  r  funcss    `     r   __pow__ContinuousDistribution.__pow__7  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   )rA  r-   rS  s     r   __radd__ContinuousDistribution.__radd__K      ||E""r   c                 @    U R                  5       R                  U5      $ r   )__neg__rA  rf  s     r   __rsub__ContinuousDistribution.__rsub__N  s    ||~%%e,,r   c                 $    U R                  U5      $ r   )rJ  rf  s     r   __rmul__ContinuousDistribution.__rmul__Q  ri  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)Nr.  r/  c                     SU -  $ rV  r<   rR  s    r   r  5ContinuousDistribution.__rtruediv__.<locals>.<lambda>W      QUr   z/(rt   c                     SU -  $ rV  r<   rs  s    r   r  rt  Z  ru  r   c                     SU S-  -  $ )Nrz   rh  r<   rs  s    r   r  rt  Z  s    Q!Vr   rY  r   r_  FzjDivision by a random variable is only implemented when the support is either non-negative or non-positive.rz   )	r  rB   r1  ru  r  r   allra  r+   )r-   rS  rP   rQ   rb  r   rc   s          r   __rtruediv__#ContinuousDistribution.__rtruediv__T  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)Nr.  r/  c                    > TU -  $ r   r<   rQ  s    r   r  1ContinuousDistribution.__rpow__.<locals>.<lambda>h  s	    UAXr   c                 ^   > [         R                  " U 5      [         R                  " T5      -  $ r   rB   r#   rQ  s    r   r  r}  i  s    RVVAY%>r   c                 d   > S[         R                  " U [         R                  " T5      -  5      -  $ rV  )rB   r!   r#   rQ  s    r   r  r}  j  s     a"&&RVVE]1B*C&Cr   z**(rt   )rZ  r]  r^  r[  r\  r   rz   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)rB   r1  ru  r  r   r`  r+   ra  )r-   rS  rb  rc   s    `  r   __rpow__ContinuousDistribution.__rpow__f  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-  $ )Nrd  r<   r9   s    r   rk  ContinuousDistribution.__neg__y  s    byr   c                     [        U 5      $ r   FoldedDistributionr9   s    r   __abs__ContinuousDistribution.__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   r<   zArgument `order` of `z,.moment` must be a finite, positive integer.r   zArgument `kind` of `z.moment` must be one of r  )r  r  rB   rM   r  rR   r=   r  rf   	Exceptionr  r   r&  )r-   orderkindkindsrc   	order_intrb   s          r   _validate_order_kind+ContinuousDistribution._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   $ rJ   )rB   rM   r   r  rF  r,   s     r   _preserve_type%ContinuousDistribution._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   rz   T)endpointr   )r   r   r<   )	rB   r   r   r   r  _num_parameterizationsintegersr   r3   )clsr  r   r  r   r2   r  rY   s           r   r  ContinuousDistribution._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  -ContinuousDistribution._num_parameterizations  s     3))**r   c                 `    U R                  5       (       d  S$ [        U R                  U   5      $ Nr   )r  r   r  )r  r  s     r   r  &ContinuousDistribution._num_parameters  s5     3355 	F//0BCD	Fr   Fc           	         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	[        XXsXYS9n
U
R                  $ )Nr   r#  r$  )r#  r#   rtolr<   )_supportrB   r   r|   emptyr   r  ry  r   r  	_tanhsinhintegral)r-   	integrandlimitsr#  r  r#   rP   rQ   r9  r  r2  s              r   _quadrature"ContinuousDistribution._quadrature  s     +1.t}}&v&f""1(vv88AGG4;;77\rt~6yFC""D)txx((tdhha? ||r   )boundsr  c          	        ^ Uc  U R                   " S0 UD6OUu  pVUc  0 OUn[        R                  " X%U5      u  p%nUR                  (       d)  [        R                  " UR
                  U R                  S9$ U4S jn[        Xr/US9u  pUR
                  n
[        R                  " XV5      u  pV[        XV5      u  pUR                  U
5      nUR                  U
5      nUR                  U
5      nUR                  U
5      n[        XXXiS9n[        U R                  5      (       a  S OU R                  n[        XR                  UR                   XS9R"                  $ )Nr   c                    > T" U 40 UD6U-
  $ r   r<   )r   _pr$  r9  s      r   r  1ContinuousDistribution._solve_bounded.<locals>.f2  s    Q>&>B&&r   r  xl0xr0r  r  r#  )rP   rQ   r#  xrtolr<   )r  rB   r   r|   r  r   r  ry  r  r  r   r   r   r  r   xlxrr   )r-   r9  r  r  r  r  r  r  f3r#  r   r  r  r2  r  s    `             r   _solve_bounded%ContinuousDistribution._solve_bounded  s    17T]],V,F
~6++AT:vv88AGG4;;77	'  V< 

]]4.
!$-||E"||E"kk% kk% BS$R  ))txxR66SVV$LNNNr   c                 X    [        U R                  US 5      n[        [        US 5      nX#L$ r   )rV  rR   r  )r-   r%  rN  super_methods       r   
_overrides!ContinuousDistribution._overrides  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$ rJ   )r  r  r  r   r  rB   r  rE  rM   rL   r   rG  rW  rX  )r-   rP   rQ   r  s       r   r  ContinuousDistribution.supportI  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  )
r  r   r6   r   r   r   r   rB   r  r  )r-   r  rP   rQ   valsr   s         r   r  ContinuousDistribution._supportc  s    ~~$$<<VDv;;(DGMME-.WW-=)1A-.WW-=)1A""1%t':':1'===r   rM  c                D    U R                   " SSU0U R                  D6S-   $ )NrN  rf  r<   )_logentropy_dispatchr  r-   rN  s     r   
logentropy!ContinuousDistribution.logentropyn  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r-   rN  r  s      r   r  +ContinuousDistribution._logentropy_dispatchr  sZ    ??011--F
 	 __/0011F  00Fr   c                 ,    [        U R                  5      er   r+   rD  r  s     r   r  *ContinuousDistribution._logentropy_formula|      !$"7"788r   c                 j    [         R                  " U R                  " S0 UD6S-   5      n[        U5      $ )Nrf  r<   )rB   r#   _entropy_dispatchr  )r-   r  r2  s      r   _logentropy_logexp)ContinuousDistribution._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 rJ   )r  rB   isinfr"  r  r   rM   r  )r-   r  r   maskr  r  params_masks          r   r  .ContinuousDistribution._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      -   $ Nrf  )_logpdf_dispatchrB   r#   )r   r  r	  r-   s      r   logintegrandCContinuousDistribution._logentropy_quadrature.<locals>.logintegrand  s0    **177FBFF2f9---r   T)r  r#   rg  )r  r  rB   rC   )r-   r  r  r2  s   `   r   r  -ContinuousDistribution._logentropy_quadrature  s6    	. |E$S2558^44r   c                >    U R                   " SSU0U R                  D6$ NrN  r<   )r  r  r  s     r   entropyContinuousDistribution.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  (ContinuousDistribution._entropy_dispatch  sZ    ??-..**F
 	 __233))F  --Fr   c                 ,    [        U R                  5      er   r  r  s     r   r  'ContinuousDistribution._entropy_formula  r  r   c           	      v    [         R                  " [         R                  " U R                  " S0 UD65      5      $ rJ   )rB   r"  r"   r  r  s     r   r  &ContinuousDistribution._entropy_logexp  s(    wwrvvd77A&ABCCr   c                 0   ^  U 4S jnT R                  X!S9* $ )Nc                 X   > TR                   " U 40 UD6nTR                  " U 40 UD6nX2-  $ r   )_pdf_dispatchr  )r   r  r
  r	  r-   s       r   r  =ContinuousDistribution._entropy_quadrature.<locals>.integrand  s5    $$Q1&1C**177F<r   r  r  )r-   r  r  s   `  r   r  *ContinuousDistribution._entropy_quadrature  s!    	     :::r   c                >    U R                   " SSU0U R                  D6$ r  )_median_dispatchr  r  s     r   r  ContinuousDistribution.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  'ContinuousDistribution._median_dispatch  s6    ??,--))F  &&Fr   c                 ,    [        U R                  5      er   r  r  s     r   r  &ContinuousDistribution._median_formula  r  r   c                 &    U R                   " S0 UD6$ )N)r~   _icdf_dispatchr  s     r   r  #ContinuousDistribution._median_icdf  s    ""1&11r   c                >    U R                   " SSU0U R                  D6$ r  )_mode_dispatchr  r  s     r   r  ContinuousDistribution.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  r  _mode_optimizationr  s      r   r  %ContinuousDistribution._mode_dispatch  s7     ???++''F  ,,Fr   c                 ,    [        U R                  5      er   r  r  s     r   r  $ContinuousDistribution._mode_formula  r  r   c                 <  ^  T R                   (       d)  [        R                  " T R                  T R                  S9$ T R
                  " S0 UD6u  p#T R                  " S0 UD6n[        U 4S jSUS9u  pV[        XTX#US9n[        XWR                  UR                  UR                  US9n[        R                  " UR                  5      n	UR                  S:H  n
XR                   UR"                  :*  -  nXR$                  UR"                  :  -  nX+   X'   X<   X'   U	S   $ )Nr   c                 ,   > TR                   " U 40 UD6* $ r   r  )r   r  r-   s     r   r  ;ContinuousDistribution._mode_optimization.<locals>.<lambda>  s    D4F4Fq4SF4S3Sr   r<   r  )r  r  r#  )r#  rd  )r  rB   r  r  r  r  r  ry  r   r   r  xmr  rM   r   statusflfmfr)r-   r  rP   rQ   mr9  r#  res_br2  r  mode_at_boundarymode_at_leftmode_at_rights   `            r   r  )ContinuousDistribution._mode_optimization  s    zz88DKKt{{;;}}&v&!!+F+S$&v7 ADA$Q%((EHH4Pzz#%%  <<2-'88uxx+?@(HHuxx,?@_.Bxr   c                $    U R                  SSUS9$ )Nrz   rawr  rN  momentr  s     r   r  ContinuousDistribution.mean  s    {{15{88r   c                $    U R                  SSUS9$ )Nrh  centralr  r  r  s     r   r  ContinuousDistribution.variance  s    {{19V{<<r   c                H    [         R                  " U R                  US95      $ NrM  )rB   sqrtr  r  s     r   r  )ContinuousDistribution.standard_deviation  s    wwt}}F}344r   c                $    U R                  SSUS9$ )Nr  standardizedr  r  r  s     r   r  ContinuousDistribution.skewness  s    {{1>&{AAr   
non-excess)rN  
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$ )
Nr*  excesszParameter `convention` of `z.kurtosis` must be one of r  r  r(  r  r  )rR   r=   r&  r  r  )r-   rN  r+  conventionsrc   ks         r   r  ContinuousDistribution.kurtosis  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$ NrN  )r  r  r-   r   rN  s      r   r	  ContinuousDistribution.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  r7  r   r  _logpdf_logexpr-   r   rN  r  s       r   r  'ContinuousDistribution._logpdf_dispatch!	  sE    ??,--))F  TXX((Fr   c                 ,    [        U R                  5      er   r  r-   r   r  s      r   r7  &ContinuousDistribution._logpdf_formula)	  r  r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rB   r#   r  r<  s      r   r8  %ContinuousDistribution._logpdf_logexp,	  !    vvd((5f566r   c               @    U R                   " U4SU0U R                  D6$ r2  )r  r  r3  s      r   r
  ContinuousDistribution.pdf/	  #    !!!GFGd6F6FGGr   c                f    U R                  S5      (       a  U R                  nU$ U R                  nU$ )N_pdf_formula)r  rE  _pdf_logexpr9  s       r   r  $ContinuousDistribution._pdf_dispatch3	  s5    ??>**&&F  %%Fr   c                 ,    [        U R                  5      er   r  r<  s      r   rE  #ContinuousDistribution._pdf_formula;	  r  r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rB   r"   r  r<  s      r   rF  "ContinuousDistribution._pdf_logexp>	  !    vvd++A8899r   c               F    Uc  U R                  XS9$ U R                  XUS9$ r$  )r  re  r-   r   rj  rN  s       r   logcdfContinuousDistribution.logcdfC	  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$ )NrN  rf  )_logcdf2_dispatchr  rB   r   r   complexfloating)r-   r   rj  rN  r   s        r   re  ContinuousDistribution._logcdf2I	  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  rV  _logcdf2_subtraction_logcdf2_logexp_safe_logcdf2_quadraturer-   r   rj  rN  r  s        r   rR  (ContinuousDistribution._logcdf2_dispatchN	  s     ??-..**F  oo/00!344..F  oon--11..F  --Fr   c                 ,    [        U R                  5      er   r  r-   r   rj  r  s       r   rV  'ContinuousDistribution._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   $ )Nrd  rg  r<   )rB   minimummaximum_logcdf_dispatch_logccdf_dispatchri  	logaddexpr  rC   r  r"  )r-   r   rj  r  	flip_signlogcdf_xlogcdf_y	logccdf_x	logccdf_y	case_left
case_rightcase_centrallog_masslog_tails                 r   r[  +ContinuousDistribution._logcdf2_subtractiona	  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_dispatchrB   r  r#   )r-   r   rj  r  express        r   _logcdf2_logexp&ContinuousDistribution._logcdf2_logexpr	  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 rJ   )
rw  rB   r  r"  r  r   r  r   rM   r]  )	r-   r   rj  r  r   r  r  r  r  s	            r   r\  +ContinuousDistribution._logcdf2_logexp_safew	  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  )r-   r   rj  r  logress        r   r]  *ContinuousDistribution._logcdf2_quadrature	  s-    !!$"7"7&*6 " ;r   c                @    U R                   " U4SU0U R                  D6$ r2  )rf  r  r3  s      r   r  ContinuousDistribution._logcdf1	  r5  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$ )NrW  rX  rY  )r  rW  _logcdf_complement_logcdf_logexp_safe_logcdf_quadraturer9  s       r   rf  'ContinuousDistribution._logcdf_dispatch	  s}    ??,--))F  __/00,,F
 	 __^,,--F  ,,Fr   c                 ,    [        U R                  5      er   r  r<  s      r   rW  &ContinuousDistribution._logcdf_formula	  r  r   c                 :    [        U R                  " U40 UD65      $ r   )r  rg  r<  s      r   r  )ContinuousDistribution._logcdf_complement	  s    //<V<==r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rB   r#   _cdf_dispatchr<  s      r   _logcdf_logexp%ContinuousDistribution._logcdf_logexp	  r@  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 rJ   )	r  rB   r  r  r   r  r   rM   r  r-   r   r  r   r  r  r  r  s           r   r  *ContinuousDistribution._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#   r<   r  r  r  r-   r   r  rP   _s        r   r  )ContinuousDistribution._logcdf_quadrature	  >    }}&v& 5 5qf'-4   9 	9r   c               F    Uc  U R                  XS9$ U R                  XUS9$ r$  )r  ra  rN  s       r   cdfContinuousDistribution.cdf	  s+    9::a://::a6:22r   c                @    U R                   " X4SU0U R                  D6$ r2  )ru  r  rN  s       r   ra  ContinuousDistribution._cdf2	  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_formularW  rX  rY  rZ  )r  r  _cdf2_logexp_cdf2_subtraction_safe_cdf2_quadraturer^  s        r   ru  %ContinuousDistribution._cdf2_dispatch	  s     ???++''F  oo/00!344&&F
 	 __^,,0P0P00F  **Fr   c                 ,    [        U R                  5      er   r  ra  s       r   r  $ContinuousDistribution._cdf2_formula	  r  r   c           	      x    [         R                  " [         R                  " U R                  " X40 UD65      5      $ r   )rB   r"  r"   rR  ra  s       r   r  #ContinuousDistribution._cdf2_logexp	  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_dispatchrB   r   )	r-   r   rj  r  cdf_xcdf_yccdf_xccdf_yr   s	            r   _cdf2_subtraction(ContinuousDistribution._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/   /UQ76 X'   U	S   $ s  snnf )Nr~   r<   )r  r  rB   r   rp  r  epsr   r  r%  re  spacingr!   r  r   r  r   rM   r  )r-   r   rj  r  r  r  r  r  r   r   r  r  cdf_maxccdf_maxr  r  r  r  r  s                      r   r  -ContinuousDistribution._cdf2_subtraction_safe	  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MMCI2w	;s   :2G$c                 :    U R                  U R                  X4US9$ )Nr  r  )r  r  ra  s       r   r  'ContinuousDistribution._cdf2_quadrature	  s"     2 2A6&QQr   c                @    U R                   " U4SU0U R                  D6$ r2  )r  r  r3  s      r   r  ContinuousDistribution._cdf1	  rC  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$ )NrY  rW  rZ  )r  rY  _cdf_logexp_cdf_complement_safe_cdf_quadraturer9  s       r   r  $ContinuousDistribution._cdf_dispatch	  s|    ??>**&&F  __.//%%F
 	 ___--..F  ))Fr   c                 ,    [        U R                  5      er   r  r<  s      r   rY  #ContinuousDistribution._cdf_formula
  r  r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rB   r"   rf  r<  s      r   r  "ContinuousDistribution._cdf_logexp
  rL  r   c                 .    SU R                   " U40 UD6-
  $ rV  )r  r<  s      r   _cdf_complement&ContinuousDistribution._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 Nrz   r<   )r  rB   rp  r  r  r   r  r%  r  r  r   r  r   rM   r  )r-   r   r  r  r   r  r  r  r  r  r  s              r   r  +ContinuousDistribution._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  r<   r  r  r  r  s        r   r  &ContinuousDistribution._cdf_quadrature
  <    }}&v& 2 2A6'-   / 	/r   c               F    Uc  U R                  XS9$ U R                  XUS9$ r$  )r  	_logccdf2rN  s       r   logccdfContinuousDistribution.logccdf
  s+    9>>!>33>>!v>66r   c                @    U R                   " X4SU0U R                  D6$ r2  )_logccdf2_dispatchr  rN  s       r   r   ContinuousDistribution._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  )ContinuousDistribution._logccdf2_dispatch&
  s8     ??.//++F  ,,Fr   c                 ,    [        U R                  5      er   r  ra  s       r   r  (ContinuousDistribution._logccdf2_formula0
  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   )rf  rg  r   r  )r-   r   rj  r  rj  rm  s         r   r  )ContinuousDistribution._logccdf2_addition3
  sB    ((5f5**177	  (!6Q??r   c                @    U R                   " U4SU0U R                  D6$ r2  )rg  r  r3  s      r   r   ContinuousDistribution._logccdf18
  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$ )NrX  rW  rZ  )r  rX  _logccdf_complement_logccdf_logexp_safe_logccdf_quadraturer9  s       r   rg  (ContinuousDistribution._logccdf_dispatch<
  s}    ??-..**F  __.//--F
 	 ___--..F  --Fr   c                 ,    [        U R                  5      er   r  r<  s      r   rX  'ContinuousDistribution._logccdf_formulaH
  r  r   c                 :    [        U R                  " U40 UD65      $ r   )r  rf  r<  s      r   r  *ContinuousDistribution._logccdf_complementK
  s    ..q;F;<<r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rB   r#   r  r<  s      r   _logccdf_logexp&ContinuousDistribution._logccdf_logexpN
  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 rJ   )	r  rB   r  r  r   r  r   rM   r  r  s           r   r  +ContinuousDistribution._logccdf_logexp_safeQ
  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  r-   r   r  r  rQ   s        r   r  *ContinuousDistribution._logccdf_quadrature[
  r  r   c               F    Uc  U R                  XS9$ U R                  XUS9$ r$  )r  rb  rN  s       r   r  ContinuousDistribution.ccdf`
  s+    9;;q;00;;qF;33r   c                @    U R                   " X4SU0U R                  D6$ r2  )_ccdf2_dispatchr  rN  s       r   rb  ContinuousDistribution._ccdf2f
  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  r  _ccdf2_additionr^  s        r   r  &ContinuousDistribution._ccdf2_dispatchj
  s6    ??+,,((F  ))Fr   c                 ,    [        U R                  5      er   r  ra  s       r   r  %ContinuousDistribution._ccdf2_formular
  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  )r-   r   rj  r  r  r  s         r   r  &ContinuousDistribution._ccdf2_additionu
  s4    ""1//$$Q1&1~r   c                @    U R                   " U4SU0U R                  D6$ r2  )r  r  r3  s      r   r  ContinuousDistribution._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$ )NrZ  rX  rY  )r  rZ  _ccdf_logexp_ccdf_complement_safe_ccdf_quadraturer9  s       r   r  %ContinuousDistribution._ccdf_dispatch
  s|    ???++''F  __/00&&F
 	 __^,,//F  **Fr   c                 ,    [        U R                  5      er   r  r<  s      r   rZ  $ContinuousDistribution._ccdf_formula
  r  r   c                 P    [         R                  " U R                  " U40 UD65      $ r   )rB   r"   rg  r<  s      r   r  #ContinuousDistribution._ccdf_logexp
  s!    vvd,,Q9&9::r   c                 .    SU R                   " U40 UD6-
  $ rV  )r  r<  s      r   _ccdf_complement'ContinuousDistribution._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  rB   rp  r  r  r   r  r%  r  r  r   r  r   rM   r  )r-   r   r  r  r   r  r  r  r  r  r  s              r   r  ,ContinuousDistribution._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   r  'ContinuousDistribution._ccdf_quadrature
  r  r   c               @    U R                   " U4SU0U R                  D6$ r2  )_ilogcdf_dispatchr  r-   logprN  s      r   r  ContinuousDistribution.ilogcdf
  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  r  _ilogcdf_complement_ilogcdf_inversionr9  s       r   r  (ContinuousDistribution._ilogcdf_dispatch
  sZ    ??-..**F
 	 __011--F  ,,Fr   c                 ,    [        U R                  5      er   r  r<  s      r   r  'ContinuousDistribution._ilogcdf_formula
  r  r   c                 :    U R                   " [        U5      40 UD6$ r   )_ilogccdf_dispatchr  r<  s      r   r  *ContinuousDistribution._ilogcdf_complement
  s    &&y|>v>>r   c                 6    U R                  U R                  XS9$ Nr  )r  rf  r<  s      r   r  )ContinuousDistribution._ilogcdf_inversion
  s    ""4#8#8!"KKr   c               @    U R                   " U4SU0U R                  D6$ r2  )r   r  r-   r  rN  s      r   r  ContinuousDistribution.icdf
  r  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  r)  _icdf_complement_safe_icdf_inversionr9  s       r   r   %ContinuousDistribution._icdf_dispatch
  sY    ???++''F
 	 __-..//F  ))Fr   c                 ,    [        U R                  5      er   r  r<  s      r   r)  $ContinuousDistribution._icdf_formula
  r  r   c                 .    U R                   " SU-
  40 UD6$ rV  )_iccdf_dispatchr<  s      r   _icdf_complement'ContinuousDistribution._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  )r2  rB   rp  r  r  r   r  r%  r  r  r   r  r   rM   r,  
r-   r   r  r   r  r  r  r  r  r  s
             r   r+  ,ContinuousDistribution._icdf_complement_safe
  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$ r#  )r  r  r<  s      r   r,  &ContinuousDistribution._icdf_inversion
  s    ""4#5#5q"HHr   c               @    U R                   " U4SU0U R                  D6$ r2  )r   r  r  s      r   r  ContinuousDistribution.ilogccdf
  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$ )Nr  r  )r  r  _ilogccdf_complement_ilogccdf_inversionr9  s       r   r   )ContinuousDistribution._ilogccdf_dispatch
  sZ    ??.//++F
 	 __/00..F  --Fr   c                 ,    [        U R                  5      er   r  r<  s      r   r  (ContinuousDistribution._ilogccdf_formula
  r  r   c                 :    U R                   " [        U5      40 UD6$ r   )r  r  r<  s      r   r=  +ContinuousDistribution._ilogccdf_complement
  s    %%il=f==r   c                 6    U R                  U R                  XS9$ r#  )r  rg  r<  s      r   r>  *ContinuousDistribution._ilogccdf_inversion
  s    ""4#9#91"LLr   c               @    U R                   " U4SU0U R                  D6$ r2  )r1  r  r&  s      r   r  ContinuousDistribution.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$ )Nr*  r)  )r  r*  _iccdf_complement_safe_iccdf_inversionr9  s       r   r1  &ContinuousDistribution._iccdf_dispatch
  sY    ??+,,((F
 	 ___--00F  **Fr   c                 ,    [        U R                  5      er   r  r<  s      r   r*  %ContinuousDistribution._iccdf_formula  r  r   c                 .    U R                   " SU-
  40 UD6$ rV  r  r<  s      r   _iccdf_complement(ContinuousDistribution._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  )rO  rB   rp  r  r  r   r  r%  r  r  r   r  r   rM   rJ  r5  s
             r   rI  -ContinuousDistribution._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	;r7  c                 6    U R                  U R                  XS9$ r#  )r  r  r<  s      r   rJ  'ContinuousDistribution._iccdf_inversion  s    ""4#6#6"IIr   rN  r   c                d   [         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                  " XE4UUS.U R                  D6nUR                  U R                  SS9$ )NrU  Fr  )rB   r   r   r  r   r   	QMCEnginer   r   rR  r  rF  r  )r-   r   rN  r   sample_shape
full_shaper2  s          r   r  ContinuousDistribution.sample:  s     (*{{5'9'9xuU|!KK/
0:30N0Nbii##C(TW##L AV(+A/3/?/?A 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   rW  r\  _sample_inverse_transform)r-   rX  rY  rN  r   r  s         r   rR  'ContinuousDistribution._sample_dispatchE  sH     ??,--jcmm6T6T))F  33Fr   c                ,    [        U R                  5      er   r  )r-   rX  rY  r   r  s        r   r\  &ContinuousDistribution._sample_formulaN  r  r   c                    [        U[        R                  5      (       a  U R                  " X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   rW  _qmc_uniformr   r  r   )r-   rX  rY  r   r  r   s         r   r]  0ContinuousDistribution._sample_inverse_transformQ  sW    c3==))''UsUfUGjjjjDG""75f55r   c                   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   rz   )dscrambleoptimizationbitsseedr<   rd  )mathr   r   r   rR   ru  rg  _optimizationr   r   Sobolri  r   r   r  rB   r   stackrM   )r-   rX  rY  rb  r  n_low_discrepancyn_independentrngs
qrng_classr$  uniformsr   r   s                r   rc  #ContinuousDistribution._qmc_uniformX  s   
 0<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
quadraturer<   r9   s    r   _moment_methods&ContinuousDistribution._moment_methods  s    6 	6r   c                 (    U R                  5       S   $ r  
_constantsr9   s    r   _zeroContinuousDistribution._zero       ##r   c                 (    U R                  5       S   $ rV  r  r9   s    r   _oneContinuousDistribution._one  r  r   c                     U R                   b  U R                   $ U R                  SS/5      nU R                  [        :w  a  Xl         U$ Nr   rz   )r   r  rW  rX  )r-   	constantss     r   r  !ContinuousDistribution._constants  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r  r!  r(  rM  )_moment_raw_moment_central_moment_standardizedr  r-   r  r  rN  r  moment_kinds         r   r  ContinuousDistribution.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  r-   r  rN  r  s       r   r  "ContinuousDistribution._moment_raw  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$ )	Nrv  rw  rz  rz   rx  r{  centerquadrature_icdf)
r  r_   _moment_raw_formula_moment_raw_transform_moment_raw_general_moment_integrate_pdfr  _moment_integrate_icdfrW  rX  r-   r  r  r  r  s        r   r  +ContinuousDistribution._moment_raw_dispatch  s   g++//t<F>i72--e>v>F>kW4//@@F>i72--e>v>F>lg5//SdjjSFSF>/7:00TtzzTVTF$"3"3y"@,2""5)r   c                     g r   r<   r-   r  r  s      r   r  *ContinuousDistribution._moment_raw_formula      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	$ )Nrz   >   rv  rw  rx  ry  r  r  >   rv  rw  r{  r  r<   )r   r   _moment_central_dispatchr  r  r  _moment_transform_centerr  )
r-   r  r  central_momentsr   r  moment_imean_methodsr  r  s
             r   r  ,ContinuousDistribution._moment_raw_transform  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  *ContinuousDistribution._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  &ContinuousDistribution._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$ )Nrv  rw  rz  ry  rh  rx  r{  r  r  r  )r  r_   _moment_central_formula_moment_central_transform_moment_central_normalize_moment_central_generalr  r  r|  r  r  rW  rX  )r-   r  r  r  r  r  s         r   r  /ContinuousDistribution._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//MdMfMF>/7:,,TYY K& K595I5IKD00NtNvNF$"3"3y"@06&&u-r   c                     g r   r<   r  s      r   r  .ContinuousDistribution._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	$ )Nrz   >   rv  rw  rx  r  r  r<   )r   r   r  r  r|  r  r  r  )
r-   r  r  raw_momentsr   r  r  r  r  r  s
             r   r  0ContinuousDistribution._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>   rv  rw  rx  r  rh  rh  )_moment_standardized_dispatchr  r|  )r-   r  r  r  standard_momentvars         r   r  0ContinuousDistribution._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      $ )Nr  r  r  r_   )r-   r  r  general_central_momentss       r   r  .ContinuousDistribution._moment_central_general8  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  +ContinuousDistribution._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$ )Nrv  rw  ry  Frx  T)r  r_   _moment_standardized_formula_moment_standardized_normalize_moment_standardized_generalrW  rX  r  s        r   r  4ContinuousDistribution._moment_standardized_dispatchB  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   r<   r  s      r   r  3ContinuousDistribution._moment_standardized_formulaY  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{  >   rv  rw  rz  r  rh  r  )r  r|  )r-   r  use_quadraturer  r  central_momentr  s          r   r  5ContinuousDistribution._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   rz   rh  r  )r-   r  r  general_standard_momentss       r   r  3ContinuousDistribution._moment_standardized_generalg  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
  r-   s        r   r  ?ContinuousDistribution._moment_integrate_pdf.<locals>.integrandl  s*    $$Q1&1C&5(((r   )r#  r  r  r-   r  r  r  r  s   `    r   r  ,ContinuousDistribution._moment_integrate_pdfk  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  r-   s       r   r  @ContinuousDistribution._moment_integrate_icdf.<locals>.integrandr  s%    ##A00AHu$$r   )r  r  )r  r#  r  r  r  s   `    r   r  -ContinuousDistribution._moment_integrate_icdfq  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)Nrz   rd  r  )r  r   r   )
rB   r   aranger   r  r  r   binomr  r   )	r-   r  	moment_asrP   rQ   r2   r   
n_choose_imoment_bs	            r   r  /ContinuousDistribution._moment_transform_centerx  s    ..q@i@yIIacN""B4AFF
?3"]]1(
[[*vvj2AC13<?aHH + +*s   "B==
C)	logcenterr(  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$ )NTrh  )_logmoment_quadr  rB   r   r  )r-   r  r  r(  logmeanr2  logvars          r   
_logmoment!ContinuousDistribution._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  ri  rB   r#   )r   r  r  r  r	  r-   s        r   r  <ContinuousDistribution._logmoment_quad.<locals>.logintegrand  s9    **177FM"&&R.)$LLLLr   T)r#  r  r#   r  )r-   r  r  r  r  s   `    r   r  &ContinuousDistribution._logmoment_quad  s/    	M 93E'-4   9 	9r   )r  gMb@?gCl?)taxc          
         1 Skn1 SknUR                  U5      nUR                  SS15      nU R                  n	XpUS   [        R                  " USS 5      pU	(       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[        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X;   a  UO[        X
5      " U5      nX;   a  UO[        X5      " U5      nUR#                  X5        UR%                  SU
 S35        UR'                  SU S35        UR)                  [+        U 5      5        [-        U R.                  5      (       a  / nU R0                  R2                  n[5        U5      nU Vs/ s H&  n[        R6                  " U R.                  U   5      PM(     nn[9        U6  HX  n[9        UU5       VVs/ s H  u  nnSUU   R:                   SUS 3PM     nnnUR=                  SR?                  U5      5        MZ     URA                  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
    ``'pdf'`` (the probability density function). Valid values are:
    'x', 'pdf', 'cdf', 'ccdf', 'icdf', 'iccdf', 'logpdf', 'logcdf',
    'logccdf', 'ilogcdf', 'ilogccdf'.
t : 3-tuple of (str, float, float), optional
    Tuple indicating the limits within which the quantities are plotted.
    Default is ``('cdf', 0.001, 0.999)`` indicating that the central
    99.9% of the distribution is to be shown. 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   r  r  r  r  >   r  r  rO  r  r
  r	  r   rz   Nz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 rr   z) produced r  i,  $z$ = z.4gru   )!unionr  rB   rM   newaxisrR   r=   r  rE  matplotlib.pyplotpyplotModuleNotFoundErrorgcarV  rx  r  linspaceplot
set_xlabel
set_ylabel	set_titler   r   r  r  rY   r   r  r   rW   r  r   legend)r-   r   rj  r  r  t_is_quantilet_is_probabilityvalid_tvalid_xyr  x_namey_namet_nametlimrc   pltexcqlimgridqlabelrY   param_namespnameparam_arrays
param_valsrV   r  assignmentss                                r   r  ContinuousDistribution.plot  s   X F?%%&67MM5("34zztRZZ!".&*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%% {{1a%&*tArzzM"GtAwa(D00 (Agd.CA.F(Agd.CA.F 	
&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$   N /-O8#O
O
&OO
)rE  r!  r   r  rG  rS  r  r  r  r  rD  r  r  r  r  r  r  r  r  r)  rW  r  r  )NNNN)r   )NNNFr   r<   rz   r  r   )r   r
  )r=   r>   r?   r@   rA   __array_priority__r  _nullrS   r  r  r  r  r  r  r  r  r  r  setterrW  r  r6  r:   rA  rD  rJ  rM  rc  rg  rl  ro  ry  r  rk  r  r  r  classmethodr  r  r  r  r  r  r  r  rK  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  rA  r	  r  r7  r8  r
  r  rE  rF  rO  rm  re  rR  rV  r[  rw  r\  r]  r  rf  rW  r  r  r  r  r  ra  ru  r  r  r  r  r  r  r  rY  r  r  r  r  r  r  r  r  r  r  rg  rX  r  r  r  r  r  rb  r  r  r  r  r  rZ  r  r  r  r  r  r  r  r  r  r  r   r)  r2  r+  r,  r  r   r  r=  r>  r  r1  r*  rO  rI  rJ  r  rR  r\  r]  rc  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  rE   r<   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$ OF*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:
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?L #' I I  95
I *. P P  9>M $( J J  94
JB	34 	3  96+@ 6 6 $ $ $ $	 1D 1 1UT U4&1
Y Y
B .8Fd F.	-9PEt% 9$_(?D _ _r   r  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VonMisesLineWeibullReflectedWeibullWrappedCauchyLine)vonmises_lineweibull_minweibull_max
wrapcauchyc                   ^ ^^^ T [         R                  [         R                  1;   a  [        ST R                   S35      e[        T [         R                  5      (       d  Sn[        U5      e/ 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     [        USS9n[        SUS	S
9m["        R%                  T R                  T R                  R'                  5       5      m " UUU4S jS[(        5      nU 4S jn	S0S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.
nS S!S"10nUR+                  5        H{  u  nnT R                  U;   a  UUT R                     ;   a  M+  [        T R,                  US5      n[        [         R                  US5      nUULd  Md  [/        UU[        T U5      5        M}     U 4S# jnU" S$5      (       a  UR0                  R2                  nXl        U" S%5      (       a  Xl        U" S&5      (       a  Xl        U" S'5      (       a  Xl        U" S%5      (       d  Xl        Xl        [?        US(S)9RA                  5       nS*T R                   S+3S,T S-3S.U 3/nS/RC                  U5      Ul"        U$ )1a(  Generate a `ContinuousDistribution` from an instance of `rv_continuous`

The returned value is a `ContinuousDistribution` subclass. Like any subclass
of `ContinuousDistribution`, 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
`ContinuousDistribution`; e.g., `scipy.stats.Normal`.

.. note::

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

Parameters
----------
dist : `rv_continuous`
    Instance of `rv_continuous`.

Returns
-------
CustomDistribution : `ContinuousDistribution`
    A subclass of `ContinuousDistribution` 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`).

Notes
-----
The documentation of `ContinuousDistribution` 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
>>> LogU = stats.make_distribution(stats.loguniform)
>>> X = LogU(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()

r   z` is not supported.z4The argument must be an instance of `rv_continuous`.r  rN   rO   )r   TTr   )rd  rz   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
$ )-make_distribution.<locals>.CustomDistributioni  c                 D   > [         TU ]  5       nUR                  ST5      $ NCustomDistribution)rK   r6  rU  r-   srR   repr_strs     r   r6  6make_distribution.<locals>.CustomDistribution.__repr__  s"     "A9918<<r   c                 D   > [         TU ]  5       nUR                  ST5      $ r  )rK   r:   rU  r  s     r   r:   5make_distribution.<locals>.CustomDistribution.__str__  s!    !A9918<<r   r<   )r=   r>   r?   r@   r   r  r  r6  r:   rE   rl   )rR   _x_paramrY   r  s   @r   r  r    s-    BL0*=>#% 			=	= 	=r   r  c                    > TR                   " S0 U D6u  p[        R                  " U5      S   [        R                  " U5      S   4$ rJ   )_get_supportrB   rM   )ra   rP   rQ   r  s      r   r6   2make_distribution.<locals>.get_numerical_endpoints	  s>      4#34zz!}R "**Q-"333r   Nr   c                ,   > TR                   " SX#S.UD6$ )N)r|   random_stater<   )_rvs)r-   r  rY  r   r$  r  s        r   r\  *make_distribution.<locals>._sample_formula  s    yyEjEfEEr   c                 <   > TR                   " [        U5      40 UD6$ r   )_munpr   r-   r  r$  r  s      r   r  .make_distribution.<locals>._moment_raw_formula  s    zz#e*///r   c                 <   > US:w  a  g TR                   " S0 UD6S   $ )Nrz   r   r<   _statsr  s      r   _moment_raw_formula_10make_distribution.<locals>._moment_raw_formula_1  $    A:{{$V$Q''r   c                 <   > US:w  a  g TR                   " S0 UD6S   $ )Nrh  rz   r<   r  r  s      r   r  2make_distribution.<locals>._moment_central_formula  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  momentsrz   r  r/  r<   )_stats_has_momentsr  r   )r-   r  r$  r/  r  s       r   _moment_standard_formula3make_distribution.<locals>._moment_standard_formula  s    A:&&$'y!;;((UQY88aZ&&$'y!%f%c%!)n5A	1,q1u,r   r7  rE  rW  rY  rX  rZ  r)  r*  r  r  )
_logpdf_pdf_logcdf_cdf_logsf_sf_ppf_isf_entropy_medianr~  r  r  c                 h   > [        TR                  U S 5      [        [        R                  U S 5      L$ r   )rV  rR   r   rv_continuous)r%  r  s    r   r  %make_distribution.<locals>._overridesB  s1    T:u22KFG 	Hr   r  r  r  r  Fr  z#This class represents `scipy.stats.z,` as a subclass of `ContinuousDistribution`.z(The `repr`/`str` of class instances is `z`.z'The PDF of the distribution is defined r  r  )#r   rn  vonmisesr+   rV   r   r  r  rV  rP   rQ   _shape_inforo   rN   rO   r   r  _distribution_namesr_   
capitalizer  r   rR   r  r  r   r6   r  r\  r  r  r  r  r   rA   )r  rc   rw  r  
shape_infor   rZ   
_x_supportr  r6   r\  r  r  r  r  r  skip_override
old_method
new_methodrN  r  r  support_etcdocsr  rY   r  s   `                       @@@r   r   r     s   h !!5>>22!Adii[0C"DEEdE//00H!!JEdJ(89G&&(
z';';'1';';=zv>% Z__% ) w,GJc*gFH"&&tyy$))2F2F2HIH= =3 = 4Ft F F0(
(
 ,%+%+%&'-+	-G $eV_5M")--/
J99%*dii8P*PT:u22JE%&
GD*4MN #2H .!!#--44)@&'1D.&-<*(:R7'""5J29P6 2UKRRTK
-dii[ 9$ 	$
28*B?
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   $ rJ   )r=   rV  _dist
_transformrB   real_if_closer   )r-   r   rj  r=  rH  rW  r#  r$  rf   r9  xtytfxyfyxfuncs                 r   r[  8_shift_scale_distribution_function_2arg.<locals>.wrappedo  s    }}DJJ% __QU+__QU+((((((C 89"==r   r<   )r  r[  s   ` r   '_shift_scale_distribution_function_2argr  n  s    > Nr   c                 &   ^ ^ SSSSS.mUU 4S jnU$ )Nrg  r  rf  r  )rf  r  rg  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   $ rJ   )r=   rV  r  r  rB   r   )r-   r   r=  rH  rW  r#  r$  rf   r9  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   r<   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$ )Nr   r1  r  r   )r  r   r   r1  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   $ rJ   )r=   rV  r  _itransformrB   r   )r-   r  r=  rH  rW  r#  r$  rf   r9  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   r<   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                ,  > 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 ]<  " U0 UD6  g )Nz!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  r  r  rY   r   r  r  r   intersectionrR   r=   r  rX   rK   rS   )	r-   r  r#  r$  dist_parameters
set_paramsr  rc   rR   s	           r   rS    TransformedDistribution.__init__  s    ##%
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  rK   )r-   r%  rR   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  rK   )r-   rR   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 )Nr  r<   )rX   r  r  rK   r  )r-   r  r  rY   rR   s       r   r  *TransformedDistribution._update_parameters  sF    

 	$**99:&!"U5FU*Ur   c                 :    U R                   R                  " S0 UD6$ rJ   )r  r  r  s     r   r  +TransformedDistribution._process_parameters  s    zz--777r   c                     [        5       er   r*   r9   s    r   r6   TransformedDistribution.__repr__      !##r   c                     [        5       er   r*   r9   s    r   r:   TransformedDistribution.__str__  r  r   )r  r  )r=   r>   r?   r@   rS   r  r  r  r  r6  r:   rE   rl   rm   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$ )TruncatedDistributioni  zTruncated distribution.ub)TFr  lbb_l)皙?g?rW   r   r   )FTb_u)g?g?r  r  c               0   > [         TU ]  " U/UQ7X#S.UD6$ )Nr   rK   rS   )r-   r  r  r  r#  r$  rR   s         r   rS   TruncatedDistribution.__init__  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$ )Nr<   r   )r  r  _a_blogmass)	rB   r  r   r  r  r  rR  rX   ru  )r-   r  r  r  rY   rP   rQ   r'  s           r   r  )TruncatedDistribution._process_parameters  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$ rJ   )r  r  rB   re  rd  )r-   r  r  r  rP   rQ   s         r   r  TruncatedDistribution._support  s8    zz"",V,zz! "**Q"333r   c                     gNFr<   r-   r%  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  )
r-   r   r  r  r%  r&  r'  r#  r  r	  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  rR  )
r-   r   r  r  r%  r&  r'  r#  r  rO  s
             r   rf  &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   r2  )
r-   r   r  r  r%  r&  r'  r#  r  r  s
             r   rg  '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   r2  )r-   r   rj  r  r  r%  r&  r'  r#  r  logcdf2s              r   rR  '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  rf  rB   rh  r  )r-   r  r  r  r%  r&  r'  r#  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  rg  rB   rh  r   )r-   r  r  r  r%  r&  r'  r#  r  log_cFbr;  s              r   r   (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  rB   r"   r   )r-   r  r  r  r%  r&  r'  r#  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  rB   r"   r1  )r-   r  r  r  r%  r&  r'  r#  r  cFbrB  s              r   r1  %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Nr.  r/  z	truncate(z, lb=z, ub=rt   )rB   r1  r  r  r  r  r9   s    r   r6  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rH  )rB   r1  r   r  r  r  r9   s    r   r:   TruncatedDistribution.__str__)  sQ    __r*DJJ0 1dgg,uS\N!= +**rJ  r<   NN)r=   r>   r?   r@   rA   ro   r   
_lb_domainr   	_lb_param
_ub_domain	_ub_paramr   r  rB   rS   r  r  r  r  rf  rg  rR  r  r   r   r1  r6  r:   rE   rl   rm   s   @r   r  r    s    ! d|}MJtF'1:GI c{mLJ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, ub=3)
>>> W.plot()
>>> plt.show()

r   )r  )r  r  r  s      r   r    r    /  s    z !b11r   c                   0   \ 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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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) r,S* r-S+ r.S, r/S- r0S.r1g)0r?  io  z8Distribution with a standard shift/scale transformation.r  r  r=  z\murz   rh  r  rH  z\sigma)r  r.  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$ )Nr<   r   r=  rH  rW  )rB   
zeros_liker  r  r  rX   ru  )r-   r=  rH  r  rW  rY   s         r   r  -ShiftedScaledDistribution._process_parameters~  sp    _c"--*>r*B*S0A"0EqyZZ33=f=
$3$?@r   c                     X-
  U-  $ r   r<   r-   r   r=  rH  r$  s        r   r  $ShiftedScaledDistribution._transform  s    r   c                     X-  U-   $ r   r<   rZ  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$ rJ   )r  r  r  rB   r   )r-   r=  rH  rW  r  rP   rQ   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Nr.  r/  *r   z - z + )
rB   r1  r  rH  r  r=  r  r  can_castr   r-   results     r   r6  "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ra  )
rB   r1  r   rH  r  r=  r  r  rc  r   rd  s     r   r:   !ShiftedScaledDistribution.__str__  s    __r*TZZ)3tzz?*;<F88==TXX\CTXXI/00&&Q''TXX^^TZZ5E5EFF CDHH// +  +* rg  c                    U R                   R                  " U0 UD6[        R                  " [        R                  " U5      5      -   $ r   )r  r  rB   r#   r!   )r-   r=  rH  rW  r#  r  s         r   r  +ShiftedScaledDistribution._entropy_dispatch  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$ )Nrf  r   r   )r  r  rB   r#   r!   r   r  r   )r-   r=  rH  rW  r#  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  r-   rN  r=  rH  rW  r  r  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  r  r  rq  s          r   r  (ShiftedScaledDistribution._mode_dispatch  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  rB   r#   r!   )r-   r   r=  rH  rW  r#  r  r	  s           r   r  *ShiftedScaledDistribution._logpdf_dispatch  sL    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  r  rB   r!   )r-   r   r=  rH  rW  r#  r  r
  s           r   r  'ShiftedScaledDistribution._pdf_dispatch  sC    OOAE*jj&&q:4:6:RVVE]""r   rM  c                    g r   r<   r9  s       r   rf  *ShiftedScaledDistribution._logcdf_dispatch      r   c                    g r   r<   r9  s       r   r  'ShiftedScaledDistribution._cdf_dispatch  r{  r   c                    g r   r<   r9  s       r   rg  +ShiftedScaledDistribution._logccdf_dispatch  r{  r   c                    g r   r<   r9  s       r   r  (ShiftedScaledDistribution._ccdf_dispatch  r{  r   c                    g r   r<   r^  s        r   rR  +ShiftedScaledDistribution._logcdf2_dispatch  r{  r   c                    g r   r<   r^  s        r   ru  (ShiftedScaledDistribution._cdf2_dispatch  r{  r   c                    g r   r<   r^  s        r   r  ,ShiftedScaledDistribution._logccdf2_dispatch  r{  r   c                    g r   r<   r^  s        r   r  )ShiftedScaledDistribution._ccdf2_dispatch  r{  r   c                    g r   r<   r9  s       r   r  +ShiftedScaledDistribution._ilogcdf_dispatch  r{  r   c                    g r   r<   r9  s       r   r   (ShiftedScaledDistribution._icdf_dispatch  r{  r   c                    g r   r<   r9  s       r   r   ,ShiftedScaledDistribution._ilogccdf_dispatch  r{  r   c                    g r   r<   r9  s       r   r1  )ShiftedScaledDistribution._iccdf_dispatch  r{  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  rB   rW  r-   r  r=  rH  rW  r  r  r2  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      $ )Nrz   r  )r   r   r|  r  r  r  r  r  )r-   r  r=  rH  rW  r  r  r  methods_highest_orderr   r  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                  " X4XsS.UD6n	U R                  " U	4XEUS.UD6$ )NrU  rV  )r  rR  r  )
r-   rX  rY  r   r=  rH  rW  rN  r  rvss
             r   rR  *ShiftedScaledDistribution._sample_dispatch  sI    jj))H-3H@FHOOOOr   c                 Z    [        U R                  U R                  U-   U R                  S9$ N)r=  rH  r?  r  r=  rH  r@  s     r   rA  !ShiftedScaledDistribution.__add__%  &    (C/3zz; 	;r   c                 Z    [        U R                  U R                  U-
  U R                  S9$ r  r  r@  s     r   rD  !ShiftedScaledDistribution.__sub__)  r  r   c                 `    [        U R                  U R                  U-  U R                  U-  S9$ r  r  rI  s     r   rJ  !ShiftedScaledDistribution.__mul__-  /    (-1XX-=/3zzE/AC 	Cr   c                 `    [        U R                  U R                  U-  U R                  U-  S9$ r  r  rI  s     r   rM  %ShiftedScaledDistribution.__truediv__2  r  r   r<   rM  )2r=   r>   r?   r@   rA   ro   r   _loc_domainr   
_loc_param_scale_domain_scale_paramr   r  r  r  r  r  r6  r:   r  r  r  r  r  r  r  rf  r  rg  r  r  rR  ru  r  r  r  r  r   r   r1  r  r  r  rR  rA  rD  rJ  rM  rE   r<   r   r   r?  r?  o  s   B#s|LKf'2FDJ  C4+NM!'))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   r?  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$ )OrderStatisticDistributioni8  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()

)rz   r2   r  r  rrT  r  rz   r2   )rz   r  c               2   > [         TU ]  " U/UQ7X#S.UD6  g )Nr  r2   r"  )r-   r  r  r2   r#  r$  rR   s         r   rS   #OrderStatisticDistribution.__init__  s    999&9r   c                :    U R                   R                  " U0 UD6$ r   )r  r  )r-   r  r2   r#  r$  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  r<   )r  r  rX   ru  )r-   r  r2   r  rY   s        r   r  .OrderStatisticDistribution._process_parameters  s1    ZZ33=f=
$.)r   c                     US;   $ )N>   rY  rE  rZ  r)  r*  r7  r<   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-
  $ )Nrz   r   )
r   betalnr  r  rf  r"  rg  rB   r   r  )r-   r   r  r2   r$  
log_factorlog_fXlog_FXlog_cFX
rm1_log_FXnmr_log_cFXs              r   r7  *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-  $ rV  )r   betar  r  r  r  )	r-   r   r  r2   r$  factorfXFXcFXs	            r   rE  'OrderStatisticDistribution._pdf_formula  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      $ rV  )r  r  r   betaincr-   r   r  r2   r$  x_s         r   rY  '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      $ rV  )r  r  r   betainccr  s         r   rZ  (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$ rV  )r   
betaincinvr  r   r-   r  r  r2   r$  p_s         r   r)  (OrderStatisticDistribution._icdf_formula  s6    Q3q5!,zz((6v66r   c                 v    [         R                  " X#U-
  S-   U5      nU R                  R                  " U40 UD6$ rV  )r   betainccinvr  r   r  s         r   r*  )OrderStatisticDistribution._iccdf_formula  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Nr.  r/  zorder_statistic(z, r=z, n=rt   )rB   r1  r  r  r  r2   r9   s    r   r6  #OrderStatisticDistribution.__repr__  sS    __r*&tDJJ'7&8T$&&\N Kdffa) +**rJ  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  )rB   r1  r   r  r  r2   r9   s    r   r:   "OrderStatisticDistribution.__str__  sR    __r*&s4::&7tCK= ITVVQ( +**rJ  r<   rM  )r=   r>   r?   r@   rA   ro   	_r_domainr   _r_paramrB   r   	_n_domain_n_paramr\   r   r  rS   r  r  r  r7  rE  rY  rZ  r)  r*  r6  r:   rE   rl   rm   s   @r   r  r  8  s    =B h,GIc)VDHq"&&k\JI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  )rB   rM   r  floorr  r  )r  r  r2   rc   s       r   r   r     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.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&S.SSS'.S( jjr'S) r(S* r)S+r*g)/r   i  aA  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

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`.r<   z5All elements of `components` must have scalar shapes.z5`components` and `weights` must have the same length.z)`weights` must have floating point dtype.r  z`weights` must sum to 1.0.z#All `weights` must be non-negative.)r   r  r   r  r  rB   rM   r   r   r   ro  iscloser   rx  )r-   
componentsweightsrc   r  s        r   _input_validationMixture._input_validationa  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   )r  r  r  s     r   r	  #Mixture.__init__.<locals>.<genexpr>  s      Bzzr  c              3   8   #    U  H  oR                   v   M     g 7fr   )r  r  s     r   r	  r    s     +M*3JJ*r  rz   r   )r  r   rB   r   r   r  r  _componentsr   _weightsr  )r-   r  r  r2   r   s        r   rS   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  r9   s    r   r  Mixture.components  s    D$$%%r   c                 6    U R                   R                  5       $ r   )r  rL   r9   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     -H4Cii4r  c              3   8   #    U  H  oR                   v   M     g 7fr   r  r  s     r   r	  r    s     2M99r  r   )rB   rM   r   r  r   r  r   )r-   r  r#  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   r<   )r  r   r  r  rV  )r-   funr#  r   r  weights         r   _sumMixture._sum  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   r<   )	r  rB   r   r   r  r#   r  rh  rV  )r-   r  r#  r   r  
log_weights         r   _logsumMixture._logsum  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  rB   r   r  rd  r  re  )r-   rP   rQ   r  s       r   r  Mixture.support  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_method  s    %&WXX r   rM  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  )r	  r"  rB   r#   r   r-   s    r   log_integrand)Mixture.logentropy.<locals>.log_integrand  s8    
 ;;qvv&AFF0Cb0H)IIIr   r#   Trg  )r  r  r  r  r  rB   rC   )r-   rN  r  r2  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   )r
  r	  r  s    r   r  !Mixture.entropy.<locals>.<lambda>  s    DHHQK<$++a.#@r   )r  r  r  r  r  s   ` r   r  Mixture.entropy  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   )r
  r  s    r   r9  Mixture.mode.<locals>.f  s    $((1+%r   r  )r  r  )r  r  r   r   r  r  r  r   )r-   rN  rP   rQ   r9  r2  s   `     r   r  Mixture.mode  sR    f%||~%q"15$Q?uur   c                F    U R                  U5        U R                  S5      $ r  )r  r  r  s     r   r  Mixture.median  s    f%yy~r   c                F    U R                  U5        U R                  S5      $ )Nr  r  r  r  s     r   r  Mixture.mean  s    f%yy  r   c                F    U R                  U5        U R                  S5      $ )Nrh  )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   r  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   r  r  r<   )r  r   r  r  r  )r-   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   rz   r!  r/  r<   )	r   r  r   r  r  r   r  r  r  )	r-   r  r   r  r  r  rP   rQ   r  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  )r-   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      $ )Nr
  r   r3  s      r   r
  Mixture.pdf  s!    f%yy""r   c               H    U R                  U5        U R                  SU5      $ )Nr	  r  r  r3  s      r   r	  Mixture.logpdf  !    f%||Ha((r   c               \    U R                  U5        Uc  U4OX4nU R                  " S/UQ76 $ Nr  r   r-   r   rj  rN  r#  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 $ NrO  r8  r=  s        r   rO  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 $ Nr  r   r=  s        r   r  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  r8  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   r<   )r   r  r  s     r   r  !Mixture._invert.<locals>.<lambda>#  s    Q!r   r  )rP   rQ   r#  )r  rV  r  r   r   r  r  r   )	r-   r  r  r  r  r9  r  r  r2  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  rK  r&  s      r   r  Mixture.icdf(  s!    f%||E1%%r   c               H    U R                  U5        U R                  SU5      $ rC  rN  r&  s      r   r  Mixture.iccdf,  s!    f%||FA&&r   c               H    U R                  U5        U R                  SU5      $ r@  rN  r&  s      r   r  Mixture.ilogcdf0  r:  r   c               H    U R                  U5        U R                  SU5      $ rF  rN  r&  s      r   r  Mixture.ilogccdf4  s!    f%||Iq))r   )r   rN  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   r   r<   )r  rB   r   r   r   r  r   r  r   r  r  r   r   r   )	r-   r   r   rN  r|   nsr2   r  r   s	            r   r  Mixture.sample8  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    [
r.  r/  z        z,
z    ],
z    weights=rt   )rB   r1  r  r  r  r-   re  	components      r   r6  Mixture.__repr__A  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rZ  )rB   r1  r  r   r  r[  s      r   r:   Mixture.__str__L  s    )__r*!__	HS^$4C88 -j FS%6$7s;;F	 +
 	# +*r^  )r  r  r  r  r  r  r   r  )+r=   r>   r?   r@   rA   r  rS   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r	  r  rO  r  r  rK  r  r  r  r  r  r6  r:   rE   r<   r   r   r   r     s[   J\$#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$ )ra  iX  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  )rR  r^  s    r   r  ;MonotonicTransformedDistribution.__init__.<locals>.<lambda>  s    bffRUmr   z(***))rK   rS   _g_h_dh_logdhr  r  _xdfr  _cxdfr   _ixdfr1  _icxdfrf  _logxdfrg  _logcxdfr  _ilogxdfr   	_ilogcxdf_increasingr=   _repr_pattern_str_pattern)r-   r  rZ  r]  r^  rb  r_  r[  r\  r#  r$  rR   s       `      r   rS   )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Nr.  r/  z***)rB   r1  rs  rU  r  r  r9   s    r   r6  )MonotonicTransformedDistribution.__repr__  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rw  )rB   r1  rt  rU  r   r  r9   s    r   r:   (MonotonicTransformedDistribution.__str__  s8    __r*$$,,UC

OD +**ry  c                     gr,  r<   r-  s     r   r  +MonotonicTransformedDistribution._overrides      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  r<   )	r  r  rB   r   rM   r   r  rr  rf  )r-   r  rP   rQ   s       r   r  )MonotonicTransformedDistribution._support  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  rg  ri  r-   r   r#  r  s       r   r  1MonotonicTransformedDistribution._logpdf_dispatch  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  r  rg  rh  r  s       r   r  .MonotonicTransformedDistribution._pdf_dispatch  s7    zz''
DTDVDtxxPQ{RRr   c                 L    U R                   " U R                  U5      /UQ70 UD6$ r   )rn  rg  r  s       r   rf  1MonotonicTransformedDistribution._logcdf_dispatch  s#    ||DGGAJ8888r   c                 L    U R                   " U R                  U5      /UQ70 UD6$ r   )rj  rg  r  s       r   r  .MonotonicTransformedDistribution._cdf_dispatch  s#    yy5d5f55r   c                 L    U R                   " U R                  U5      /UQ70 UD6$ r   )ro  rg  r  s       r   rg  2MonotonicTransformedDistribution._logccdf_dispatch  s#    }}TWWQZ9$9&99r   c                 L    U R                   " U R                  U5      /UQ70 UD6$ r   )rk  rg  r  s       r   r  /MonotonicTransformedDistribution._ccdf_dispatch  s#    zz$''!*6t6v66r   c                 L    U R                  U R                  " U/UQ70 UD65      $ r   )rf  rp  r-   r  r#  r  s       r   r  2MonotonicTransformedDistribution._ilogcdf_dispatch  s$    wwt}}Q88899r   c                 L    U R                  U R                  " U/UQ70 UD65      $ r   )rf  rl  r  s       r   r   /MonotonicTransformedDistribution._icdf_dispatch  s$    wwtzz!5d5f566r   c                 L    U R                  U R                  " U/UQ70 UD65      $ r   )rf  rq  r  s       r   r   3MonotonicTransformedDistribution._ilogccdf_dispatch  s$    wwt~~a9$9&9::r   c                 L    U R                  U R                  " U/UQ70 UD65      $ r   )rf  rm  r  s       r   r1  0MonotonicTransformedDistribution._iccdf_dispatch  s$    wwt{{16t6v677r   c                b    U R                   R                  " X4X4S.UD6nU R                  U5      $ NrU  )r  rR  rf  r-   rX  rY  rN  r   r  r  s          r   rR  1MonotonicTransformedDistribution._sample_dispatch  s:    jj))H-3H@FHwws|r   )rk  rh  rf  rg  rm  rq  rp  rr  rl  ro  ri  rn  rs  rt  rj  )r=   r>   r?   r@   rA   rS   r6  r:   r  r  r  r  rf  r  rg  r  r  r   r   r1  rR  rE   rl   rm   s   @r   ra  ra  X  st    #J 59 t!> >>GE.YS96:7:7;8 r   ra  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 )NTrz   )rK   rS   r  r   rO   )r-   r  r#  r$  rR   s       r   rS   FoldedDistribution.__init__  sI    ,T,V,
 ,01F1F1P1PQR1S*T'r   c                     gr,  r<   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  rB   r!   rd  re  rM   )r-   r  rP   rQ   a_b_r   s          r   r  FoldedDistribution._support  s    zz"",V,BFF1IBB#RZZ%7BUq1uZZ^"vr"v~r   NrM  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$ )NrN  r   r   r<   )
rB   r!   r  r  rM   r  r   rn  r   r  )
r-   r   rN  r#  r  rw   rv   rP   rQ   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-   $ )NrN  r   r<   )rB   r!   r  r  rM   r  )	r-   r   rN  r#  r  rw   rv   rP   rQ   s	            r   r   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  )rB   r!   r  r  re  rd  rR  r"  	r-   r   rN  r#  r  rP   rQ   r  r  s	            r   rf  #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$ rJ   )rB   r!   r  r  re  rd  ru  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  )rB   r!   r  r  re  rd  r  r"  r  s	            r   rg  $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  )rB   r!   r  r  re  rd  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                  " X4X4S.UD6n[        R                  " U5      $ r  )r  rR  rB   r!   r  s          r   rR  #FoldedDistribution._sample_dispatch5  s:    jj))H-3H@FHvvc{r   c                     [         R                  " SS9   S[        U R                  5       S3sS S S 5        $ ! , (       d  f       g = fNr.  r/  zabs(rt   )rB   r1  r  r  r9   s    r   r6  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  )rB   r1  r   r  r9   s    r   r:   FoldedDistribution.__str__?  s/    __r*#djj/*!, +**r  r<   )r=   r>   r?   r@   rA   rS   r  r  r  r  rf  r  rg  r  rR  r6  r:   rE   rl   rm   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!   D  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 -  $ rV  r<   rs  s    r   r  exp.<locals>.<lambda>  s    PQTUPUr   c                 0    [         R                  " U 5      * $ r   r  rs  s    r   r  r    s    RVVAYJr   rZ  r]  r^  rb  )ra  rB   r"   r#   r  s    r   r"   r"   n  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   r<   rs  s    r   r  log.<locals>.<lambda>  s    Ar   r  )rB   r  r  r+   ra  r#   r"   )r  rc   s     r   r#   r#     sY    V 
vvaiik!nq !!.!'**+A266bff2=? ?r   rM  )Kr?  abcr   r   r   rk  numpyrB   r   scipy._lib._utilr   r   scipy._lib._docscraper	   r
   scipyr   r   scipy.integrater   r  scipy.optimize._bracketr   r   scipy.optimize._chandrupatlar   r   %scipy.stats._probability_distributionr   scipy.statsr   r   r  r   __all__r  rX  r'   rG   ro   r   r   r   r   rA  rK  r^  rm  rr  ry  r  ri  r  r  r  r  r  r  r  r   r  r  r  r  r  r    r?  r  r   r   ra  r  r!   r"   r#   r<   r   r   <module>r     s    # %    3 :   1 C N J  	*, 		h-$c -$`D"G D"NY- Yx	"] 	"a$ a$H7)Z 7)tG  G TGT)X&RBJ,&5R&& , 48 ,:pfs5 sh>IWII LI =	I
 mI I ]I .I %I "I =I .I I (I "I  $!I" (#I$ +%I& ''I( ")I* 0+I, /-I. /I0 !1I2 ,3I4 N5I6 7I8 *9I: #;I< =I> !?I@ "AIB CID "EIF GIH IIJ \KIL \MIN 'OIP -QIR jSIT <UIV 
WIX ,YIZ {[I\ ,]I^ "_I` 
=aIb HcId +eIf 
gIh iIj SkIl 0mIn 0oIp ,qIr NsIt ,uIv wIx +yIz {I| }I~ lI@ (AIB "CID $EIF *GIH =IIJ $%%QI Zp~ *(/$4 /$dS>3 S>l FF7rvv =2@FC 7 FCRJ)!8 J)ZJ3ZC& CL
}'> }@i-0 i-X'!T+H\0?r   