AffineTransform

class paddle.distribution. AffineTransform ( loc, scale ) [源代码]

仿射变换 \(y = loc + scale \times x\)

参数

  • loc (Tensor) - 表示偏置参数。

  • scale (Tensor) - 表示缩放参数。

代码示例

>>> import paddle

>>> x = paddle.to_tensor([1., 2.])
>>> affine = paddle.distribution.AffineTransform(paddle.to_tensor(0.), paddle.to_tensor(1.))

>>> print(affine.forward(x))
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [1., 2.])
>>> print(affine.inverse(affine.forward(x)))
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [1., 2.])
>>> print(affine.forward_log_det_jacobian(x))
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        0.)

方法

forward(x)

计算正变换 \(y=f(x)\) 的结果。

参数

  • x (Tensor) - 正变换输入参数,通常为 Distribution 的随机采样结果。

返回

  • y (Tensor) - 正变换的计算结果。

inverse(y)

计算逆变换 \(x = f^{-1}(y)\)

参数

  • y (Tensor) - 逆变换的输入参数。

返回

  • x (Tensor) - 逆变换的计算结果。

forward_log_det_jacobian(x)

计算正变换雅可比行列式绝对值的对数。

如果变换不是一一映射,则雅可比矩阵不存在,返回 NotImplementedError

参数

  • x (Tensor) - 输入参数。

返回

  • Tensor - 正变换雅可比行列式绝对值的对数。

inverse_log_det_jacobian(y)

计算逆变换雅可比行列式绝对值的对数。

forward_log_det_jacobian 互为负数。

参数

  • y (Tensor) - 输入参数。

返回

  • Tensor - 逆变换雅可比行列式绝对值的对数。

forward_shape(shape)

推断正变换输出形状。

参数

  • shape (Sequence[int]) - 正变换输入的形状。

返回

  • Sequence[int] - 正变换输出的形状。

inverse_shape(shape)

推断逆变换输出形状。

参数

  • shape (Sequence[int]) - 逆变换输入的形状。

返回

  • Sequence[int] - 逆变换输出的形状。