Skip to content

Commit 118df85

Browse files
committed
add Independent,Multinomial,TransformedDistribution chinese documents
1 parent f77eadc commit 118df85

File tree

9 files changed

+305
-9
lines changed

9 files changed

+305
-9
lines changed

docs/api/paddle/distribution/AbsTransform_cn.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ AbsTransform
77
88
取绝对值变换 :math:`y = |x|` .
99

10-
``AbsTransform`` 不是一种双射变换,其逆变换处理逻辑如下:
10+
``AbsTransform`` 不是双射变换,其逆变换处理逻辑如下:
1111

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

docs/api/paddle/distribution/ExpTransform_cn.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,27 @@ ExpTransform
77
88
指数变换 :math:`y = exp(x)` .
99

10+
1011
代码示例
1112
:::::::::
1213

13-
COPY-FROM: paddle.distribution.ExpTransform
14+
.. code-block:: python
15+
16+
import paddle
17+
exp = paddle.distribution.ExpTransform()
18+
print(exp.forward(paddle.to_tensor([1., 2., 3.])))
19+
# Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
20+
# [2.71828175 , 7.38905621 , 20.08553696])
21+
print(exp.inverse(paddle.to_tensor([1., 2., 3.])))
22+
# Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
23+
# [0. , 0.69314718, 1.09861231])
24+
print(exp.forward_log_det_jacobian(paddle.to_tensor([1., 2., 3.])))
25+
# Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
26+
# [1., 2., 3.])
27+
print(exp.inverse_log_det_jacobian(paddle.to_tensor([1., 2., 3.])))
28+
# Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
29+
# [ 0. , -0.69314718, -1.09861231])
30+
1431
1532
方法
1633
:::::::::
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
.. _cn_api_paddle_distribution_Independent:
2+
3+
Independent
4+
-------------------------------
5+
6+
.. py:class:: paddle.distribution.Independent(base, reinterpreted_batch_rank)
7+
8+
将一个基础分布 ``base`` 的最右侧 ``reinterpreted_batch_rank`` 批维度转换为事件维度。
9+
10+
11+
参数
12+
:::::::::
13+
14+
- **base** (Distribution) - 基础分布。
15+
- **reinterpreted_batch_rank** (int) - 用于转换为事件维度的批维度数量。
16+
17+
代码示例
18+
:::::::::
19+
20+
COPY-FROM: paddle.distribution.Independent
21+
22+
23+
方法
24+
:::::::::
25+
26+
property mean
27+
'''''''''
28+
29+
计算分布均值。
30+
31+
32+
property variance
33+
'''''''''
34+
35+
计算分布方差。
36+
37+
38+
prob(value)
39+
'''''''''
40+
41+
计算value的概率。
42+
43+
**参数**
44+
45+
- **value** (Tensor) - 待计算值。
46+
47+
**返回**
48+
49+
- Tensor: value的概率。
50+
51+
52+
log_prob(value)
53+
'''''''''
54+
55+
计算value的对数概率。
56+
57+
**参数**
58+
59+
- **value** (Tensor) - 待计算值。
60+
61+
**返回**
62+
63+
- Tensor: value的对数概率。
64+
65+
66+
sample(shape=())
67+
'''''''''
68+
69+
从Beta分布中生成满足特定形状的样本数据。
70+
71+
**参数**
72+
73+
- **shape** (Sequence[int], 可选):采样次数。最终生成样本形状为 ``shape+batch_shape`` .
74+
75+
**返回**
76+
77+
- Tensor: 样本数据。
78+
79+
entropy()
80+
'''''''''
81+
82+
计算信息熵。
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
.. _cn_api_paddle_distribution_Multinomial:
2+
3+
Multinomial
4+
-------------------------------
5+
6+
.. py:class:: paddle.distribution.Multinomial(total_count, probs)
7+
8+
9+
``Multinomial`` 表示实验次数为 ``total_count`` ,概率为 ``probs`` 的多项分布。
10+
11+
在概率论中,多项分布是二项分布的多元推广,表示具有 :math:`k` 个类别的事件重复实验 :math:`n`
12+
次,每个类别出现次数的概率。当 :math:`k=2` 且 :math:`n=1` 时,为伯努利分布,
13+
:math:`k=2` 且 :math:`n>1` 时,为二项分布,当 :math:`k>2` 且 :math:`n=1` 时,
14+
为分类分布。
15+
16+
多项分布概率密度函数如下:
17+
18+
.. math::
19+
20+
f(x_1, ..., x_k; n, p_1,...,p_k) = \frac{n!}{x_1!...x_k!}p_1^{x_1}...p_k^{x_k}
21+
22+
23+
其中, :math:`n` 表示实验次数, :math:`k` 表示类别数, :math:`p_i` 表示一次实验中,实验结果
24+
为第 :math:`i` 个类比的概率,需要满足 :math:`{\textstyle \sum_{i=1}^{k}p_i=1}, p_i \ge 0` ,
25+
:math:`x_i` 表示第 :math:`i` 个分类出现的次数。
26+
27+
28+
29+
参数
30+
:::::::::
31+
32+
- **total_count** (int) - 实验次数。
33+
- **probs** (Tensor) - 每个类别发生的概率。最后一维为事件维度,其它维为批维度。``probs`` 中
34+
的每个元素取值范围为 ``[0,1]`` 。如果输入数据大于1,会沿着最后一维进行归一化操作。
35+
36+
代码示例
37+
:::::::::
38+
39+
COPY-FROM: paddle.distribution.Multinomial
40+
41+
42+
属性
43+
:::::::::
44+
45+
mean
46+
'''''''''
47+
48+
均值
49+
50+
variance
51+
'''''''''
52+
53+
方差
54+
55+
56+
方法
57+
:::::::::
58+
59+
prob(value)
60+
'''''''''
61+
62+
计算value的概率。
63+
64+
**参数**
65+
66+
- **value** (Tensor) - 待计算值。
67+
68+
**返回**
69+
70+
- Tensor: value的概率。
71+
72+
73+
log_prob(value)
74+
'''''''''
75+
76+
计算value的对数概率。
77+
78+
**参数**
79+
80+
- **value** (Tensor) - 待计算值。
81+
82+
**返回**
83+
84+
- Tensor: value的对数概率。
85+
86+
87+
sample(shape=())
88+
'''''''''
89+
90+
生成满足特定形状的样本数据。
91+
92+
**参数**
93+
94+
- **shape** (Sequence[int], 可选):采样形状。
95+
96+
**返回**
97+
98+
- Tensor: 样本数据。
99+
100+

docs/api/paddle/distribution/Overview_cn.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ paddle.distribution 目录下包含飞桨框架支持的随机变量的概率分
2727
" :ref:`Uniform <cn_api_distribution_Uniform>` ", "Uniform概率分布类"
2828
" :ref:`Beta <cn_api_paddle_distribution_Beta>` ", "Beta概率分布类"
2929
" :ref:`Dirichlet <cn_api_paddle_distribution_Dirichlet>` ", "Dirichlet概率分布类"
30+
" :ref:`Multinomial <cn_api_paddle_distribution_Multinomial>` ", "Multinomial概率分布类"
31+
" :ref:`Independent <cn_api_paddle_distribution_Independent>` ", "Independent概率分布类"
32+
" :ref:`TransfomedDistribution <cn_api_paddle_distribution_TransformedDistribution>` ", "TransformedDistribution概率分布类"
3033

3134
.. _about_distribution_transform:
3235

@@ -39,7 +42,17 @@ paddle.distribution 目录下包含飞桨框架支持的随机变量的概率分
3942

4043
" :ref:`Transform <cn_api_paddle_distribution_Transform>` ", "随机变量变换的基类"
4144
" :ref:`AbsTransform <cn_api_paddle_distribution_AbsTransform>` ", "绝对值变换"
42-
" :ref:`AffineTransform <cn_api_paddle_distribution_AffineTransform>` ", "放射变换"
45+
" :ref:`AffineTransform <cn_api_paddle_distribution_AffineTransform>` ", "仿射变换"
46+
" :ref:`ChainTransform <cn_api_paddle_distribution_ChainTransform>` ", "链式组合变换"
47+
" :ref:`ExpTransform <cn_api_paddle_distribution_ExpTransform>` ", "指数变换"
48+
" :ref:`IndependentTransform <cn_api_paddle_distribution_IndependentTransform>` ", "Independent变换"
49+
" :ref:`PowerTransform <cn_api_paddle_distribution_PowerTransform>` ", "幂变换"
50+
" :ref:`ReshapeTransform <cn_api_paddle_distribution_ReshapeTransform>` ", "Reshape变换"
51+
" :ref:`SigmoidTransform <cn_api_paddle_distribution_SigmoidTransform>` ", "Sigmoid变换"
52+
" :ref:`SoftmaxTransform <cn_api_paddle_distribution_SoftmaxTransform>` ", "Softmax变换"
53+
" :ref:`StackTransform <cn_api_paddle_distribution_StackTransform>` ", "Stack变换"
54+
" :ref:`StickBreakingTransform <cn_api_paddle_distribution_StickBreakingTransform>` ", "StickBreaking变换"
55+
" :ref:`TanhTransform <cn_api_paddle_distribution_TanhTransform>` ", "Tanh变换"
4356

4457
.. _about_distribution_kl:
4558

docs/api/paddle/distribution/SoftmaxTransform_cn.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ SoftmaxTransform
77
88
Softmax变换,首先进行 :math:`y = exp(x)` 变换, 然后归一化。
99

10-
Softmax变换主要用途是将一个无约束空间变换为单纯形。Softmax不是双射函数,
11-
所以 ``forward_log_det_jacobian`` 、 ``inverse_log_det_jacobian`` 未实现。
10+
Softmax变换将向量变换为单纯形。
11+
12+
注意,Softmax不是双射函数,所以 ``forward_log_det_jacobian`` 、 ``inverse_log_det_jacobian`` 未实现。
1213

1314
代码示例
1415
:::::::::

docs/api/paddle/distribution/StickBreakingTransform_cn.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ StickBreakingTransform
88
``StickBreakingTransform`` 将一个长度为K的向量通过StackBreaking构造过程变换为标准K-单纯
99
形。
1010

11+
1112
代码示例
1213
:::::::::
1314

docs/api/paddle/distribution/TanhTransform_cn.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,29 @@ TanhTransform
55

66
.. py:class:: paddle.distribution.TanhTransform
77
8-
Tanh变 :math:`y = tanh(x)`
8+
Tanh变换 :math:`y = tanh(x)`
9+
910

1011
代码示例
1112
:::::::::
1213

13-
COPY-FROM: paddle.distribution.TanhTransform
14+
.. code-block:: python
15+
16+
import paddle
17+
exp = paddle.distribution.ExpTransform()
18+
print(exp.forward(paddle.to_tensor([1., 2., 3.])))
19+
# Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
20+
# [2.71828175 , 7.38905621 , 20.08553696])
21+
print(exp.inverse(paddle.to_tensor([1., 2., 3.])))
22+
# Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
23+
# [0. , 0.69314718, 1.09861231])
24+
print(exp.forward_log_det_jacobian(paddle.to_tensor([1., 2., 3.])))
25+
# Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
26+
# [1., 2., 3.])
27+
print(exp.inverse_log_det_jacobian(paddle.to_tensor([1., 2., 3.])))
28+
# Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
29+
# [ 0. , -0.69314718, -1.09861231])
30+
1431
1532
方法
1633
:::::::::
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
.. _cn_api_paddle_distribution_TransformedDistribution:
2+
3+
TransformedDistribution
4+
-------------------------------
5+
6+
基于一个基础分布和一系列分布变换构建一个新的分布。
7+
8+
.. py:class:: paddle.distribution.TransformedDistribution(base, transforms)
9+
10+
参数
11+
:::::::::
12+
13+
- **base** (Distribution) - 基础分布。
14+
- **transforms** (Sequence[Transform]) - 变换序列。
15+
16+
代码示例
17+
:::::::::
18+
19+
COPY-FROM: paddle.distribution.TransformedDistribution
20+
21+
方法
22+
:::::::::
23+
24+
25+
prob(value)
26+
'''''''''
27+
28+
计算value的概率。
29+
30+
**参数**
31+
32+
- **value** (Tensor) - 待计算值。
33+
34+
**返回**
35+
36+
- Tensor: value的概率。
37+
38+
39+
log_prob(value)
40+
'''''''''
41+
42+
计算value的对数概率。
43+
44+
**参数**
45+
46+
- **value** (Tensor) - 待计算值。
47+
48+
**返回**
49+
50+
- Tensor: value的对数概率。
51+
52+
53+
sample(shape=())
54+
'''''''''
55+
56+
生成满足特定形状的样本数据。
57+
58+
**参数**
59+
60+
- **shape** (Sequence[int], 可选):采样形状。
61+
62+
**返回**
63+
64+
- Tensor: 样本数据。
65+
66+

0 commit comments

Comments
 (0)