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gZG dd dejZdddZdS )zLogNormal distribution classes.    )absolute_import)division)print_functionN)v2)exp)logistic)transformed_distribution)assert_utilLogLogisticc                   s   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 Zdd Zd"ddZdd Zdd Zdd Zdd Zdd  Z  ZS )#r
   zThe log-logistic distribution.FTc          	      sN   t t }t|0}tt| jtj|||dt	
 |||d W dQ R X dS )a  Construct a log-logistic distribution.

    The LogLogistic distribution models positive-valued random variables
    whose logarithm is a logistic distribution with loc `loc` and
    scale `scale`. It is constructed as the exponential
    transformation of a Logistic distribution.

    Args:
      loc: Floating-point `Tensor`; the loc of the underlying logistic
        distribution(s).
      scale: Floating-point `Tensor`; the scale of the underlying logistic
        distribution(s).
      validate_args: Python `bool`, default `False`. Whether to validate input
        with asserts. If `validate_args` is `False`, and the inputs are invalid,
        correct behavior is not guaranteed.
      allow_nan_stats: Python `bool`, default `True`. If `False`, raise an
        exception if a statistic (e.g. mean/mode/etc...) is undefined for any
        batch member If `True`, batch members with valid parameters leading to
        undefined statistics will return NaN for this statistic.
      name: The name to give Ops created by the initializer.
    )locscaleallow_nan_stats)distributionZbijectorvalidate_args
parametersnameN)dictlocalstf
name_scopesuperr
   __init__r   ZLogisticexp_bijectorExp)selfr   r   r   r   r   r   )	__class__ m/home/dcms/DCMS/lib/python3.7/site-packages/tensorflow_probability/python/distributions/_numpy/loglogistic.pyr   %   s    


zLogLogistic.__init__c             C   s   t dddS )Nr   )r   r   )r   )clsr   r   r   _params_event_ndimsJ   s    zLogLogistic._params_event_ndimsc             C   s   | j jS )z6Distribution parameter of the underlying distribution.)r   r   )r   r   r   r   r   N   s    zLogLogistic.locc             C   s   | j jS )z6Distribution parameter of the underlying distribution.)r   r   )r   r   r   r   r   S   s    zLogLogistic.scalec          	   C   s|   t | j}t | jrg ntj|t jg | jdddg8 t j	
| jt| }t |dkt jtj| jd|S Q R X d S )N)dtypezMean undefined for scale >= 1.)messageg      ?)r   convert_to_tensorr   control_dependenciesr   r	   assert_lessZonesr    mathr   r   sincwherecastnpnan)r   r   Zmeanr   r   r   _meanX   s    zLogLogistic._meanc          	   C   s   t | j}t | jrg ntj|t d| jddgT t j	
d| j dtd|  dt|d    }t |dkt jtj| jd|S Q R X d S )Ng      ?z$Variance undefined for scale >= 1/2.)r!      g      ?)r    )r   r"   r   r#   r   r	   r$   Zconstantr    r%   r   r   r&   r'   r(   r)   r*   )r   r   Zvariancer   r   r   	_variancec   s    ,zLogLogistic._variancec             C   sV   t | j}| j|t j| t j|   }t |dkt jd| jdt j	|S )Ng      ?g        )r    )
r   r"   r   r   r%   log1pr'   r(   r    r   )r   r   Zlog_moder   r   r   _moden   s
    zLogLogistic._modec             C   s   d| j  tj| j S )Ng       @)r   r   r%   logr   )r   r   r   r   _entropyu   s    zLogLogistic._entropyNc          	   C   sR   |dkr| j n|}|dkr | jn|}td tj|| j  | j S Q R X dS )z&Returns log of the standardized input.NZlog_standardize)r   r   r   r   r%   r0   )r   xr   r   r   r   r   _log_zx   s    zLogLogistic._log_zc             C   sV   t | j}t | j}| j|||d}t j| | d| |  dt j|  S )N)r   r   g      ?r,   )r   r"   r   r   r3   r%   r0   softplus)r   r2   r   r   Zlog_zr   r   r   	_log_prob   s    zLogLogistic._log_probc             C   s   t j| |  S )N)r   r%   r4   r3   )r   r2   r   r   r   _log_cdf   s    zLogLogistic._log_cdfc             C   s   |  || | S )N)r6   r3   )r   r2   r   r   r   _log_survival_function   s    z"LogLogistic._log_survival_functionc             C   s&   g }| j s|S |tj|dd |S )NzSample must be non-negative.)r!   )r   appendr	   Zassert_non_negative)r   r2   Z
assertionsr   r   r   _sample_control_dependencies   s    z(LogLogistic._sample_control_dependenciesc             C   s   t j| jdS )N)r   )r   r   r   )r   r   r   r   _default_event_space_bijector   s    z)LogLogistic._default_event_space_bijector)FTr
   )NN)__name__
__module____qualname____doc__r   classmethodr   propertyr   r   r+   r-   r/   r1   r3   r5   r6   r7   r9   r:   __classcell__r   r   )r   r   r
   "   s"      
	c          	   C   sF   |pd}t |* | tj9 } t | dkt j| |  dS Q R X dS )z/Calculate the (normalized) sinus cardinal of x.r&   g        g      ?N)r   r   r)   pir'   r%   sin)r2   r   r   r   r   r&      s    
r&   )N)r>   
__future__r   r   r   numpyr)   Z;tensorflow_probability.python.internal.backend.numpy.compatr   r   Z.tensorflow_probability.python.bijectors._numpyr   r   Z2tensorflow_probability.python.distributions._numpyr   r   Z-tensorflow_probability.python.internal._numpyr	   __all__ZTransformedDistributionr
   r&   r   r   r   r   <module>   s   w