o
    +ôjp  ã                   @   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   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                    sN   t ||ƒ\| _| _t|tƒrt|tƒrt ¡ }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__© úm/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/torch/distributions/cauchy.pyr   "   s
   

zCauchy.__init__c                    sR   |   t|¡}t |¡}| j |¡|_| j |¡|_tt|ƒj|dd� | j	|_	|S )NFr   )
Ú_get_checked_instancer   r   r   r	   Úexpandr
   r   r   Ú_validate_args)r   r   Ú	_instanceÚnewr   r   r   r   *   s   
zCauchy.expandc                 C   ó   t j|  ¡ t| jj| jjd�S ©N)ÚdtypeÚdevice)r   ÚfullÚ_extended_shaper   r	   r    r!   ©r   r   r   r   Úmean3   ó   ÿzCauchy.meanc                 C   s   | j S ©N)r	   r$   r   r   r   Úmode9   s   zCauchy.modec                 C   r   r   )r   r"   r#   r   r	   r    r!   r$   r   r   r   Úvariance=   r&   zCauchy.variancec                 C   s*   |   |¡}| j |¡ ¡ }| j|| j  S r'   )r#   r	   r   Úcauchy_r
   )r   Ú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   r0   r   Úatanr	   r
   r1   r3   r5   r   r   r   ÚcdfQ   s   
 z
Cauchy.cdfc                 C   s    t  tj|d  ¡| j | j S r8   )r   Útanr1   r3   r
   r	   r5   r   r   r   ÚicdfV   s    zCauchy.icdfc                 C   s   t  dt j ¡| j ¡  S )Né   )r1   r2   r3   r
   r$   r   r   r   ÚentropyY   s   zCauchy.entropyr'   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚrealÚpositiveÚarg_constraintsÚsupportÚhas_rsampler   r   Úpropertyr%   r(   r)   r   r   r.   r7   r:   r<   r>   Ú__classcell__r   r   r   r   r      s$    	


	)r1   Únumbersr   r   r   r   Ztorch.distributionsr   Ú torch.distributions.distributionr   Útorch.distributions.utilsr   Ú__all__r   r   r   r   r   Ú<module>   s    