
    rhd                         d dl Z d dlmZmZ d dlZd dlmZmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZ dgZ G d	 de      Zy)
    N)OptionalUnion)infnanTensor)constraints)Distribution)broadcast_all)_Number_sizeCauchyc            	       8    e Zd ZdZej
                  ej                  dZej
                  ZdZ		 dde
eef   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j,                         fdedefdZd Zd Zd Zd Z xZS )r   aC  
    Samples from a Cauchy (Lorentz) distribution. The distribution of the ratio of
    independent normally distributed random variables with means `0` follows a
    Cauchy distribution.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = Cauchy(torch.tensor([0.0]), torch.tensor([1.0]))
        >>> m.sample()  # sample from a Cauchy distribution with loc=0 and scale=1
        tensor([ 2.3214])

    Args:
        loc (float or Tensor): mode or median of the distribution.
        scale (float or Tensor): half width at half maximum.
    )locscaleTNr   r   validate_argsreturnc                     t        ||      \  | _        | _        t        |t              r%t        |t              rt        j                         }n| j                  j                         }t        | %  ||       y )Nr   )
r
   r   r   
isinstancer   torchSizesizesuper__init__)selfr   r   r   batch_shape	__class__s        m/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/torch/distributions/cauchy.pyr   zCauchy.__init__&   sY      -S%8$*c7#
5'(B**,K((--/KMB    c                 *   | j                  t        |      }t        j                  |      }| j                  j                  |      |_        | j                  j                  |      |_        t        t        |#  |d       | j                  |_	        |S )NFr   )
_get_checked_instancer   r   r   r   expandr   r   r   _validate_args)r   r   	_instancenewr   s       r   r"   zCauchy.expand3   st    ((;jj-((//+.JJ%%k2	fc#Ku#E!00
r   c                     t        j                  | j                         t        | j                  j
                  | j                  j                        S N)dtypedevice)r   full_extended_shaper   r   r(   r)   r   s    r   meanzCauchy.mean<   5    zz  "Ctxx~~dhhoo
 	
r   c                     | j                   S N)r   r,   s    r   modezCauchy.modeB   s    xxr   c                     t        j                  | j                         t        | j                  j
                  | j                  j                        S r'   )r   r*   r+   r   r   r(   r)   r,   s    r   variancezCauchy.varianceF   r.   r   sample_shapec                     | j                  |      }| j                  j                  |      j                         }| j                  || j                  z  z   S r0   )r+   r   r%   cauchy_r   )r   r4   shapeepss       r   rsamplezCauchy.rsampleL   sE    $$\2hhll5!))+xx#

***r   c                    | j                   r| j                  |       t        j                  t        j                         | j
                  j                         z
  || j                  z
  | j
                  z  dz  j                         z
  S )N   )r#   _validate_samplemathlogpir   r   log1pr   values     r   log_probzCauchy.log_probQ   sl    !!%(XXdggjjnn!TZZ/A5<<>?	
r   c                     | j                   r| j                  |       t        j                  || j                  z
  | j
                  z        t        j                  z  dz   S Ng      ?)r#   r<   r   atanr   r   r=   r?   rA   s     r   cdfz
Cauchy.cdfZ   sH    !!%(zz5488+tzz9:TWWDsJJr   c                     t        j                  t        j                  |dz
  z        | j                  z  | j
                  z   S rE   )r   tanr=   r?   r   r   rA   s     r   icdfzCauchy.icdf_   s0    yyECK01DJJ>IIr   c                     t        j                  dt         j                  z        | j                  j                         z   S )N   )r=   r>   r?   r   r,   s    r   entropyzCauchy.entropyb   s)    xxDGG$tzz~~'777r   r0   )__name__
__module____qualname____doc__r   realpositivearg_constraintssupporthas_rsampler   r   floatr   boolr   r"   propertyr-   r1   r3   r   r   r   r9   rC   rG   rJ   rM   __classcell__)r   s   @r   r   r      s   " *..9M9MNOGK )-	C65=!C VU]#C  ~	C
 
C 
f 
 

 f   
& 
 

 -7EJJL +E +V +

K
J8r   )r=   typingr   r   r   r   r   r   torch.distributionsr    torch.distributions.distributionr	   torch.distributions.utilsr
   torch.typesr   r   __all__r    r   r   <module>rb      s7     "  " " + 9 3 & *S8\ S8r   