Esempio n. 1
0
def constrained_model(data):
    locs = pyro.param("locs", torch.randn(3), constraint=constraints.real)
    scales = pyro.param("scales",
                        ops.exp(torch.randn(3)),
                        constraint=constraints.positive)
    p = torch.tensor([0.5, 0.3, 0.2])
    x = pyro.sample("x", dist.Categorical(p))
    pyro.sample("obs", dist.Normal(locs[x], scales[x]), obs=data)
Esempio n. 2
0
 def guide(data):
     guide_loc = pyro.param("guide_loc", torch.tensor(0.))
     guide_scale = ops.exp(pyro.param("guide_scale_log", torch.tensor(0.)))
     pyro.sample("loc", dist.Normal(guide_loc, guide_scale))
Esempio n. 3
0
 def model(data):
     loc = pyro.sample("loc", dist.Normal(0., 1.))
     with pyro.plate("data", len(data), dim=-1):
         pyro.sample("obs", dist.Normal(loc, 1.), obs=data)
Esempio n. 4
0
 def model(data=None):
     loc = pyro.param("loc", torch.tensor(expected_mean))
     scale = pyro.param("scale", torch.tensor(1.0))
     with pyro.plate("data", 1000, dim=-1):
         x = pyro.sample("x", dist.Normal(loc, scale), obs=data)
     return x
Esempio n. 5
0
 def model(data=None):
     loc = pyro.param("loc", torch.tensor(2.0))
     scale = pyro.param("scale", torch.tensor(1.0))
     x = pyro.sample("x", dist.Normal(loc, scale), obs=data)
     return x
Esempio n. 6
0
 def guide():
     loc = pyro.param("loc", torch.tensor(0.0))
     scale = pyro.param("scale", torch.tensor(1.0))
     with pyro.plate("plate_outer", data.size(-1), dim=-1):
         pyro.sample("x", dist.Normal(loc, scale))
Esempio n. 7
0
 def model():
     locs = pyro.param("locs", torch.tensor([-1.0, 0.0, 1.0]))
     with pyro.plate("plate", len(data), dim=-1):
         x = pyro.sample("x", dist.Categorical(torch.ones(3) / 3))
         pyro.sample("obs", dist.Normal(locs[x], 1.0), obs=data)
Esempio n. 8
0
 def model():
     locs = pyro.param("locs", torch.tensor([0.2, 0.3, 0.5]))
     p = torch.tensor([0.2, 0.3, 0.5])
     with pyro.plate("plate", len(data), dim=-1):
         x = pyro.sample("x", dist.Categorical(p))
         pyro.sample("obs", dist.Normal(locs[x], 1.0), obs=data)
Esempio n. 9
0
 def model():
     loc = torch.tensor(3.0)
     with pyro.plate("plate_outer", data.size(-1), dim=-1):
         x = pyro.sample("x", dist.Normal(loc, 1.0))
         with pyro.plate("plate_inner", data.size(-2), dim=-2):
             pyro.sample("y", dist.Normal(x, 1.0), obs=data)
Esempio n. 10
0
 def model(data):
     loc = pyro.param("loc", torch.tensor(0.0))
     pyro.sample("x", dist.Normal(loc, 1.0), obs=data)
Esempio n. 11
0
 def guide(data):
     guide_loc = pyro.param("guide_loc", torch.tensor(0.))
     guide_scale = pyro.param("guide_scale",
                              torch.tensor(1.),
                              constraint=constraints.positive)
     pyro.sample("loc", dist.Normal(guide_loc, guide_scale))
Esempio n. 12
0
 def guide():
     loc = pyro.param("loc", torch.tensor(0.))
     y = pyro.sample("y", dist.Normal(loc, 1.))
     pyro.sample("x", dist.Normal(y, 1.))
Esempio n. 13
0
 def model():
     x = pyro.sample("x", dist.Normal(0., 1.))
     pyro.sample("y", dist.Normal(x, 1.))
Esempio n. 14
0
 def guide(data):
     guide_loc = pyro.param("guide_loc", torch.tensor(0.))
     guide_scale = pyro.param(
         "guide_scale_log", torch.tensor(0.),
         torch.distributions.constraints.positive).exp()
     pyro.sample("loc", dist.Normal(guide_loc, guide_scale))