def evalapp_bind(app_expr, env={}): return store_bind_answer(env, app_expr, map(lambda a: evalapp_bind(a, env), app_expr.args), inner_interp=lambda e: evalapp_memo(evalDExpr(e)), answer_interp=lambda sym, *args: sym.func(*args), is_bind=lambda sym: type(sym) == Bind)
def evalapp_bind(app_expr, env={}): return store_bind_answer( env, app_expr, map(lambda a: evalapp_bind(a, env), app_expr.args), inner_interp = lambda e: evalapp_memo(evalDExpr(e)), answer_interp = lambda sym, *args: sym.func(*args), is_bind = lambda sym: type(sym) == Bind)
is_bind=lambda sym: False) def evalapp_bind(app_expr, env={}): return store_bind_answer(env, app_expr, map(lambda a: evalapp_bind(a, env), app_expr.args), inner_interp=lambda e: evalapp_memo(evalDExpr(e)), answer_interp=lambda sym, *args: sym.func(*args), is_bind=lambda sym: type(sym) == Bind) # An interpreter that fails early given an evidence query unDE_evidence = lambda evidence: mapd(lambda (k, v): (evalDExpr(k), v), evidence) def check_evidence(v, val, evidence): if evidence.has_key(v): if isfunction(evidence[v]): return evidence[v](val) else: return val == evidence[v] else: return True def inconsistent(env, evidence): cleaned = cleanEnv(env) res = not conj(
def Pr(query, evidence={}, impl=rejectionN(1000)): eval_evidence = dict(map(lambda (k, v): (evalDExpr(k), v), evidence.items())) return impl(evalDExpr(query), eval_evidence)
map(lambda a: evalapp_bind(a, env), app_expr.args), inner_interp = None, answer_interp = lambda sym, *args: sym.func(*args), is_bind = lambda sym: False) def evalapp_bind(app_expr, env={}): return store_bind_answer( env, app_expr, map(lambda a: evalapp_bind(a, env), app_expr.args), inner_interp = lambda e: evalapp_memo(evalDExpr(e)), answer_interp = lambda sym, *args: sym.func(*args), is_bind = lambda sym: type(sym) == Bind) # An interpreter that fails early given an evidence query unDE_evidence = lambda evidence: mapd(lambda (k, v): (evalDExpr(k), v), evidence) def check_evidence(v, val, evidence): if evidence.has_key(v): if isfunction(evidence[v]): return evidence[v](val) else: return val == evidence[v] else: return True def inconsistent(env, evidence): cleaned = cleanEnv(env) res = not conj(map(lambda (k, v): check_evidence(k, v, evidence), cleaned.items())) return res
def Pr(query, evidence={}, impl=rejectionN(1000)): eval_evidence = dict( map(lambda (k, v): (evalDExpr(k), v), evidence.items())) return impl(evalDExpr(query), eval_evidence)