
    9i}                     l    S SK r S SKJrJr  S SKrS SKJrJr  S SKJrJ	r	  S SK
Jr  S/r " S S\	5      rg)    N)NumberReal)infnan)constraintsDistribution)broadcast_allGeneralizedParetoc                   >  ^  \ rS rSrSr\R                  \R                  \R                  S.rSr	SU 4S jjr
SU 4S jjr\R                  " 5       4S jrS rS	 rS
 rS rS rS r\S 5       r\S 5       rS r\S 5       r\R4                  " SSS9S 5       rSrU =r$ )r
      a]  
Creates a Generalized Pareto distribution parameterized by :attr:`loc`, :attr:`scale`, and :attr:`concentration`.

The Generalized Pareto distribution is a family of continuous probability distributions on the real line.
Special cases include Exponential (when :attr:`loc` = 0, :attr:`concentration` = 0), Pareto (when :attr:`concentration` > 0,
:attr:`loc` = :attr:`scale` / :attr:`concentration`), and Uniform (when :attr:`concentration` = -1).

This distribution is often used to model the tails of other distributions. This implementation is based on the
implementation in TensorFlow Probability.

Example::

    >>> # xdoctest: +IGNORE_WANT("non-deterministic")
    >>> m = GeneralizedPareto(torch.tensor([0.1]), torch.tensor([2.0]), torch.tensor([0.4]))
    >>> m.sample()  # sample from a Generalized Pareto distribution with loc=0.1, scale=2.0, and concentration=0.4
    tensor([ 1.5623])

