B
    `[                 @   s   d Z ddlmZ ddlmZ 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d	lmZ dd
lmZ ddlmZ dgZG dd dejZdS )z#The Exponential distribution class.    )absolute_import)division)print_functionN)v2)softplus)gamma)
dtype_util)samplers)tensor_utilExponentialc                   sp   e Zd ZdZd fdd	Zedd Zedd	 Ze	d
d Z
dd Zdd ZdddZdd Zdd Z  ZS )r   a  Exponential distribution.

  The Exponential distribution is parameterized by an event `rate` parameter.

  #### Mathematical Details

  The probability density function (pdf) is,

  ```none
  pdf(x; lambda, x > 0) = exp(-lambda x) / Z
  Z = 1 / lambda
  ```

  where `rate = lambda` and `Z` is the normalizaing constant.

  The Exponential distribution is a special case of the Gamma distribution,
  i.e.,

  ```python
  Exponential(rate) = Gamma(concentration=1., rate)
  ```

  The Exponential distribution uses a `rate` parameter, or "inverse scale",
  which can be intuited as,

  ```none
  X ~ Exponential(rate=1)
  Y = X / rate
  ```

  FTc          	      sf   t t }t|H}tj|dtj|gtjdd| _	t
t| jd| j	|||d || _W dQ R X dS )a  Construct Exponential distribution with parameter `rate`.

    Args:
      rate: Floating point tensor, equivalent to `1 / mean`. Must contain only
        positive values.
      validate_args: Python `bool`, default `False`. When `True` distribution
        parameters are checked for validity despite possibly degrading runtime
        performance. When `False` invalid inputs may silently render incorrect
        outputs.
      allow_nan_stats: Python `bool`, default `True`. When `True`, statistics
        (e.g., mean, mode, variance) use the value "`NaN`" to indicate the
        result is undefined. When `False`, an exception is raised if one or
        more of the statistic's batch members are undefined.
      name: Python `str` name prefixed to Ops created by this class.
    rate)Z
dtype_hint)namedtypeg      ?)Zconcentrationr   allow_nan_statsvalidate_argsr   N)dictlocalstfZ
name_scoper
   Zconvert_nonref_to_tensorr   Zcommon_dtypefloat32_ratesuperr   __init___parameters)selfr   r   r   r   
parameters)	__class__ m/home/dcms/DCMS/lib/python3.7/site-packages/tensorflow_probability/python/distributions/_numpy/exponential.pyr   F   s    

zExponential.__init__c             C   s   dt j| t jdiS )Nr   )r   )r   convert_to_tensorint32)Zsample_shaper   r   r   _param_shapesl   s    zExponential._param_shapesc             C   s
   t ddS )Nr   )r   )r   )clsr   r   r   _params_event_ndimsp   s    zExponential._params_event_ndimsc             C   s   | j S )N)r   )r   r   r   r   r   t   s    zExponential.ratec             C   s   t j| j |  S )N)r   mathexpm1r   )r   valuer   r   r   _cdfx   s    zExponential._cdfc             C   s&   t | j}| j||dt j| S )N)r   )r   r   r   Z	_log_probr#   log)r   r%   r   r   r   r   _log_survival_function{   s    z"Exponential._log_survival_functionNc             C   s\   t | j}t |gt |gd}tj|tt	
| jjd|| jd}t j| | S )Nr   g      ?)minvalmaxvalseedr   )r   r   r   concatshaper	   uniformnpZfinfor   Zas_numpy_dtyper   Ztinyr#   r'   )r   nr+   r   r-   Zsampledr   r   r   	_sample_n   s    	
zExponential._sample_nc             C   s   t j|  | j S )N)r   r#   log1pr   )r   r%   r   r   r   	_quantile   s    zExponential._quantilec             C   s   t j| jdS )N)r   )softplus_bijectorZSoftplusr   )r   r   r   r   _default_event_space_bijector   s    z)Exponential._default_event_space_bijector)FTr   )N)__name__
__module____qualname____doc__r   staticmethodr    classmethodr"   propertyr   r&   r(   r1   r3   r5   __classcell__r   r   )r   r   r   %   s     "
)r9   
__future__r   r   r   numpyr/   Z;tensorflow_probability.python.internal.backend.numpy.compatr   r   Z.tensorflow_probability.python.bijectors._numpyr   r4   Z2tensorflow_probability.python.distributions._numpyr   Z-tensorflow_probability.python.internal._numpyr   r	   r
   __all__Gammar   r   r   r   r   <module>   s   