sample()和rsample()之间有什么区别?

2024-09-29 01:22:55 发布

您现在位置:Python中文网/ 问答频道 /正文

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

import torch, seaborn as sns

x = torch.distributions.Normal(torch.tensor([0.0]), torch.tensor([1.0]))
^{tb1}$

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


Tags: sampleimportastorchpytorchseaborndistributionstensor
1条回答
网友
1楼 · 发布于 2024-09-29 01:22:55

使用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.

相关问题 更多 >