From b7ef2d66bb60dffcd01c03e2a22f9b2a7b9a0acb Mon Sep 17 00:00:00 2001 From: AyaseNana <13659110308@163.com> Date: Wed, 22 Nov 2023 17:54:45 +0800 Subject: [PATCH 1/7] add hack19 docs --- .../distribution/ContinuousBernoulli_cn.rst | 206 ++++++++++++++++++ .../distribution/MultivariateNormal_cn.rst | 151 +++++++++++++ docs/api/paddle/distribution/Overview_cn.rst | 2 + 3 files changed, 359 insertions(+) create mode 100644 docs/api/paddle/distribution/ContinuousBernoulli_cn.rst create mode 100644 docs/api/paddle/distribution/MultivariateNormal_cn.rst diff --git a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst new file mode 100644 index 00000000000..bda5eecb302 --- /dev/null +++ b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst @@ -0,0 +1,206 @@ +.. _cn_api_paddle_distribution_ContinuousBernoulli: + +ContinuousBernoulli +------------------------------- + +.. py:class:: paddle.distribution.ContinuousBernoulli(probability, eps=1e-4) + + +ContinuousBernoulli 是一种定义在 [0,1] 区间上的连续型概率分布,参数 :attr:`probability` 描述了其概率密度函数的形状。它可以被视为连续型的伯努利分布。 +出自 [1] Loaiza-Ganem, G., & Cunningham, J. P. The continuous Bernoulli: fixing a pervasive error in variational autoencoders. 2019. + +其概率密度函数(pdf)为: + +.. math:: + + p(x;\lambda) = C(\lambda)\lambda^x (1-\lambda)^{1-x} + +其中: + +- :math:`x` 在 [0, 1] 区间内是连续的。 +- :math:`\lambda` 表示事件发生的概率。 +- :math:`C(\lambda)` 表示归一化常数因子,表达式如下: + +.. math:: + + { C(\lambda) = + \left\{ + \begin{aligned} + &2 & \text{ if $\lambda = \frac{1}{2}$} \\ + &\frac{2\tanh^{-1}(1-2\lambda)}{1 - 2\lambda} & \text{ otherwise} + \end{aligned} + \right. } + +参数 +::::::::: + +- **probability** (int|float|np.ndarray|Tensor) - 即上述公式中 :math:`\lambda` 参数,在 [0, 1] 内,表示事件平均概率,刻画 ContinuousBernoulli 分布的 + 概率密度函数的形状。:attr:`probability` 的数据类型会被转换为 float32 类型。 + +- **eps** (float) - 表示概率计算非稳定区域的区域宽度,概率计算非稳定区域即为 [0.5 - :attr:`eps`, 0.5 + :attr:`eps`] ,非稳定区域的概率计算使用泰勒展开做近似。 + 默认值为 1e-4。 + +代码示例 +::::::::: + +COPY-FROM: paddle.distribution.ContinuousBernoulli + +属性 +::::::::: + +mean +''''''''' + +ContinuousBernoulli 分布的均值 + +**返回** + +Tensor,均值 + +variance +''''''''' + +ContinuousBernoulli 分布的方差 + +**返回** + +Tensor,方差 + +方法 +::::::::: + +prob(value) +''''''''' + +计算 :attr:`value` 的概率。 + +**参数** + +- **value** (Tensor) - 待计算值。 + +**返回** + +- Tensor: :attr:`value` 的概率。数据类型与 :attr:`value` 相同。 + + +log_prob(value) +''''''''' + +计算 value 的对数概率。 + +**参数** + +- **value** (Tensor) - 待计算值。 + +**返回** + +- Tensor: :attr:`value` 的对数概率。数据类型与 :attr:`value` 相同。 + + +cdf(value) +''''''''' + +计算 :attr:`value` 的累计分布 quantile 值。 + +.. math:: + + { P(X \le t; \lambda) = + F(t;\lambda) = + \left\{ + \begin{aligned} + &t & \text{ if $\lambda = \frac{1}{2}$} \\ + &\frac{\lambda^t (1 - \lambda)^{1 - t} + \lambda - 1}{2\lambda - 1} & \text{ otherwise} + \end{aligned} + \right. } + +**参数** + +- **value** (Tensor) - 待计算值。 + +**返回** + +- Tensor: :attr:`value` 的累积分布函数对应的 quantile 值。数据类型与 :attr:`value` 相同。 + + +icdf(value) +''''''''' + +计算 value 的逆累计分布值。 + +.. math:: + + { F^{-1}(x;\lambda) = + \left\{ + \begin{aligned} + &x & \text{ if $\lambda = \frac{1}{2}$} \\ + &\frac{\log(1+(\frac{2\lambda - 1}{1 - \lambda})x)}{\log(\frac{\lambda}{1-\lambda})} & \text{ otherwise} + \end{aligned} + \right. } + +**参数** + +- **value** (Tensor) - 待计算 quantile。 + +**返回** + +- Tensor: ContinuousBernoulli 随机变量在对应 quantile 下的值。数据类型与 :attr:`value` 相同。 + + +sample(shape=()) +''''''''' + +从 ContinuousBernoulli 分布中生成满足特定形状的样本数据。最终生成样本形状为 ``shape+batch_shape`` 。 + +**参数** + +- **shape** (Sequence[int],可选):采样次数。 + +**返回** + +- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape}` 。数据类型为 float32 。 + + +rsample(shape=()) +''''''''' + +重参数化采样,生成指定维度的样本。最终生成样本形状为 ``shape+batch_shape`` 。 + +**参数** + +- **shape** (Sequence[int],可选):采样次数。 + +**返回** + +- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape}` 。数据类型为 float32 。 + + +entropy() +''''''''' + +计算 ContinuousBernoulli 分布的信息熵。 + +.. math:: + + \mathcal{H}(X) = -\log C + \left[ \log (1 - \lambda) -\log \lambda \right] \mathbb{E}(X) - \log(1 - \lambda) + +**返回** + +类别分布的信息熵,数据类型为 float32。 + + +kl_divergence(other) +''''''''' + +相对于另一个类别分布的 KL 散度,两个分布需要有相同的 :math:`\text{batch shape}`。 + +.. math:: + + KL\_divergence(\lambda_1, \lambda_2) = - H - \{\log C_2 + [\log \lambda_2 - \log (1-\lambda_2)] \mathbb{E}_1(X) + \log (1-\lambda_2) \} + +**参数** + + - **other** (ContinuousBernoulli) - 输入的另一个类别分布。 + +**返回** + +相对于另一个类别分布的 KL 散度,数据类型为 float32。 diff --git a/docs/api/paddle/distribution/MultivariateNormal_cn.rst b/docs/api/paddle/distribution/MultivariateNormal_cn.rst new file mode 100644 index 00000000000..86b693712f8 --- /dev/null +++ b/docs/api/paddle/distribution/MultivariateNormal_cn.rst @@ -0,0 +1,151 @@ +.. _cn_api_paddle_distribution_MultivariateNormal: + +MultivariateNormal +------------------------------- + +.. py:class:: paddle.distribution.MultivariateNormal(loc, covariance_matrix=None, precision_matrix=None, scale_tril=None) + + +MultivariateNormal 是一种定义在实数域上的多元连续型概率分布,参数 :attr:`loc` 表示均值,以及需要传入以下任意一种矩阵描述其方差: +:attr:`covariance_matrix`、 :attr:`precision_matrix`、 :attr:`scale_tril`。 + +其概率密度函数(pdf)为: + +.. math:: + + p(X ;\mu, \Sigma) = \frac{1}{\sqrt{(2\pi)^k |\Sigma|}} \exp(-\frac{1}{2}(X - \mu)^{\intercal} \Sigma^{-1} (X - \mu)) + +其中: + +- :math:`X` 是 k 维随机向量。 +- :math:`\mu` 是 k 维均值向量。 +- :math:`\Sigma` 是 k 阶协方差矩阵。 + + +参数 +::::::::: + +- **loc** (int|float|np.ndarray|Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的均值向量。:attr:`loc` 的数据类型会被转换为 float32 类型。 + +- **covariance_matrix** (Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的协方差矩阵。:attr:`covariance_matrix` 的数据类型会被转换为 float32 类型。 + +- **precision_matrix** (Tensor) - 是 MultivariateNormal 协方差矩阵的逆矩阵。:attr:`precision_matrix` 的数据类型会被转换为 float32 类型。 + +- **scale_tril** (Tensor) - 是 MultivariateNormal 协方差矩阵的柯列斯基分解的下三角矩阵。:attr:`scale_tril` 的数据类型会被转换为 float32 类型。 + + +代码示例 +::::::::: + +COPY-FROM: paddle.distribution.MultivariateNormal + +属性 +::::::::: + +mean +''''''''' + +MultivariateNormal 分布的均值 + +**返回** + +Tensor,均值 + +variance +''''''''' + +MultivariateNormal 分布的方差 + +**返回** + +Tensor,方差 + +方法 +::::::::: + +prob(value) +''''''''' + +计算 :attr:`value` 的概率。 + +**参数** + +- **value** (Tensor) - 待计算值。 + +**返回** + +- Tensor: :attr:`value` 的概率。数据类型与 :attr:`value` 相同。 + + +log_prob(value) +''''''''' + +计算 value 的对数概率。 + +**参数** + +- **value** (Tensor) - 待计算值。 + +**返回** + +- Tensor: :attr:`value` 的对数概率。数据类型与 :attr:`value` 相同。 + + +sample(shape=()) +''''''''' + +从 MultivariateNormal 分布中生成满足特定形状的样本数据。最终生成样本形状为 ``sample_shape + batch_shape + event_shape`` 。 + +**参数** + +- **shape** (Sequence[int],可选):采样次数。 + +**返回** + +- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型为 float32 。 + + +rsample(shape=()) +''''''''' + +重参数化采样,生成指定维度的样本。最终生成样本形状为 ``sample_shape + batch_shape + event_shape`` 。 + +**参数** + +- **shape** (Sequence[int],可选):采样次数。 + +**返回** + +- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型为 float32 。 + + +entropy() +''''''''' + +计算 MultivariateNormal 分布的信息熵。 + +.. math:: + + \mathcal{H}(X) = \frac{n}{2} \log(2\pi) + \log {\det A} + \frac{n}{2} + +**返回** + +类别分布的信息熵,数据类型为 float32。 + + +kl_divergence(other) +''''''''' + +相对于另一个类别分布的 KL 散度,两个分布需要有相同的 :math:`\text{batch shape}` 和 :math:`\text{event shape}`。 + +.. math:: + + KL\_divergence(\lambda_1, \lambda_2) = \log(\det A_2) - \log(\det A_1) -\frac{n}{2} +\frac{1}{2}[tr [\Sigma_2^{-1} \Sigma_1] + (\mu_1 - \mu_2)^{\intercal} \Sigma_2^{-1} (\mu_1 - \mu_2)] + +**参数** + + - **other** (MultivariateNormal) - 输入的另一个类别分布。 + +**返回** + +相对于另一个类别分布的 KL 散度,数据类型为 float32。 diff --git a/docs/api/paddle/distribution/Overview_cn.rst b/docs/api/paddle/distribution/Overview_cn.rst index 47d2c6f692b..21fb47c00f6 100644 --- a/docs/api/paddle/distribution/Overview_cn.rst +++ b/docs/api/paddle/distribution/Overview_cn.rst @@ -23,12 +23,14 @@ paddle.distribution 目录下包含飞桨框架支持的随机变量的概率分 " :ref:`Distribution ` ", "Distribution 概率分布抽象基类" " :ref:`ExponentialFamily ` ", "ExponentialFamily 指数型分布族基类" " :ref:`Bernoulli ` ", "Bernoulli 概率分布类" + " :ref:`ContinuousBernoulli ` ", "ContinuousBernoulli 概率分布类" " :ref:`Categorical ` ", "Categorical 概率分布类" " :ref:`Cauchy ` ", "Cauchy 概率分布类" " :ref:`Normal ` ", "Normal 概率分布类" " :ref:`Uniform ` ", "Uniform 概率分布类" " :ref:`Beta ` ", "Beta 概率分布类" " :ref:`Dirichlet ` ", "Dirichlet 概率分布类" + " :ref:`MultivariateNormal ` ", "MultivariateNormal 概率分布类" " :ref:`Multinomial ` ", "Multinomial 概率分布类" " :ref:`Independent ` ", "Independent 概率分布类" " :ref:`TransfomedDistribution ` ", "TransformedDistribution 概率分布类" From 01b9a92a94fcd8fe0a746e07f0ce5eba1a35c1b3 Mon Sep 17 00:00:00 2001 From: AyaseNana <13659110308@163.com> Date: Wed, 13 Dec 2023 14:56:02 +0800 Subject: [PATCH 2/7] update docs --- .../distribution/ContinuousBernoulli_cn.rst | 24 +++++++++---------- .../distribution/MultivariateNormal_cn.rst | 20 ++++++++-------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst index bda5eecb302..e8ee159c7d4 100644 --- a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst +++ b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst @@ -3,7 +3,7 @@ ContinuousBernoulli ------------------------------- -.. py:class:: paddle.distribution.ContinuousBernoulli(probability, eps=1e-4) +.. py:class:: paddle.distribution.ContinuousBernoulli(probability, eps=0.02) ContinuousBernoulli 是一种定义在 [0,1] 区间上的连续型概率分布,参数 :attr:`probability` 描述了其概率密度函数的形状。它可以被视为连续型的伯努利分布。 @@ -34,11 +34,11 @@ ContinuousBernoulli 是一种定义在 [0,1] 区间上的连续型概率分布 参数 ::::::::: -- **probability** (int|float|np.ndarray|Tensor) - 即上述公式中 :math:`\lambda` 参数,在 [0, 1] 内,表示事件平均概率,刻画 ContinuousBernoulli 分布的 - 概率密度函数的形状。:attr:`probability` 的数据类型会被转换为 float32 类型。 +- **probability** (int|float|Tensor) - 即上述公式中 :math:`\lambda` 参数,在 [0, 1] 内,刻画 ContinuousBernoulli 分布的 + 概率密度函数的形状。如果 :attr:`probability` 的输入数据类型是 `int` 或 `float` ,则会被转换为数据类型为 paddle 全局默认数据类型的 1-D Tensor。 - **eps** (float) - 表示概率计算非稳定区域的区域宽度,概率计算非稳定区域即为 [0.5 - :attr:`eps`, 0.5 + :attr:`eps`] ,非稳定区域的概率计算使用泰勒展开做近似。 - 默认值为 1e-4。 + 默认值为 0.02。 代码示例 ::::::::: @@ -80,7 +80,7 @@ prob(value) **返回** -- Tensor: :attr:`value` 的概率。数据类型与 :attr:`value` 相同。 +- Tensor: :attr:`value` 的概率。数据类型与 :attr:`probability` 相同。 log_prob(value) @@ -94,7 +94,7 @@ log_prob(value) **返回** -- Tensor: :attr:`value` 的对数概率。数据类型与 :attr:`value` 相同。 +- Tensor: :attr:`value` 的对数概率。数据类型与 :attr:`probability` 相同。 cdf(value) @@ -119,7 +119,7 @@ cdf(value) **返回** -- Tensor: :attr:`value` 的累积分布函数对应的 quantile 值。数据类型与 :attr:`value` 相同。 +- Tensor: :attr:`value` 的累积分布函数对应的 quantile 值。数据类型与 :attr:`probability` 相同。 icdf(value) @@ -143,7 +143,7 @@ icdf(value) **返回** -- Tensor: ContinuousBernoulli 随机变量在对应 quantile 下的值。数据类型与 :attr:`value` 相同。 +- Tensor: ContinuousBernoulli 随机变量在对应 quantile 下的值。数据类型与 :attr:`probability` 相同。 sample(shape=()) @@ -157,7 +157,7 @@ sample(shape=()) **返回** -- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape}` 。数据类型为 float32 。 +- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape}` 。 rsample(shape=()) @@ -171,7 +171,7 @@ rsample(shape=()) **返回** -- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape}` 。数据类型为 float32 。 +- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape}` 。 entropy() @@ -185,7 +185,7 @@ entropy() **返回** -类别分布的信息熵,数据类型为 float32。 +类别分布的信息熵。 kl_divergence(other) @@ -203,4 +203,4 @@ kl_divergence(other) **返回** -相对于另一个类别分布的 KL 散度,数据类型为 float32。 +相对于另一个类别分布的 KL 散度。 diff --git a/docs/api/paddle/distribution/MultivariateNormal_cn.rst b/docs/api/paddle/distribution/MultivariateNormal_cn.rst index 86b693712f8..a87355935f4 100644 --- a/docs/api/paddle/distribution/MultivariateNormal_cn.rst +++ b/docs/api/paddle/distribution/MultivariateNormal_cn.rst @@ -25,13 +25,13 @@ MultivariateNormal 是一种定义在实数域上的多元连续型概率分布 参数 ::::::::: -- **loc** (int|float|np.ndarray|Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的均值向量。:attr:`loc` 的数据类型会被转换为 float32 类型。 +- **loc** (int|float|Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的均值向量。如果 :attr:`loc` 的输入数据类型是 `int` 或 `float` 则会被转换为数据类型为 paddle 全局默认数据类型的 1-D Tensor。 -- **covariance_matrix** (Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的协方差矩阵。:attr:`covariance_matrix` 的数据类型会被转换为 float32 类型。 +- **covariance_matrix** (Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的协方差矩阵。:attr:`covariance_matrix` 的数据类型会被转换为与 :attr:`loc` 相同的类型。 -- **precision_matrix** (Tensor) - 是 MultivariateNormal 协方差矩阵的逆矩阵。:attr:`precision_matrix` 的数据类型会被转换为 float32 类型。 +- **precision_matrix** (Tensor) - 是 MultivariateNormal 协方差矩阵的逆矩阵。:attr:`precision_matrix` 的数据类型会被转换为与 :attr:`loc` 相同的类型。 -- **scale_tril** (Tensor) - 是 MultivariateNormal 协方差矩阵的柯列斯基分解的下三角矩阵。:attr:`scale_tril` 的数据类型会被转换为 float32 类型。 +- **scale_tril** (Tensor) - 是 MultivariateNormal 协方差矩阵的柯列斯基分解的下三角矩阵。:attr:`scale_tril` 的数据类型会被转换为与 :attr:`loc` 相同的类型。 代码示例 @@ -74,7 +74,7 @@ prob(value) **返回** -- Tensor: :attr:`value` 的概率。数据类型与 :attr:`value` 相同。 +- Tensor: :attr:`value` 的概率。数据类型与 :attr:`loc` 相同。 log_prob(value) @@ -88,7 +88,7 @@ log_prob(value) **返回** -- Tensor: :attr:`value` 的对数概率。数据类型与 :attr:`value` 相同。 +- Tensor: :attr:`value` 的对数概率。数据类型与 :attr:`loc` 相同。 sample(shape=()) @@ -102,7 +102,7 @@ sample(shape=()) **返回** -- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型为 float32 。 +- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型为 paddle 全局默认数据类型。 rsample(shape=()) @@ -116,7 +116,7 @@ rsample(shape=()) **返回** -- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型为 float32 。 +- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型为 paddle 全局默认数据类型。 entropy() @@ -130,7 +130,7 @@ entropy() **返回** -类别分布的信息熵,数据类型为 float32。 +类别分布的信息熵,数据类型为 paddle 全局默认数据类型。 kl_divergence(other) @@ -148,4 +148,4 @@ kl_divergence(other) **返回** -相对于另一个类别分布的 KL 散度,数据类型为 float32。 +相对于另一个类别分布的 KL 散度,数据类型为 paddle 全局默认数据类型。 From 754bef85a308d0ed1f254082933248926bfaf01d Mon Sep 17 00:00:00 2001 From: AyaseNana <13659110308@163.com> Date: Wed, 13 Dec 2023 15:08:02 +0800 Subject: [PATCH 3/7] update docs --- .../paddle/distribution/ContinuousBernoulli_cn.rst | 8 ++++---- .../paddle/distribution/MultivariateNormal_cn.rst | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst index e8ee159c7d4..8e312b23ad1 100644 --- a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst +++ b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst @@ -80,7 +80,7 @@ prob(value) **返回** -- Tensor: :attr:`value` 的概率。数据类型与 :attr:`probability` 相同。 +- Tensor: :attr:`value` 的概率。数据类型与 `self.probability` 相同。 log_prob(value) @@ -94,7 +94,7 @@ log_prob(value) **返回** -- Tensor: :attr:`value` 的对数概率。数据类型与 :attr:`probability` 相同。 +- Tensor: :attr:`value` 的对数概率。数据类型与 `self.probability` 相同。 cdf(value) @@ -119,7 +119,7 @@ cdf(value) **返回** -- Tensor: :attr:`value` 的累积分布函数对应的 quantile 值。数据类型与 :attr:`probability` 相同。 +- Tensor: :attr:`value` 的累积分布函数对应的 quantile 值。数据类型与 `self.probability` 相同。 icdf(value) @@ -143,7 +143,7 @@ icdf(value) **返回** -- Tensor: ContinuousBernoulli 随机变量在对应 quantile 下的值。数据类型与 :attr:`probability` 相同。 +- Tensor: ContinuousBernoulli 随机变量在对应 quantile 下的值。数据类型与 `self.probability` 相同。 sample(shape=()) diff --git a/docs/api/paddle/distribution/MultivariateNormal_cn.rst b/docs/api/paddle/distribution/MultivariateNormal_cn.rst index a87355935f4..16adb4ee6a2 100644 --- a/docs/api/paddle/distribution/MultivariateNormal_cn.rst +++ b/docs/api/paddle/distribution/MultivariateNormal_cn.rst @@ -74,7 +74,7 @@ prob(value) **返回** -- Tensor: :attr:`value` 的概率。数据类型与 :attr:`loc` 相同。 +- Tensor: :attr:`value` 的概率。数据类型与 `self.loc` 相同。 log_prob(value) @@ -88,7 +88,7 @@ log_prob(value) **返回** -- Tensor: :attr:`value` 的对数概率。数据类型与 :attr:`loc` 相同。 +- Tensor: :attr:`value` 的对数概率。数据类型与 `self.loc` 相同。 sample(shape=()) @@ -102,7 +102,7 @@ sample(shape=()) **返回** -- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型为 paddle 全局默认数据类型。 +- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型与 `self.loc` 相同。 rsample(shape=()) @@ -116,7 +116,7 @@ rsample(shape=()) **返回** -- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型为 paddle 全局默认数据类型。 +- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型与 `self.loc` 相同。 entropy() @@ -130,7 +130,7 @@ entropy() **返回** -类别分布的信息熵,数据类型为 paddle 全局默认数据类型。 +类别分布的信息熵,数据类型与 `self.loc` 相同。 kl_divergence(other) @@ -148,4 +148,4 @@ kl_divergence(other) **返回** -相对于另一个类别分布的 KL 散度,数据类型为 paddle 全局默认数据类型。 +相对于另一个类别分布的 KL 散度,数据类型与 `self.loc` 相同。 From f308f4bdcb806736126e6cf4fcbe3407492a147e Mon Sep 17 00:00:00 2001 From: AyaseNana <13659110308@163.com> Date: Wed, 13 Dec 2023 20:25:39 +0800 Subject: [PATCH 4/7] update cb reference --- docs/api/paddle/distribution/ContinuousBernoulli_cn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst index 8e312b23ad1..02d7e92df58 100644 --- a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst +++ b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst @@ -7,7 +7,7 @@ ContinuousBernoulli ContinuousBernoulli 是一种定义在 [0,1] 区间上的连续型概率分布,参数 :attr:`probability` 描述了其概率密度函数的形状。它可以被视为连续型的伯努利分布。 -出自 [1] Loaiza-Ganem, G., & Cunningham, J. P. The continuous Bernoulli: fixing a pervasive error in variational autoencoders. 2019. +出自 `The continuous Bernoulli: fixing a pervasive error in variational autoencoders. `_ 其概率密度函数(pdf)为: From 2e104efa7a42b2c41c2c3629734ca3cd721bf694 Mon Sep 17 00:00:00 2001 From: AyaseNana <13659110308@163.com> Date: Thu, 14 Dec 2023 13:07:18 +0800 Subject: [PATCH 5/7] update cb api --- .../distribution/ContinuousBernoulli_cn.rst | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst index 02d7e92df58..d90d9dd939b 100644 --- a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst +++ b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst @@ -3,10 +3,10 @@ ContinuousBernoulli ------------------------------- -.. py:class:: paddle.distribution.ContinuousBernoulli(probability, eps=0.02) +.. py:class:: paddle.distribution.ContinuousBernoulli(probs, eps=0.02) -ContinuousBernoulli 是一种定义在 [0,1] 区间上的连续型概率分布,参数 :attr:`probability` 描述了其概率密度函数的形状。它可以被视为连续型的伯努利分布。 +ContinuousBernoulli 是一种定义在 [0,1] 区间上的连续型概率分布,参数 :attr:`probs` 描述了其概率密度函数的形状。它可以被视为连续型的伯努利分布。 出自 `The continuous Bernoulli: fixing a pervasive error in variational autoencoders. `_ 其概率密度函数(pdf)为: @@ -34,11 +34,10 @@ ContinuousBernoulli 是一种定义在 [0,1] 区间上的连续型概率分布 参数 ::::::::: -- **probability** (int|float|Tensor) - 即上述公式中 :math:`\lambda` 参数,在 [0, 1] 内,刻画 ContinuousBernoulli 分布的 - 概率密度函数的形状。如果 :attr:`probability` 的输入数据类型是 `int` 或 `float` ,则会被转换为数据类型为 paddle 全局默认数据类型的 1-D Tensor。 +- **probs** (int|float|Tensor) - 即上述公式中 :math:`\lambda` 参数,在 [0, 1] 内,刻画 ContinuousBernoulli 分布的 + 概率密度函数的形状。如果 :attr:`probs` 的输入数据类型是 `int` 或 `float` ,则会被转换为数据类型为 paddle 全局默认数据类型的 1-D Tensor。 -- **eps** (float) - 表示概率计算非稳定区域的区域宽度,概率计算非稳定区域即为 [0.5 - :attr:`eps`, 0.5 + :attr:`eps`] ,非稳定区域的概率计算使用泰勒展开做近似。 - 默认值为 0.02。 +- **lims** (float) - 表示概率计算非稳定区域的区域宽度,非稳定区域的概率计算使用泰勒展开做近似。默认值为 (0.499, 0.501)。 代码示例 ::::::::: @@ -80,7 +79,7 @@ prob(value) **返回** -- Tensor: :attr:`value` 的概率。数据类型与 `self.probability` 相同。 +- Tensor: :attr:`value` 的概率。数据类型与 `self.probs` 相同。 log_prob(value) @@ -94,7 +93,7 @@ log_prob(value) **返回** -- Tensor: :attr:`value` 的对数概率。数据类型与 `self.probability` 相同。 +- Tensor: :attr:`value` 的对数概率。数据类型与 `self.probs` 相同。 cdf(value) @@ -119,7 +118,7 @@ cdf(value) **返回** -- Tensor: :attr:`value` 的累积分布函数对应的 quantile 值。数据类型与 `self.probability` 相同。 +- Tensor: :attr:`value` 的累积分布函数对应的 quantile 值。数据类型与 `self.probs` 相同。 icdf(value) @@ -143,7 +142,7 @@ icdf(value) **返回** -- Tensor: ContinuousBernoulli 随机变量在对应 quantile 下的值。数据类型与 `self.probability` 相同。 +- Tensor: ContinuousBernoulli 随机变量在对应 quantile 下的值。数据类型与 `self.probs` 相同。 sample(shape=()) From b5b25f860b5e2ecc0d5341519c0929d0f95c6994 Mon Sep 17 00:00:00 2001 From: AyaseNana <13659110308@163.com> Date: Thu, 14 Dec 2023 16:35:40 +0800 Subject: [PATCH 6/7] update docs --- .../distribution/ContinuousBernoulli_cn.rst | 40 +++++++++---------- .../distribution/MultivariateNormal_cn.rst | 32 +++++++-------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst index d90d9dd939b..a95b60ac545 100644 --- a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst +++ b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst @@ -3,7 +3,7 @@ ContinuousBernoulli ------------------------------- -.. py:class:: paddle.distribution.ContinuousBernoulli(probs, eps=0.02) +.. py:class:: paddle.distribution.ContinuousBernoulli(probs, lims=(0.499, 0.501)) ContinuousBernoulli 是一种定义在 [0,1] 区间上的连续型概率分布,参数 :attr:`probs` 描述了其概率密度函数的形状。它可以被视为连续型的伯努利分布。 @@ -34,10 +34,10 @@ ContinuousBernoulli 是一种定义在 [0,1] 区间上的连续型概率分布 参数 ::::::::: -- **probs** (int|float|Tensor) - 即上述公式中 :math:`\lambda` 参数,在 [0, 1] 内,刻画 ContinuousBernoulli 分布的 - 概率密度函数的形状。如果 :attr:`probs` 的输入数据类型是 `int` 或 `float` ,则会被转换为数据类型为 paddle 全局默认数据类型的 1-D Tensor。 + - **probs** (int|float|Tensor) - 即上述公式中 :math:`\lambda` 参数,在 [0, 1] 内,刻画 ContinuousBernoulli 分布的 + 概率密度函数的形状。如果 :attr:`probs` 的输入数据类型是 `int` 或 `float` ,则会被转换为数据类型为 paddle 全局默认数据类型的 1-D Tensor。 -- **lims** (float) - 表示概率计算非稳定区域的区域宽度,非稳定区域的概率计算使用泰勒展开做近似。默认值为 (0.499, 0.501)。 + - **lims** (tuple) - 表示概率计算非稳定区域的区域宽度,非稳定区域的概率计算使用泰勒展开做近似。默认值为 (0.499, 0.501)。 代码示例 ::::::::: @@ -75,11 +75,11 @@ prob(value) **参数** -- **value** (Tensor) - 待计算值。 + - **value** (Tensor) - 待计算值。 **返回** -- Tensor: :attr:`value` 的概率。数据类型与 `self.probs` 相同。 +Tensor,:attr:`value` 的概率。数据类型与 `self.probs` 相同。 log_prob(value) @@ -89,11 +89,11 @@ log_prob(value) **参数** -- **value** (Tensor) - 待计算值。 + - **value** (Tensor) - 待计算值。 **返回** -- Tensor: :attr:`value` 的对数概率。数据类型与 `self.probs` 相同。 +Tensor,:attr:`value` 的对数概率。数据类型与 `self.probs` 相同。 cdf(value) @@ -114,11 +114,11 @@ cdf(value) **参数** -- **value** (Tensor) - 待计算值。 + - **value** (Tensor) - 待计算值。 **返回** -- Tensor: :attr:`value` 的累积分布函数对应的 quantile 值。数据类型与 `self.probs` 相同。 +Tensor: :attr:`value` 的累积分布函数对应的 quantile 值。数据类型与 `self.probs` 相同。 icdf(value) @@ -138,11 +138,11 @@ icdf(value) **参数** -- **value** (Tensor) - 待计算 quantile。 + - **value** (Tensor) - 待计算 quantile。 **返回** -- Tensor: ContinuousBernoulli 随机变量在对应 quantile 下的值。数据类型与 `self.probs` 相同。 +Tensor,ContinuousBernoulli 随机变量在对应 quantile 下的值。数据类型与 `self.probs` 相同。 sample(shape=()) @@ -152,11 +152,11 @@ sample(shape=()) **参数** -- **shape** (Sequence[int],可选):采样次数。 + - **shape** (Sequence[int],可选):采样次数。 **返回** -- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape}` 。 +Tensor,样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape}` 。 rsample(shape=()) @@ -166,11 +166,11 @@ rsample(shape=()) **参数** -- **shape** (Sequence[int],可选):采样次数。 + - **shape** (Sequence[int],可选):采样次数。 **返回** -- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape}` 。 +Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape}` 。 entropy() @@ -184,13 +184,13 @@ entropy() **返回** -类别分布的信息熵。 +连续伯努利分布的信息熵。 kl_divergence(other) ''''''''' -相对于另一个类别分布的 KL 散度,两个分布需要有相同的 :math:`\text{batch shape}`。 +相对于另一个连续伯努利分布的 KL 散度,两个分布需要有相同的 :math:`\text{batch shape}`。 .. math:: @@ -198,8 +198,8 @@ kl_divergence(other) **参数** - - **other** (ContinuousBernoulli) - 输入的另一个类别分布。 + - **other** (ContinuousBernoulli) - 输入的另一个连续伯努利分布。 **返回** -相对于另一个类别分布的 KL 散度。 +相对于另一个连续伯努利分布的 KL 散度。 diff --git a/docs/api/paddle/distribution/MultivariateNormal_cn.rst b/docs/api/paddle/distribution/MultivariateNormal_cn.rst index 16adb4ee6a2..17933b2e259 100644 --- a/docs/api/paddle/distribution/MultivariateNormal_cn.rst +++ b/docs/api/paddle/distribution/MultivariateNormal_cn.rst @@ -25,13 +25,13 @@ MultivariateNormal 是一种定义在实数域上的多元连续型概率分布 参数 ::::::::: -- **loc** (int|float|Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的均值向量。如果 :attr:`loc` 的输入数据类型是 `int` 或 `float` 则会被转换为数据类型为 paddle 全局默认数据类型的 1-D Tensor。 + - **loc** (int|float|Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的均值向量。如果 :attr:`loc` 的输入数据类型是 `int` 或 `float` 则会被转换为数据类型为 paddle 全局默认数据类型的 1-D Tensor。 -- **covariance_matrix** (Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的协方差矩阵。:attr:`covariance_matrix` 的数据类型会被转换为与 :attr:`loc` 相同的类型。 + - **covariance_matrix** (Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的协方差矩阵。:attr:`covariance_matrix` 的数据类型会被转换为与 :attr:`loc` 相同的类型。默认值为 None。 -- **precision_matrix** (Tensor) - 是 MultivariateNormal 协方差矩阵的逆矩阵。:attr:`precision_matrix` 的数据类型会被转换为与 :attr:`loc` 相同的类型。 + - **precision_matrix** (Tensor) - 是 MultivariateNormal 协方差矩阵的逆矩阵。:attr:`precision_matrix` 的数据类型会被转换为与 :attr:`loc` 相同的类型。默认值为 None。 -- **scale_tril** (Tensor) - 是 MultivariateNormal 协方差矩阵的柯列斯基分解的下三角矩阵。:attr:`scale_tril` 的数据类型会被转换为与 :attr:`loc` 相同的类型。 + - **scale_tril** (Tensor) - 是 MultivariateNormal 协方差矩阵的柯列斯基分解的下三角矩阵。:attr:`scale_tril` 的数据类型会被转换为与 :attr:`loc` 相同的类型。默认值为 None。 代码示例 @@ -70,11 +70,11 @@ prob(value) **参数** -- **value** (Tensor) - 待计算值。 + - **value** (Tensor) - 待计算值。 **返回** -- Tensor: :attr:`value` 的概率。数据类型与 `self.loc` 相同。 +Tensor,:attr:`value` 的概率。数据类型与 `self.loc` 相同。 log_prob(value) @@ -84,11 +84,11 @@ log_prob(value) **参数** -- **value** (Tensor) - 待计算值。 + - **value** (Tensor) - 待计算值。 **返回** -- Tensor: :attr:`value` 的对数概率。数据类型与 `self.loc` 相同。 +Tensor,:attr:`value` 的对数概率。数据类型与 `self.loc` 相同。 sample(shape=()) @@ -98,11 +98,11 @@ sample(shape=()) **参数** -- **shape** (Sequence[int],可选):采样次数。 + - **shape** (Sequence[int],可选):采样次数。 **返回** -- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型与 `self.loc` 相同。 +Tensor,样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型与 `self.loc` 相同。 rsample(shape=()) @@ -112,11 +112,11 @@ rsample(shape=()) **参数** -- **shape** (Sequence[int],可选):采样次数。 + - **shape** (Sequence[int],可选):采样次数。 **返回** -- Tensor:样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型与 `self.loc` 相同。 +Tensor,样本数据。其维度为 :math:`\text{sample shape} + \text{batch shape} + \text{event shape}` 。数据类型与 `self.loc` 相同。 entropy() @@ -130,13 +130,13 @@ entropy() **返回** -类别分布的信息熵,数据类型与 `self.loc` 相同。 +多元正态分布的信息熵,数据类型与 `self.loc` 相同。 kl_divergence(other) ''''''''' -相对于另一个类别分布的 KL 散度,两个分布需要有相同的 :math:`\text{batch shape}` 和 :math:`\text{event shape}`。 +相对于另一个多元正态分布的 KL 散度,两个分布需要有相同的 :math:`\text{batch shape}` 和 :math:`\text{event shape}`。 .. math:: @@ -144,8 +144,8 @@ kl_divergence(other) **参数** - - **other** (MultivariateNormal) - 输入的另一个类别分布。 + - **other** (MultivariateNormal) - 输入的另一个多元正态分布。 **返回** -相对于另一个类别分布的 KL 散度,数据类型与 `self.loc` 相同。 +相对于另一个多元正态分布的 KL 散度,数据类型与 `self.loc` 相同。 From edcef72452b2bd45ac3f7eba8d4aed6a90f5b87c Mon Sep 17 00:00:00 2001 From: AyaseNana <49900969+NKNaN@users.noreply.github.com> Date: Mon, 18 Dec 2023 11:39:07 +0800 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: zachary sun <70642955+sunzhongkai588@users.noreply.github.com> --- docs/api/paddle/distribution/ContinuousBernoulli_cn.rst | 2 +- docs/api/paddle/distribution/MultivariateNormal_cn.rst | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst index a95b60ac545..41b72024718 100644 --- a/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst +++ b/docs/api/paddle/distribution/ContinuousBernoulli_cn.rst @@ -37,7 +37,7 @@ ContinuousBernoulli 是一种定义在 [0,1] 区间上的连续型概率分布 - **probs** (int|float|Tensor) - 即上述公式中 :math:`\lambda` 参数,在 [0, 1] 内,刻画 ContinuousBernoulli 分布的 概率密度函数的形状。如果 :attr:`probs` 的输入数据类型是 `int` 或 `float` ,则会被转换为数据类型为 paddle 全局默认数据类型的 1-D Tensor。 - - **lims** (tuple) - 表示概率计算非稳定区域的区域宽度,非稳定区域的概率计算使用泰勒展开做近似。默认值为 (0.499, 0.501)。 + - **lims** (tuple,可选) - 表示概率计算非稳定区域的区域宽度,非稳定区域的概率计算使用泰勒展开做近似。默认值为 (0.499, 0.501)。 代码示例 ::::::::: diff --git a/docs/api/paddle/distribution/MultivariateNormal_cn.rst b/docs/api/paddle/distribution/MultivariateNormal_cn.rst index 17933b2e259..3d09e3803c5 100644 --- a/docs/api/paddle/distribution/MultivariateNormal_cn.rst +++ b/docs/api/paddle/distribution/MultivariateNormal_cn.rst @@ -27,11 +27,11 @@ MultivariateNormal 是一种定义在实数域上的多元连续型概率分布 - **loc** (int|float|Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的均值向量。如果 :attr:`loc` 的输入数据类型是 `int` 或 `float` 则会被转换为数据类型为 paddle 全局默认数据类型的 1-D Tensor。 - - **covariance_matrix** (Tensor) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的协方差矩阵。:attr:`covariance_matrix` 的数据类型会被转换为与 :attr:`loc` 相同的类型。默认值为 None。 + - **covariance_matrix** (Tensor,可选) - 即上述公式中 :math:`\mu` 参数,是 MultivariateNormal 的协方差矩阵。:attr:`covariance_matrix` 的数据类型会被转换为与 :attr:`loc` 相同的类型。默认值为 None。 - - **precision_matrix** (Tensor) - 是 MultivariateNormal 协方差矩阵的逆矩阵。:attr:`precision_matrix` 的数据类型会被转换为与 :attr:`loc` 相同的类型。默认值为 None。 + - **precision_matrix** (Tensor,可选) - 是 MultivariateNormal 协方差矩阵的逆矩阵。:attr:`precision_matrix` 的数据类型会被转换为与 :attr:`loc` 相同的类型。默认值为 None。 - - **scale_tril** (Tensor) - 是 MultivariateNormal 协方差矩阵的柯列斯基分解的下三角矩阵。:attr:`scale_tril` 的数据类型会被转换为与 :attr:`loc` 相同的类型。默认值为 None。 + - **scale_tril** (Tensor,可选) - 是 MultivariateNormal 协方差矩阵的柯列斯基分解的下三角矩阵。:attr:`scale_tril` 的数据类型会被转换为与 :attr:`loc` 相同的类型。默认值为 None。 代码示例