1

How does one sample a multivariate distribution in Pyro? I just want a (M, N) Beta distribution, but the following doesn't work:

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)))

FBruzzesi
  • 6,385
  • 3
  • 15
  • 37
Rylan Schaeffer
  • 1,945
  • 2
  • 28
  • 50

2 Answers2

2

Use to_event(n) to declare depdent samples.

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)
1

For both PyTorch and Pyro distributions, the syntax is the same:

import pyro.distributions as dist

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

You shouldn't need to the plate notion unless if you're only wanting to sample a distribution.

James C
  • 23
  • 3
  • I don't understand. I do want the plate notion to indicate that the $M$ draws from the $N$ dimensions are conditionally independent given the distribution's parameters. Isn't that precisely what plates are for? – Rylan Schaeffer Aug 29 '20 at 18:02