Ë
    f^(hõ  ã                   ód   — d dl Z d dl mZmZ d dlmZ d dlmZ d dlmZm	Z	m
Z
 dgZ G d„ de«      Zy)é    N)ÚnanÚTensor)Úconstraints)ÚDistribution)Úlazy_propertyÚlogits_to_probsÚprobs_to_logitsÚCategoricalc                   ót  ‡ — e Zd ZdZej
                  ej                  dœZdZdˆ fd„	Z	dˆ fd„	Z
d„ Z ej                  dd¬«      d	„ «       Zed
efd„«       Zed
efd„«       Zed
ej(                  fd„«       Zed
efd„«       Zed
efd„«       Zed
efd„«       Z ej(                  «       fd„Zd„ Zd„ Zdd„Zˆ xZS )r
   aä  
    Creates a categorical distribution parameterized by either :attr:`probs` or
    :attr:`logits` (but not both).

    .. note::
        It is equivalent to the distribution that :func:`torch.multinomial`
        samples from.

    Samples are integers from :math:`\{0, \ldots, K-1\}` where `K` is ``probs.size(-1)``.

    If `probs` is 1-dimensional with length-`K`, each element is the relative probability
    of sampling the class at that index.

    If `probs` is N-dimensional, the first N-1 dimensions are treated as a batch of
    relative probability vectors.

    .. note:: The `probs` argument must be non-negative, finite and have a non-zero sum,
              and it will be normalized to sum to 1 along the last dimension. :attr:`probs`
              will return this normalized value.
              The `logits` argument will be interpreted as unnormalized log probabilities
              and can therefore be any real number. It will likewise be normalized so that
              the resulting probabilities sum to 1 along the last dimension. :attr:`logits`
              will return this normalized value.

    See also: :func:`torch.multinomial`

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = Categorical(torch.tensor([ 0.25, 0.25, 0.25, 0.25 ]))
        >>> m.sample()  # equal probability of 0, 1, 2, 3
        tensor(3)

    Args:
        probs (Tensor): event probabilities
        logits (Tensor): event log probabilities (unnormalized)
    )ÚprobsÚlogitsTc                 óX  •— |d u |d u k(  rt        d«      ‚|�:|j                  «       dk  rt        d«      ‚||j                  dd¬«      z  | _        n9|j                  «       dk  rt        d«      ‚||j	                  dd¬«      z
  | _        |�| j                  n| j
                  | _        | j                  j                  «       d   | _        | j                  j                  «       dkD  r| j                  j                  «       d d nt        j                  «       }t        ‰| �5  ||¬	«       y )
Nz;Either `probs` or `logits` must be specified, but not both.é   z3`probs` parameter must be at least one-dimensional.éÿÿÿÿT)Úkeepdimz4`logits` parameter must be at least one-dimensional.)Údimr   ©Úvalidate_args)Ú
ValueErrorr   Úsumr   Ú	logsumexpr   Ú_paramÚsizeÚ_num_eventsÚ
ndimensionÚtorchÚSizeÚsuperÚ__init__)Úselfr   r   r   Úbatch_shapeÚ	__class__s        €ú]/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/distributions/categorical.pyr   zCategorical.__init__6   s  ø€ Ø�TˆM˜v¨˜~Ò.ÜØMóð ð ÐØ�y‰y‹{˜QŠÜ Ð!VÓWÐWØ §¡¨2°t Ó!<Ñ<ˆD�Jà�z‰z‹|˜aÒÜ Ð!WÓXÐXà  6×#3Ñ#3¸ÀDÐ#3Ó#IÑIˆDŒKØ$)Ð$5�d—j’j¸4¿;¹;ˆŒØŸ;™;×+Ñ+Ó-¨bÑ1ˆÔà'+§{¡{×'=Ñ'=Ó'?À!Ò'CˆD�K‰K×ÑÓ˜s Ñ#ÌÏÉËð 	ô 	‰Ñ˜°MÐÕBó    c                 ó  •— | j                  t        |«      }t        j                  |«      }|t        j                  | j                  f«      z   }d| j
                  v r1| j                  j                  |«      |_        |j                  |_        d| j
                  v r1| j                  j                  |«      |_	        |j                  |_        | j                  |_        t        t        |�/  |d¬«       | j                  |_        |S )Nr   r   Fr   )Ú_get_checked_instancer
   r   r   r   Ú__dict__r   Úexpandr   r   r   r   Ú_validate_args)r    r!   Ú	_instanceÚnewÚparam_shaper"   s        €r#   r(   zCategorical.expandK   sÍ   ø€ Ø×(Ñ(¬°iÓ@ˆÜ—j‘j Ó-ˆØ!¤E§J¡J°×0@Ñ0@Ð/BÓ$CÑCˆØ�d—m‘mÑ#ØŸ
