Uniform
DistributionUniform(low: Tensor | float, high: Tensor | float, validate_args: bool | None = None)Continuous Uniform distribution on the half-open interval .
Maximum-entropy distribution over a bounded interval of fixed length: every point in is equally likely. Widely used as a non-informative prior, as the source of randomness for inverse-CDF sampling of arbitrary distributions, and as a quasi-Monte-Carlo integration measure.
Parameters
lowTensor or floathighTensor or floatvalidate_argsbool= NoneTrue, validate parameter constraints at construction time.Notes
Probability density (constant on the support):
Cumulative distribution:
Moments:
Higher moments (centred at the midpoint ): ; odd central moments are zero by symmetry.
The Uniform is the maximum-entropy distribution over a bounded interval of fixed length, and it underpins the inverse-CDF (Smirnov) sampling identity: if and is the quantile function of any 1-D distribution, then has that distribution.
Reparameterised sampling uses the location-scale transform so gradients flow through both endpoints.
Examples
>>> import lucid
>>> from lucid.distributions import Uniform
>>> d = Uniform(low=0.0, high=1.0)
>>> d.mean
Tensor(0.5)
>>> d.rsample((4,))
Tensor([...])
>>> d.log_prob(lucid.tensor(0.5))
Tensor(0.0)Methods (9)
__init__
→None__init__(low: Tensor | float, high: Tensor | float, validate_args: bool | None = None)Construct a Uniform distribution on [low, high).
Parameters
lowTensor | floathighTensor | floatvalidate_argsbool | None= NoneTrue, validate parameter constraints at construction time.Notes
The Uniform distribution has constant PDF on its support:
All values in the interval are equally likely. The distribution is the maximum-entropy distribution over a bounded interval, and is widely used for non-informative priors and Monte-Carlo sampling via the inverse-CDF method.
Examples
>>> from lucid.distributions import Uniform
>>> d = Uniform(low=0.0, high=1.0)
>>> d.mean
Tensor(0.5)support
→Constraintsupport: ConstraintThe support constraint of the Uniform distribution.
Returns the real constraint as a conservative fallback, because
the bounds may be arbitrary tensors and a precise interval constraint
would require tensor-aware bound tracking.
Returns
ConstraintThe real constraint object.
mean
→Tensormean: TensorExpected value of the Uniform distribution.
Returns
TensorMidpoint , shape batch_shape.
Examples
>>> Uniform(low=2.0, high=8.0).mean
Tensor(5.0)variance
→Tensorvariance: TensorVariance of the Uniform distribution.
Returns
TensorVariance , shape batch_shape.
Examples
>>> Uniform(low=0.0, high=1.0).variance # 1/12 ≈ 0.0833
Tensor(0.0833)rsample
→Tensorrsample(sample_shape: tuple[int, ...] = ())Reparameterised sample using the location-scale transform.
Gradients flow through both and .
Parameters
sample_shapetuple[int, ...]= ()().Returns
TensorSamples in of shape sample_shape + batch_shape.
Examples
>>> d = Uniform(low=-1.0, high=1.0)
>>> x = d.rsample((100,))
>>> (x >= -1.0).all() and (x < 1.0).all()
Truelog_prob
→Tensorlog_prob(value: Tensor)Log-density of value under the Uniform distribution.
Returns inside the support and outside:
Parameters
valueTensorReturns
TensorElement-wise log-densities, shape batch_shape.
Examples
>>> Uniform(low=0.0, high=2.0).log_prob(lucid.tensor(1.0))
Tensor(-0.6931)cdf
→Tensorcdf(value: Tensor)Cumulative distribution function of the Uniform distribution.
Parameters
valueTensorReturns
TensorCDF values in , shape batch_shape.
Examples
>>> Uniform(low=0.0, high=4.0).cdf(lucid.tensor(1.0))
Tensor(0.25)icdf
→Tensoricdf(value: Tensor)Inverse CDF (quantile function) of the Uniform distribution.
Parameters
valueTensorReturns
TensorQuantiles in , shape batch_shape.
Examples
>>> Uniform(low=0.0, high=10.0).icdf(lucid.tensor(0.5))
Tensor(5.0)entropy
→Tensorentropy()Shannon entropy of the Uniform distribution (in nats).
The Uniform distribution maximises entropy among all distributions supported on a bounded interval of fixed length.
Returns
TensorEntropy in nats, shape batch_shape.
Examples
>>> Uniform(low=0.0, high=1.0).entropy() # log(1) = 0.0
Tensor(0.0)