
    sgw	                     l    d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 dgZ G d de      Zy)	    N)inf)constraints)Cauchy)TransformedDistribution)AbsTransform
HalfCauchyc                        e Zd ZdZdej
                  iZej                  ZdZ	d fd	Z
d fd	Zed        Zed        Zed        Zed	        Zd
 Zd Zd Zd Z xZS )r   a  
    Creates a half-Cauchy distribution parameterized by `scale` where::

        X ~ Cauchy(0, scale)
        Y = |X| ~ HalfCauchy(scale)

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = HalfCauchy(torch.tensor([1.0]))
        >>> m.sample()  # half-cauchy distributed with scale=1
        tensor([ 2.3214])

    Args:
        scale (float or Tensor): scale of the full Cauchy distribution
    scaleTc                 V    t        d|d      }t        | 	  |t               |       y )Nr   F)validate_args)r   super__init__r   )selfr
   r   	base_dist	__class__s       R/var/www/html/venv/lib/python3.12/site-packages/torch/distributions/half_cauchy.pyr   zHalfCauchy.__init__$   s'    1e59	LN-P    c                 R    | j                  t        |      }t        |   ||      S )N)	_instance)_get_checked_instancer   r   expand)r   batch_shaper   newr   s       r   r   zHalfCauchy.expand(   s(    ((Y?w~kS~99r   c                 .    | j                   j                  S N)r   r
   r   s    r   r
   zHalfCauchy.scale,   s    ~~###r   c                     t        j                  | j                         t        j                  | j
                  j                  | j
                  j                        S )Ndtypedevice)torchfull_extended_shapemathr   r
   r   r    r   s    r   meanzHalfCauchy.mean0   s@    zz  "HH**""::$$	
 	
r   c                 @    t        j                  | j                        S r   )r!   
zeros_liker
   r   s    r   modezHalfCauchy.mode9   s    

++r   c                 .    | j                   j                  S r   )r   variancer   s    r   r*   zHalfCauchy.variance=   s    ~~&&&r   c                    | j                   r| j                  |       t        j                  || j                  j
                  j                  | j                  j
                  j                        }| j                  j                  |      t        j                  d      z   }t        j                  |dk\  |t               }|S )Nr      r   )_validate_args_validate_sampler!   	as_tensorr   r
   r   r    log_probr$   logwherer   )r   valuer0   s      r   r0   zHalfCauchy.log_probA   s    !!%(--33DNN<P<P<W<W
 >>**51DHHQK?;;uz8cT:r   c                 ~    | j                   r| j                  |       d| j                  j                  |      z  dz
  S )Nr,      )r-   r.   r   cdf)r   r3   s     r   r6   zHalfCauchy.cdfK   s8    !!%(4>>%%e,,q00r   c                 D    | j                   j                  |dz   dz        S )Nr5   r,   )r   icdf)r   probs     r   r8   zHalfCauchy.icdfP   s    ~~""D1H>22r   c                 b    | j                   j                         t        j                  d      z
  S )Nr,   )r   entropyr$   r1   r   s    r   r;   zHalfCauchy.entropyS   s"    ~~%%'$((1+55r   r   )__name__
__module____qualname____doc__r   positivearg_constraintsnonnegativesupporthas_rsampler   r   propertyr
   r%   r(   r*   r0   r6   r8   r;   __classcell__)r   s   @r   r   r      s       4 45O%%GKQ: $ $ 
 
 , , ' '1
36r   )r$   r!   r   torch.distributionsr   torch.distributions.cauchyr   ,torch.distributions.transformed_distributionr   torch.distributions.transformsr   __all__r    r   r   <module>rM      s2       + - P 7 .E6( E6r   