™
×)Ñ)¨+Ó6ˆCŒIØŸ™ˆCŒJØ�t—}‘}Ñ$ØŸ™×+Ñ+¨KÓ8ˆCŒJØŸ™ˆCŒJØ×*Ñ*ˆŒÜŒk˜3Ñ(¨ÀEÐ(ÔJØ!×0Ñ0ˆÔØˆ
r$   c                 ó:   —  | j                   j                  |i |¤ŽS ©N)r   r+   )r    ÚargsÚkwargss      r#   Ú_newzCategorical._newZ   s   € Øˆt�{‰{�‰ Ð/¨Ñ/Ð/r$   r   )Úis_discreteÚ	event_dimc                 óH   — t        j                  d| j                  dz
  «      S )Nr   r   )r   Úinteger_intervalr   ©r    s    r#   ÚsupportzCategorical.support]   s    € ä×+Ñ+¨A¨t×/?Ñ/?À!Ñ/CÓDÐDr$   Úreturnc                 ó,   — t        | j                  «      S r.   )r	   r   r6   s    r#   r   zCategorical.logitsa   s   € ä˜tŸz™zÓ*Ð*r$   c                 ó,   — t        | j                  «      S r.   )r   r   r6   s    r#   r   zCategorical.probse   s   € ä˜tŸ{™{Ó+Ð+r$   c                 ó6   — | j                   j                  «       S r.   )r   r   r6   s    r#   r,   zCategorical.param_shapei   s   € à�{‰{×ÑÓ!Ð!r$   c                 ó¨   — t        j                  | j                  «       t        | j                  j
                  | j                  j                  ¬«      S ©N©ÚdtypeÚdevice©r   ÚfullÚ_extended_shaper   r   r?   r@   r6   s    r#   ÚmeanzCategorical.meanm   ó<   € ä�z‰zØ× Ñ Ó"ÜØ—*‘*×"Ñ"Ø—:‘:×$Ñ$ô	
ð 	
r$   c                 ó:   — | j                   j                  d¬«      S )Nr   )r   )r   Úargmaxr6   s    r#   ÚmodezCategorical.modev   s   € à�z‰z× Ñ  RÐ Ó(Ð(r$   c                 ó¨   — t        j                  | j                  «       t        | j                  j
                  | j                  j                  ¬«      S r=   rA   r6   s    r#   ÚvariancezCategorical.variancez   rE   r$   c                 óJ  — t        |t        j                  «      st        j                  |«      }| j                  j	                  d| j
                  «      }t        j                  ||j                  «       d«      j                  }|j	                  | j                  |«      «      S )Nr   T)
Ú
isinstancer   r   r   Úreshaper   ÚmultinomialÚnumelÚTrC   )r    Úsample_shapeÚprobs_2dÚ
samples_2ds       r#   ÚsamplezCategorical.sampleƒ   sy   € Ü˜,¬¯
©
Ô3Ü Ÿ:™: lÓ3ˆLØ—:‘:×%Ñ% b¨$×*:Ñ*:Ó;ˆÜ×&Ñ& x°×1CÑ1CÓ1EÀtÓL×NÑNˆ
Ø×!Ñ! $×"6Ñ"6°|Ó"DÓEÐEr$   c                 ó  — | j                   r| j                  |«       |j                  «       j                  d«      }t	        j
                  || j                  «      \  }}|dd d…f   }|j                  d|«      j                  d«      S )Nr   .r   )	r)   Ú_validate_sampleÚlongÚ	unsqueezer   Úbroadcast_tensorsr   ÚgatherÚsqueeze)r    ÚvalueÚlog_pmfs      r#   Úlog_probzCategorical.log_probŠ   sv   € Ø×ÒØ×!Ñ! %Ô(Ø—
‘
“×&Ñ& rÓ*ˆÜ×0Ñ0°¸¿¹ÓD‰ˆˆwØ�c˜2˜A˜2�g‘ˆØ�~‰~˜b %Ó(×0Ñ0°Ó4Ð4r$   c                 óì   — t        j                  | j                  j                  «      j                  }t        j
                  | j                  |¬«      }|| j                  z  }|j                  d«       S )N)Úminr   )r   Úfinfor   r?   r`   Úclampr   r   )r    Úmin_realr   Úp_log_ps       r#   ÚentropyzCategorical.entropy’   sS   € Ü—;‘;˜tŸ{™{×0Ñ0Ó1×5Ñ5ˆÜ—‘˜TŸ[™[¨hÔ7ˆØ˜4Ÿ:™:Ñ%ˆØ—‘˜B“ÐÐr$   c                 ó&  — | j                   }t        j                  |t        j                  | j                  j
                  ¬«      }|j                  ddt        | j                  «      z  z   «      }|r|j                  d| j                  z   «      }|S )Nr>   )r   )r   )
r   r   ÚarangerW   r   r@   ÚviewÚlenÚ_batch_shaper(   )r    r(   Ú
num_eventsÚvaluess       r#   Úenumerate_supportzCategorical.enumerate_support˜   sq   € Ø×%Ñ%ˆ
Ü—‘˜j´·
±
À4Ç;Á;×CUÑCUÔVˆØ—‘˜U T¬C°×0AÑ0AÓ,BÑ%BÑBÓCˆÙØ—]‘] 5¨4×+<Ñ+<Ñ#<Ó=ˆFØˆr$   )NNNr.   )T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚsimplexÚreal_vectorÚarg_constraintsÚhas_enumerate_supportr   r(   r1   Údependent_propertyr7   r   r   r   r   Úpropertyr   r   r,   rD   rH   rJ   rT   r^   re   rm   Ú__classcell__)r"   s   @r#   r
   r
      s%  ø„ ñ$ðL !,× 3Ñ 3¸{×?VÑ?VÑW€OØ ÐõCõ*ò0ð $€[×#Ñ#°ÀÔBñEó CðEð ð+˜ò +ó ð+ð ð,�vò ,ó ð,ð ð"˜UŸZ™Zò "ó ð"ð ð
�fò 
ó ð
ð ð)�fò )ó ð)ð ð
˜&ò 
ó ð
ð #- %§*¡*£,ó Fò5ò ÷r$   )r   r   r   Útorch.distributionsr   Ú torch.distributions.distributionr   Útorch.distributions.utilsr   r   r	   Ú__all__r
   © r$   r#   ú<module>r~      s.   ðã ß Ý +Ý 9ß UÑ Uð ˆ/€ôR�,õ Rr$   