webppl icon indicating copy to clipboard operation
webppl copied to clipboard

Improve binomial scorer performance

Open longouyang opened this issue 8 years ago • 4 comments

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 avatar Jul 29 '16 00:07 longouyang

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

longouyang avatar Jul 29 '16 01:07 longouyang

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.

longouyang avatar Jul 29 '16 19:07 longouyang

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

stuhlmueller avatar Jul 29 '16 19:07 stuhlmueller

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

longouyang avatar Jul 29 '16 19:07 longouyang