ó
    Eñi…  ã                   ód   • S SK r S SK JrJr  S SKJr  S SKJr  S SKJrJ	r	J
r
  S/r " S S\5      rg)é    N)ÚnanÚTensor)Úconstraints)ÚDistribution)Úlazy_propertyÚlogits_to_probsÚprobs_to_logitsÚCategoricalc            	       óº  ^ • \ rS rSrSr\R                  \R                  S.rSr	   SS\
S-  S\
S-  S\S-  S	S4U 4S
 jjjrSU 4S jjrS r\R                  " SSS9S 5       r\S	\
4S j5       r\S	\
4S j5       r\S	\R,                  4S j5       r\S	\
4S j5       r\S	\
4S j5       r\S	\
4S j5       r\R,                  " 5       4S jrS rS rSS jrSrU =r $ )r
   é   ax  
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ÚlogitsTNr   r   Úvalidate_argsÚreturnc                 ój  >• US L US L :X  a  [        S5      eUb7  UR                  5       S:  a  [        S5      eXR                  SSS9-  U l        ODUc  [	        S5      eUR                  5       S:  a  [        S5      eX"R                  SSS	9-
  U l        Ub  U R                  OU R                  U l        U R                  R                  5       S   U l	        U R                  R                  5       S:”  a  U R                  R                  5       S S O[        R                  " 5       n[        TU ]9  XCS
9  g )Nz;Either `probs` or `logits` must be specified, but not both.é   z3`probs` parameter must be at least one-dimensional.éÿÿÿÿT)Úkeepdimzlogits is unexpectedly Nonez4`logits` parameter must be at least one-dimensional.)Údimr   ©r   )Ú
ValueErrorr   Úsumr   ÚAssertionErrorÚ	logsumexpr   Ú_paramÚsizeÚ_num_eventsÚ
ndimensionÚtorchÚSizeÚsuperÚ__init__)Úselfr   r   r   Úbatch_shapeÚ	__class__s        €Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/distributions/categorical.pyr"   ÚCategorical.__init__8   s  ø€ ð �TˆM˜v¨˜~Ó.ÜØMóð ð ÑØ�y‰y‹{˜Q‹Ü Ð!VÓWÐWà§¡¨2°t Ð!<Ñ<ˆD�Jà‰~Ü$Ð%BÓCÐCØ�z‰z‹|˜aÓÜ Ð!WÓXÐXð !×#3Ñ#3¸ÀDÐ#3Ð#IÑIˆDŒKØ$)Ñ$5�d—j’j¸4¿;¹;ˆŒØŸ;™;×+Ñ+Ó-¨bÑ1ˆÔà'+§{¡{×'=Ñ'=Ó'?À!Ó'CˆD�K‰K×ÑÓ˜s Ñ#ÌÏÊËð 	ô 	‰Ñ˜ÐÒBó    c                 ó  >• U R                  [        U5      n[        R                  " U5      nU[        R                  " U R                  45      -   nSU R
                  ;   a1  U R                  R                  U5      Ul        UR                  Ul        SU R
                  ;   a1  U R                  R                  U5      Ul	        UR                  Ul        U R                  Ul        [        [        U]/  USS9  U R                  Ul        U$ )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,   ÚCategorical.expandW   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                 ó:   • U R                   R                  " U0 UD6$ ©N)r   r/   )r#   ÚargsÚkwargss      r&   Ú_newÚCategorical._newf   s   € Ø�{‰{�Š Ð/¨Ñ/Ð/r(   r   )Úis_discreteÚ	event_dimc                 óJ   • [         R                  " SU R                  S-
  5      $ )Nr   r   )r   Úinteger_intervalr   ©r#   s    r&   ÚsupportÚCategorical.supporti   s"   € ô ×+Ò+¨A¨t×/?Ñ/?À!Ñ/CÓDÐDr(   c                 ó,   • [        U R                  5      $ r3   )r	   r   r<   s    r&   r   ÚCategorical.logitsn   s   € ä˜tŸz™zÓ*Ð*r(   c                 ó,   • [        U R                  5      $ r3   )r   r   r<   s    r&   r   ÚCategorical.probsr   s   € ä˜tŸ{™{Ó+Ð+r(   c                 ó6   • U R                   R                  5       $ r3   )r   r   r<   s    r&   r0   ÚCategorical.param_shapev   s   € à�{‰{×ÑÓ!Ð!r(   c                 ó¤   • [         R                  " U R                  5       [        U R                  R
                  U R                  R                  S9$ ©N©ÚdtypeÚdevice©r   ÚfullÚ_extended_shaper   r   rH   rI   r<   s    r&   ÚmeanÚCategorical.meanz   ó<   € ä�zŠzØ× Ñ Ó"ÜØ—*‘*×"Ñ"Ø—:‘:×$Ñ$ñ	
