Uniform

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

均匀分布

概率密度函数(pdf)为:

\[ \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和high的维度必须能够支持广播。

参数

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

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

代码示例

import numpy as np
from paddle.fluid import layers
from paddle.fluid.layers import Uniform

# 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]])

# With broadcasting:
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) - 长整型数。

返回

预先设计好维度的张量,数据类型为float32

返回类型

Variable

entropy ( )

信息熵

返回

均匀分布的信息熵,数据类型为float32

返回类型

Variable

log_prob ( value )

对数概率密度函数

参数

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

返回

对数概率,数据类型与value相同

返回类型

Variable