
    Vh	                     p    d dl Z 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	 d dl
mZ dgZ G d de	      Zy)	    N)infTensor)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efd       Zedefd       Zedefd	       Zedef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       O/home/dcms/DCMS/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   returnc                 .    | 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.mean1   s@    zz  "HH**""::$$	
 	
r   c                 @    t        j                  | j                        S r   )r#   
zeros_liker   r   s    r   modezHalfCauchy.mode:   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   valuer2   s      r   r2   zHalfCauchy.log_probB   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/   r0   r   cdf)r   r5   s     r   r8   zHalfCauchy.cdfL   s8    !!%(4>>%%e,,q00r   c                 D    | j                   j                  |dz   dz        S )Nr7   r.   )r   icdf)r   probs     r   r:   zHalfCauchy.icdfQ   s    ~~""D1H>22r   c                 b    | j                   j                         t        j                  d      z
  S )Nr.   )r   entropyr&   r3   r   s    r   r=   zHalfCauchy.entropyT   s"    ~~%%'$((1+55r   r   )__name__
__module____qualname____doc__r   positivearg_constraintsnonnegativesupporthas_rsampler   r   propertyr   r   r'   r*   r,   r2   r8   r:   r=   __classcell__)r   s   @r   r	   r	      s    "  4 45O%%GKQ: $v $ $ 
f 
 
 ,f , , '& ' '1
36r   )r&   r#   r   r   torch.distributionsr   torch.distributions.cauchyr   ,torch.distributions.transformed_distributionr   torch.distributions.transformsr   __all__r	    r   r   <module>rO      s2       + - P 7 .F6( F6r   