/* Loaded coin in Picat. From Osvaldo Martin: "Bayesian Analysis with Python", 2nd edition, page 39, exercise 6. """ Let's suppose that we have two coins; when we toss the first coin, half of the time it lands tails and half of the time on heads. The other coin is a loaded coin that always lands on heads. If we take one if the coins at random and get a head, what is the probability the the coin is the unfair one? """ This is a port of my Gamble model gamble_loaded_coin.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 : coin Probabilities: loaded: 0.6641987422505686 fair: 0.3358012577494313 mean = [loaded = 0.664199,fair = 0.335801] */ go ?=> reset_store(), run_model(30_000,model,[show_probs_trunc,mean]), nl, % fail, nl. go => true. model() => % What coin? Coin = categorical([1/2,1/2], [fair,loaded]), % We toss the coin, what's the outcome Outcome = cond(Coin == fair, categorical([1/2,1/2],[tail,head]), head), % We observe it's head observe(Outcome == head), if observed_ok then add("coin",Coin) end.