
    AVh                        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       G d dej.                               Z G d de      Zy)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                        e Zd ZdZ ej
                  ddd      	 	 	 d fd	       Zed        Ze	d        Z
e	d	        Zd
 Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )r   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_oncec           
      v   t        t                     }t        j                  |||g      5 }t        j                  |rt        j                  |      gng       5  t        j                  |d      | _	        t        j                  |d      | _
        t        j                  | j                  | j                  g       ddd       t        t        | ;  | j                  j                  t         j"                  |||| j                  | j                  g|       ddd       y# 1 sw Y   dxY w# 1 sw Y   yxY w)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__s          [/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/distributions/laplace.pyr.   zLaplace.__init__G   s   J fhJ	c5\	2 d##$1 &/%>%>u%E$F79; D&&s7	((W=))499dkk*BC	D
 GT#		"."D"D%)DKK0 $  D D s%   .D/A$D# AD/#D,	(D//D8c           	      z    t        t        dt        j                  | t        j
                        gdz              S )Nr   r   r      )r$   zipr   convert_to_tensorr   int32)sample_shapes    r3   _param_shapeszLaplace._param_shapes|   s=     5 5!.  /12 3 	56 6    c                     | j                   S )z(Distribution parameter for the location.)r*   r1   s    r3   r   zLaplace.loc   s     99r=   c                     | j                   S )z!Distribution parameter for scale.)r+   r?   s    r3   r   zLaplace.scale   s     ;;r=   c                     t        j                  t        j                  | j                        t        j                  | j                              S N)r   broadcast_dynamic_shapeshaper   r   r?   s    r3   _batch_shape_tensorzLaplace._batch_shape_tensor   s6    ,,!9??4::#>@ @r=   c                     t        j                  | j                  j                         | j                  j                               S rB   )r   broadcast_static_shaper   	get_shaper   r?   s    r3   _batch_shapezLaplace._batch_shape   s4    ++djj2246 6r=   c                 L    t        j                  g t        j                        S )Nr6   )r   constantr   r:   r?   s    r3   _event_shape_tensorzLaplace._event_shape_tensor   s    &,,77r=   c                 ,    t        j                  g       S rB   )r   TensorShaper?   s    r3   _event_shapezLaplace._event_shape   s    ##B''r=   c           	         t        j                  |g| j                         gd      }t        j                  |t        j                  | j                  j                  d      | j                  j                  d            d| j                  |      }| j                  | j                  t        j                  |      z  t        j                  t        j                  |             z  z
  S )Nr   g      g              ?)rD   minvalmaxvalr   seed)r   concatbatch_shape_tensorr   random_uniformnp	nextafterr   as_numpy_dtyper   r   r	   signlog1pabs)r1   nrT   rD   uniform_sampless        r3   	_sample_nzLaplace._sample_n   s    qc4#:#:#<=qAE !//||DJJ55c: JJ55b9;jjO HHtzzHMM/$BBNNHLL99:; ; <r=   c                 F    | j                  |      | j                         z
  S rB   )_log_unnormalized_prob_log_normalizationr1   xs     r3   	_log_probzLaplace._log_prob   s!    &&q)D,C,C,EEEr=   c                 J    t        j                  | j                  |            S rB   )r	   exprf   rd   s     r3   _probzLaplace._prob   s    <<q)**r=   c                 J    t        j                  | j                  |            S rB   r   log_cdf_laplace_zrd   s     r3   _log_cdfzLaplace._log_cdf   s    ''
33r=   c                 L    t        j                  | j                  |             S rB   rk   rd   s     r3   _log_survival_functionzLaplace._log_survival_function   s    ''44r=   c                     | j                  |      }ddt        j                  |      z  dt        j                  t        j                  |             z
  z  z   S )Ng      ?rQ   )rm   r	   r[   rh   r]   )r1   re   zs      r3   _cdfzLaplace._cdf   sM    
A#a(((,,Q/002 2 3r=   c                 L    t        j                  | j                  |             S rB   )r	   r]   rm   rd   s     r3   rb   zLaplace._log_unnormalized_prob   s    LL$$$r=   c                 l    t        j                  d      t        j                  | j                        z   S N       @)mathlogr	   r   r?   s    r3   rc   zLaplace._log_normalization   s"    88B<(,,tzz222r=   c                     | j                   t        j                  | j                        z   }t	        j
                  d      dz   t        j
                  |      z   S )Nrw   rQ   )r   r   
zeros_liker   rx   ry   r	   )r1   r   s     r3   _entropyzLaplace._entropy   s@    JJ--dhh77E88B<"x||E222r=   c                 Z    | j                   t        j                  | j                        z   S rB   )r   r   r{   r   r?   s    r3   _meanzLaplace._mean   s     88i**4::666r=   c                     t        j                  d      | j                  z  t        j                  | j
                        z   S rv   )rx   sqrtr   r   r{   r   r?   s    r3   _stddevzLaplace._stddev   s-    99R=4::%	(<(<TXX(FFFr=   c                 "    | j                         S rB   r~   r?   s    r3   _medianzLaplace._median       ::<r=   c                 "    | j                         S rB   r   r?   s    r3   _modezLaplace._mode   r   r=   c                 :    || j                   z
  | j                  z  S rB   r5   rd   s     r3   rm   z
Laplace._z   s    LDJJ&&r=   )FTr   rB   )__name__
__module____qualname____doc__r   
deprecatedr.   staticmethodr<   propertyr   r   rE   rI   rL   rO   r`   rf   ri   rn   rp   rs   rb   rc   r|   r~   r   r   r   rm   __classcell__r2   s   @r3   r   r   *   s    6 ;'
  ##++Z 6 6
    @68(<$F+453
%33
7G'r=   c                   Z     e Zd ZdZ ej
                  ddd      	 	 	 d fd	       Z xZS )r   z)Laplace with softplus applied to `scale`.r   z5Use `tfd.Laplace(loc, tf.nn.softplus(scale)) instead.Tr   c                     t        t                     }t        j                  |||g      5 }t        t
        |   |t        j                  |d      |||       d d d        || _	        y # 1 sw Y   || _	        y xY w)Nr   softplus_scaler   )r   r   r    r!   r   )
r$   r%   r   r&   r-   r   r.   r
   softplus_parametersr0   s          r3   r.   z!LaplaceWithSoftplusScale.__init__   sx     fhJ	c5\	2 d$d4E(89%) 5  "D "Ds   .A,,A<)FTr   )r   r   r   r   r   r   r.   r   r   s   @r3   r   r      s;    1;	 ##."
"r=   )r   rx   numpyrX   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    r=   r3   <module>r      s    &   3 . + 4 + + * $ , < < . 6  &'(j'l'' j' )j'Z"w "r=   