U
    9%e                     @   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/Darija-Ai-API/env/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_Z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"   r0   r   r)   r   expm1r+   r   r2   r   r   r   cdfR   s
    
zLaplace.cdfc                 C   s.   |d }| j | j|  td|    S )Nr5   )r   r   r)   r   r*   r+   )r   r3   termr   r   r   icdfY   s    zLaplace.icdfc                 C   s   dt d| j  S )Nr&   r   )r   r1   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   r/   r4   r7   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   