IndependentTransform

class paddle.distribution. IndependentTransform ( base, reinterpreted_batch_rank ) [source]

IndependentTransform wraps a base transformation, reinterprets some of the rightmost batch axes as event axes.

Generally, it is used to expand the event axes. This has no effect on the forward or inverse transformation, but does sum out the reinterpreted_batch_rank rightmost dimensions in computing the determinant of Jacobian matrix.

To see this, consider the ExpTransform applied to a Tensor which has sample, batch, and event (S,B,E) shape semantics. Suppose the Tensor’s partitioned-shape is (S=[4], B=[2, 2], E=[3]) , reinterpreted_batch_rank is 1. Then the reinterpreted Tensor’s shape is (S=[4], B=[2], E=[2, 3]) . The shape returned by forward and inverse is unchanged, ie, [4,2,2,3] . However the shape returned by inverse_log_det_jacobian is [4,2], because the Jacobian determinant is a reduction over the event dimensions.

Parameters
  • base (Transform) – The base transformation.

  • reinterpreted_batch_rank (int) – The num of rightmost batch rank that will be reinterpreted as event rank.

Examples

>>> import paddle

>>> x = paddle.to_tensor([[1., 2., 3.], [4., 5., 6.]])

>>> # Exponential transform with event_rank = 1
>>> multi_exp = paddle.distribution.IndependentTransform(
...     paddle.distribution.ExpTransform(), 1)
>>> print(multi_exp.forward(x))
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[2.71828175  , 7.38905621  , 20.08553696 ],
         [54.59814835 , 148.41316223, 403.42880249]])
>>> print(multi_exp.forward_log_det_jacobian(x))
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [6. , 15.])
forward ( x )

forward

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

Useful for turning one random outcome into another.

Parameters

x (Tensor) – 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]