
    IЦiy                     j    S SK Jr  S SKrS SKJr  S SKJr  S SKJr  S SK	J
r
  S/rS r " S	 S\5      rg)
    )NumberN)constraints)ExponentialFamily)broadcast_all)_sizeGammac                 .    [         R                  " U 5      $ N)torch_standard_gamma)concentrations    X/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torch/distributions/gamma.pyr   r      s      //    c                   4  ^  \ rS rSrSr\R                  \R                  S.r\R                  r	Sr
Sr\S 5       r\S 5       r\S 5       rSU 4S	 jjrSU 4S
 jjr\R&                  " 5       4S\S\R*                  4S jjrS rS r\S 5       rS rS rSrU =r$ )r      a#  
Creates a Gamma distribution parameterized by shape :attr:`concentration` and :attr:`rate`.

Example::

    >>> # xdoctest: +IGNORE_WANT("non-deterministic")
    >>> m = Gamma(torch.tensor([1.0]), torch.tensor([1.0]))
    >>> m.sample()  # Gamma distributed with concentration=1 and rate=1
    tensor([ 0.1046])

Args:
    concentration (float or Tensor): shape parameter of the distribution
        (often referred to as alpha)
    rate (float or Tensor): rate parameter of the distribution
        (often referred to as beta), rate = 1 / scale
r   rateTr   c                 4    U R                   U R                  -  $ r
   r   selfs    r   mean
Gamma.mean+   s    !!DII--r   c                 T    U R                   S-
  U R                  -  R                  SS9$ )N   r   min)r   r   clampr   s    r   mode
Gamma.mode/   s*    ##a'4994;;;BBr   c                 R    U R                   U R                  R                  S5      -  $ )N   )r   r   powr   s    r   varianceGamma.variance3   s     !!DIIMM!$444r   c                   > [        X5      u  U l        U l        [        U[        5      (       a+  [        U[        5      (       a  [
        R                  " 5       nOU R                  R                  5       n[        TU ]%  XCS9  g )Nvalidate_args)
r   r   r   
isinstancer   r   Sizesizesuper__init__)r   r   r   r'   batch_shape	__class__s        r   r,   Gamma.__init__7   s_    (5m(J%DImV,,D&1I1I**,K,,113KBr   c                 &  > U R                  [        U5      n[        R                  " U5      n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,   _validate_args)r   r-   	_instancenewr.   s       r   r2   Gamma.expand?   sy    ((	:jj- ..55kB99##K0eS";e"D!00
r   sample_shapereturnc                 2   U R                  U5      n[        U R                  R                  U5      5      U R                  R                  U5      -  nUR                  5       R                  [        R                  " UR                  5      R                  S9  U$ )Nr   )_extended_shaper   r   r2   r   detachclamp_r   finfodtypetiny)r   r7   shapevalues       r   rsampleGamma.rsampleH   s    $$\2 2 2 9 9% @ADIIDTDTE
 
 	EKK(-- 	 	
 r   c                    [         R                  " XR                  R                  U R                  R                  S9nU R
                  (       a  U R                  U5        [         R                  " U R                  U R                  5      [         R                  " U R                  S-
  U5      -   U R                  U-  -
  [         R                  " U R                  5      -
  $ )N)r>   devicer   )
r   	as_tensorr   r>   rE   r3   _validate_samplexlogyr   lgammar   rA   s     r   log_probGamma.log_probR   s    YY__TYYEUEUV!!%(KK**DII6kk$,,q0%89ii%  ll4--./	
r   c                     U R                   [        R                  " U R                  5      -
  [        R                  " U R                   5      -   SU R                   -
  [        R
                  " U R                   5      -  -   $ )Ng      ?)r   r   logr   rI   digammar   s    r   entropyGamma.entropy]   sf    ii		"#ll4--./ T'''5==9K9K+LLM	
r   c                 :    U R                   S-
  U R                  * 4$ Nr   r   r   s    r   _natural_paramsGamma._natural_paramse   s    ""Q&
33r   c                     [         R                  " US-   5      US-   [         R                  " UR                  5       * 5      -  -   $ rS   )r   rI   rN   
reciprocal)r   xys      r   _log_normalizerGamma._log_normalizeri   s4    ||AE"a!euyy!,,./I%IIIr   c                     U R                   (       a  U R                  U5        [        R                  R	                  U R
                  U R                  U-  5      $ r
   )r3   rG   r   specialgammaincr   r   rJ   s     r   cdf	Gamma.cdfl   s?    !!%(}}%%d&8&8$))e:KLLr   r
   )__name__
__module____qualname____firstlineno____doc__r   positivearg_constraintsnonnegativesupporthas_rsample_mean_carrier_measurepropertyr   r   r#   r,   r2   r   r)   r   TensorrB   rK   rP   rT   rZ   r_   __static_attributes____classcell__)r.   s   @r   r   r      s    " %--$$O %%GK. . C C 5 5C -2JJL E U\\ 	

 4 4JM Mr   )numbersr   r   torch.distributionsr   torch.distributions.exp_familyr   torch.distributions.utilsr   torch.typesr   __all__r   r    r   r   <module>rw      s6      + < 3  )0]M ]Mr   