/* Gaussian mixture model in Picat. From "CAV 2020 Tutorial: Probabilistic Programming: A Guide for Verificationists" https://www.youtube.com/watch?v=yz5uUf_03Ik&t=2657s Around @23:30 Cf my Gamble model gamble_gaussian_mixture_model2.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.9999586896352295 true: 0.0000413103647705 mean = [false = 0.999959,true = 4.13104e-05] Histogram: false : 24206 ############################################################ (1.000 / 1.000) true : 1 (0.000 / 1.000) var : pr Probabilities (truncated): 0.467366615062285: 0.0000826207295410 0.992915843144486: 0.0000413103647705 0.990565984039831: 0.0000413103647705 0.989434624085871: 0.0000413103647705 ......... 0.000082686543503: 0.0000413103647705 0.000070875976268: 0.0000413103647705 0.000024808570754: 0.0000413103647705 0.000019972212622: 0.0000413103647705 mean = 0.334671 Histogram: 0.000: 617 ############################### (0.025 / 0.025) 0.025: 1198 ############################################################ (0.049 / 0.075) 0.050: 1121 ######################################################## (0.046 / 0.121) 0.074: 1110 ######################################################## (0.046 / 0.167) 0.099: 1049 ##################################################### (0.043 / 0.210) 0.124: 1050 ##################################################### (0.043 / 0.254) 0.149: 1062 ##################################################### (0.044 / 0.298) 0.174: 963 ################################################ (0.040 / 0.338) 0.199: 910 ############################################## (0.038 / 0.375) 0.223: 961 ################################################ (0.040 / 0.415) 0.248: 887 ############################################ (0.037 / 0.451) 0.273: 895 ############################################# (0.037 / 0.488) 0.298: 844 ########################################## (0.035 / 0.523) 0.323: 846 ########################################## (0.035 / 0.558) 0.348: 775 ####################################### (0.032 / 0.590) 0.372: 710 #################################### (0.029 / 0.620) 0.397: 684 ################################## (0.028 / 0.648) 0.422: 721 #################################### (0.030 / 0.678) 0.447: 646 ################################ (0.027 / 0.704) 0.472: 658 ################################# (0.027 / 0.731) 0.496: 623 ############################### (0.026 / 0.757) 0.521: 557 ############################ (0.023 / 0.780) 0.546: 555 ############################ (0.023 / 0.803) 0.571: 485 ######################## (0.020 / 0.823) 0.596: 499 ######################### (0.021 / 0.844) 0.621: 441 ###################### (0.018 / 0.862) 0.645: 418 ##################### (0.017 / 0.879) 0.670: 406 #################### (0.017 / 0.896) 0.695: 358 ################## (0.015 / 0.911) 0.720: 351 ################## (0.014 / 0.925) 0.745: 316 ################ (0.013 / 0.938) 0.770: 310 ################ (0.013 / 0.951) 0.794: 271 ############## (0.011 / 0.962) 0.819: 214 ########### (0.009 / 0.971) 0.844: 184 ######### (0.008 / 0.979) 0.869: 144 ####### (0.006 / 0.985) 0.894: 141 ####### (0.006 / 0.991) 0.918: 97 ##### (0.004 / 0.995) 0.943: 76 #### (0.003 / 0.998) 0.968: 54 ### (0.002 / 1.000) var : x Probabilities (truncated): 14.599990751079622: 0.0000413103647705 14.599978703095944: 0.0000413103647705 14.599972719242565: 0.0000413103647705 14.599966518167353: 0.0000413103647705 ......... 14.400031583264596: 0.0000413103647705 14.40002289148873: 0.0000413103647705 14.400017783624339: 0.0000413103647705 14.400014710985703: 0.0000413103647705 mean = 14.4942 Histogram: 14.400: 369 ############################ (0.015 / 0.015) 14.405: 685 ##################################################### (0.028 / 0.044) 14.410: 697 ###################################################### (0.029 / 0.072) 14.415: 687 ##################################################### (0.028 / 0.101) 14.420: 708 ###################################################### (0.029 / 0.130) 14.425: 680 #################################################### (0.028 / 0.158) 14.430: 705 ###################################################### (0.029 / 0.187) 14.435: 663 ################################################### (0.027 / 0.215) 14.440: 629 ################################################ (0.026 / 0.241) 14.445: 676 #################################################### (0.028 / 0.268) 14.450: 644 ################################################## (0.027 / 0.295) 14.455: 661 ################################################### (0.027 / 0.322) 14.460: 636 ################################################# (0.026 / 0.349) 14.465: 675 #################################################### (0.028 / 0.377) 14.470: 638 ################################################# (0.026 / 0.403) 14.475: 639 ################################################# (0.026 / 0.429) 14.480: 628 ################################################ (0.026 / 0.455) 14.485: 616 ############################################### (0.025 / 0.481) 14.490: 637 ################################################# (0.026 / 0.507) 14.495: 585 ############################################# (0.024 / 0.531) 14.500: 625 ################################################ (0.026 / 0.557) 14.505: 628 ################################################ (0.026 / 0.583) 14.510: 599 ############################################## (0.025 / 0.608) 14.515: 589 ############################################# (0.024 / 0.632) 14.520: 547 ########################################## (0.023 / 0.655) 14.525: 552 ########################################## (0.023 / 0.677) 14.530: 540 ########################################## (0.022 / 0.700) 14.535: 572 ############################################ (0.024 / 0.723) 14.540: 558 ########################################### (0.023 / 0.746) 14.545: 595 ############################################## (0.025 / 0.771) 14.550: 568 ############################################ (0.023 / 0.794) 14.555: 541 ########################################## (0.022 / 0.817) 14.560: 525 ######################################## (0.022 / 0.838) 14.565: 571 ############################################ (0.024 / 0.862) 14.570: 541 ########################################## (0.022 / 0.884) 14.575: 510 ####################################### (0.021 / 0.905) 14.580: 516 ######################################## (0.021 / 0.927) 14.585: 505 ####################################### (0.021 / 0.948) 14.590: 487 ##################################### (0.020 / 0.968) 14.595: 780 ############################################################ (0.032 / 1.000) */ go ?=> reset_store, run_model(500_000,$model,[show_probs_trunc,mean,show_histogram]), nl, % fail, nl. go => true. model() => Pr = uniform(0,1), P = flip(Pr), X = condt(P, normal_dist(10.0,1.0), normal_dist(14.0,0.5)), observe(abs(X-14.5) <0.1), if observed_ok then add("pr",Pr), add("p",P), add("x",X) end.