Args:
    loc (float or Tensor): Location parameter of the distribution
    scale (float or Tensor): Scale parameter of the distribution
    concentration (float or Tensor): Concentration parameter of the distribution
)locscaleconcentrationTc                 <  > [        XU5      u  U l        U l        U l        [	        U[
        5      (       a@  [	        U[
        5      (       a+  [	        U[
        5      (       a  [        R                  " 5       nOU R                  R                  5       n[        TU ])  XTS9  g )Nvalidate_args)r	   r   r   r   
isinstancer   torchSizesizesuper__init__)selfr   r   r   r   batch_shape	__class__s         f/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/torch/distributions/generalized_pareto.pyr   GeneralizedPareto.__init__-   ss    3@4
0$*d0 sF##5&))=&11**,K((--/KB    c                 f  > U R                  [        U5      n[        R                  " U5      nU R                  R                  U5      Ul        U R                  R                  U5      Ul        U R                  R                  U5      Ul        [        [        U]'  USS9  U R                  Ul
        U$ )NFr   )_get_checked_instancer
   r   r   r   expandr   r   r   r   _validate_args)r   r   	_instancenewr   s       r   r!   GeneralizedPareto.expand;   s    (():IFjj-((//+.JJ%%k2	 ..55kB.{%.P!00
r   c                     U R                  U5      n[        R                  " X R                  R                  U R                  R
                  S9nU R                  U5      $ )N)dtypedevice)_extended_shaper   randr   r'   r(   icdf)r   sample_shapeshapeus       r   rsampleGeneralizedPareto.rsampleE   s@    $$\2JJuHHNN488??Kyy|r   c           	         U R                   (       a  U R                  U5        U R                  U5      n[        R                  " U R
                  [        R                  " S5      5      n[        R                  " U[        R                  " U R
                  5      U R
                  5      nSU-  [        R                  " U5      -   n[        R                  " US:H  XU[        R                  " XB-  5      -  5      n[        U R                  [        5      (       a   [        R                  " U R                  5      OU R                  R                  5       nU* [        R                  " X2U5      -
  $ )N           r   )r"   _validate_sample_zr   iscloser   tensorwhere	ones_likelog1pr   r   r   mathlog)r   valuezeq_zero	safe_concywhere_nonzero	log_scales           r   log_probGeneralizedPareto.log_probJ   s    !!%(GGEN-- 2 2ELL4EFKKU__T%7%78$:L:L
	 	MEOOA..AFA5;;y}3M/MN$.tzz4$@$@DHHTZZ djjnnFV 	 zEKKMBBBr   c                    U R                   (       a  U R                  U5        U R                  U5      n[        R                  " U R
                  [        R                  " S5      5      n[        R                  " U[        R                  " U R
                  5      U R
                  5      n[        R                  " XB-  5      * U-  n[        R                  " X2* U5      $ )Nr2   )
r"   r4   r5   r   r6   r   r7   r8   r9   r:   )r   r=   r>   r?   r@   rB   s         r   log_survival_function'GeneralizedPareto.log_survival_functionY   s    !!%(GGEN-- 2 2ELL4EFKKU__T%7%78$:L:L
	 Y]33i?{{7B66r   c                 v    [         R                  " [         R                  " U R                  U5      5      * 5      $ N)r   r:   exprG   r   r=   s     r   log_cdfGeneralizedPareto.log_cdfd   s(    {{EIId&@&@&GHHIIr   c                 L    [         R                  " U R                  U5      5      $ rJ   )r   rK   rM   rL   s     r   cdfGeneralizedPareto.cdfg   s    yye,--r   c                    U R                   nU R                  nU R                  n[        R                  " U[        R
                  " U5      5      n[        R                  " U[        R                  " U5      U5      n[        R                  " U* 5      nX#U-  [        R                  " U* U-  5      -  -   nX#U-  -
  n	[        R                  " XYU5      $ rJ   )
r   r   r   r   r6   
zeros_liker8   r9   r:   expm1)
r   r=   r   r   r   r?   r@   logurB   
where_zeros
             r   r+   GeneralizedPareto.icdfj   s    hh

**--u/?/?/NOKK)GW	{{E6"i/%++yj4>O2PPP4<'
{{7>>r   c                 8    XR                   -
  U R                  -  $ rJ   )r   r   )r   xs     r   r5   GeneralizedPareto._zu   s    HH

**r   c                     U R                   nUS:  n[        R                  " X!S5      nU R                  U R                  SU-
  -  -   n[        R                  " X$[
        5      $ )Nr3         ?)r   r   r8   r   r   r   r   r   validr@   results        r   meanGeneralizedPareto.meanx   sS    **!KKc:	DJJ!i-88{{5#..r   c                     U R                   nUS:  n[        R                  " X!S5      nU R                  S-  SU-
  S-  SSU-  -
  -  -  n[        R                  " X$[        5      $ )Nr\   g      ?   r3   )r   r   r8   r   r   r]   s        r   varianceGeneralizedPareto.variance   sa    **#KKd;	Q1y=Q"6!a)m:K"LM{{5#..r   c                     [         R                  " U R                  5      U R                  -   S-   n[         R                  " XR
                  5      $ )Nr3   )r   r<   r   r   broadcast_to_batch_shape)r   anss     r   entropyGeneralizedPareto.entropy   s;    ii

#d&8&881<!!#'8'899r   c                     U R                   $ rJ   )r   )r   s    r   modeGeneralizedPareto.mode   s    xxr   Fr   )is_discrete	event_dimc                     U R                   n[        R                  " U R                  S:  XR                  U R                  -  -
  [
        5      n[        R                  " X5      $ )Nr   )r   r   r8   r   r   r   r   interval)r   loweruppers      r   supportGeneralizedPareto.support   sP    "EJJ9K9K,K$KS
 ##E11r   )r   r   r   rJ   )__name__
__module____qualname____firstlineno____doc__r   realpositivearg_constraintshas_rsampler   r!   r   r   r/   rD   rG   rM   rP   r+   r5   propertyr`   rd   rj   rm   dependent_propertyru   __static_attributes____classcell__)r   s   @r   r
   r
      s    0 %%$))O
 KC $)::< 
C	7J.	?+ / / / /:   ##C2 D2r   )r;   numbersr   r   r   r   r   torch.distributionsr   r   torch.distributions.utilsr	   __all__r
    r   r   <module>r      s/         9 3 
H2 H2r   