335 Star 1.5K Fork 861

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
standard_laplace.md 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
TingWang 提交于 2023-09-18 10:08 . update link logo

比较与torch.distributions.laplace.Laplace的差异

查看源文件

torch.distributions.laplace.Laplace

torch.distributions.laplace.Laplace(loc, scale) -> Class Instance

更多内容详见torch.distributions.laplace.Laplace

mindspore.ops.standard_laplace

mindspore.ops.standard_laplace(shape, seed=None) -> Tensor

更多内容详见mindspore.ops.standard_laplace

差异对比

PyTorch:创建一个Laplace分布实例,调用该实例sample接口进行采样可以生成符合Laplace分布的随机值。

MindSpore:生成符合标准Laplace(mean=0, lambda=1)分布的随机数。当PyTorch中loc=0,scale=1,sample函数输入shape与MindSpore一致时,两API实现功能一致。

分类 子类 PyTorch MindSpore 差异
参数 参数1 loc - MindSpore无此参数,默认实现loc=0的功能
参数2 scale - MindSpore无此参数,默认实现scale=1的功能
参数3 - shape PyTorch这个参数在调用sample接口时传入
参数4 - seed 算子层的随机种子,PyTorch无此参数

代码示例

PyTorch中每一个生成的随机值占用一维度,因此在MindSpore中传入的shape最内层增加一个长度为1的维度,两API实现功能一致。

# PyTorch
import torch

m = torch.distributions.laplace.Laplace(torch.tensor([0.0]), torch.tensor([1.0]))
shape = (4, 4)
sample = m.sample(shape)
print(tuple(sample.shape))
# (4, 4, 1)

# MindSpore
import mindspore
from mindspore import ops

shape = (4, 4, 1)
output = ops.standard_laplace(shape)
result = output.shape
print(result)
# (4, 4, 1)
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
master

搜索帮助