o
    h                     @   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      | j S Nr   self r   Q/var/www/html/ai/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$   6   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_probM   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   cdfR   s
   
zLaplace.cdfc                 C   s.   |d }| j | j|  td|    S )NrA   )r   r   r1   r   r2   r3   )r   r?   termr   r   r   icdfY   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   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   __all__r   r   r   r   r   <module>   s    