o
    i e                     @   s   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dG dd dejZdS )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                       s   e Zd ZdZejdddd					 d+ fd	d
	Zedd Ze	dd Z
e	dd Zd,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d)d* Z  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_once              ?Fc              	      s   t t }tj|||gdA}t|rtj||ddgng ! tj|dd| _	tj|dd| _
t| j	| j
g W d   n1 sCw   Y  W d   n1 sRw   Y  tt| j| j	jtj|||| j	| j
g|d dS )	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__ Z/var/www/myenv/lib/python3.10/site-packages/tensorflow/python/ops/distributions/uniform.pyr'   L   s8   
"

zUniform.__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_shaper,   r,   r-   _param_shapes   s
   zUniform._param_shapesc                 C      | j S )z&Lower boundary of the output interval.)r#   r)   r,   r,   r-   r         zUniform.lowc                 C   r6   )z&Upper boundary of the output interval.)r$   r7   r,   r,   r-   r      r8   zUniform.highrangec                 C   s:   |  | | j| j W  d   S 1 sw   Y  dS )z`high - low`.N)_name_scoper   r   )r)   r   r,   r,   r-   r9      s   
$zUniform.rangec                 C   s   t t | jt | jS N)r   broadcast_dynamic_shapeshaper   r   r7   r,   r,   r-   _batch_shape_tensor   s   

zUniform._batch_shape_tensorc                 C   s   t | j | j S r;   )r   broadcast_static_shaper   	get_shaper   r7   r,   r,   r-   _batch_shape   s   zUniform._batch_shapec                 C   s   t jg tjdS Nr/   )r   constantr   r3   r7   r,   r,   r-   _event_shape_tensor      zUniform._event_shape_tensorc                 C   s
   t g S r;   )r   TensorShaper7   r,   r,   r-   _event_shape   s   
zUniform._event_shapeNc                 C   s:   t |g|  gd}tj|| j|d}| j|  |  S )Nr   )r=   r   seed)r   concatbatch_shape_tensorr	   random_uniformr   r   r9   )r)   nrH   r=   samplesr,   r,   r-   	_sample_n   s   zUniform._sample_nc                 C   s^   |t j|  |jd }t t||t t|| jk || j	kt 
|t ||   S rB   )r   onesrJ   r   where_v2r   is_nan
logical_orr   r   
zeros_like	ones_liker9   )r)   xbroadcasted_xr,   r,   r-   _prob   s   

zUniform._probc                 C   st   t t ||  }t j|| jd}t j|| jd}|| }t || jk ||| j | 	  }t || j
k||S rB   )r   r<   r=   rJ   zerosr   rO   rP   r   r9   r   )r)   rU   broadcast_shaperX   rO   rV   result_if_not_bigr,   r,   r-   _cdf   s   zUniform._cdfc                 C   s   t |  S r;   )r   logr9   r7   r,   r,   r-   _entropy   s   zUniform._entropyc                 C   s   | j | j d S )Ng       @r.   r7   r,   r,   r-   _mean   rE   zUniform._meanc                 C   s   t |  d S Ng      (@)r   squarer9   r7   r,   r,   r-   	_variance      zUniform._variancec                 C   s   |   td S r_   )r9   mathsqrtr7   r,   r,   r-   _stddev   rb   zUniform._stddev)r   r   FTr   )r9   r;   )__name__
__module____qualname____doc__r   
deprecatedr'   staticmethodr5   propertyr   r   r9   r>   rA   rD   rG   rN   rW   r[   r]   r^   ra   re   __classcell__r,   r,   r*   r-   r       s>    *	-





r   )ri   rc   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   r,   r,   r,   r-   <module>   s   