ð 	
r(   c                 ó4   • U R                   R                  SS9$ )Nr   )r   )r   Úargmaxr<   s    r&   ÚmodeÚCategorical.modeƒ   s   € à�z‰z× Ñ  RÐ Ð(Ð(r(   c                 ó¤   • [         R                  " U R                  5       [        U R                  R
                  U R                  R                  S9$ rF   rJ   r<   s    r&   ÚvarianceÚCategorical.variance‡   rO   r(   c                 óV  • [        U[        R                  5      (       d  [        R                  " U5      nU R                  R	                  SU R
                  5      n[        R                  " X!R                  5       S5      R                  nUR	                  U R                  U5      5      $ )Nr   T)
Ú
isinstancer   r    r   Úreshaper   ÚmultinomialÚnumelÚTrL   )r#   Úsample_shapeÚprobs_2dÚ
samples_2ds       r&   ÚsampleÚCategorical.sample�   sz   € Ü˜,¬¯
©
×3Ñ3Ü Ÿ:š: lÓ3ˆLØ—:‘:×%Ñ% b¨$×*:Ñ*:Ó;ˆÜ×&Ò& x×1CÑ1CÓ1EÀtÓL×NÑNˆ
Ø×!Ñ! $×"6Ñ"6°|Ó"DÓEÐEr(   c                 ó  • U R                   (       a  U R                  U5        UR                  5       R                  S5      n[        R
                  " XR                  5      u  pUSS S24   nUR                  SU5      R                  S5      $ )Nr   .r   )	r-   Ú_validate_sampleÚlongÚ	unsqueezer   Úbroadcast_tensorsr   ÚgatherÚsqueeze)r#   ÚvalueÚlog_pmfs      r&   Úlog_probÚCategorical.log_prob—   sr   € Ø××Ø×!Ñ! %Ô(Ø—
‘
“×&Ñ& rÓ*ˆÜ×0Ò0°¿¹ÓD‰ˆØ�c˜2˜A˜2�g‘ˆØ�~‰~˜b %Ó(×0Ñ0°Ó4Ð4r(   c                 óè   • [         R                  " U R                  R                  5      R                  n[         R
                  " U R                  US9nX R                  -  nUR                  S5      * $ )N)Úminr   )r   Úfinfor   rH   rn   Úclampr   r   )r#   Úmin_realr   Úp_log_ps       r&   ÚentropyÚCategorical.entropyŸ   sQ   € Ü—;’;˜tŸ{™{×0Ñ0Ó1×5Ñ5ˆÜ—’˜TŸ[™[¨hÑ7ˆØŸ:™:Ñ%ˆØ—‘˜B“ÐÐr(   c                 ó,  • U R                   n[        R                  " U[        R                  U R                  R
                  S9nUR                  SS[        U R                  5      -  -   5      nU(       a  UR                  SU R                  -   5      nU$ )NrG   )r   )r   )
r   r   Úarangerd   r   rI   ÚviewÚlenÚ_batch_shaper,   )r#   r,   Ú
num_eventsÚvaluess       r&   Úenumerate_supportÚCategorical.enumerate_support¥   sq   € Ø×%Ñ%ˆ
Ü—’˜j´·
±
À4Ç;Á;×CUÑCUÑVˆØ—‘˜U T¬C°×0AÑ0AÓ,BÑ%BÑBÓCˆÞØ—]‘] 5¨4×+<Ñ+<Ñ#<Ó=ˆFØˆr(   )r   r   r   r   )NNNr3   )T)!Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚsimplexÚreal_vectorÚarg_constraintsÚhas_enumerate_supportr   Úboolr"   r,   r6   Údependent_propertyr=   r   r   r   Úpropertyr   r    r0   rM   rR   rU   r`   rk   rs   r|   Ú__static_attributes__Ú__classcell__)r%   s   @r&   r
   r
      sm  ø† ñ$ðN !,× 3Ñ 3¸{×?VÑ?VÑW€OØ Ðð  $Ø $Ø%)ñ	Cà˜‰}ðCð ˜‘ðCð ˜d‘{ð	Cð
 
÷Cð 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‘      s0   ðó ß Ý +Ý 9ß UÑ Uð ˆ/€ô^�,õ ^r(   