a
    –¥»aš
  ã                   @   sd   d dl Z d dlmZmZ d dlmZ d dlZd dlmZ d dl	m
Z
 d dlmZ G dd„ de
ƒZdS )	é    N)ÚinfÚnan)ÚNumber)Úconstraints)ÚDistribution)Úbroadcast_allc                       s�   e Zd ZdZejejdœZejZdZ	d‡ fdd„	Z
d‡ fdd„	Zed	d
„ ƒZedd„ ƒZe ¡ fdd„Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚCauchya	  
    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::

        >>> 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                    sR   t ||ƒ\| _| _t|tƒr0t|tƒr0t ¡ }n
| j ¡ }tt	| ƒj
||d� d S )N©Úvalidate_args)r   r	   r
   Ú
isinstancer   ÚtorchÚSizeÚsizeÚsuperr   Ú__init__)Úselfr	   r
   r   Úbatch_shape©Ú	__class__© úT/home/yuhw/wc/pochoir/venv/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   '   s    
zCauchy.expandc                 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   Úmean0   s    zCauchy.meanc                 C   s   t j|  ¡ t| jj| jjd�S r   )r   r   r    r   r	   r   r   r!   r   r   r   Úvariance4   s    zCauchy.variancec                 C   s*   |   |¡}| j |¡ ¡ }| j|| j  S )N)r    r	   r   Zcauchy_r
   )r   Zsample_shapeÚshapeZepsr   r   r   Úrsample8   s    
zCauchy.rsamplec                 C   sD   | j r|  |¡ t tj¡ | j ¡  d|| j | j d   ¡  S )Né   é   )r   Ú_validate_sampleÚmathÚlogÚpir
   r	   ©r   Úvaluer   r   r   Úlog_prob=   s    
zCauchy.log_probc                 C   s0   | j r|  |¡ t || j | j ¡tj d S ©Ng      à?)r   r(   r   Úatanr	   r
   r)   r+   r,   r   r   r   ÚcdfB   s    
z
Cauchy.cdfc                 C   s    t  tj|d  ¡| j | j S r/   )r   Útanr)   r+   r
   r	   r,   r   r   r   ÚicdfG   s    zCauchy.icdfc                 C   s   t  dt j ¡| j ¡  S )Né   )r)   r*   r+   r
   r!   r   r   r   ÚentropyJ   s    zCauchy.entropy)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚrealZpositiveZarg_constraintsZsupportZhas_rsampler   r   Úpropertyr"   r#   r   r   r%   r.   r1   r3   r5   Ú__classcell__r   r   r   r   r      s   	

r   )r)   Z
torch._sixr   r   Znumbersr   r   Ztorch.distributionsr   Z torch.distributions.distributionr   Ztorch.distributions.utilsr   r   r   r   r   r   Ú<module>   s   