/* Animal population in Picat. Cf my Gamble model gamble_animal_population.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. import util. main => go. /* Model 1 var : mice Probabilities (truncated): 5: 0.2569000000000000 6: 0.2031000000000000 4: 0.1992000000000000 3: 0.1232000000000000 ......... 1: 0.0105000000000000 9: 0.0100000000000000 10: 0.0008000000000000 0: 0.0008000000000000 mean = 4.9884 var : p Probabilities: false: 0.9320000000000001 true: 0.0680000000000000 mean = [false = 0.932,true = 0.068] var : rabbits Probabilities: 2: 0.3041000000000000 1: 0.2738000000000000 3: 0.1944000000000000 0: 0.1063000000000000 4: 0.0886000000000000 5: 0.0272000000000000 6: 0.0048000000000000 7: 0.0007000000000000 8: 0.0001000000000000 mean = 1.9901 var : voles Probabilities: 3: 0.2714000000000000 2: 0.2231000000000000 4: 0.2040000000000000 1: 0.1179000000000000 5: 0.1058000000000000 6: 0.0387000000000000 0: 0.0299000000000000 7: 0.0079000000000000 8: 0.0010000000000000 9: 0.0003000000000000 mean = 3.0215 */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => AllAnimals = ones(30,voles) ++ ones(50,mice) ++ ones(20,rabbits), Animals = resample(10,AllAnimals), Voles = count_occurrences(voles,Animals), Mice = count_occurrences(mice,Animals), Rabbits = count_occurrences(rabbits,Animals), P = check( (Voles == 4, Mice == 5, Rabbits == 1)), add("voles",Voles), add("mice",Mice), add("rabbits",Rabbits), add("p",P). /* Model 2: Same as model 1 but using categorical_n/3 instead of resample, and using get_freq/1 for the occurrences. var : mice Probabilities (truncated): 5: 0.2444000000000000 6: 0.2049000000000000 4: 0.2011000000000000 3: 0.1244000000000000 ......... 9: 0.0097000000000000 1: 0.0097000000000000 0: 0.0011000000000000 10: 0.0006000000000000 mean = 4.9798 var : p Probabilities: false: 0.9357000000000000 true: 0.0643000000000000 mean = [false = 0.9357,true = 0.0643] var : rabbits Probabilities: 2: 0.3012000000000000 1: 0.2713000000000000 3: 0.1964000000000000 0: 0.1087000000000000 4: 0.0884000000000000 5: 0.0280000000000000 6: 0.0054000000000000 7: 0.0006000000000000 mean = 1.9931 var : voles Probabilities: 3: 0.2633000000000000 2: 0.2260000000000000 4: 0.2057000000000000 1: 0.1200000000000000 5: 0.1079000000000000 6: 0.0378000000000000 0: 0.0286000000000000 7: 0.0096000000000000 8: 0.0010000000000000 9: 0.0001000000000000 mean = 3.0271 */ go2 ?=> reset_store, run_model(10_000,$model2,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go2 => true. model2() => Animals = categorical_n([30,50,20],[voles,mice,rabbits],10), Freq = Animals.get_freq(), Voles = Freq.get(voles,0), Mice = Freq.get(mice,0), Rabbits = Freq.get(rabbits,0), P = check( (Voles == 4, Mice == 5, Rabbits == 1)), add("voles",Voles), add("mice",Mice), add("rabbits",Rabbits), add("p",P).