observe with multivariate gaussian

35 views
Skip to first unread message

Thalia Vrantsidis

unread,
Jun 22, 2020, 6:12:28 PM6/22/20
to webppl-dev
Hello,

I am trying to put an observe statement where the observation is a single 2-d value from a multivariate gaussian distribution. 
When I try what I think should be correct, it doesn't give an error, but seems to get stuck forever on: Initialization warning [4/4]: Trace not initialized after 1000000 attempts.

I think I am just running into a syntax issue that I can't figure out. 

My current code is below.  
Any help on this would be appreciated! 

//observing two pieces of evidence (mu1 and mu2) with certain reliabilities (var 1 and var2)
//the two pieces of evidence have possibly correlated noise

var inference_model = function(mu1,mu2,var1,var2, cor) {
  return Infer({method: 'MCMC', samples: 10000}, function() {
    var prior = Gaussian({mu: 50, sigma: 25})

    var trueX = sample(prior) 

    var cov = cor*Math.sqrt(var1)*Math.sqrt(var2)
    var evidence = MultivariateGaussian({mu: Vector([trueX,trueX]),
                          cov: Matrix([[var1,cov],
                                       [cov,var2]])})

    observe(evs, [mu1,mu2]) 
    //observe(evs,  {"0":mu1,"1":mu2}) 
    
    return {'trueX':trueX}
  })
}
var Posterior = inference_model(40, 60, 10,10, 0.1)
viz.marginals(Posterior)

null-a

unread,
Jun 23, 2020, 3:51:54 AM6/23/20
to webppl-dev
Hi. I think you just need to pass the observation as a vector rather than an array, i.e. `observe(evs, Vector([mu1,mu2]))`?

Thalia Vrantsidis

unread,
Jun 23, 2020, 10:09:15 AM6/23/20
to webppl-dev
Yes, passing it as a vector worked! 
Thanks!!

Reply all
Reply to author
Forward
0 new messages