TanhTransform¶
Tanh 变换 \(y = tanh(x)\)
代码示例¶
>>> import paddle
>>> tanh = paddle.distribution.TanhTransform()
>>> x = paddle.to_tensor([[1., 2., 3.], [4., 5., 6.]])
>>> print(tanh.forward(x))
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
    [[0.76159418, 0.96402758, 0.99505472],
        [0.99932921, 0.99990916, 0.99998784]])
>>> print(tanh.inverse(tanh.forward(x)))
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
    [[1.        , 2.        , 2.99999666],
        [3.99993253, 4.99977016, 6.00527668]])
>>> print(tanh.forward_log_det_jacobian(x))
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[-0.86756170 , -2.65000558 , -4.61865711 ],
         [-6.61437654 , -8.61379623 , -10.61371803]])
>>> print(tanh.inverse_log_det_jacobian(tanh.forward(x)))
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[0.86756176 , 2.65000558 , 4.61866283 ],
         [6.61441946 , 8.61399269 , 10.61451530]])
         方法¶
forward(x)¶
计算正变换 \(y=f(x)\) 的结果。
参数
- x (Tensor) - 正变换输入参数,通常为 Distribution 的随机采样结果。 
返回
- y (Tensor) - 正变换的计算结果。 
forward_log_det_jacobian(x)¶
计算正变换雅可比行列式绝对值的对数。
如果变换不是一一映射,则雅可比矩阵不存在,返回 NotImplementedError 。
参数
- x (Tensor) - 输入参数。 
返回
- Tensor - 正变换雅可比行列式绝对值的对数。 
inverse_log_det_jacobian(y)¶
计算逆变换雅可比行列式绝对值的对数。
与 forward_log_det_jacobian 互为负数。
参数
- y (Tensor) - 输入参数。 
返回
- Tensor - 逆变换雅可比行列式绝对值的对数。