Uniform¶

class paddle.fluid.layers. Uniform ( low, high ) [源代码]

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

$$low = a$$$$high = b$$$$Z$$：正态分布常量。

参数¶

• low (float|list|numpy.ndarray|Variable) - 均匀分布的下边界。数据类型为float32。

• high (float|list|numpy.ndarray|Variable) - 均匀分布的上边界。数据类型为float32。

代码示例¶

import numpy as np

# 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
value_npdata = np.array([0.8], dtype="float32")
value_tensor = layers.create_tensor(dtype="float32")
layers.assign(value_npdata, value_tensor)

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

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


参数¶

• shape (list) - 1维列表，指定生成样本的维度。数据类型为int32。

• seed (int) - 长整型数。

Variable

entropy ( )

返回类型¶

Variable

log_prob ( value )

参数¶

• value (Variable) - 输入张量。数据类型为float32或float64。

Variable