# Normal¶

class paddle.fluid.layers. Normal ( loc, scale ) [源代码]

\begin{align}\begin{aligned}pdf(x; \mu, \sigma) = \frac{1}{Z}e^{\frac {-0.5 (x - \mu)^2} {\sigma^2} }\\Z = (2 \pi \sigma^2)^{0.5}\end{aligned}\end{align}

$$loc = \mu$$：平均值。 $$scale = \sigma$$：标准差。 $$Z$$：正态分布常量。

## 参数¶

• loc (float|list|numpy.ndarray|Variable) - 正态分布平均值。数据类型为float32。

• scale (float|list|numpy.ndarray|Variable) - 正态分布标准差。数据类型为float32。

## 代码示例¶

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

# Define a single scalar Normal distribution.
dist = Normal(loc=0., scale=3.)
# Define a batch of two scalar valued Normals.
# The first has mean 1 and standard deviation 11, the second 2 and 22.
dist = Normal(loc=[1., 2.], scale=[11., 22.])
# Get 3 samples, returning a 3 x 2 tensor.
dist.sample([3])

# Define a batch of two scalar valued Normals.
# Both have mean 1, but different standard deviations.
dist = Normal(loc=1., scale=[11., 22.])

# Complete example
value_npdata = np.array([0.8], dtype="float32")
value_tensor = layers.create_tensor(dtype="float32")
layers.assign(value_npdata, value_tensor)

normal_a = Normal([0.], [1.])
normal_b = Normal([0.5], [2.])

sample = normal_a.sample([2])
# a random tensor created by normal distribution with shape: [2, 1]
entropy = normal_a.entropy()
# [1.4189385] with shape: [1]
lp = normal_a.log_prob(value_tensor)
# [-1.2389386] with shape: [1]
kl = normal_a.kl_divergence(normal_b)
# [0.34939718] with shape: [1]

## 参数¶

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

• seed (int) - 长整型数。

Variable

entropy ( )

## 返回类型¶

Variable

log_prob ( value )

## 参数¶

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

## 返回类型¶

Variable

kl_divergence ( other )

## 参数¶

• other (Normal) - Normal的实例。

Variable