/* PPL in Picat. This is a port of my PSI model youtube6.wppl (from a now unavailable YouTube video) """ def main() { x := uniform(0,1); y := uniform(0,1); // z := y - 2*x; // 𝔼[x] = 1/4 // cobserve(z,0); z := y/x; // 𝔼[x] = 1/4 cobserve(z,2); return x; } """ The (exact) expected value from PSI is E[x] = 1/3 (0.3333) Cf my Gamble model gamble_youtube6.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 : x Probabilities (truncated): 0.525951048138529: 0.0001000000000000 0.525374848174571: 0.0001000000000000 0.524806940241161: 0.0001000000000000 0.524341818189408: 0.0001000000000000 ......... 0.006926609672106: 0.0001000000000000 0.006104269999128: 0.0001000000000000 0.004969122356255: 0.0001000000000000 0.003065420781758: 0.0001000000000000 mean = 0.335194 var : y Probabilities (truncated): 0.999886195640958: 0.0001000000000000 0.999858767725462: 0.0001000000000000 0.999838099349215: 0.0001000000000000 0.999831553548496: 0.0001000000000000 ......... 0.013509441639068: 0.0001000000000000 0.012532647239292: 0.0001000000000000 0.010166814555492: 0.0001000000000000 0.006299870557291: 0.0001000000000000 mean = 0.668598 var : z Probabilities (truncated): 2.099983690497761: 0.0001000000000000 2.09993300104227: 0.0001000000000000 2.099926465809096: 0.0001000000000000 2.099886348427928: 0.0001000000000000 ......... 1.900119742327797: 0.0001000000000000 1.900084010604907: 0.0001000000000000 1.900078498904452: 0.0001000000000000 1.900044464391844: 0.0001000000000000 mean = 1.99628 */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean,min_accepted_samples=10000,show_accepted_samples=true]), nl, % fail, nl. go => true. model() => X = uniform(0,1), Y = uniform(0,1), Z = Y / X, observe(abs(Z-2.0) < 0.1), if observed_ok then add("x",X), add("y",Y), add("z",Z), end.