o
    h                     @   sb   d dl Z d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 dgZG dd deZdS )	    N)Tensor)constraints)Distribution)broadcast_all)_Number_sizeLaplacec                       s   e Zd ZdZejejdZejZdZ	e
defddZe
defddZe
defd	d
Ze
defddZd fdd	Zd fdd	Ze fded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scaleTreturnc                 C      | j S Nr	   self r   o/var/www/html/construction_image-detection-poc/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"   1   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'   9   s   
zLaplace.expandsample_shapec                 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   r+   shaper1   ur   r   r   rsampleB   s   

 $zLaplace.rsamplec                 C   s8   | j r| | td| j  t|| j | j  S r   )r(   _validate_sampler   logr
   r7   r	   r   valuer   r   r   log_probP   s   
(zLaplace.log_probc                 C   sB   | j r| | dd|| j   t|| j   | j   S )N      ?)r(   r?   r	   r5   r   expm1r7   r
   rA   r   r   r   cdfU   s
   
zLaplace.cdfc                 C   s.   |d }| j | j|  td|    S )NrD   )r	   r
   r5   r   r6   r7   )r   rB   termr   r   r   icdf\   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   r>   rC   rF   rI   rJ   __classcell__r   r   r$   r   r      s(    	)r   r   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   torch.typesr   r   __all__r   r   r   r   r   <module>   s   