Ë
    óÍ:j}  ã                   ól   — d dl Z d dlmZmZ d dlZd dlmZmZ d dlmZm	Z	 d dl
mZ dgZ G d„ de	«      Zy)é    N)ÚNumberÚReal)ÚinfÚnan)ÚconstraintsÚDistribution)Úbroadcast_allÚGeneralizedParetoc                   ó2  ‡ — e Zd ZdZej
                  ej                  ej
                  dœZdZdˆ fd„	Z	dˆ fd„	Z
 ej                  «       fd„Zd„ Zd„ Zd	„ Zd
„ Zd„ Zd„ Zed„ «       Zed„ «       Zd„ Zed„ «       Z ej2                  dd¬«      d„ «       Zˆ xZS )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                 ó&  •— t        |||«      \  | _        | _        | _        t	        |t
        «      r5t	        |t
        «      r%t	        |t
        «      rt        j                  «       }n| j                  j                  «       }t        ‰| �)  ||¬«       y )N©Úvalidate_args)r	   r   r   r   Ú
isinstancer   ÚtorchÚSizeÚsizeÚsuperÚ__init__)Úselfr   r   r   r   Úbatch_shapeÚ	__class__s         €ú{/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/torch/distributions/generalized_pareto.pyr   zGeneralizedPareto.__init__-   sn   ø€ Ü3@Ø�˜ó4
Ñ0ˆŒ�$”*˜dÔ0ô �sœFÔ#Ü˜5¤&Ô)Ü˜=¬&Ô1äŸ*™*›,‰KàŸ(™(Ÿ-™-›/ˆKÜ‰Ñ˜°MÐÕBó    c                 ój  •— | j                  t        |«      }t        j                  |«      }| j                  j                  |«      |_        | j                  j                  |«      |_        | j                  j                  |«      |_        t        t        |�'  |d¬«       | j                  |_
        |S )NFr   )Ú_get_checked_instancer
   r   r   r   Úexpandr   r   r   r   Ú_validate_args)r   r   Ú	_instanceÚnewr   s       €r   r   zGeneralizedPareto.expand;   s�   ø€ Ø×(Ñ(Ô):¸IÓFˆÜ—j‘j Ó-ˆØ—(‘(—/‘/ +Ó.ˆŒØ—J‘J×%Ñ% kÓ2ˆŒ	Ø ×.Ñ.×5Ñ5°kÓBˆÔÜÔ Ñ.¨{È%Ð.ÔPØ!×0Ñ0ˆÔØˆ
r   c                 óÆ   — | j                  |«      }t        j                  || j                  j                  | j                  j
                  ¬«      }| j                  |«      S )N)ÚdtypeÚdevice)Ú_extended_shaper   Úrandr   r$   r%   Úicdf)r   Úsample_shapeÚshapeÚus       r   ÚrsamplezGeneralizedPareto.rsampleE   sB   € Ø×$Ñ$ \Ó2ˆÜ�J‰J�u D§H¡H§N¡N¸4¿8¹8¿?¹?ÔKˆØ�y‰y˜‹|Ðr   c           	      ó¸  — | j                   r| j                  |«       | j                  |«      }t        j                  | j
                  t        j                  d«      «      }t        j                  |t        j                  | j
                  «      | j
                  «      }d|z  t        j                  |«      z   }t        j                  |dk(  ||t        j                  ||z  «      z  «      }t        | j                  t        «      rt        j                  | j                  «      n| j                  j                  «       }| t        j                  |||«      z
  S )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_probzGeneralizedPareto.log_probJ   sû   € Ø×ÒØ×!Ñ! %Ô(Ø�G‰G�E‹NˆÜ—-‘- × 2Ñ 2´E·L±LÀÓ4EÓFˆÜ—K‘KØ”U—_‘_ T×%7Ñ%7Ó8¸$×:LÑ:Ló
ˆ	ð �	‰MœEŸO™O¨AÓ.Ñ.ˆÜŸ™ A¨¡F¨A¨q´5·;±;¸yÈ1¹}Ó3MÑ/MÓNˆä$.¨t¯z©z¼4Ô$@ŒD�H‰H�T—Z‘ZÔ ÀdÇjÁjÇnÁnÓFVð 	ð ˆzœEŸK™K¨°°MÓBÑBÐBr   c                 ó¨  — | j                   r| j                  |«       | j                  |«      }t        j                  | j
                  t        j                  d«      «      }t        j                  |t        j                  | j
                  «      | j
                  «      }t        j                  ||z  «       |z  }t        j                  || |«      S )Nr.   )
