o
    /ôj»  ã                   @   sR   d dl mZ d dl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 )é    )ÚNumberN)Úconstraints)ÚDistribution)Úbroadcast_allÚLaplacec                       s¨   e Zd ZdZejejdœZejZdZ	e
dd„ ƒZe
dd„ ƒZe
dd	„ ƒZe
d
d„ ƒZd‡ fdd„	Zd‡ fdd„	Ze ¡ fdd„Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )r   a¾  
    Creates a Laplace distribution parameterized by :attr:`loc` and :attr:`scale`.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = Laplace(torch.tensor([0.0]), torch.tensor([1.0]))
        >>> m.sample()  # Laplace distributed with loc=0, scale=1
        tensor([ 0.1046])

    Args:
        loc (float or Tensor): mean of the distribution
        scale (float or Tensor): scale of the distribution
    )ÚlocÚscaleTc                 C   ó   | j S ©N©r   ©Úself© r   úl/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torch/distributions/laplace.pyÚmean   ó   zLaplace.meanc                 C   r	   r
   r   r   r   r   r   Úmode#   r   zLaplace.modec                 C   s   d| j  d¡ S ©Né   )r   Úpowr   r   r   r   Úvariance'   s   zLaplace.variancec                 C   s
   d| j  S )NgÍ;fž ö?)r   r   r   r   r   Ústddev+   s   
zLaplace.stddevNc                    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__)r   r   r   r   Úbatch_shape©Ú	__class__r   r   r   /   s
   

zLaplace.__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$   7   s   
zLaplace.expandc                 C   s®   |   |¡}t | jj¡}tj ¡ r8tj|| jj| jjd�d d }| j| j	| 
¡  t | ¡ j|jd� ¡  S | j |¡ |jd d¡}| j| j	| 
¡  t | ¡  ¡  S )N)ÚdtypeÚdevicer   é   )Úmin)Ú_extended_shaper   Úfinfor   r(   Ú_CÚ_get_tracing_stateÚrandr)   r   ÚsignÚlog1pÚabsÚclampÚtinyr'   Úuniform_Úeps)r   Úsample_shapeÚshaper-   Úur   r   r   Úrsample@   s   

 ÿ$zLaplace.rsamplec                 C   s8   | j r|  |¡ t d| j ¡ t || j ¡| j  S r   )r%   Ú_validate_sampler   Úlogr   r3   r   ©r   Úvaluer   r   r   Úlog_probN   s   
(zLaplace.log_probc                 C   sB   | j r|  |¡ dd|| j  ¡  t || j  ¡  | j ¡  S )Nç      à?)r%   r<   r   r1   r   Úexpm1r3   r   r>   r   r   r   ÚcdfS   s
   
ÿzLaplace.cdfc                 C   s.   |d }| j | j| ¡  t d| ¡  ¡  S )NrA   éþÿÿÿ)r   r   r1   r   r2   r3   )r   r?   Útermr   r   r   ÚicdfZ   s   &zLaplace.icdfc                 C   s   dt  d| j ¡ S )Nr*   r   )r   r=   r   r   r   r   r   Úentropy^   s   zLaplace.entropyr
   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚrealÚpositiveÚarg_constraintsÚsupportÚhas_rsampleÚpropertyr   r   r   r   r   r$   r   r   r;   r@   rC   rF   rG   Ú__classcell__r   r   r!   r   r      s(    



	)Únumbersr   r   Ztorch.distributionsr   Ú torch.distributions.distributionr   Útorch.distributions.utilsr   Ú__all__r   r   r   r   r   Ú<module>   s   