
    Vh                     x    d dl 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)infnanTensor)constraints)Distribution)broadcast_all)_Number_sizeCauchyc                   
    e Zd ZdZej
                  ej                  d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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scaleTc                     t        ||      \  | _        | _        t        |t              r%t        |t              rt        j                         }n| j                  j                         }t        | %  ||       y )Nvalidate_args)
r   r   r   
isinstancer	   torchSizesizesuper__init__)selfr   r   r   batch_shape	__class__s        J/home/dcms/DCMS/lib/python3.12/site-packages/torch/distributions/cauchy.pyr   zCauchy.__init__%   sW    ,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.expand-   st    ((;jj-((//+.JJ%%k2	fc#Ku#E!00
r   returnc                     t        j                  | j                         t        | j                  j
                  | j                  j                        S N)dtypedevice)r   full_extended_shaper   r   r&   r'   r   s    r   meanzCauchy.mean6   5    zz  "Ctxx~~dhhoo
 	
r   c                     | j                   S N)r   r*   s    r   modezCauchy.mode<   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.variance@   r,   r   sample_shapec                     | j                  |      }| j                  j                  |      j                         }| j                  || j                  z  z   S r.   )r)   r   r"   cauchy_r   )r   r2   shapeepss       r   rsamplezCauchy.rsampleF   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_probK   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=   r?   s     r   cdfz
Cauchy.cdfT   sH    !!%(zz5488+tzz9:TWWDsJJr   c                     t        j                  t        j                  |dz
  z        | j                  z  | j
                  z   S rC   )r   tanr;   r=   r   r   r?   s     r   icdfzCauchy.icdfY   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.entropy\   s)    xxDGG$tzz~~'777r   r.   )__name__
__module____qualname____doc__r   realpositivearg_constraintssupporthas_rsampler   r   propertyr   r+   r/   r1   r   r   r
   r7   rA   rE   rH   rK   __classcell__)r   s   @r   r   r      s    " *..9M9MNOGKC 
f 
 

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

 -7EJJL +E +V +

K
J8r   )r;   r   r   r   r   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   torch.typesr	   r
   __all__r    r   r   <module>r]      s4      " " + 9 3 & *N8\ N8r   