/* Chicken pecking in Picat. From (PSI model) "HACSTFB - Probabilistic Programming Language ψ" https://www.youtube.com/watch?v=COS5YThEm1A About @10:04 ff 10 chicken are arranged in a ring. With probability 1/2 a chicken picks the chicken at left and probability 1/2 at right, What is the probability of unpecked chickens? From the PSI model, probabilities of number of unpecked chicken = 0,1,2,3,4,5,6,7,8,9,10; E[r1_,r2_,r3_,r4_,r5_,r6_,r7_,r8_,r9_,r10_,r11_] = (1/256,5/64,55/128,25/64,25/256,0,0,0,0,0,0) (0.00390625,0.078125,0.4296875,0.390625,0.09765625,0,0,0,0,0,0) This is a port of my WebPPL model chicken_pecking.wppl This matched the exact PSI model (as well as the WebPPL model) (2 : 55/128 (0.4296875)) (3 : 25/64 (0.390625)) (4 : 25/256 (0.09765625)) (1 : 5/64 (0.078125)) (0 : 1/256 (0.00390625)) (mean: 2.5) This is a port of my Racket/Gamble model chicken_pecking.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 : unpecked Probabilities: 2: 0.42640000000000000 (533 / 1250) 3: 0.39379999999999998 (1969 / 5000) 4: 0.09650000000000000 (193 / 2000) 1: 0.07990000000000000 (799 / 10000) 0: 0.00340000000000000 (17 / 5000) mean = 2.5001 */ go ?=> reset_store(), N = 10, run_model(10_000,$model(N),[show_probs_rat,mean]), fail, nl. go => true. % This was inspired by the PSI model (via the Gamble model) model(N) => % Initialize all chickens to be unpecked Pecked = [false : _ in 1..N], % Flag the chicken that was picked upon foreach(I in 1..N) V = mod_replace(I + condt(flip(),-1,1),N), Pecked[V] := true end, % Update the value of unpecked chickens Unpecked = [cond(Pecked[I] == false,1,0) : I in 1..N].sum, add("unpecked",Unpecked).