# Uniform¶

class paddle.distribution. Uniform ( low, high, name=None ) [source]

Uniform distribution with low and high parameters.

Mathematical Details

The probability density function (pdf) is

$\begin{split}pdf(x; a, b) = \\frac{1}{Z}, \ a <=x <b\end{split}$
$Z = b - a$

In the above equation:

• $$low = a$$,

• $$high = b$$,

• $$Z$$: is the normalizing constant.

Parameters
• low (int|float|list|tuple|numpy.ndarray|Tensor) – The lower boundary of uniform distribution.The data type is int, float, list, numpy.ndarray or Tensor

• high (int|float|list|tuple|numpy.ndarray|Tensor) – The higher boundary of uniform distribution.The data type is int, float, list, numpy.ndarray or Tensor

• name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Examples

import paddle

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

u4 = Uniform(low=3.0, high=[5.0, 6.0, 7.0])

# Complete example

uniform = Uniform([0.], [2.])

sample = uniform.sample()
# a random tensor created by uniform distribution with shape: [2, 1]
entropy = uniform.entropy()
# [0.6931472] with shape: 
lp = uniform.log_prob(value_tensor)
# [-0.6931472] with shape: 
p = uniform.probs(value_tensor)
# [0.5] with shape: 

sample ( shape, seed=0 )

Generate samples of the specified shape.

Parameters
• shape (list) – 1D int32. Shape of the generated samples.

• seed (int) – Python integer number.

Returns

A tensor with prepended dimensions shape.The data type is float32.

Return type

Tensor

log_prob ( value )

Log probability density/mass function.

Parameters

value (Tensor) – The input tensor.

Returns

log probability.The data type is same with value.

Return type

Tensor

probs ( value )

Probability density/mass function.

Parameters

value (Tensor) – The input tensor.

Returns

probability.The data type is same with value.

Return type

Tensor

entropy ( )

Shannon entropy in nats.

The entropy is

$\begin{split}entropy(low, high) = \\log (high - low)\end{split}$
Returns

Shannon entropy of uniform distribution.The data type is float32.

Return type

Tensor

kl_divergence ( other )

The KL-divergence between self distributions and other.