Example #1
0
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)
Example #2
0
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)
Example #3
0
                             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(
Example #4
0
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)
Example #5
0
            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
Example #6
0
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)