AbsTransform

class paddle.distribution. AbsTransform [source]

Absolute transformation with formula \(y = f(x) = abs(x)\), element-wise.

This non-injective transformation allows for transformations of scalar distributions with the absolute value function, which maps (-inf, inf) to [0, inf) .

  • For y in (0, inf) , AbsTransform.inverse(y) returns the set invese {x  in (-inf, inf) : |x| = y} as a tuple, -y, y .

  • For y equal 0 , AbsTransform.inverse(0) returns 0, 0, which is not the set inverse (the set inverse is the singleton {0}), but “works” in conjunction with TransformedDistribution to produce a left semi-continuous pdf.

  • For y in (-inf, 0) , AbsTransform.inverse(y) returns the wrong thing -y, y. This is done for efficiency.

Examples

>>> import paddle

>>> abs = paddle.distribution.AbsTransform()

>>> print(abs.forward(paddle.to_tensor([-1., 0., 1.])))
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [1., 0., 1.])

>>> print(abs.inverse(paddle.to_tensor([1.])))
(Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [-1.]), Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [1.]))

>>> # The |dX/dY| is constant 1. So Log|dX/dY| == 0
>>> print(abs.inverse_log_det_jacobian(paddle.to_tensor(1.)))
(Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        0.), Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        0.))

>>> #Special case handling of 0.
>>> print(abs.inverse(paddle.to_tensor([0.])))
(Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.]), Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.]))
>>> print(abs.inverse_log_det_jacobian(paddle.to_tensor(0.)))
(Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        0.), Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        0.))
forward ( x )

forward

Forward transformation with mapping \(y = f(x)\).

Useful for turning one random outcome into another.

Parameters

x (Tensos) – Input parameter, generally is a sample generated from Distribution.

Returns

Outcome of forward transformation.

Return type

Tensor

forward_log_det_jacobian ( x )

forward_log_det_jacobian

The log of the absolute value of the determinant of the matrix of all first-order partial derivatives of the inverse function.

Parameters

x (Tensor) – Input tensor, generally is a sample generated from Distribution

Returns

The log of the absolute value of Jacobian determinant.

Return type

Tensor

forward_shape ( shape )

forward_shape

Infer the shape of forward transformation.

Parameters

shape (Sequence[int]) – The input shape.

Returns

The output shape.

Return type

Sequence[int]

inverse ( y )

inverse

Inverse transformation \(x = f^{-1}(y)\). It’s useful for “reversing” a transformation to compute one probability in terms of another.

Parameters

y (Tensor) – Input parameter for inverse transformation.

Returns

Outcome of inverse transform.

Return type

Tensor

inverse_log_det_jacobian ( y )

inverse_log_det_jacobian

Compute \(log|det J_{f^{-1}}(y)|\). Note that forward_log_det_jacobian is the negative of this function, evaluated at \(f^{-1}(y)\).

Parameters

y (Tensor) – The input to the inverse Jacobian determinant evaluation.

Returns

The value of \(log|det J_{f^{-1}}(y)|\).

Return type

Tensor

inverse_shape ( shape )

inverse_shape

Infer the shape of inverse transformation.

Parameters

shape (Sequence[int]) – The input shape of inverse transformation.

Returns

The output shape of inverse transformation.

Return type

Sequence[int]