/* Cookie problem in Picat. From Think Bayes, page 3 """ Suppose there are two bowls of cookies. Bowl 1 contains 30 vanilla cookies and 10 chocolate cookies. Bowl 2 contains 20 of each. Now suppose you choose one of the bowls at random and, without looking, select a cookie at random. The cookie is vanilla. What is the probability that it came from Bowl 1? """ Exact probabilities from my Gamble model: var : cookie vanilla: 1 (1.0) var : bowl bowl1: 3/5 (0.6) bowl2: 2/5 (0.4) This is a port of my Gamble model gamble_cookie_problem.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 : bowl Probabilities: bowl1: 0.60036301516122148 (5623 / 9366) bowl2: 0.39963698483877858 (3743 / 9366) mean = [bowl1 = 0.600363,bowl2 = 0.399637] var : cookie Probabilities: vanilla: 1.00000000000000000 (1 / 1) mean = [vanilla = 1.0] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_rat,mean]), nl. go => true. model() => Cookies = ["vanilla","chocolate"], Bowls = ["bowl1","bowl2"], Bowl = uniform_draw(Bowls), Cookie = cond(Bowl == "bowl1", categorical([30,10],Cookies), categorical([20,20],Cookies)), observe(Cookie == "vanilla"), if observed_ok then add("cookie",Cookie), add("bowl",Bowl) end.