-
Notifications
You must be signed in to change notification settings - Fork 876
【Hackathon 6th No.5】Add chi2/LKJCholesky API to Paddle #6627
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ec805a7
【Hackathon 6th No.5】Add chi2/LKJCholesky API to Paddle
cmcamdy 518a9a8
fix doc
cmcamdy da32606
fix lkj
cmcamdy c9b074f
fix lkj
cmcamdy f91f8f9
add doc distribution overview cn
cmcamdy 2b75a5e
add doc distribution overview cn
cmcamdy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| .. _cn_api_paddle_distribution_Chi2: | ||
|
|
||
| Chi2 | ||
| ------------------------------- | ||
| .. py:class:: paddle.distribution.Chi2(df) | ||
|
|
||
|
|
||
| 卡方分布是基于标准正态分布随机变量的平方和定义的一种连续概率分布。如果有 *k* 个独立的标准正态分布随机变量 | ||
| :math:`Z_1, Z_2, \ldots, Z_k`, 那么这些随机变量的平方和 | ||
| :math:`X = Z_1^2 + Z_2^2 + \cdots + Z_k^2` | ||
|
|
||
| 服从自由度为 *k* 的卡方分布,记作 | ||
| :math:`X \sim \chi^2(k)` | ||
|
|
||
|
|
||
|
|
||
| 参数 | ||
| :::::::::::: | ||
|
|
||
| - **df** (float|Tensor) - 参数表示自由度,该值必须大于零。支持 Broadcast 语义。当参数类型为 Tensor 时,表示批量创建多个不同参数的分布,``batch_shape`` (参考 :ref:`cn_api_paddle_distribution_Distribution` 基类) 为参数。 | ||
|
|
||
| 代码示例 | ||
| :::::::::::: | ||
|
|
||
| COPY-FROM: paddle.distribution.Chi2 | ||
|
|
||
|
|
||
| 属性 | ||
| ::::::::: | ||
|
|
||
| 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) - Chi2 的实例。 | ||
|
|
||
| **返回** | ||
|
|
||
| - Tensor: 两个卡方分布之间的 KL 散度。 | ||
|
|
||
|
|
||
| sample(shape) | ||
| ''''''''' | ||
| 随机采样,生成指定维度的样本。 | ||
|
|
||
| **参数** | ||
|
|
||
| - **shape** (Sequence[int], optional) - 采样的样本维度。 | ||
|
|
||
| **返回** | ||
|
|
||
| - **Tensor** - 指定维度的样本数据。数据类型为 float32。 | ||
|
|
||
|
|
||
| rsample(shape) | ||
| ''''''''' | ||
| 重参数化采样,生成指定维度的样本。 | ||
|
|
||
| **参数** | ||
|
|
||
| - **shape** (Sequence[int], optional) - 重参数化采样的样本维度。 | ||
|
|
||
| **返回** | ||
|
|
||
| - **Tensor** - 指定维度的样本数据。数据类型为 float32。 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| .. _cn_api_paddle_distribution_LKJCholesky: | ||
|
|
||
| LKJCholesky | ||
| ------------------------------- | ||
| .. py:class:: paddle.distribution.LKJCholesky(dim, concentration=1.0, sample_method = 'onion') | ||
|
|
||
|
|
||
|
|
||
| LKJ 分布是一种用于生成随机相关矩阵的概率分布,广泛应用于贝叶斯统计中,特别是作为协方差矩阵的先验分布。它能够调节相关矩阵的集中度,从而控制变量间的相关性。 | ||
|
|
||
| LKJ 分布通常定义为对相关矩阵 :math:`\Omega` 的分布,其密度函数为: | ||
|
|
||
| .. math:: | ||
|
|
||
| p(\Omega \mid \eta) \propto |\Omega|^{\eta - 1} | ||
|
|
||
| 其中,:math:`\Omega` 是一个 :math:`n \times n` 的相关矩阵,:math:`\eta` 是分布的形状参数,:math:`|\Omega|` 是矩阵的行列式。参数 :math:`\eta` 调节矩阵元素的分布集中度。 | ||
|
|
||
|
|
||
| 相关矩阵的下三角 Choleskey 因子的 LJK 分布支持两种 sample 方法:`onion` 和 `cvine` | ||
|
|
||
| 参数 | ||
| :::::::::::: | ||
|
|
||
| - **dim** (int) - 目标相关矩阵的维度。 | ||
| - **concentration** (float|Tensor) - 集中参数,这个参数控制了生成的相关矩阵的分布,值必须大于 0。concentration 越大,生成的矩阵越接近单位矩阵。 | ||
| - **sample_method** (str) - 不同采样策略,可选项有:`onion` 和 `cvine`. 这两种 sample 方法都在 `Generating random correlation matrices based on vines and extended onion method <https://www.sciencedirect.com/science/article/pii/S0047259X09000876>`_ 中提出,并且在相关矩阵上提供相同的分布。但是它们在如何生成样本方面是不同的。默认为“onion”。 | ||
| 代码示例 | ||
| :::::::::::: | ||
|
|
||
| COPY-FROM: paddle.distribution.LKJCholesky | ||
|
|
||
|
|
||
| 方法 | ||
| ::::::::: | ||
|
|
||
|
|
||
| log_prob(value) | ||
| ''''''''' | ||
| 卡方分布的对数概率密度函数。 | ||
|
|
||
| **参数** | ||
|
|
||
| - **value** (float|Tensor) - 输入值。 | ||
|
|
||
| **返回** | ||
|
|
||
| - **Tensor** - value 对应的对数概率密度。 | ||
|
|
||
|
|
||
|
|
||
| sample(shape) | ||
| ''''''''' | ||
| 随机采样,生成指定维度的样本。 | ||
|
|
||
| **参数** | ||
|
|
||
| - **shape** (Sequence[int], optional) - 采样的样本维度。 | ||
|
|
||
| **返回** | ||
|
|
||
| - **Tensor** - 指定维度的样本数据。数据类型为 float32。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.