r    r0   r1   r   r2   r   r3   r4   r5   r6   )r   r9   r:   r;   r<   r>   s         r   Úlog_survival_functionz'GeneralizedPareto.log_survival_functionY   s    € Ø×ÒØ×!Ñ! %Ô(Ø�G‰G�E‹NˆÜ—-‘- × 2Ñ 2´E·L±LÀÓ4EÓFˆÜ—K‘KØ”U—_‘_ T×%7Ñ%7Ó8¸$×:LÑ:Ló
ˆ	ô Ÿ™ Y°¡]Ó3Ð3°iÑ?ˆÜ�{‰{˜7 Q B¨Ó6Ð6r   c                 ór   — t        j                  t        j                  | j                  |«      «       «      S ©N)r   r6   ÚexprB   ©r   r9   s     r   Úlog_cdfzGeneralizedPareto.log_cdfd   s(   € Ü�{‰{œEŸI™I d×&@Ñ&@ÀÓ&GÓHÐHÓIÐIr   c                 óJ   — t        j                  | j                  |«      «      S rD   )r   rE   rG   rF   s     r   ÚcdfzGeneralizedPareto.cdfg   s   € Ü�y‰y˜Ÿ™ eÓ,Ó-Ð-r   c                 óž  — | j                   }| j                  }| j                  }t        j                  |t        j
                  |«      «      }t        j                  |t        j                  |«      |«      }t        j                  | «      }|||z  t        j                  | |z  «      z  z   }|||z  z
  }	t        j                  ||	|«      S rD   )
r   r   r   r   r2   Ú
zeros_liker4   r5   r6   Úexpm1)
r   r9   r   r   r   r;   r<   Úlogur>   Ú
where_zeros
             r   r(   zGeneralizedPareto.icdfj   sª   € Ø�h‰hˆØ—
‘
ˆØ×*Ñ*ˆÜ—-‘- ¬u×/?Ñ/?ÀÓ/NÓOˆÜ—K‘K ¬¯©¸Ó)GÈÓWˆ	Ü�{‰{˜E˜6Ó"ˆØ˜e iÑ/´%·+±+¸y¸jÈ4Ñ>OÓ2PÑPÑPˆØ˜5 4™<Ñ'ˆ
Ü�{‰{˜7 J°Ó>Ð>r   c                 ó:   — || j                   z
  | j                  z  S rD   )r   r   )r   Úxs     r   r1   zGeneralizedPareto._zu   s   € Ø�D—H‘H‘ §
¡
Ñ*Ð*r   c                 óÆ   — | j                   }|dk  }t        j                  ||d«      }| j                  | j                  d|z
  z  z   }t        j                  ||t
        «      S )Nr/   ç      à?)r   r   r4   r   r   r   ©r   r   Úvalidr<   Úresults        r   ÚmeanzGeneralizedPareto.meanx   sW   € à×*Ñ*ˆØ Ñ!ˆÜ—K‘K  }°cÓ:ˆ	Ø—‘˜DŸJ™J¨!¨i©-Ñ8Ñ8ˆÜ�{‰{˜5 &¬#Ó.Ð.r   c                 óÊ   — | j                   }|dk  }t        j                  ||d«      }| j                  dz  d|z
  dz  dd|z  z
  z  z  }t        j                  ||t        «      S )NrR   g      Ð?é   r/   )r   r   r4   r   r   rS   s        r   ÚvariancezGeneralizedPareto.variance€   se   € à×*Ñ*ˆØ Ñ#ˆÜ—K‘K  }°dÓ;ˆ	Ø—‘˜Q‘ 1 y¡=°QÑ"6¸!¸aÀ)¹mÑ:KÑ"LÑMˆÜ�{‰{˜5 &¬#Ó.Ð.r   c                 ó    — t        j                  | j                  «      | j                  z   dz   }t        j                  || j
                  «      S )Nr/   )r   r8   r   r   Úbroadcast_toÚ_batch_shape)r   Úanss     r   ÚentropyzGeneralizedPareto.entropyˆ   s=   € Ü�i‰i˜Ÿ
™
Ó# d×&8Ñ&8Ñ8¸1Ñ<ˆÜ×!Ñ! # t×'8Ñ'8Ó9Ð9r   c                 ó   — | j                   S rD   )r   )r   s    r   ÚmodezGeneralizedPareto.modeŒ   s   € à�x‰xˆr   Fr   )Úis_discreteÚ	event_dimc                 óÊ   — | j                   }t        j                  | j                  dk  || j                  | j                  z  z
  t
        «      }t        j                  ||«      S )Nr   )r   r   r4   r   r   r   r   Úinterval)r   ÚlowerÚuppers      r   ÚsupportzGeneralizedPareto.support�   sT   € à—‘ˆÜ—‘Ø×Ñ Ñ" E¨D¯J©J¸×9KÑ9KÑ,KÑ$KÌSó
ˆô ×#Ñ# E¨5Ó1Ð1r   rD   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚrealÚpositiveÚarg_constraintsÚhas_rsampler   r   r   r   r,   r@   rB   rG   rI   r(   r1   ÚpropertyrV   rY   r^   r`   Údependent_propertyrg   Ú__classcell__)r   s   @r   r
   r
      sÕ   ø„ ñð0 ×ÑØ×%Ñ%Ø$×)Ñ)ñ€Oð
 €KõCõð $. 5§:¡:£<ó ò
Cò	7òJò.ò	?ò+ð ñ/ó ð/ð ñ/ó ð/ò:ð ñó ðð $€[×#Ñ#°ÀÔCñ2ó Dô2r   )r7   Únumbersr   r   r   r   r   Útorch.distributionsr   r   Útorch.distributions.utilsr	   Ú__all__r
   © r   r   ú<module>rx      s/   ðã ß  ã ß ß 9Ý 3ð Ð
€ôH2˜õ H2r   