U
    ©Ê¹jo  ã                   @   sj   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gZG dd„ de	ƒZdS )	é    N)ÚNumber)ÚinfÚnan)Úconstraints)ÚDistribution)Úbroadcast_allÚCauchyc                       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dd„ ƒZe ¡ fdd„Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )r   aB  
    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-deterinistic")
        >>> 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                    sN   t ||ƒ\| _| _t|tƒr0t|tƒr0t ¡ }n
| j ¡ }tƒ j	||d� d S )N©Úvalidate_args)
r   r	   r
   Ú
isinstancer   ÚtorchÚSizeÚsizeÚsuperÚ__init__)Úselfr	   r
   r   Úbatch_shape©Ú	__class__© úY/var/www/html/bwave/python/venv/lib/python3.8/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   Úmean3   s       ÿzCauchy.meanc                 C   s   | j S ©N)r	   r!   r   r   r   Úmode9   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   Úvariance=   s       ÿzCauchy.variancec                 C   s*   |   |¡}| j |¡ ¡ }| j|| j  S r#   )r    r	   r   Zcauchy_r
   )r   Zsample_shapeÚshapeÚepsr   r   r   ÚrsampleC   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_probH   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   ÚcdfQ   s    
z
Cauchy.cdfc                 C   s    t  tj|d  ¡| j | j S r2   )r   Útanr+   r-   r
   r	   r/   r   r   r   ÚicdfV   s    zCauchy.icdfc                 C   s   t  dt j ¡| j ¡  S )Né   )r+   r,   r-   r
   r!   r   r   r   ÚentropyY   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   r4   r6   r8   Ú__classcell__r   r   r   r   r      s"   	


	)r+   Únumbersr   r   r   r   Ztorch.distributionsr   Z torch.distributions.distributionr   Ztorch.distributions.utilsr   Ú__all__r   r   r   r   r   Ú<module>   s   