
    rh0
                         d dl Z d dlmZm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)OptionalUnion)infTensor)constraints)Cauchy)TransformedDistribution)AbsTransform
HalfCauchyc                       e Zd ZU dZdej
                  iZej                  ZdZ	e
ed<   	 ddeeef   dee   ddf 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
    scaleT	base_distNvalidate_argsreturnc                 V    t        d|d      }t        | 	  |t               |       y )Nr   F)r   )r   super__init__r
   )selfr   r   r   	__class__s       r/var/www/html/ai-insurance-compliance-backend/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.scale3   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.mean7   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.varianceD   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   valuer4   s      r   r4   zHalfCauchy.log_probH   s    !!%(--33DNN<P<P<W<W
 >>**51DHHQK?;;uz8cT:r   c                 ~    | j                   r| j                  |       d| j                  j                  |      z  dz
  S )Nr0      )r1   r2   r   cdf)r   r7   s     r   r:   zHalfCauchy.cdfR   s8    !!%(4>>%%e,,q00r   c                 D    | j                   j                  |dz   dz        S )Nr9   r0   )r   icdf)r   probs     r   r<   zHalfCauchy.icdfW   s    ~~""D1H>22r   c                 b    | j                   j                         t        j                  d      z
  S )Nr0   )r   entropyr(   r5   r    s    r   r?   zHalfCauchy.entropyZ   s"    ~~%%'$((1+55r   r   )__name__
__module____qualname____doc__r   positivearg_constraintsnonnegativesupporthas_rsampler   __annotations__r   r   floatr   boolr   r   propertyr   r)   r,   r.   r4   r:   r<   r?   __classcell__)r   s   @r   r   r      s    "  4 45O%%GK
 )-QVU]#Q  ~Q 
	Q: $v $ $ 
f 
 
 ,f , , '& ' '1
36r   )r(   typingr   r   r%   r   r   torch.distributionsr   torch.distributions.cauchyr   ,torch.distributions.transformed_distributionr	   torch.distributions.transformsr
   __all__r    r   r   <module>rU      s5     "   + - P 7 .K6( K6r   