def checkAAAParticleWeights(sp, seed): if inParallel() and "make_suff_stat_bernoulli" in sp and backend_name( ) == "puma": raise SkipTest( "The Lite SPs in Puma interface is not thread-safe, and make_suff_stat_bernoulli comes from Lite." ) if "dir_cat" in sp and backend_name() == 'puma': raise SkipTest( "Dirichlet categorical in Puma does not accept objects parameter. Issue #340" ) ripl = get_ripl(seed=seed) ripl.assume("a", "1.0") # bogus labelled directives, so the infer step can forget them ripl.predict("nil", label="f") ripl.predict("nil", label="pid") predictions = collectSamples(ripl, "pid", infer="""\ (do (resample 10) (forget 'pid) (forget 'f) (assume f %s f) (predict (f) pid) (observe (f) true obs1) (observe (f) true obs2) (resample 1) (forget 'obs2) (forget 'obs1))""" % sp) ans = [(False, .25), (True, .75)] return reportKnownDiscrete(ans, predictions)
def testInvWishartPrior4(seed): # Confirm that as dof increases, the elements of a Wishart obey the # central limit theorem. if inParallel() and backend_name() == "puma": raise SkipTest("The Lite SPs in Puma interface is not thread-safe, and wishart comes from Lite.") ripl = get_ripl(seed=seed) ripl.assume("s", "(scale_matrix 10000 (id_matrix 3))") ripl.assume("m", "(inv_wishart s 10000)") ripl.predict("(lookup m (pair 0 1))", label="prediction") predictions = collectSamples(ripl, "prediction") return reportKnownGaussian(0, 0.01, predictions)
def testInvWishartPrior2(seed): # Confirm that the diagonal elements of an inverse Wishart are an # inverse Gamma distribution. if inParallel() and backend_name() == "puma": raise SkipTest("The Lite SPs in Puma interface is not thread-safe, and wishart comes from Lite.") ripl = get_ripl(seed=seed) ripl.assume("s", "(matrix (array (array 2 -1) (array -1 3)))") ripl.assume("m", "(inv_wishart s 4.2)") ripl.predict("(lookup m (pair 1 1))", label="prediction") predictions = collectSamples(ripl, "prediction") cdf = scipy.stats.invgamma(a=1.6, scale=1.5).cdf return reportKnownContinuous(cdf, predictions)
def testWishartPrior1(seed): # Confirm that the diagonal elements of a Wishart are a chi-squared # distribution. if inParallel() and backend_name() == "puma": raise SkipTest("The Lite SPs in Puma interface is not thread-safe, and wishart comes from Lite.") ripl = get_ripl(seed=seed) ripl.assume("s", "(matrix (array (array 2 -1) (array -1 3)))") ripl.assume("m", "(wishart s 5)") ripl.predict("(lookup m (pair 0 0))", label="prediction") predictions = collectSamples(ripl, "prediction") cdf = scipy.stats.chi2(df=5, scale=2).cdf return reportKnownContinuous(cdf, predictions)
def checkMakeBetaBernoulli1(maker, hyper, seed): if rejectionSampling() and hyper == "(normal 10.0 1.0)": raise SkipTest( "Too slow. Tightening the rejection bound is Issue #468.") if inParallel() and "make_suff_stat_bernoulli" in maker and backend_name( ) == "puma": raise SkipTest( "The Lite SPs in Puma interface is not thread-safe, and make_suff_stat_bernoulli comes from Lite." ) ripl = get_ripl(seed=seed) ripl.assume("a", hyper) ripl.assume("f", "(%s a a)" % maker) ripl.predict("(f)", label="pid") for _ in range(20): ripl.observe("(f)", "true") predictions = collectSamples(ripl, "pid") ans = [(False, .25), (True, .75)] return reportKnownDiscrete(ans, predictions)
def checkMakeBetaBernoulli4(maker, seed): if inParallel() and "make_suff_stat_bernoulli" in maker and backend_name( ) == "puma": raise SkipTest( "The Lite SPs in Puma interface is not thread-safe, and make_suff_stat_bernoulli comes from Lite." ) ripl = get_ripl(seed=seed) ripl.assume("a", "(normal 10.0 1.0)") ripl.assume("f", """ (if (lt a 10.0) ({0} a a) ({0} a a))""".format(maker)) ripl.predict("(f)", label="pid") for _ in range(20): ripl.observe("(f)", "true") predictions = collectSamples(ripl, "pid") ans = [(False, .25), (True, .75)] return reportKnownDiscrete(ans, predictions)