-
Notifications
You must be signed in to change notification settings - Fork 17
MLN Benchmark
rockt edited this page Sep 12, 2014
·
2 revisions
case class World(smokes: Pred[Symbol], cancer: Pred[Symbol],
friends: Pred[(Symbol, Symbol)])
implicit def persons = List('Anna, 'Bob)
def worlds = all(World)
def mln(world: World) = {
import world._
sum(persons) { p =>
1.5 * I(smokes(p) --> cancer(p)) } +
sum(persons) { p1 => sum(persons) { p2 =>
1.1 * I(friends(p1, p2) --> (smokes(p1) == smokes(p2))) } }
}
def evidence(world: World) = world.smokes('Anna) && world.friends('Anna, 'Bob)
def query(world: World) = oneHot(world.cancer('Bob))
val mu = expect(worlds where evidence) { mln } { query }
barChart(mu)
(define (implies x y) (or (not x) y))
(define samples
(mh-query 1000 100
(define people (list 'anna 'bob))
(define smokes (mem (lambda (person) (flip))))
(define cancer (mem (lambda (person) (flip))))
(define friends (mem (lambda (x y) (flip))))
(define smokes-cancer (sum (map
(lambda (x) (if (implies (smokes x) (cancer x)) 0 -1.5))
people
)))
(define friends-smoke (sum (map
(lambda (x) (sum (map
(lambda (y) (if (implies (friends x y) (eq? (smokes x) (smokes y))) 0 -1.1))
people
)))
people
)))
(define model (+ smokes-cancer friends-smoke))
(define evidence (and (smokes 'anna) (friends 'anna 'bob)))
(cancer 'bob)
(and evidence (< (uniform 0 1) (exp model)))
)
)
(hist samples)