def extract_assessment(maker, params, data): r = get_ripl() r.assume("maker", maker) r.assume("made", v.app(v.sym("maker"), *[v.app(v.sym("exactly"), p) for p in params])) for item in data: r.observe("(made)", item) ans = r.infer("global_log_likelihood") return ans
def extract_sample(maker, params, index, seed): r = get_ripl(seed=seed) r.assume("maker", maker) expr = v.app(v.sym("list"), *[v.app(v.sym("made")) for _ in range(index+1)]) def one_sample(): r.assume("made", v.app(v.sym("maker"), *params)) ans = r.sample(expr)[-1] r.forget("made") return ans results = [one_sample() for _ in range(default_num_samples(5))] return results
def extract_cross_sample(maker, params, index1, index2, combiner, seed): r = get_ripl(seed=seed) r.assume("maker", maker) index = max(index1, index2) expr = v.app(v.sym("list"), *[v.app(v.sym("made")) for _ in range(index+1)]) def one_sample(): r.assume("made", v.app(v.sym("maker"), *params)) vec = r.sample(expr) r.forget("made") return combiner(vec[index1], vec[index2]) results = [one_sample() for _ in range(default_num_samples(5))] return results
def _collectData(iid,ripl,address,num_samples=None,infer=None): if num_samples is None: num_samples = default_num_samples() if infer is None: infer = defaultInfer() elif infer == "mixes_slowly": # TODO Replace this awful hack with proper adjustment of tests for difficulty infer = defaultInfer() if infer is not "(rejection default all 1)": infer = "(repeat 4 (do %s))" % infer predictions = [] for _ in range(num_samples): # TODO Consider going direct here to avoid the parser ripl.infer(infer) predictions.append(ripl.report(address)) if iid: ripl.sivm.core_sivm.engine.reinit_inference_problem() ripl.infer(v.app(v.sym("incorporate"))) return predictions
def observe(i, d): r.observe(expr.app(expr.symbol("datum"), expr.integer(i), d), dataset[i][d])
def testBasicAnnotation(): sivm = get_ripl().sivm expr = v.app(v.sym("add"), v.num(1), v.sym("foo")) err.assert_sivm_annotation_succeeds(sivm.assume, v.sym("x"), expr)
def one_sample(): r.assume("made", v.app(v.sym("maker"), *params)) vec = r.sample(expr) r.forget("made") return combiner(vec[index1], vec[index2])
def one_sample(): r.assume("made", v.app(v.sym("maker"), *params)) ans = r.sample(expr)[-1] r.forget("made") return ans
}, 'beta_bernoulli' : { 'native' : native_beta_bernoulli, 'optimized' : ['make_beta_bernoulli', 'make_uc_beta_bernoulli', suff_stat_beta_bernoulli], 'gibbs' : 'make_uc_beta_bernoulli', 'param_sets' : [(1.0, 1.0), (2.0, 3.0)], 'reporter' : reportSameDiscrete, 'combiner' : lambda x, y: (x,y) }, 'dir_cat' : { 'native' : native_dir_cat, 'optimized' : ['make_dir_cat', 'make_uc_dir_cat'], 'gibbs' : 'make_uc_dir_cat', 'param_sets' : [(v.app("array", 0.5, 0.5, 0.5),), (v.app("array", 0.2, 0.2, 0.2, 0.2, 0.2),)], 'reporter' : reportSameDiscrete, 'combiner' : lambda x, y: (x,y), }, 'sym_dir_cat' : { 'native' : native_sym_dir_cat, 'optimized' : ['make_sym_dir_cat', 'make_uc_sym_dir_cat'], 'gibbs' : 'make_uc_sym_dir_cat', 'param_sets' : [(0.5, 4), (0.2, 8)], 'reporter' : reportSameDiscrete, 'combiner' : lambda x, y: (x,y), }, 'gamma_poisson' : { 'native' : native_gamma_poisson, 'optimized' : ['make_gamma_poisson', 'make_uc_gamma_poisson',