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)
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))
def guide_constrained_model(data): q = pyro.param("q", ops.exp(torch.randn(3)), constraint=constraints.simplex) pyro.sample("x", dist.Categorical(q))