-
Notifications
You must be signed in to change notification settings - Fork 876
【Hackathon 6th No.11】Add log_normal and log_normal_ API to Paddle #6664
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
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
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 |
|---|---|---|
|
|
@@ -172,6 +172,7 @@ Methods | |
| logical_not | ||
| logical_or | ||
| logical_xor | ||
| log_normal_ | ||
| logsumexp | ||
| masked_select | ||
| matmul | ||
|
|
||
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
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,12 @@ | ||
| .. _cn_api_paddle_log_normal_: | ||
|
|
||
| log\_normal\_ | ||
| ------------------------------- | ||
|
|
||
| .. py:function:: paddle.log_normal_(x, mean=1.0, std=2.0, name=None) | ||
|
|
||
| Inplace 版本的 :ref:`cn_api_paddle_log_normal` API,对输入 `x` 采用 Inplace 策略。 | ||
|
|
||
| 更多关于 inplace 操作的介绍请参考 `3.1.3 原位(Inplace)操作和非原位操作的区别`_ 了解详情。 | ||
|
|
||
| .. _3.1.3 原位(Inplace)操作和非原位操作的区别: https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/beginner/tensor_cn.html#id3 |
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,40 @@ | ||
| .. _cn_api_paddle_log_normal: | ||
|
|
||
| log\_normal | ||
| ------------------------------- | ||
|
|
||
| .. py:function:: paddle.log_normal(mean=1.0, std=2.0, shape=None, name=None) | ||
|
|
||
|
|
||
| 返回符合对数正态分布(对应正态分布的均值为 ``mean``,标准差为 ``std``)的随机 Tensor,对数正态分布的分布函数如下 | ||
|
|
||
| .. math:: | ||
|
|
||
| f(x) = \frac{1}{x\sigma\sqrt{2\pi}}e^{-\frac{(\ln{x}-\mu)^2}{2\sigma^2}} | ||
|
|
||
| 其中: | ||
|
|
||
| - :math:`mu` 表示对应正态分布的平均值。 | ||
| - :math:`sigma` 表示对应正态分布的标准差。 | ||
|
|
||
| 如果 ``mean`` 是 Tensor,则输出 Tensor 和 ``mean`` 具有相同的形状和数据类型。 | ||
| 如果 ``mean`` 不是 Tensor,且 ``std`` 是 Tensor,则输出 Tensor 和 ``std`` 具有相同的形状和数据类型。 | ||
| 如果 ``mean`` 和 ``std`` 都不是 Tensor,则输出 Tensor 的形状为 ``shape``,数据类型为 float32。 | ||
| 如果 ``mean`` 和 ``std`` 都是 Tensor,则 ``mean`` 和 ``std`` 的元素个数应该相同。 | ||
|
|
||
| 参数 | ||
| :::::::::: | ||
|
|
||
| - **mean** (float|Tensor,可选) - 输出 Tensor 对应正态分布的平均值。如果 ``mean`` 是 float,则表示输出 Tensor 中所有元素的正态分布的平均值。如果 ``mean`` 是 Tensor (支持的数据类型为 float32、float64),则表示输出 Tensor 中每个元素对应正态分布的平均值。默认值为 1.0。 | ||
| - **std** (float|Tensor,可选) - 输出 Tensor 对应正态分布的标准差。如果 ``std`` 是 float,则表示输出 Tensor 中所有元素的正态分布的标准差。如果 ``std`` 是 Tensor (支持的数据类型为 float32、float64),则表示输出 Tensor 中每个元素对应正态分布的标准差。默认值为 2.0。 | ||
| - **shape** (list|tuple|Tensor,可选) - 生成的随机 Tensor 的形状。如果 ``shape`` 是 list、tuple,则其中的元素可以是 int,或者是形状为[]且数据类型为 int32、int64 的 0-D Tensor。如果 ``shape`` 是 Tensor,则是数据类型为 int32、int64 的 1D Tensor。如果 ``mean`` 或者 ``std`` 是 Tensor,输出 Tensor 的形状和 ``mean`` 或者 ``std`` 相同(此时 ``shape`` 无效)。默认值为 None。 | ||
| - **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||
|
|
||
| 返回 | ||
| :::::::::: | ||
| Tensor,符合对数正态分布(对应正态分布的均值为 ``mean``,标准差为 ``std``)的随机 Tensor。 | ||
|
|
||
| 示例代码 | ||
| :::::::::: | ||
|
|
||
| COPY-FROM: paddle.log_normal | ||
33 changes: 33 additions & 0 deletions
33
..._convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log_normal_.md
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,33 @@ | ||
| ## [ torch 参数更多 ]torch.Tensor.log_normal_ | ||
|
|
||
| ### [torch.Tensor.log_normal_](https://pytorch.org/docs/stable/generated/torch.Tensor.log_normal_.html#torch-tensor-log-normal) | ||
|
|
||
| ```python | ||
| torch.Tensor.log_normal_(mean=1, std=2, *, generator=None) | ||
| ``` | ||
|
|
||
| ### [paddle.Tensor.log_normal_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#log_normal-mean-1-0-std-2-0-shape-none-name-none) | ||
|
|
||
| ```python | ||
| paddle.Tensor.log_normal_(mean=1.0, std=2.0, name=None) | ||
| ``` | ||
|
|
||
| PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
|
||
| ### 参数映射 | ||
|
|
||
| | PyTorch | PaddlePaddle | 备注 | | ||
| | ------------- | ------------ | ----------------------------------------------------------------------------------- | | ||
| | generator | - | 用于采样的伪随机数生成器, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
|
|
||
| ### 转写示例 | ||
|
|
||
| ```python | ||
| # torch 写法 | ||
| x = torch.randn(2, 3) | ||
| y = x.log_normal_() | ||
|
|
||
| # paddle 写法 | ||
| x = paddle.randn([2, 3]) | ||
| y = x.log_normal_() | ||
| ``` |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
既然英文文档都写公式了,中文文档也同步加一下吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已添加