o
    ?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)Z	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)dtypeZreparameterization_typevalidate_argsallow_nan_stats
parametersZgraph_parentsr   )dictlocalsr   Z
name_scopeZcontrol_dependenciesr   Zassert_lessr   identity_low_highZ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/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   Zconvert_to_tensorr   int32)Z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   r,   )z&Upper boundary of the output interval.)r   r-   r$   r$   r%   r      r.   zUniform.highrangec                 C   s:   |  | | j| j W  d   S 1 sw   Y  dS )z`high - low`.N)Z_name_scoper   r   )r!   r   r$   r$   r%   r/      s   
$zUniform.rangec                 C   s   t t | jt | jS N)r   broadcast_dynamic_shapeshaper   r   r-   r$   r$   r%   _batch_shape_tensor   s   

zUniform._batch_shape_tensorc                 C   s   t | j | j S r0   )r   Zbroadcast_static_shaper   	get_shaper   r-   r$   r$   r%   _batch_shape   s   zUniform._batch_shapec                 C   s   t jg tjdS Nr'   )r   Zconstantr   r*   r-   r$   r$   r%   _event_shape_tensor      zUniform._event_shape_tensorc                 C   s
   t g S r0   )r   ZTensorShaper-   r$   r$   r%   _event_shape   s   
zUniform._event_shapeNc                 C   s:   t |g|  gd}tj|| j|d}| j|  |  S )Nr   )r2   r   seed)r   concatbatch_shape_tensorr	   Zrandom_uniformr   r   r/   )r!   nr:   r2   Z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 r6   )r   onesr<   r   where_v2r   is_nan
logical_orr   r   Z
zeros_likeZ	ones_liker/   )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 r6   )r   r1   r2   r<   zerosr   r?   r@   r   r/   r   )r!   rC   Zbroadcast_shaperF   r?   rD   Zresult_if_not_bigr$   r$   r%   _cdf   s   zUniform._cdfc                 C   s   t |  S r0   )r   logr/   r-   r$   r$   r%   _entropy   s   zUniform._entropyc                 C   s   | j | j d S )Ng       @r&   r-   r$   r$   r%   _mean   r8   zUniform._meanc                 C   s   t |  d S Ng      (@)r   Zsquarer/   r-   r$   r$   r%   	_variance      zUniform._variancec                 C   s   |   td S rK   )r/   mathsqrtr-   r$   r$   r%   _stddev   rM   zUniform._stddev)r   r   FTr   )r/   r0   )__name__
__module____qualname____doc__r   
deprecatedr    staticmethodr+   propertyr   r   r/   r3   r5   r7   r9   r>   rE   rG   rI   rJ   rL   rP   __classcell__r$   r$   r"   r%   r       s>    *	-





r   )rT   rN   Ztensorflow.python.frameworkr   r   r   r   Ztensorflow.python.opsr   r   r   r	   Z#tensorflow.python.ops.distributionsr
   Ztensorflow.python.utilr   Z tensorflow.python.util.tf_exportr   Distributionr   r$   r$   r$   r%   <module>   s   
