
    קg                         d dl Z d dl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dS )
    N)Number)infnan)constraints)Distribution)broadcast_all)_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             Zed             Zed	             Z ej                    fd
edej        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scaleTNc                 6   t          ||          \  | _        | _        t          |t                    r)t          |t                    rt          j                    }n| j                                        }t                      	                    ||           d S )Nvalidate_args)
r   r   r   
isinstancer   torchSizesizesuper__init__)selfr   r   r   batch_shape	__class__s        V/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/distributions/cauchy.pyr   zCauchy.__init__%   s}    ,S%88$*c6"" 	*z%'@'@ 	**,,KK(--//KMBBBBB    c                 N   |                      t          |          }t          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-   s    ((;;j--(//+..J%%k22	fc##Ku#EEE!0
r   c                     t          j        |                                 t          | j        j        | j        j                  S N)dtypedevice)r   full_extended_shaper   r   r$   r%   r   s    r   meanzCauchy.mean6   8    z  ""Ctx~dho
 
 
 	
r   c                     | j         S N)r   r(   s    r   modezCauchy.mode<   s	    xr   c                     t          j        |                                 t          | j        j        | j        j                  S r#   )r   r&   r'   r   r   r$   r%   r(   s    r   variancezCauchy.variance@   r*   r   sample_shapereturnc                     |                      |          }| j                            |                                          }| j        || j        z  z   S r,   )r'   r   r!   cauchy_r   )r   r0   shapeepss       r   rsamplezCauchy.rsampleF   sH    $$\22hll5!!))++x#
***r   c                     | j         r|                     |           t          j        t          j                   | j                                        z
  || j        z
  | j        z  dz                                  z
  S )N   )r   _validate_samplemathlogpir   r   log1pr   values     r   log_probzCauchy.log_probK   ss     	)!!%(((Xdgjnn!TZ/A5<<>>?	
r   c                     | j         r|                     |           t          j        || j        z
  | j        z            t          j        z  dz   S Ng      ?)r   r9   r   atanr   r   r:   r<   r>   s     r   cdfz
Cauchy.cdfT   sK     	)!!%(((z548+tz9::TWDsJJr   c                 j    t          j        t          j        |dz
  z            | j        z  | j        z   S rB   )r   tanr:   r<   r   r   r>   s     r   icdfzCauchy.icdfY   s+    yECK011DJ>IIr   c                 x    t          j        dt           j        z            | j                                        z   S )N   )r:   r;   r<   r   r(   s    r   entropyzCauchy.entropy\   s)    xDG$$tz~~'7'777r   r,   )__name__
__module____qualname____doc__r   realpositivearg_constraintssupporthas_rsampler   r   propertyr)   r-   r/   r   r   r	   Tensorr6   r@   rD   rG   rJ   __classcell__)r   s   @r   r
   r
      sV          *.9MNNOGKC C C C C C      
 
 X

   X 
 
 X

 -7EJLL + +E +U\ + + + +

 
 
K K K
J J J8 8 8 8 8 8 8r   )r:   numbersr   r   r   r   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   torch.typesr	   __all__r
    r   r   <module>r^      s                    + + + + + + 9 9 9 9 9 9 3 3 3 3 3 3       *M8 M8 M8 M8 M8\ M8 M8 M8 M8 M8r   