Skip to content

Commit

Permalink
新增随机变量变换相关API中文文档 (PaddlePaddle#4642)
Browse files Browse the repository at this point in the history
* add paddle.distribution.Transform chinese document

* add paddle.distribution.AbsTransform chinese document

* add paddle.distribution.AffineTransform chinese document

* add ChainTransform,ExpTransform,IndependentTransform chinese document

* add PowerTransform,ReshapeTransform chinese document

* add SigmoidTransform,SoftmaxTransform,StackTransform,StickBreakingTransform,TanhTransform chinese documents

* add Independent,Multinomial,TransformedDistribution chinese documents

* fix transform's APIs format problem
  • Loading branch information
cxxly committed Apr 22, 2022
1 parent 3d71058 commit 8ae8384
Show file tree
Hide file tree
Showing 17 changed files with 1,767 additions and 3 deletions.
113 changes: 113 additions & 0 deletions docs/api/paddle/distribution/AbsTransform_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
.. _cn_api_paddle_distribution_AbsTransform:

AbsTransform
-------------------------------

.. py:class:: paddle.distribution.AbsTransform()
取绝对值变换 :math:`y = |x|` .

``AbsTransform`` 不是双射变换,其逆变换处理逻辑如下:

* 当 :math:`y \in (0, +\infty )` , ``AbsTransform.inverse(y)`` 返回元组 ``(-y, y)`` .
* 当 :math:`y=0` , ``AbsTransform.inverse(y)`` 返回 ``(0, 0)`` .
* 当 :math:`y \in (-\infty, 0)` , 为了避免对 ``Tensor`` 数据进行判断带来性能下降,
``AbsTransform.inverse(y)`` 仍返回 ``(-y, y)`` , 注意这本质上是一个错误结果,仅仅出于
性能考虑。


代码示例
:::::::::

COPY-FROM: paddle.distribution.AbsTransform

方法
:::::::::

forward(x)
'''''''''

计算正变换 :math:`y=f(x)` 的结果。

**参数**

- **x** (Tensor) - 正变换输入参数,通常为 :ref:`cn_api_distribution_Distribution`
的随机采样结果。

**返回**

- **y** (Tensor) - 正变换的计算结果。


inverse(y)
'''''''''

计算逆变换 :math:`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] - 逆变换输出的形状。

111 changes: 111 additions & 0 deletions docs/api/paddle/distribution/AffineTransform_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
.. _cn_api_paddle_distribution_AffineTransform:

AffineTransform
-------------------------------

.. py:class:: paddle.distribution.AffineTransform(loc, scale)
仿射变换 :math:`y = loc + scale \times x` .

参数
:::::::::

- **loc** (Tensor) - 表示偏置参数。
- **scale** (Tensor) - 表示缩放参数。


代码示例
:::::::::

COPY-FROM: paddle.distribution.AffineTransform

方法
:::::::::

forward(x)
'''''''''

计算正变换 :math:`y=f(x)` 的结果。

**参数**

- **x** (Tensor) - 正变换输入参数,通常为 :ref:`cn_api_distribution_Distribution`
的随机采样结果。

**返回**

- **y** (Tensor) - 正变换的计算结果。


inverse(y)
'''''''''

计算逆变换 :math:`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] - 逆变换输出的形状。

112 changes: 112 additions & 0 deletions docs/api/paddle/distribution/ChainTransform_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
.. _cn_api_paddle_distribution_ChainTransform:

ChainTransform
-------------------------------

.. py:class:: paddle.distribution.ChainTransform(transforms)
变换的链式组合。

``ChainTransform`` 将一些列变换以链式组合方式作用于一个随机变量,计算变换后的结果。

参数
:::::::::

- **transforms** (Sequence[Transform]) - 输入的变换序列。


代码示例
:::::::::

COPY-FROM: paddle.distribution.ChainTransform

方法
:::::::::

forward(x)
'''''''''

计算正变换 :math:`y=f(x)` 的结果。

**参数**

- **x** (Tensor) - 正变换输入参数,通常为 :ref:`cn_api_distribution_Distribution`
的随机采样结果。

**返回**

- **y** (Tensor) - 正变换的计算结果。


inverse(y)
'''''''''

计算逆变换 :math:`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] - 逆变换输出的形状。

Loading

0 comments on commit 8ae8384

Please sign in to comment.