SigmoidTransform

class paddle.distribution. SigmoidTransform [源代码]

Sigmoid变换 \(y = \frac{1}{1 + \exp(-x)}\) , \(x = \text{logit}(y)\)

代码示例

import paddle

x = paddle.ones((2,3))
t = paddle.distribution.SigmoidTransform()
print(t.forward(x))
# Tensor(shape=[2, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
#        [[0.73105860, 0.73105860, 0.73105860],
#         [0.73105860, 0.73105860, 0.73105860]])
print(t.inverse(t.forward(x)))
# Tensor(shape=[2, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
#        [[1.00000012, 1.00000012, 1.00000012],
#         [1.00000012, 1.00000012, 1.00000012]])
print(t.forward_log_det_jacobian(x))
# Tensor(shape=[2, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
#        [[-1.62652326, -1.62652326, -1.62652326],
#         [-1.62652326, -1.62652326, -1.62652326]])

方法

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] - 逆变换输出的形状。