/* Murder mystery in Picat. From Andy Gordon: "Reverend Bayes, meet Countess Lovelace: Probabilistic Programming for Machine Learning" https://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012/Reverend-Bayes-meet-Countess-Lovelace-Probabilistic-Programming-for-Machine-Learning Around @14:00 """ Miss Scarlett dunnit 30%. Col Mustard dunnit 70%. Scarlett uses gun 3%, uses pipe 97%. Mustard uses gun 80%, uses pipe 20%. ... We found a gun at the Scene. What is the probability that Scarlett dunnit? """ * This is a port of my Gamble model gamble_murder_mystery.rkt This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils. main => go. /* * Original question: we found a gun, what is the probability that Scarlet did it? var : mustard Probabilities: true: 0.7021313766596785 false: 0.2978686233403214 mean = [true = 0.702131,false = 0.297869] var : scarlett Probabilities: false: 0.9814814814814815 true: 0.0185185185185185 mean = [false = 0.981481,true = 0.0185185] var : withGun Probabilities: true: 1.0000000000000000 mean = [true = 1.0] var : withPipe Probabilities: false: 0.7819706498951782 true: 0.2180293501048218 mean = [false = 0.781971,true = 0.218029] * If we had found a pipe instead: var : mustard Probabilities: true: 0.6982276119402985 false: 0.3017723880597015 mean = [true = 0.698228,false = 0.301772] var : scarlett Probabilities: true: 0.6721082089552238 false: 0.3278917910447761 mean = [true = 0.672108,false = 0.327892] var : withGun Probabilities: false: 0.7140858208955224 true: 0.2859141791044776 mean = [false = 0.714086,true = 0.285914] var : withPipe Probabilities: true: 1.0000000000000000 mean = [true = 1.0] */ go ?=> reset_store(), run_model(10_000,model,[show_probs_trunc,mean]), nl, % fail, nl. go => true. model() => Scarlett = flip(0.30), Mustard = flip(0.70), WithGun = condt(Scarlett, flip(0.03), flip(0.80)), WithPipe = condt(Scarlett, flip(0.97), flip(0.20)), observe(WithGun), % observe(WithPipe), if observed_ok then add_all([["scarlett",Scarlett], ["mustard",Mustard], ["withPipe",WithPipe], ["withGun",WithGun] ]) end.