def testInferWithNoEntropy():
    # Makes sure that infer doesn't crash when there are no random
    # choices in the trace
    ripl = get_ripl()
    ripl.infer(defaultInfer())
    ripl.predict("(if true 1 2)")
    ripl.infer(defaultInfer())
Exemple #2
0
def testMemBasic3():
    # MSPs should always give the same answer when called on the same arguments
    ripl = get_ripl()
    ripl.assume("f", "(mem (lambda (x y) (bernoulli 0.5)))")
    for i in range(10):
        ripl.predict("(f 1 2)", label="p%d" % i)
    for _ in range(5):
        assert all_equal([ripl.report("p%d" % i) for i in range(10)])
        ripl.infer(defaultInfer())
def test_foreign_aaa_uc():
    builtins = builtin.builtInSPs()
    ripl = get_ripl()
    ripl.bind_foreign_sp("test_sym_dir_cat", builtins["make_uc_sym_dir_cat"])

    ripl.assume("f", "(test_sym_dir_cat 1 1)")
    assert ripl.sample("f")["counts"] == [0]

    ripl.observe("(f)", "integer<0>")
    assert ripl.sample("f")["counts"] == [1]

    ripl.infer(defaultInfer())
    assert ripl.sample("f")["counts"] == [1]
def test_foreign_latents():
    builtins = builtin.builtInSPs()
    ripl = get_ripl()
    ripl.bind_foreign_sp("test_lazy_hmm", builtins["make_lazy_hmm"])

    ripl.assume("f", "(test_lazy_hmm (simplex 1) (id_matrix 1) (id_matrix 1))")
    assert ripl.sample("f")[0] == []

    ripl.observe("(f 1)", "integer<0>")
    assert ripl.sample("f")[0] == [np.matrix([[1]]), np.matrix([[1]])]

    ripl.infer(defaultInfer())
    assert ripl.sample("f")[0] == [np.matrix([[1]]), np.matrix([[1]])]