o
    2h                     @   s   d Z ddl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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dlmZ ddgZedgdG dd dejZG dd deZdS )zThe Laplace distribution class.    N)constant_op)dtypes)ops)tensor_shape)	array_ops)	check_ops)math_ops)nn)
random_ops)distribution)special_math)deprecation)	tf_exportLaplaceLaplaceWithSoftplusScalezdistributions.Laplace)v1c                       s   e Zd ZdZejdddd			 d4 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d5ddZdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Z  ZS )6r   a  The Laplace distribution with location `loc` and `scale` parameters.

  #### Mathematical details

  The probability density function (pdf) of this distribution is,

  ```none
  pdf(x; mu, sigma) = exp(-|x - mu| / sigma) / Z
  Z = 2 sigma
  ```

  where `loc = mu`, `scale = sigma`, and `Z` is the normalization constant.

  Note that the Laplace distribution can be thought of two exponential
  distributions spliced together "back-to-back."

  The Lpalce distribution is a member of the [location-scale family](
  https://en.wikipedia.org/wiki/Location-scale_family), i.e., it can be
  constructed as,

  ```none
  X ~ Laplace(loc=0, scale=1)
  Y = loc + scale * X
  ```

  
2019-01-01zThe TensorFlow Distributions library has moved to TensorFlow Probability (https://github.com/tensorflow/probability). You should update all references to use `tfp.distributions` instead of `tf.distributions`.T	warn_onceFc              
      s   t t }tj|||gdU}t|rt|gng ! tj|dd| _	tj|dd| _
t| j	| j
g W d   n1 s@w   Y  tt| j| j	jtj|||| j	| j
g|d W d   dS 1 sfw   Y  dS )aY  Construct Laplace distribution with parameters `loc` and `scale`.

    The parameters `loc` and `scale` must be shaped in a way that supports
    broadcasting (e.g., `loc / scale` is a valid operation).

    Args:
      loc: Floating point tensor which characterizes the location (center)
        of the distribution.
      scale: Positive floating point tensor which characterizes the spread of
        the distribution.
      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.

    Raises:
      TypeError: if `loc` and `scale` are of different dtype.
    valueslocnamescaleN)dtypereparameterization_typevalidate_argsallow_nan_stats
parametersgraph_parentsr   )dictlocalsr   
name_scopecontrol_dependenciesr   assert_positiver   identity_loc_scaleassert_same_float_dtypesuperr   __init__r   r   FULLY_REPARAMETERIZEDselfr   r   r   r   r   r   	__class__ f/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorflow/python/ops/distributions/laplace.pyr+   G   s*   
%

"zLaplace.__init__c                 C   s    t tdtj| tjdgd S )Nr   r   r      )r!   zipr   convert_to_tensorr   int32)sample_shaper1   r1   r2   _param_shapes|   s   zLaplace._param_shapesc                 C      | j S )z(Distribution parameter for the location.)r'   r.   r1   r1   r2   r         zLaplace.locc                 C   r;   )z!Distribution parameter for scale.)r(   r<   r1   r1   r2   r      r=   zLaplace.scalec                 C   s   t t | jt | jS N)r   broadcast_dynamic_shapeshaper   r   r<   r1   r1   r2   _batch_shape_tensor   s   zLaplace._batch_shape_tensorc                 C   s   t | j | j S r>   )r   broadcast_static_shaper   	get_shaper   r<   r1   r1   r2   _batch_shape   s   zLaplace._batch_shapec                 C   s   t jg tjdS )Nr4   )r   constantr   r8   r<   r1   r1   r2   _event_shape_tensor      zLaplace._event_shape_tensorc                 C   s
   t g S r>   )r   TensorShaper<   r1   r1   r2   _event_shape   s   
zLaplace._event_shapeNc                 C   sl   t |g|  gd}tj|t| jd| jdd| j|d}| j	| j
t| tt|   S )Nr   g      g              ?)r@   minvalmaxvalr   seed)r   concatbatch_shape_tensorr
   random_uniformnp	nextafterr   as_numpy_dtyper   r   r   signlog1pabs)r.   nrM   r@   uniform_samplesr1   r1   r2   	_sample_n   s   
zLaplace._sample_nc                 C   s   |  ||   S r>   )_log_unnormalized_prob_log_normalizationr.   xr1   r1   r2   	_log_prob      zLaplace._log_probc                 C      t | |S r>   )r   expr^   r\   r1   r1   r2   _prob   rG   zLaplace._probc                 C   r`   r>   r   log_cdf_laplace_zr\   r1   r1   r2   _log_cdf   rG   zLaplace._log_cdfc                 C   s   t | | S r>   rc   r\   r1   r1   r2   _log_survival_function   r_   zLaplace._log_survival_functionc                 C   s2   |  |}ddt| dtt|    S )Ng      ?rJ   )re   r   rT   ra   rV   )r.   r]   zr1   r1   r2   _cdf   s   
zLaplace._cdfc                 C   s   t | | S r>   )r   rV   re   r\   r1   r1   r2   rZ      r_   zLaplace._log_unnormalized_probc                 C   s   t dt| j S N       @)mathlogr   r   r<   r1   r1   r2   r[      s   zLaplace._log_normalizationc                 C   s*   | j t| j }tdd t| S )Nrk   rJ   )r   r   
zeros_liker   rl   rm   r   )r.   r   r1   r1   r2   _entropy   s   zLaplace._entropyc                 C   s   | j t| j S r>   )r   r   rn   r   r<   r1   r1   r2   _mean   r_   zLaplace._meanc                 C   s   t d| j t| j S rj   )rl   sqrtr   r   rn   r   r<   r1   r1   r2   _stddev   s   zLaplace._stddevc                 C      |   S r>   rp   r<   r1   r1   r2   _median      zLaplace._medianc                 C   rs   r>   rt   r<   r1   r1   r2   _mode   rv   zLaplace._modec                 C   s   || j  | j S r>   r3   r\   r1   r1   r2   re      rG   z
Laplace._z)FTr   r>   )__name__
__module____qualname____doc__r   
deprecatedr+   staticmethodr:   propertyr   r   rA   rD   rF   rI   rY   r^   rb   rf   rg   ri   rZ   r[   ro   rp   rr   ru   rw   re   __classcell__r1   r1   r/   r2   r   *   sF    -



c                       s8   e Zd ZdZejdddd			 d	 fdd	Z  ZS )
r   z)Laplace with softplus applied to `scale`.r   z5Use `tfd.Laplace(loc, tf.nn.softplus(scale)) instead.Tr   Fc                    sj   t t }tj|||gd}tt| j|tj|dd|||d W d    n1 s+w   Y  || _	d S )Nr   softplus_scaler   )r   r   r   r   r   )
r!   r"   r   r#   r*   r   r+   r	   softplus_parametersr-   r/   r1   r2   r+      s   


z!LaplaceWithSoftplusScale.__init__)FTr   )rx   ry   rz   r{   r   r|   r+   r   r1   r1   r/   r2   r      s    )r{   rl   numpyrQ   tensorflow.python.frameworkr   r   r   r   tensorflow.python.opsr   r   r   r	   r
   #tensorflow.python.ops.distributionsr   r   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   __all__Distributionr   r   r1   r1   r1   r2   <module>   s.   
 .