probmods / webppl

Probabilistic programming for the web
http://webppl.org
Other
620 stars 86 forks source link

Allow continuous distributions to be serialized #488

Open mhtess opened 8 years ago

mhtess commented 8 years ago

For example, is something like this ever conceivable?

Infer({method: "enumerate"}, function(){
    return flip(0.5) ? Beta({a:1,b:1}) : Beta({a:0.01,b:0.01})
})
stuhlmueller commented 8 years ago

Looks fine to me. The code below seems to work:

var hyperDist = Infer({method: "enumerate"}, function(){
  return flip(.5) ? Beta({a:1,b:1}) : Beta({a:0.01,b:0.01})
});

expectation(Infer({method: "rejection", samples: 5000}, function(){
  var dist = sample(hyperDist);
  return sample(dist);
}));

Are you looking for something else?

mhtess commented 8 years ago

Hm. I get not implemented

stuhlmueller commented 8 years ago

Oh, you're right—I wasn't running the test on the public version of webppl. It would definitely be possible to make this work, e.g. by providing a toJSON function for continuous distributions.

Note that this already works:

Infer({method: "enumerate"}, function(){
  return flip(.5) ? Bernoulli({p: .5}) : Bernoulli({p: .7});
});
longouyang commented 8 years ago

Maybe we could serialize continuous distributions (and, say, variational programs; #27) as computation graphs in JSON.