Skip to content

【Hackathon 5th No.20】为 Paddle 新增 Exponential 和 Gamma API #6413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions docs/api/paddle/distribution/Exponential_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
.. _cn_api_paddle_distribution_Exponential:

Exponential
-------------------------------

.. py:class:: paddle.distribution.Exponential(rate)

指数分布

指数分布的概率密度满足一下公式:

.. math::

f(x; \theta) = \theta e^{- \theta x }, (x \ge 0) $$

上面数学公式中:

:math:`rate=\theta`:表示率参数。


参数
::::::::::::

- **rate** (float|Tensor) - 率参数,该值必须大于零。

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

COPY-FROM: paddle.distribution.Exponential

属性
:::::::::

mean
'''''''''
指数分布的均值。


variance
'''''''''
指数分布的方差。


方法
:::::::::

prob(value)
'''''''''
指数分布的概率密度函数。

**参数**

- **value** (float|Tensor) - 输入值。

数学公式:
.. math::

f(x; \theta) = \theta e^{- \theta x }, (x \ge 0) $$

上面数学公式中:

:math:`rate=\theta`:表示率参数。

**返回**

- **Tensor** - value 对应的概率密度。


log_prob(value)
'''''''''
指数分布的对数概率密度函数。

**参数**

- **value** (float|Tensor) - 输入值。

**返回**

- **Tensor** - value 对应的对数概率密度。

entropy()
'''''''''
指数分布的信息熵。

**返回**

- Tensor: 信息熵。

cdf(k)
'''''''''
指数分布的累积分布函数。

**参数**

- **value** (float|Tensor) - 输入值。

数学公式:

.. math::

cdf(x; \theta) = 1 - e^{- \theta x }, (x \ge 0)

上面的数学公式中:

:math:`rate=\theta`:表示率参数。

**返回**

- Tensor: value 对应的累积分布。

icdf(k)
'''''''''
指数分布的逆累积分布函数。

**参数**

- **value** (float|Tensor) - 输入值。

数学公式:

.. math::

icdf(x; \theta) = -\frac{ 1 }{ \theta } ln(1 + x), (x \ge 0)

上面的数学公式中:

:math:`rate=\theta`:表示率参数。

**返回**

- Tensor: value 对应的逆累积分布。


kl_divergence(other)
'''''''''
两个指数分布之间的 KL 散度。

**参数**

- **other** (Geometric) - Exponential 的实例。

**返回**

- Tensor: 两个指数分布之间的 KL 散度。


sample(shape)
'''''''''
随机采样,生成指定维度的样本。

**参数**

- **shape** (Sequence[int], optional) - 采样的样本维度。

**返回**

- **Tensor** - 指定维度的样本数据。数据类型为 float32。


rsample(shape)
'''''''''
重参数化采样,生成指定维度的样本。

**参数**

- **shape** (Sequence[int], optional) - 重参数化采样的样本维度。

**返回**

- **Tensor** - 指定维度的样本数据。数据类型为 float32。
126 changes: 126 additions & 0 deletions docs/api/paddle/distribution/Gamma_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
.. _cn_api_paddle_distribution_Gamma:

Gamma
-------------------------------

.. py:class:: paddle.distribution.Gamma(concentration, rate)

伽马分布

伽马分布的概率密度满足一下公式:

.. math::

f(x; \alpha, \beta, x > 0) = \frac{\beta^{\alpha}}{\Gamma(\alpha)} x^{\alpha-1}e^{-\beta x}

\Gamma(\alpha)=\int_{0}^{\infty} x^{\alpha-1} e^{-x} \mathrm{~d} x, (\alpha>0)

上面数学公式中:

:math:`concentration=\alpha`:表示集中参数。

:math:`rate=\beta`:表示率参数。


参数
::::::::::::

- **concentration** (float|Tensor) - 率参数,该值必须大于零。支持 Broadcast 语义。当参数类型为 Tensor 时,表示批量创建多个不同参数的分布,``batch_shape`` (参考 :ref:`cn_api_paddle_distribution_Distribution` 基类) 为参数。

- **rate** (float|Tensor) - 率参数,该值必须大于零。支持 Broadcast 语义。当参数类型为 Tensor 时,表示批量创建多个不同参数的分布,``batch_shape`` (参考 :ref:`cn_api_paddle_distribution_Distribution` 基类) 为参数。

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

COPY-FROM: paddle.distribution.Gamma


属性
:::::::::

mean
'''''''''
伽马分布的均值。


variance
'''''''''
伽马分布的方差。


方法
:::::::::

prob(value)
'''''''''
伽马分布的概率密度函数。

**参数**

- **value** (float|Tensor) - 输入值。


**返回**

- **Tensor** - value 对应的概率密度。


log_prob(value)
'''''''''
伽马分布的对数概率密度函数。

**参数**

- **value** (float|Tensor) - 输入值。

**返回**

- **Tensor** - value 对应的对数概率密度。


entropy()
'''''''''
伽马分布的信息熵。

**返回**

- Tensor: 信息熵。


kl_divergence(other)
'''''''''
两个伽马分布之间的 KL 散度。

**参数**

- **other** (Geometric) - Gamma 的实例。

**返回**

- Tensor: 两个伽马分布之间的 KL 散度。


sample(shape)
'''''''''
随机采样,生成指定维度的样本。

**参数**

- **shape** (Sequence[int], optional) - 采样的样本维度。

**返回**

- **Tensor** - 指定维度的样本数据。数据类型为 float32。


rsample(shape)
'''''''''
重参数化采样,生成指定维度的样本。

**参数**

- **shape** (Sequence[int], optional) - 重参数化采样的样本维度。

**返回**

- **Tensor** - 指定维度的样本数据。数据类型为 float32。
2 changes: 2 additions & 0 deletions docs/api/paddle/distribution/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ paddle.distribution 目录下包含飞桨框架支持的随机变量的概率分
" :ref:`LogNormal <cn_api_paddle_distribution_LogNormal>` ", "LogNormal 概率分布类"
" :ref:`Gumbel <cn_api_paddle_distribution_Gumbel>` ", "Gumbel 概率分布类"
" :ref:`Geometric <cn_api_paddle_distribution_Geometric>` ", "Geometric 概率分布类"
" :ref:`Exponential <cn_api_paddle_distribution_Exponential>` ", "Exponential 概率分布类"
" :ref:`Gamma <cn_api_paddle_distribution_Gamma>` ", "Gamma 概率分布类"

.. _about_distribution_transform:

Expand Down