/* Size of group of people in Picat. https://pedrozudo.github.io/docs/20_thesis/thesis_final_online_compressed.pdf page 86 """ Example 6.2. In this example we show how to model the size of a group of people as a Poisson distribution and answer queries about the size of the group using the comparison predicates > / 2 and =:= / 2 . 1 n_people ~ poisson(6). 2 3 more_than_five:- n_people>5. 4 exactly_five:- n_people=:=5. 5 6 query(more_than_five). 7 query(exactly_five). """ * > 5: Picat> X = 1 - poisson_dist_cdf(6,5) X = 0.554320358635389 * = 5: Picat> X = poisson_dist_pdf(6,5) X = 0.16062314104798 Cf my Gamble model gamble_size_of_group_of_people.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. % import ordset. main => go. /* var : n people Probabilities: 5: 0.1601000000000000 6: 0.1509000000000000 4: 0.1440000000000000 7: 0.1348000000000000 8: 0.1051000000000000 3: 0.0919000000000000 9: 0.0706000000000000 2: 0.0418000000000000 10: 0.0393000000000000 11: 0.0235000000000000 1: 0.0152000000000000 12: 0.0102000000000000 13: 0.0051000000000000 0: 0.0035000000000000 14: 0.0020000000000000 15: 0.0014000000000000 16: 0.0004000000000000 17: 0.0002000000000000 mean = 5.9752 var : more than five Probabilities: true: 0.5435000000000000 false: 0.4565000000000000 mean = 0.5435 var : exactly five Probabilities: false: 0.8399000000000000 true: 0.1601000000000000 mean = 0.1601 */ go ?=> reset_store, run_model(10_000,$model,[show_probs,mean % , % show_percentiles, % show_hpd_intervals,hpd_intervals=[0.94], % show_histogram, % min_accepted_samples=1000,show_accepted_samples=true ]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => NPeople = poisson_dist(6), MoreThanFive = check(NPeople > 5), ExactlyFive = check(NPeople == 5), add("n people",NPeople), add("more than five",MoreThanFive), add("exactly five",ExactlyFive).