o
    ?e                     @   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Z	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)dtypeZreparameterization_typevalidate_argsallow_nan_stats
parametersZgraph_parentsr   )dictlocalsr   
name_scopeZcontrol_dependenciesr   Zassert_positiver   identity_loc_scaleZassert_same_float_dtypesuperr   __init__r   r   ZFULLY_REPARAMETERIZEDselfr   r   r   r   r   r   	__class__ l/home/www/facesmatcher.com/pyenv/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   Zconvert_to_tensorr   int32)Zsample_shaper*   r*   r+   _param_shapes|   s   zLaplace._param_shapesc                 C      | j S )z(Distribution parameter for the location.)r"   r'   r*   r*   r+   r         zLaplace.locc                 C   r2   )z!Distribution parameter for scale.)r#   r3   r*   r*   r+   r      r4   zLaplace.scalec                 C   s   t t | jt | jS N)r   Zbroadcast_dynamic_shapeshaper   r   r3   r*   r*   r+   _batch_shape_tensor   s   zLaplace._batch_shape_tensorc                 C   s   t | j | j S r5   )r   Zbroadcast_static_shaper   	get_shaper   r3   r*   r*   r+   _batch_shape   s   zLaplace._batch_shapec                 C   s   t jg tjdS )Nr-   )r   Zconstantr   r0   r3   r*   r*   r+   _event_shape_tensor      zLaplace._event_shape_tensorc                 C   s
   t g S r5   )r   ZTensorShaper3   r*   r*   r+   _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              ?)r6   minvalmaxvalr   seed)r   concatZbatch_shape_tensorr
   Zrandom_uniformnp	nextafterr   Zas_numpy_dtyper   r   r   signlog1pabs)r'   nr@   r6   Zuniform_samplesr*   r*   r+   	_sample_n   s   
zLaplace._sample_nc                 C   s   |  ||   S r5   )_log_unnormalized_prob_log_normalizationr'   xr*   r*   r+   	_log_prob      zLaplace._log_probc                 C      t | |S r5   )r   exprM   rK   r*   r*   r+   _prob   r;   zLaplace._probc                 C   rO   r5   r   Zlog_cdf_laplace_zrK   r*   r*   r+   _log_cdf   r;   zLaplace._log_cdfc                 C   s   t | | S r5   rR   rK   r*   r*   r+   _log_survival_function   rN   zLaplace._log_survival_functionc                 C   s2   |  |}ddt| dtt|    S )Ng      ?r=   )rS   r   rD   rP   rF   )r'   rL   zr*   r*   r+   _cdf   s   
zLaplace._cdfc                 C   s   t | | S r5   )r   rF   rS   rK   r*   r*   r+   rI      rN   zLaplace._log_unnormalized_probc                 C   s   t dt| j S N       @)mathlogr   r   r3   r*   r*   r+   rJ      s   zLaplace._log_normalizationc                 C   s*   | j t| j }tdd t| S )NrY   r=   )r   r   
zeros_liker   rZ   r[   r   )r'   r   r*   r*   r+   _entropy   s   zLaplace._entropyc                 C   s   | j t| j S r5   )r   r   r\   r   r3   r*   r*   r+   _mean   rN   zLaplace._meanc                 C   s   t d| j t| j S rX   )rZ   sqrtr   r   r\   r   r3   r*   r*   r+   _stddev   s   zLaplace._stddevc                 C      |   S r5   r^   r3   r*   r*   r+   _median      zLaplace._medianc                 C   ra   r5   rb   r3   r*   r*   r+   _mode   rd   zLaplace._modec                 C   s   || j  | j S r5   r,   rK   r*   r*   r+   rS      r;   z
Laplace._z)FTr   r5   )__name__
__module____qualname____doc__r   
deprecatedr%   staticmethodr1   propertyr   r   r7   r9   r:   r<   rH   rM   rQ   rT   rU   rW   rI   rJ   r]   r^   r`   rc   re   rS   __classcell__r*   r*   r(   r+   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   Zsoftplus_scaler   )r   r   r   r   r   )
r   r   r   r    r$   r   r%   r	   Zsoftplus_parametersr&   r(   r*   r+   r%      s   


z!LaplaceWithSoftplusScale.__init__)FTr   )rf   rg   rh   ri   r   rj   r%   rm   r*   r*   r(   r+   r      s    )ri   rZ   numpyrB   Ztensorflow.python.frameworkr   r   r   r   Ztensorflow.python.opsr   r   r   r	   r
   Z#tensorflow.python.ops.distributionsr   r   Ztensorflow.python.utilr   Z tensorflow.python.util.tf_exportr   __all__Distributionr   r   r*   r*   r*   r+   <module>   s.   
 .