Esempio n. 1
0
 def auto_guide(data):
     probs_a = pyro.param("guide_probs_a")
     probs_c = pyro.param("guide_probs_c")
     a = pyro.sample("a",
                     dist.Categorical(probs_a),
                     infer={"enumerate": "parallel"})
     with pyro.plate("data", 2, dim=-1):
         pyro.sample("c", dist.Categorical(probs_c[a]))
Esempio n. 2
0
 def hand_guide(data):
     probs_a = pyro.param("guide_probs_a")
     probs_c = pyro.param("guide_probs_c")
     a = pyro.sample("a",
                     dist.Categorical(probs_a),
                     infer={"enumerate": "parallel"})
     for i in range(2):
         pyro.sample("c_{}".format(i), dist.Categorical(probs_c[a]))
Esempio n. 3
0
 def auto_model():
     probs_a = pyro.param("probs_a")
     probs_b = pyro.param("probs_b")
     probs_c = pyro.param("probs_c")
     probs_d = pyro.param("probs_d")
     with pyro.plate("a_axis", 2, dim=-1):
         a = pyro.sample("a",
                         dist.Categorical(probs_a),
                         infer={"enumerate": "parallel"})
         pyro.sample("b", dist.Categorical(probs_b[a]), obs=b_data)
     with pyro.plate("c_axis", 3, dim=-1):
         c = pyro.sample("c",
                         dist.Categorical(probs_c),
                         infer={"enumerate": "parallel"})
         pyro.sample("d", dist.Categorical(probs_d[c]), obs=d_data)
Esempio n. 4
0
 def auto_model(data):
     probs_a = pyro.param("model_probs_a")
     probs_b = pyro.param("model_probs_b")
     probs_c = pyro.param("model_probs_c")
     probs_d = pyro.param("model_probs_d")
     probs_e = pyro.param("model_probs_e")
     a = pyro.sample("a", dist.Categorical(probs_a))
     b = pyro.sample("b",
                     dist.Categorical(probs_b[a]),
                     infer={"enumerate": "parallel"})
     with pyro.plate("data", 2, dim=-1):
         c = pyro.sample("c", dist.Categorical(probs_c[a]))
         d = pyro.sample("d",
                         dist.Categorical(Vindex(probs_d)[b, c]),
                         infer={"enumerate": "parallel"})
         pyro.sample("obs", dist.Categorical(probs_e[d]), obs=data)
Esempio n. 5
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. 6
0
 def hand_model(data):
     probs_a = pyro.param("model_probs_a")
     probs_b = pyro.param("model_probs_b")
     probs_c = pyro.param("model_probs_c")
     probs_d = pyro.param("model_probs_d")
     probs_e = pyro.param("model_probs_e")
     a = pyro.sample("a", dist.Categorical(probs_a))
     b = pyro.sample("b",
                     dist.Categorical(probs_b[a]),
                     infer={"enumerate": "parallel"})
     for i in range(2):
         c = pyro.sample("c_{}".format(i), dist.Categorical(probs_c[a]))
         d = pyro.sample("d_{}".format(i),
                         dist.Categorical(Vindex(probs_d)[b, c]),
                         infer={"enumerate": "parallel"})
         pyro.sample("obs_{}".format(i),
                     dist.Categorical(probs_e[d]),
                     obs=data[i])
Esempio n. 7
0
 def hand_model():
     probs_a = pyro.param("probs_a")
     probs_b = pyro.param("probs_b")
     probs_c = pyro.param("probs_c")
     probs_d = pyro.param("probs_d")
     for i in range(2):
         a = pyro.sample("a_{}".format(i),
                         dist.Categorical(probs_a),
                         infer={"enumerate": "parallel"})
         pyro.sample("b_{}".format(i),
                     dist.Categorical(probs_b[a]),
                     obs=b_data[i])
     for j in range(3):
         c = pyro.sample("c_{}".format(j),
                         dist.Categorical(probs_c),
                         infer={"enumerate": "parallel"})
         pyro.sample("d_{}".format(j),
                     dist.Categorical(probs_d[c]),
                     obs=d_data[j])
Esempio n. 8
0
 def guide():
     d = dist.Categorical(pyro.param("q"))
     context1 = pyro.plate("outer", outer_dim, dim=-1)
     context2 = pyro.plate("inner", inner_dim, dim=-2)
     pyro.sample("w", d, infer={"enumerate": "parallel"})
     with context1:
         pyro.sample("x", d, infer={"enumerate": "parallel"})
     with context2:
         pyro.sample("y", d, infer={"enumerate": "parallel"})
     with context1, context2:
         pyro.sample("z", d, infer={"enumerate": "parallel"})
Esempio n. 9
0
 def model():
     d = dist.Categorical(p)
     context1 = pyro.plate("outer", outer_dim, dim=-1)
     context2 = pyro.plate("inner", inner_dim, dim=-2)
     pyro.sample("w", d)
     with context1:
         pyro.sample("x", d)
     with context2:
         pyro.sample("y", d)
     with context1, context2:
         pyro.sample("z", d)
Esempio n. 10
0
def guide_constrained_model(data):
    q = pyro.param("q",
                   ops.exp(torch.randn(3)),
                   constraint=constraints.simplex)
    pyro.sample("x", dist.Categorical(q))
Esempio n. 11
0
 def guide():
     with pyro.plate("plate", len(data), dim=-1):
         p = pyro.param("p", torch.ones(len(data), 3) / 3, event_dim=1)
         pyro.sample("x", dist.Categorical(p))
     return p
Esempio n. 12
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. 13
0
 def guide():
     p = pyro.param("p", torch.tensor([0.5, 0.3, 0.2]))
     with pyro.plate("plate", len(data), dim=-1):
         pyro.sample("x", dist.Categorical(p))
Esempio n. 14
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. 15
0
 def guide():
     q = pyro.param("q",
                    torch.randn(3).exp(),
                    constraint=constraints.simplex)
     pyro.sample("x", dist.Categorical(q))