Open reubenharry opened 2 years ago
Initial attempts type-checked, but either produced simulations that ground to a halt (rapidly increasing number of traced variables) or appeared not to do much. This seems like a very interesting, but non-trivial, challenge.
I haven't had the time yet to look into this thoroughly, but my initial intuition is that one should first reimplement Density
in terms of LazyPPL
(and not a free monad), and use that version.
We'd want to be a bit careful, because we don't want to trace stochastic choices that are arbitrarily far back in the past (I think?),
Yes, I'm guessing the memory leaks (it sounds like that is what you're encountering) come from Trace
. Maybe it is possible to evaluate & reset the trace at every step? I haven't yet understood what its purpose is.
~As a first step, one should re-implement simply rmsmc
, since it doesn't really make use of Traced
as far as I understand.~ EDIT: Ah no, it seems it is used in mhStep
.
So my initial thought was to use Traced.dynamic, which allows you to freeze
traced variables. That way I'd freeze old variables, and avoid a memory leak. I didn't get it to work, but it seems possible. The lazy approach seems like a great idea.
It seems like we should be able to implement an analog to RMSMC (https://github.com/tweag/monad-bayes/blob/master/src/Control/Monad/Bayes/Inference/RMSMC.hs, in particular
rmsmcDynamic
), which basically just applies MH steps to the population after resampling, to distribute mass more fairly.We'd want to be a bit careful, because we don't want to trace stochastic choices that are arbitrarily far back in the past (I think?), but I've found that this is a nice method for avoiding particle collapse (which is where a single particle dominates the population).