gpt4 book ai didi

python - sample() 和 rsample() 有什么区别?

转载 作者:行者123 更新时间:2023-12-03 09:31:04 24 4
gpt4 key购买 nike

当我从 PyTorch 的分布中采样时,samplersample似乎给出了类似的结果:

import torch, seaborn as sns

x = torch.distributions.Normal(torch.tensor([0.0]), torch.tensor([1.0]))


enter image description here
enter image description here

sns.distplot(x.sample((100000,))) sns.distplot(x.rsample((100000,)))

我应该什么时候使用 sample() ,我应该什么时候使用 rsample() ?

最佳答案

使用 rsample允许 pathwise derivatives :

The other way to implement these stochastic/policy gradients would be to use the reparameterization trick from the rsample() method, where the parameterized random variable can be constructed via a parameterized deterministic function of a parameter-free random variable. The reparameterized sample therefore becomes differentiable.

关于python - sample() 和 rsample() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60533150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com