ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more


Uniform distribution with low and high parameters.

Inherits From: Distribution

Mathematical Details

The probability density function (pdf) is,

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


  • low = a,
  • high = b,
  • Z is the normalizing constant, and
  • I[predicate] is the 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).


# 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
# With broadcasting:
u1 = Uniform(low=3.0, high=[5.0, 6.0, 7.0])  # 3 distributions

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.

InvalidArgumentError if low >= high and validate_args=False.

allow_nan_stats Python bool describing behavior when a stat is undefined.

Stats return +/- infinity when it makes sense. E.g., the variance of a Cauchy distribution is infinity. However, sometimes the statistic is undefined, e.g., if a distribution's pdf does not achieve a maximum within the support of the distribution, the mode is undefined. If the mean is undefined, then by definition the variance is undefined. E.g. the mean for Student's T for df = 1 is undefined (no clear way to say it is either + or - infinity), so the variance = E[(X - mean)**2] is also undefined.

batch_shape Shape of a single sample from a single event index as a TensorShape.

May be partially defined or unknown.

The batch dimensions are indexes into independent, non-identical parameterizations of this distribution.

dtype The DType of Tensors handled by this Distribution.
event_shape Shape of a single sample from a single batch as a TensorShape.

May be partially defined or unknown.

high Upper boundary of the output interval.
low Lower boundary of the output interval.
name Name prepended to all ops created by this Distribution.
parameters Dictionary of parameters used to instantiate this Distribution.
reparameterization_type Describes how samples from the distribution are reparameterized.

Currently this is one of the static instances distributions.FULLY_REPARAMETERIZE