U
    yh	                     @   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)ExponentialFamily)broadcast_allExponentialc                       s   e Zd ZdZdejiZejZd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edd Zdd Z  ZS )"r   an  
    Creates a Exponential distribution parameterized by :attr:`rate`.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = Exponential(torch.tensor([1.0]))
        >>> m.sample()  # Exponential distributed with rate=1
        tensor([ 0.1046])

    Args:
        rate (float or Tensor): rate = 1 / scale of the distribution
    rateTr   c                 C   s
   | j  S Nr   Z
reciprocalself r   Q/var/www/html/venv/lib/python3.8/site-packages/torch/distributions/exponential.pymean   s    zExponential.meanc                 C   s   t | jS r   )torchZ
zeros_liker   r
   r   r   r   mode#   s    zExponential.modec                 C   s
   | j  S r   r	   r
   r   r   r   stddev'   s    zExponential.stddevc                 C   s   | j dS )N)r   powr
   r   r   r   variance+   s    zExponential.varianceNc                    s<   t |\| _t|trt n| j }t j||d d S )Nvalidate_args)	r   r   
isinstancer   r   Sizesizesuper__init__)r   r   r   batch_shape	__class__r   r   r   /   s    zExponential.__init__c                    sD   |  t|}t|}| j||_tt|j|dd | j|_|S )NFr   )	Z_get_checked_instancer   r   r   r   expandr   r   _validate_args)r   r   Z	_instancenewr   r   r   r   4   s    
zExponential.expandc                 C   s    |  |}| j| | j S r   )Z_extended_shaper   r!   Zexponential_)r   Zsample_shapeshaper   r   r   rsample<   s    
zExponential.rsamplec                 C   s$   | j r| | | j | j|  S r   )r    _validate_sampler   logr   valuer   r   r   log_prob@   s    
zExponential.log_probc                 C   s&   | j r| | dt| j |  S )N   )r    r$   r   expr   r&   r   r   r   cdfE   s    
zExponential.cdfc                 C   s   t |  | j S r   )r   log1pr   r&   r   r   r   icdfJ   s    zExponential.icdfc                 C   s   dt | j S )Ng      ?)r   r%   r   r
   r   r   r   entropyM   s    zExponential.entropyc                 C   s
   | j  fS r   )r   r
   r   r   r   _natural_paramsP   s    zExponential._natural_paramsc                 C   s   t |  S r   )r   r%   )r   xr   r   r   _log_normalizerT   s    zExponential._log_normalizer)N)N)__name__
__module____qualname____doc__r   ZpositiveZarg_constraintsZnonnegativeZsupportZhas_rsampleZ_mean_carrier_measurepropertyr   r   r   r   r   r   r   r   r#   r(   r+   r-   r.   r/   r1   __classcell__r   r   r   r   r      s.   





)numbersr   r   Ztorch.distributionsr   Ztorch.distributions.exp_familyr   Ztorch.distributions.utilsr   __all__r   r   r   r   r   <module>   s   