probmods / webppl

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

Improve binomial scorer performance #604

Open longouyang opened 8 years ago

longouyang commented 8 years ago

While working on the presidential election example for the PPAML summer course, I discovered that our binomial sampler is pretty slow for values like n = 2400000, p = 0.5

We might try switching to something like Marsaglia 04: https://www.jstatsoft.org/article/view/v011b03/v11b03.pdf

longouyang commented 8 years ago

followup: it seems to be much slower inside Infer than repeat

longouyang commented 8 years ago

Noah had a good hypothesis: it's actually the scorer that's slow (this seems likely, given that the scorer computes lnfact(n)).

So maybe we could add an option to Binomial that turns on Stirling's approximation for the scorer.

stuhlmueller commented 8 years ago

Is it slow inside rejection inference? The scorer shouldn't be used there.

longouyang commented 8 years ago

It's fast inside rejection, so it does appear to be the scorer.