/* Machine working (gaussian) in Picat. From https://pedrozudo.github.io/docs/20_thesis/thesis_final_online_compressed.pdf page 96 """ Example 6.5 (DC-ProbLog Program). This example program models the correct working of a machine. The probability distribution of the temperature of the machine depends on whether it is a hot day or not. 1 machine(1). 2 3 0.2::hot. 4 0.99::cooling(1). 5 6 temperature ~ normal(27,5):- hot. 7 temperature ~ normal(20,5):- \+hot. 8 9 works(N):- machine(N), cooling(N). 10 works(N):- machine(N), temperature<25.0. 11 12 query(works(1)). """ Cf - ppl_machine_working.pi - ppl_machine_working_gaussian.pi - my Gamble model gamble_machine_working_gaussian2.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 : hot Probabilities: false: 0.7997000000000000 true: 0.2003000000000000 mean = [false = 0.7997,true = 0.2003] var : cooling Probabilities: true: 0.9903000000000000 false: 0.0097000000000000 mean = [true = 0.9903,false = 0.0097] var : temperature Probabilities (truncated): 44.969168333729442: 0.0001000000000000 43.844645487829951: 0.0001000000000000 43.744152936280486: 0.0001000000000000 42.620908846574096: 0.0001000000000000 ......... 3.476732220061415: 0.0001000000000000 3.009515821769838: 0.0001000000000000 2.836831574970866: 0.0001000000000000 2.131245361209846: 0.0001000000000000 mean = 21.3849 var : works Probabilities: true: 0.9973000000000000 false: 0.0027000000000000 mean = [true = 0.9973,false = 0.0027] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,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() => Hot = flip(0.2), Cooling = flip(99/100), Temperature = cond(Hot==true,normal_dist(27,5),normal_dist(20,5)), Works = check((Cooling == true ; Temperature < 25)), add("hot",Hot), add("cooling",Cooling), add("temperature",Temperature), add("works",Works).