TransformedDistribution

基于一个基础分布和一系列分布变换构建一个新的分布。

class paddle.distribution. TransformedDistribution ( base, transforms ) [源代码]

参数

  • base (Distribution) - 基础分布。

  • transforms (Sequence[Transform]) - 变换序列。

代码示例

import paddle
from paddle.distribution import transformed_distribution

d = transformed_distribution.TransformedDistribution(
    paddle.distribution.Normal(0., 1.),
    [paddle.distribution.AffineTransform(paddle.to_tensor(1.), paddle.to_tensor(2.))]
)

print(d.sample([10]))
# Tensor(shape=[10], dtype=float32, place=Place(gpu:0), stop_gradient=True,
#        [-0.10697651,  3.33609009, -0.86234951,  5.07457638,  0.75925219,
#         -4.17087793,  2.22579336, -0.93845034,  0.66054249,  1.50957513])
print(d.log_prob(paddle.to_tensor(0.5)))
# Tensor(shape=[1], dtype=float32, place=Place(gpu:0), stop_gradient=True,
#        [-1.64333570])

方法

prob(value)

计算value的概率。

参数

  • value (Tensor) - 待计算值。

返回

  • Tensor: value的概率。

log_prob(value)

计算value的对数概率。

参数

  • value (Tensor) - 待计算值。

返回

  • Tensor: value的对数概率。

sample(shape=())

生成满足特定形状的样本数据。

参数

  • shape (Sequence[int], 可选):采样形状。

返回

  • Tensor: 样本数据。