tweag / monad-bayes

A library for probabilistic programming in Haskell.
MIT License
407 stars 62 forks source link

Using a Different Proposal Distribution #216

Closed idontgetoutmuch closed 1 year ago

idontgetoutmuch commented 1 year ago

I have some mysterious results from monad-bayes. The MCMC sampler in monad-bayes ignores where you are and selects new sample by applying the inverse CDF to a sample from [0,1] and then applies the usual MCMC acceptance method. Now I was surprised that this converges in a reasonable number of steps but it certainly does for a linear regression model on one variable (so with 3 parameters: slope, cutoff and residual). But it does and gives surprisingly good results and a reasonable acceptance rate.

So I thought rather than doing this (what seemed to me at least) inefficient method, I should try

u' <- (\x -> 0.5 + x / pi) <$> atan <$> normal (tan (pi * ((us!!i) - 0.5))) 1.0

I.e. move randomly from where you are (us!!I is where you are) by transforming to tan space jumping a little bit and then transforming back from tan space.

But this gives worse results :disappointed: Here’s the naive way and the “sophisticated” way

idontgetoutmuch commented 1 year ago

image

image

reubenharry commented 1 year ago

Can you give the full code you're using to generate each dataset? (no need to include the histogram-making code)

reubenharry commented 1 year ago

(Summarising non-github discussion in case anyone else is interested): this change to the kernel requires accompanying changes to the MH ratio, in particular with respect to q. Gen is at the forefront of automating this sort of thing, afaik