
    AVh                         d 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  edg       G d dej$                               Zy)zThe Uniform distribution class.    N)constant_op)dtypes)ops)tensor_shape)	array_ops)	check_ops)math_ops)
random_ops)distribution)deprecation)	tf_exportzdistributions.Uniform)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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 xZS )Uniforma  Uniform distribution with `low` and `high` parameters.

  #### Mathematical Details

  The probability density function (pdf) is,

  ```none
  pdf(x; a, b) = I[a <= x < b] / Z
  Z = b - a
  ```

  where

  - `low = a`,
  - `high = b`,
  - `Z` is the normalizing constant, and
  - `I[predicate]` is the [indicator function](
    https://en.wikipedia.org/wiki/Indicator_function) for `predicate`.

  The parameters `low` and `high` must be shaped in a way that supports
  broadcasting (e.g., `high - low` is a valid operation).

  #### Examples

  ```python
  # Without broadcasting:
  u1 = Uniform(low=3.0, high=4.0)  # a single uniform distribution [3, 4]
  u2 = Uniform(low=[1.0, 2.0],
               high=[3.0, 4.0])  # 2 distributions [1, 3], [2, 4]
  u3 = Uniform(low=[[1.0, 2.0],
                    [3.0, 4.0]],
               high=[[1.5, 2.5],
                     [3.5, 4.5]])  # 4 distributions
  ```

  ```python
  # With broadcasting:
  u1 = Uniform(low=3.0, high=[5.0, 6.0, 7.0])  # 3 distributions
  ```

  z
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           	      |   t        t                     }t        j                  |||g      5 }t        j                  |rt        j                  ||d      gng       5  t        j                  |d      | _	        t        j                  |d      | _
        t        j                  | j                  | j                  g       ddd       ddd       t        t        | ;  | j                  j                  t         j"                  |||| j                  | j                  g|       y# 1 sw Y   dxY w# 1 sw Y   hxY w)	a  Initialize a batch of Uniform distributions.

    Args:
      low: Floating point tensor, lower boundary of the output interval. Must
        have `low < high`.
      high: Floating point tensor, upper boundary of the output interval. Must
        have `low < high`.
      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:
      InvalidArgumentError: if `low >= high` and `validate_args=False`.
    )valuesz%uniform not defined when low >= high.)messagelow)namehighN)dtypereparameterization_typevalidate_argsallow_nan_stats
parametersgraph_parentsr   )dictlocalsr   
name_scopecontrol_dependenciesr   assert_lessr   identity_low_high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/uniform.pyr(   zUniform.__init__L   s   D fhJ	c4[	1 CT##  

4!HJ% !" C &&s7	''6:
))499djj*ABCC 
'4!iioo , B B#'yyzz# " C CC Cs$   1D2A$D&D2&D/	+D22D;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    r,   _param_shapeszUniform._param_shapes   s8    O##LEFJ	MN N    c                     | j                   S )z&Lower boundary of the output interval.)r$   r*   s    r,   r   zUniform.low   s     99r6   c                     | j                   S )z&Upper boundary of the output interval.)r%   r8   s    r,   r   zUniform.high   s     ::r6   c                     | j                  |      5  | j                  | j                  z
  cddd       S # 1 sw Y   yxY w)z`high - low`.N)_name_scoper   r   )r*   r   s     r,   rangezUniform.range   s5    			$	 "YY!" " "s   5>c                     t        j                  t        j                  | j                        t        j                  | j                              S N)r   broadcast_dynamic_shapeshaper   r   r8   s    r,   _batch_shape_tensorzUniform._batch_shape_tensor   s5    ,,!		"$ $r6   c                     t        j                  | j                  j                         | j                  j                               S r>   )r   broadcast_static_shaper   	get_shaper   r8   s    r,   _batch_shapezUniform._batch_shape   s5    ++		 r6   c                 L    t        j                  g t        j                        S Nr/   )r   constantr   r3   r8   s    r,   _event_shape_tensorzUniform._event_shape_tensor   s    &,,77r6   c                 ,    t        j                  g       S r>   )r   TensorShaper8   s    r,   _event_shapezUniform._event_shape   s    ##B''r6   c                     t        j                  |g| j                         gd      }t        j                  || j
                  |      }| j                  | j                         |z  z   S )Nr   )r@   r   seed)r   concatbatch_shape_tensorr
   random_uniformr   r   r<   )r*   nrN   r@   sampless        r,   	_sample_nzUniform._sample_n   s\    qc4#:#:#<=qAE''e.2jj-13G 88djjlW,,,r6   c                    |t        j                  | j                         |j                        z  }t        j                  t        j                  |      |t        j                  t        j                  || j                  k  || j                  k\        t        j                  |      t        j                  |      | j                         z              S rG   )r   onesrP   r   where_v2r	   is_nan
logical_orr   r   
zeros_like	ones_liker<   )r*   xbroadcasted_xs      r,   _probzUniform._prob   s    	!2 2M& 8 - :<  /.=		?@ @r6   c                    t        j                  t        j                  |      | j                               }t        j                  || j
                        }t        j                  || j
                        }||z  }t        j                  || j                  k  ||| j                  z
  | j                         z        }t        j                  || j                  k\  ||      S rG   )r   r?   r@   rP   zerosr   rV   rW   r   r<   r   )r*   r\   broadcast_shaper`   rV   r]   result_if_not_bigs          r,   _cdfzUniform._cdf   s    77D3357OOOO4::>E>>/<DHM!**	DHHemdhh6$**,FHa499nd4EFFr6   c                 H    t        j                  | j                               S r>   )r	   logr<   r8   s    r,   _entropyzUniform._entropy   s    <<

%%r6   c                 :    | j                   | j                  z   dz  S )Ng       @r.   r8   s    r,   _meanzUniform._mean   s    HHtyy B&&r6   c                 N    t        j                  | j                               dz  S Ng      (@)r	   squarer<   r8   s    r,   	_variancezUniform._variance   s    ??4::<(3..r6   c                 N    | j                         t        j                  d      z  S rj   )r<   mathsqrtr8   s    r,   _stddevzUniform._stddev   s    ::<$))C.((r6   )g        g      ?FTr   )r<   r>   )__name__
__module____qualname____doc__r   
deprecatedr(   staticmethodr5   propertyr   r   r<   rA   rE   rI   rL   rT   r^   rc   rf   rh   rl   rp   __classcell__)r+   s   @r,   r   r       s    (T ;'
  "#++Z N N
    "
$

8(-	@G&'/)r6   r   )rt   rn   tensorflow.python.frameworkr   r   r   r   tensorflow.python.opsr   r   r	   r
   #tensorflow.python.ops.distributionsr   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   Distributionr    r6   r,   <module>r      s[    &  3 . + 4 + + * , < . 6 &'(k)l'' k) )k)r6   