/* Bag of marbles in Picat. "Probabilistic logic programming and its applications" Luc De Raedt, Leuven https://www.youtube.com/watch?v=3lnVBqxjC88 @ 3:44 """ Mike has a bag of marbles with 4 white, 8 blue, and 6 red marbles. He pulls out one marble from the bag and it is red. What is the probability that the second marble he pulls out of the bag is white? The answer is 0.235941 """ The Racket/Gamble model (as well as my other PPL models, e.g WebPPL), the probabilitu of draw1 == white is a little different from the description above: 0.23529411764705882 (vs 0.235941). Perhaps a typo? This is the exact probabilities from my Gamble model: var : draw0 red: 1 (1.0) var : draw1 blue: 8/17 (0.47058823529411764) red: 5/17 (0.29411764705882354) white: 4/17 (0.23529411764705882) var : draw1=white #f: 13/17 (0.7647058823529411) #t: 4/17 (0.23529411764705882) mean: 4/17 (0.23529411764705882) This is a port of my Gamble model gamble_bag_of_marbles.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. /* var : draw0 Probabilities: red: 1.0000000000000000 mean = not_numeric var : draw1 Probabilities: blue: 0.4748237964400908 red: 0.2921992593477482 white: 0.2329769442121610 mean = not_numeric var : p Probabilities: 0: 0.7783400000000000 1: 0.2216600000000000 mean = 0.22166 */ go ?=> reset_store, run_model(10_000,$model,[show_probs,mean]), nl. go => true. model() => Colors = ["white","blue","red"], [ProbWhite,ProbBlue,ProbRed] = Probs, Probs = [4,8,6], % First draw of a marble (it is red) Draw0 = categorical(Probs,Colors), Draw1 = cond(Draw0 == "white", categorical([ProbWhite-1,ProbBlue,ProbRed],Colors), cond(Draw0 == "blue", categorical([ProbWhite,ProbBlue-1,ProbRed],Colors), categorical([ProbWhite,ProbBlue,ProbRed-1],Colors))), P = cond(Draw1 == "white",1,0), add("p",P), observe(Draw0 == "red"), if observed_ok then add("draw0",Draw0), add("draw1",Draw1) end.