Python-PyTorch多元分布

2024-09-27 00:22:57 发布

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

一个样本在Pyro中的多元分布如何?我只想要一个(M, N)Beta发行版,但以下版本不起作用:

impor torch
import pyro
with pyro.plate("theta_plate", M):
    theta = pyro.sample("theta",
                        pyro.distributions.Beta(concentration0=torch.ones(N),
                                                concentration1=torch.ones(N)))


Tags: sampleimport版本withonestorchbetadistributions
2条回答

使用to_event(n)来声明depent示例

import torch
import pyro
import pyro.distributions as dist

def model(N, M):
    with pyro.plate("theta_plate", M):
        theta = pyro.sample("theta", dist.Beta(torch.ones(N),1.).to_event(1))
    return theta


if __name__ == '__main__':
    print(model(10,12).shape) # (10,12)

PyTorch和Pyro发行版的语法相同:

import pyro.distributions as dist

samples = dist.Beta(2, 2).sample([200]) # Will draw 200 samples.

除非你只是想对一个分布进行抽样,否则你不应该使用盘子的概念

相关问题 更多 >

    热门问题