§
    ŠŠtjÇ  ã                   ót   — 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dS )é    N)ÚNumberÚReal)ÚinfÚnan)ÚconstraintsÚDistribution)Úbroadcast_allÚGeneralizedParetoc                   ó$  ‡ — 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j        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ÚconcentrationTNc                 ón  •— t          |||¦  «        \  | _        | _        | _        t	          |t
          ¦  «        r>t	          |t
          ¦  «        r)t	          |t
          ¦  «        rt          j        ¦   «         }n| j                             ¦   «         }t          ¦   «          
                    ||¬¦  «         d S )N©Úvalidate_args)r	   r   r   r   Ú
isinstancer   ÚtorchÚSizeÚsizeÚsuperÚ__init__)Úselfr   r   r   r   Úbatch_shapeÚ	__class__s         €úd/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/distributions/generalized_pareto.pyr   zGeneralizedPareto.__init__.   s¢   ø€ Ý3@Ø�˜ñ4
ô 4
Ñ0ˆŒ�$”*˜dÔ0õ �s�FÑ#Ô#ð	*å˜5¥&Ñ)Ô)ð	*õ ˜=­&Ñ1Ô1ð	*õ
  œ*™,œ,ˆKˆKàœ(Ÿ-š-™/œ/ˆKÝ‰Œ×Ò˜°MÐÑBÔBÐBÐBÐBó    c                 óŒ  •— |                       t          |¦  «        }t          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ÔFˆÝ”j Ñ-Ô-ˆØ”(—/’/ +Ñ.Ô.ˆŒØ”J×%Ò% kÑ2Ô2ˆŒ	Ø Ô.×5Ò5°kÑBÔBˆÔÝÕ Ñ%Ô%×.Ò.¨{È%Ð.ÑPÔPÐPØ!Ô0ˆÔØˆ
r   c                 ó¬   — |                       |¦  «        }t          j        || j        j        | j        j        ¬¦  «        }|                      |¦  «        S )N)ÚdtypeÚdevice)Ú_extended_shaper   Úrandr   r$   r%   Úicdf)r   Úsample_shapeÚshapeÚus       r   ÚrsamplezGeneralizedPareto.rsampleF   sC   € Ø×$Ò$ \Ñ2Ô2ˆÝŒJ�u D¤H¤N¸4¼8¼?ÐKÑKÔKˆØ�yŠy˜‰|Œ|Ðr   c           	      ó„  — | j         r|                      |¦  «         |                      |¦  «        }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                             ¦   «         }| 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_probK   s  € ØÔð 	)Ø×!Ò! %Ñ(Ô(Ð(Ø�GŠG�E‰NŒNˆÝ”- Ô 2µE´LÀÑ4EÔ4EÑFÔFˆÝ”KØ•U”_ TÔ%7Ñ8Ô8¸$Ô:Lñ
ô 
ˆ	ð �	‰M�EœO¨AÑ.Ô.Ñ.ˆÝœ A¨¢F¨A¨qµ5´;¸yÈ1¹}Ñ3MÔ3MÑ/MÑNÔNˆå$.¨t¬z½4Ñ$@Ô$@ÐV�DŒH�T”ZÑ Ô Ð ÀdÄjÇnÂnÑFVÔFVð 	ð ˆz�EœK¨°°MÑBÔBÑBÐBr   c                 ó„  — | j         r|                      |¦  «         |                      |¦  «        }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_functionZ   s©   € ØÔð 	)Ø×!Ò! %Ñ(Ô(Ð(Ø�GŠG�E‰NŒNˆÝ”- Ô 2µE´LÀÑ4EÔ4EÑFÔFˆÝ”KØ•U”_ TÔ%7Ñ8Ô8¸$Ô:Lñ
ô 
ˆ	õ œ Y°¡]Ñ3Ô3Ð3°iÑ?ˆÝŒ{˜7 Q B¨Ñ6Ô6Ð6r   c                 óv   — t          j        t          j        |                      |¦  «        ¦  «         ¦  «        S ©N)r   r6   ÚexprB   ©r   r9   s     r   Úlog_cdfzGeneralizedPareto.log_cdfe   s-   € ÝŒ{�EœI d×&@Ò&@ÀÑ&GÔ&GÑHÔHÐHÑIÔIÐIr   c                 óP   — t          j        |                      |¦  «        ¦  «        S rD   )r   rE   rG   rF   s     r   ÚcdfzGeneralizedPareto.cdfh   s   € ÝŒy˜Ÿš eÑ,Ô,Ñ-Ô-Ð-r   c                 ór  — | 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.icdfk   s©   € ØŒhˆØ”
ˆØÔ*ˆÝ”- ­uÔ/?ÀÑ/NÔ/NÑOÔOˆÝ”K ­¬¸Ñ)GÔ)GÈÑWÔWˆ	ÝŒ{˜E˜6Ñ"Ô"ˆØ˜e iÑ/µ%´+¸y¸jÈ4Ñ>OÑ2PÔ2PÑPÑPˆØ˜5 4™<Ñ'ˆ
ÝŒ{˜7 J°Ñ>Ô>Ð>r   c                 ó&   — || j         z
  | j        z  S rD   )r   r   )r   Úxs     r   r1   zGeneralizedPareto._zv   s   € Ø�D”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.meany   sR   € àÔ*ˆØ Ò!ˆÝ”K  }°cÑ:Ô:ˆ	Ø”˜Dœ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�   sb   € àÔ*ˆØ Ò#ˆÝ”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‰   s6   € ÝŒi˜œ
Ñ#Ô# dÔ&8Ñ8¸1Ñ<ˆÝÔ! # tÔ'8Ñ9Ô9Ð9r   c                 ó   — | j         S rD   )r   )r   s    r   ÚmodezGeneralizedPareto.mode�   s	   € àŒ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‘   sO   € ð ”ˆÝ”ØÔ Ò" E¨D¬J¸Ô9KÑ,KÑ$KÍSñ
ô 
ˆõ Ô# E¨5Ñ1Ô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¢  ø€ € € € € ðð ð2 ÔØÔ%Ø$Ô)ðð €Oð
 €KðCð Cð Cð Cð Cð Cðð ð ð ð ð ð $. 5¤:¡<¤<ð ð ð ð ð
Cð Cð Cð	7ð 	7ð 	7ðJð Jð Jð.ð .ð .ð	?ð 	?ð 	?ð+ð +ð +ð ð/ð /ñ „Xð/ð ð/ð /ñ „Xð/ð:ð :ð :ð ðð ñ „Xðð $€[Ô#°ÀÐCÑCÔCð2ð 2ñ DÔCð2ð 2ð 2ð 2ð 2r   )r7   Únumbersr   r   r   r   r   Útorch.distributionsr   r   Útorch.distributions.utilsr	   Ú__all__r
   © r   r   ú<module>rx      s¹   ðà €€€Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à €€€Ø Ð Ð Ð Ð Ð Ð Ð Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3ð Ð
€ðJ2ð J2ð J2ð J2ð J2˜ñ J2ô J2ð J2ð J2ð J2r   