TransformedDistribution¶
基于一个基础分布和一系列分布变换构建一个新的分布。
参数¶
base (Distribution) - 基础分布。
transforms (Sequence[Transform]) - 变换序列。
代码示例¶
>>> import paddle
>>> paddle.seed(2023)
>>> 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(cpu), stop_gradient=True,
[ 3.22699189, 1.12264419, 0.50283587, 1.83812487, -2.00740123,
-2.70338631, 1.26663208, 4.47909021, -0.11529565, 4.32719326])
>>> print(d.log_prob(paddle.to_tensor(0.5)))
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
-1.64333570)