Transform¶
- class paddle.distribution. Transform [source]
- 
         Base class for the transformations of random variables. Transformcan be used to represent any differentiable and injective function from the subset of \(R^n\) to subset of \(R^m\), generally used for transforming a random sample generated byDistributioninstance.Suppose \(X\) is a K-dimensional random variable with probability density function \(p_X(x)\). A new random variable \(Y = f(X)\) may be defined by transforming \(X\) with a suitably well-behaved funciton \(f\). It suffices for what follows to note that if f is one-to-one and its inverse \(f^{-1}\) have a well-defined Jacobian, then the density of \(Y\) is \[p_Y(y) = p_X(f^{-1}(y)) |det J_{f^{-1}}(y)|\]where det is the matrix determinant operation and \(J_{f^{-1}}(y)\) is the Jacobian matrix of \(f^{-1}\) evaluated at \(y\). Taking \(x = f^{-1}(y)\), the Jacobian matrix is defined by \[\begin{split}J(y) = \begin{bmatrix} {\frac{\partial x_1}{\partial y_1}} &{\frac{\partial x_1}{\partial y_2}} &{\cdots} &{\frac{\partial x_1}{\partial y_K}} \\ {\frac{\partial x_2}{\partial y_1}} &{\frac{\partial x_2} {\partial y_2}}&{\cdots} &{\frac{\partial x_2}{\partial y_K}} \\ {\vdots} &{\vdots} &{\ddots} &{\vdots}\\ {\frac{\partial x_K}{\partial y_1}} &{\frac{\partial x_K}{\partial y_2}} &{\cdots} &{\frac{\partial x_K}{\partial y_K}} \end{bmatrix}\end{split}\]A Transformcan be characterized by three operations:- forward Forward implements \(x \rightarrow f(x)\), and is used to convert one random outcome into another. 
- inverse Undoes the transformation \(y \rightarrow f^{-1}(y)\). 
- 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. 
 Subclass typically implement follow methods: - _forward 
- _inverse 
- _forward_log_det_jacobian 
- _inverse_log_det_jacobian (optional) 
 If the transform changes the shape of the input, you must also implemented: - _forward_shape 
- _inverse_shape 
 - 
            
           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 
 
 - 
            
           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 
 
 - 
            
           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 
 
 - 
            
           inverse_log_det_jacobian
           (
           y
           )
           inverse_log_det_jacobian¶
- 
           Compute \(log|det J_{f^{-1}}(y)|\). Note that forward_log_det_jacobianis the negative of this function, evaluated at \(f^{-1}(y)\).- Parameters
- 
             y (Tensor) – The input to the inverseJacobian determinant evaluation.
- Returns
- 
             The value of \(log|det J_{f^{-1}}(y)|\). 
- 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_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] 
 
 
