a
    hd                     @   s   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 deZdS )
    N)OptionalUnion)infnanTensor)constraints)Distribution)broadcast_all)_Number_sizeCauchyc                       s   e Zd ZdZejejdZejZdZ	de
eef e
eef ee dd fddZd fdd		Zeed
ddZeed
ddZeed
ddZe feedddZdd Zdd Zdd Zdd Z  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scaleTN)r   r   validate_argsreturnc                    sN   t ||\| _| _t|tr0t|tr0t }n
| j }t j	||d d S )Nr   )
r	   r   r   
isinstancer
   torchSizesizesuper__init__)selfr   r   r   batch_shape	__class__ H/var/www/auris/lib/python3.9/site-packages/torch/distributions/cauchy.pyr   &   s
    

zCauchy.__init__c                    sR   |  t|}t|}| j||_| j||_tt|j|dd | j	|_	|S )NFr   )
Z_get_checked_instancer   r   r   r   expandr   r   r   _validate_args)r   r   Z	_instancenewr   r   r   r   3   s    
zCauchy.expand)r   c                 C   s   t j|  t| jj| jjdS N)dtypedevice)r   full_extended_shaper   r   r"   r#   r   r   r   r   mean<   s    zCauchy.meanc                 C   s   | j S N)r   r&   r   r   r   modeB   s    zCauchy.modec                 C   s   t j|  t| jj| jjdS r!   )r   r$   r%   r   r   r"   r#   r&   r   r   r   varianceF   s    zCauchy.variance)sample_shaper   c                 C   s*   |  |}| j| }| j|| j  S r(   )r%   r   r    Zcauchy_r   )r   r+   shapeZepsr   r   r   rsampleL   s    
zCauchy.rsamplec                 C   s@   | j r| | ttj | j  || j | j d   S )N   )r   _validate_samplemathlogpir   r   log1pr   valuer   r   r   log_probQ   s    
zCauchy.log_probc                 C   s0   | j r| | t|| j | j tj d S Ng      ?)r   r/   r   atanr   r   r0   r2   r4   r   r   r   cdfZ   s    
z
Cauchy.cdfc                 C   s    t tj|d  | j | j S r7   )r   tanr0   r2   r   r   r4   r   r   r   icdf_   s    zCauchy.icdfc                 C   s   t dt j | j  S )N   )r0   r1   r2   r   r&   r   r   r   entropyb   s    zCauchy.entropy)N)N)__name__
__module____qualname____doc__r   realZpositiveZarg_constraintsZsupportZhas_rsampler   r   floatr   boolr   r   propertyr'   r)   r*   r   r   r   r-   r6   r9   r;   r=   __classcell__r   r   r   r   r      s.    

		)r0   typingr   r   r   r   r   r   Ztorch.distributionsr   Z torch.distributions.distributionr   Ztorch.distributions.utilsr	   Ztorch.typesr
   r   __all__r   r   r   r   r   <module>   s   