/* Book bags in Picat. From the Netica model Book Bags.neta """ Book Bags Copyright 1998 Norsys Software Corp. There are two book bags each containing 10 poker chips. In one bag there are 7 red and 3 blue. In the other bag there are 3 red and 7 blue. Five chips are drawn out of one of the bags and shown to the subject (one at a time then returned to the bag). The subject does not know which bag the chips came from. There is an equal chance that the draws are made from either bag. After each draw the subject reports which bag he believes the chips are coming from and provides a probability that the chips are being drawn from that bag. The problem comes from the early "revision of judgment" work that indicated that people were conservative with respect to Bayes. """ Exact probabilities from my Gamble model model book_bags.rkt: seeing 0 blue balls var : bag bag1: 0.5 bag2: 0.5 seeing 1 blue balls var : bag bag2: 0.7 bag1: 0.30000000000000004 seeing 2 blue balls var : bag bag2: 0.8448275862068966 bag1: 0.1551724137931035 seeing 3 blue balls var : bag bag2: 0.927027027027027 bag1: 0.072972972972973 seeing 4 blue balls var : bag bag2: 0.967365028203062 bag1: 0.03263497179693797 seeing 5 blue balls var : bag bag2: 0.9857478005865102 bag1: 0.014252199413489746 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. /* Seeing 0 blue balls var : bag Probabilities: bag1: 0.5065499999999999 bag2: 0.4934500000000000 Seeing 1 blue balls var : bag Probabilities: bag2: 0.6973919968146526 bag1: 0.3026080031853474 Seeing 2 blue balls var : bag Probabilities: bag2: 0.8496278755074425 bag1: 0.1503721244925575 Seeing 3 blue balls var : bag Probabilities: bag2: 0.9276947705442903 bag1: 0.0723052294557097 Seeing 4 blue balls var : bag Probabilities: bag2: 0.9634796881411571 bag1: 0.0365203118588428 Seeing 5 blue balls var : bag Probabilities: bag2: 0.9861111111111112 bag1: 0.0138888888888889 */ go ?=> member(NumBlueBags,0..5), printf("Seeing %d blue balls\n",NumBlueBags), reset_store, run_model(10_000,$model(NumBlueBags),[show_probs]), fail, nl. go => true. draw(I,Bag) = cond(Bag=="bag1", categorical([7,3].simplex,Colors), categorical([3,7].simplex,Colors)) => Colors = ["red","blue"]. model(NumBlueBags) => Bag = categorical([1/2,1/2],["bag1","bag2"]), % Observe T number number of blue C = [cond(draw(B,Bag) == "blue",1,0) : B in 1..NumBlueBags].sum, observe(C == NumBlueBags), % add("num_blue_bags",C), % This might be confusing... if observed_ok then add("bag",Bag) end.