/* Negative Binomial distribution in Picat. See ppl_distributions.pi for details, and ppl_distributions_test.pi for some more tests. Cf my Gamble model gamble_negative_binomial_dist.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. /* var : p Probabilities: false: 0.9292000000000000 true: 0.0708000000000000 mean = [false = 0.9292,true = 0.0708] var : v Probabilities: 0: 0.3554000000000000 1: 0.3059000000000000 2: 0.1788000000000000 3: 0.0891000000000000 4: 0.0425000000000000 5: 0.0173000000000000 6: 0.0067000000000000 7: 0.0026000000000000 8: 0.0012000000000000 9: 0.0004000000000000 10: 0.0001000000000000 mean = 1.2599 */ go ?=> reset_store, run_model(10_000,$model,[show_probs,mean]), nl, % show_store_lengths, % fail, nl. go => true. model() => V = negative_binomial_dist(3,0.7), P = check(V >= 4), add("v",V), add("p",P). /* var : p Probabilities: false: 0.9876106194690265 true: 0.0123893805309735 mean = [false = 0.987611,true = 0.0123894] var : v Probabilities: 6: 0.6088495575221239 7: 0.2389380530973451 8: 0.0902654867256637 9: 0.0495575221238938 10: 0.0088495575221239 11: 0.0035398230088496 mean = 6.62124 */ go2 ?=> reset_store, run_model(50_000,$model2,[show_probs,mean]), nl, % show_store_lengths, % fail, nl. go2 => true. model2() => V = negative_binomial_dist(3,0.7), observe(V > 5), P = check(V >= 10), if observed_ok then add("v",V), add("p",P) end.