/* Mixture of Gaussian in Picat. From BLOG example/mixture-of-gaussian.blog """ A model for mixture of Gaussian distribution. The latent variable \verb|z| determines the mixture component of \verb|x|. The program asks the possible value of \verb|z| given the evidence of \verb|x| being 0.2. @author leili @since 2014-06-16 """ Cf my Gamble model gamble_mixture_of_gaussian.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 : z Probabilities: 1: 0.5237410071942447 0: 0.4762589928057554 mean = 0.523741 */ go ?=> reset_store, run_model(1_000_000,$model,[show_probs_trunc,mean]), nl, show_store_lengths, % fail, nl. go => true. model() => Z = bern(0.5), X = cond(Z == 1, normal_dist(0.5,1.0),normal_dist(-0.5,1.0)), observe(abs(X-0.2) <= 0.001), if observed_ok then add("z",Z), end.