a
    MSic.
                     @   sL   d dl mZ d dlZd dlmZ d dlmZ d dlmZ G dd deZ	dS )    )NumberN)constraints)ExponentialFamily)broadcast_allc                       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 )"Exponentiala4  
    Creates a Exponential distribution parameterized by :attr:`rate`.

    Example::

        >>> 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   
reciprocalself r   [/var/www/html/django/DPS/env/lib/python3.9/site-packages/torch/distributions/exponential.pymean   s    zExponential.meanc                 C   s   t | jS r   )torch
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t| j	||d d S )Nvalidate_args)
r   r   
isinstancer   r   Sizesizesuperr   __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   )	_get_checked_instancer   r   r   r   expandr   r   _validate_args)r   r   	_instancenewr   r   r   r"   0   s    
zExponential.expandc                 C   sT   |  |}tj r>tj|| jj| jjd}|   | j S | j	|
 | j S )N)dtypedevice)_extended_shaper   _C_get_tracing_staterandr   r&   r'   log1pr%   exponential_)r   sample_shapeshapeur   r   r   rsample8   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#   r2   r   expr   r4   r   r   r   cdfE   s    
zExponential.cdfc                 C   s   t d|  | j S r7   r   r3   r   r4   r   r   r   icdfJ   s    zExponential.icdfc                 C   s   dt | j S )Ng      ?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   r3   )r   xr   r   r   _log_normalizerT   s    zExponential._log_normalizer)N)N)__name__
__module____qualname____doc__r   positivearg_constraintsnonnegativesupporthas_rsample_mean_carrier_measurepropertyr   r   r   r   r   r"   r   r   r1   r6   r:   r<   r=   r>   r@   __classcell__r   r   r   r   r   	   s.   





r   )
numbersr   r   Ztorch.distributionsr   torch.distributions.exp_familyr   torch.distributions.utilsr   r   r   r   r   r   <module>   s
   