U
    ©Ê¹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-deterinistic")
        >>> 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   s   | j S ©N©r   ©Úself© r   úZ/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torch/distributions/laplace.pyÚmean   s    zLaplace.meanc                 C   s   | j S r	   r
   r   r   r   r   Úmode"   s    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ƒr0t|tƒr0t ¡ }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   )
Z_get_checked_instancer   r   r   r   Úexpandr   r   r   Ú_validate_args)r   r   Z	_instanceÚnewr   r   r   r!   6   s    
zLaplace.expandc                 C   s®   |   |¡}t | jj¡}tj ¡ rpt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)Z_extended_shaper   Úfinfor   r$   Z_CZ_get_tracing_stateZrandr%   r   ÚsignÚlog1pÚabsÚclampZtinyr#   Zuniform_Úeps)r   Z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   r+   r   ©r   Úvaluer   r   r   Úlog_probM   s    
zLaplace.log_probc                 C   sB   | j r|  |¡ dd|| j  ¡  t || j  ¡  | j ¡  S )Nç      à?)r"   r1   r   r)   r   Úexpm1r+   r   r3   r   r   r   ÚcdfR   s
    
ÿzLaplace.cdfc                 C   s.   |d }| j | j| ¡  t d| ¡  ¡  S )Nr6   éþÿÿÿ)r   r   r)   r   r*   r+   )r   r4   Útermr   r   r   ÚicdfY   s    zLaplace.icdfc                 C   s   dt  d| j ¡ S )Nr&   r   )r   r2   r   r   r   r   r   Úentropy]   s    zLaplace.entropy)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚrealZpositiveZarg_constraintsZsupportZhas_rsampleÚpropertyr   r   r   r   r   r!   r   r   r0   r5   r8   r;   r<   Ú__classcell__r   r   r   r   r      s&   



	)Únumbersr   r   Ztorch.distributionsr   Z torch.distributions.distributionr   Ztorch.distributions.utilsr   Ú__all__r   r   r   r   r   Ú<module>   s   