TuringLang / docs

Documentation and tutorials for the Turing language
https://turinglang.org/docs/
MIT License
229 stars 98 forks source link

Fixes to Bayes SDE notebook #449

Closed gjgress closed 4 months ago

gjgress commented 4 months ago

Updated retcode success check to the current version used by SciMLBase. Introduced new noisy observations that are better suited for the problem, and corrected the model to calculate the likelihood based on multiple trajectories rather than a single trajectory.

446

https://github.com/TuringLang/Turing.jl/issues/2216

yebai commented 4 months ago

Thanks, @gjgress -- this looks like a pseudo-marginal HMC algorithm, although the stochasticity in the likelihood function might interact with the simulation of Hamiltonian dynamics of HMC. It seems like a correct MCMC algorithm, but it is not entirely clear that this has been done in the literature.

cc @PatrickGanRZ @THargreaves @FredericWantiez @torfjelde

THargreaves commented 4 months ago

It's my understanding that pseudo-marginal HMC, as introduced in Alenlöv et al., 2016, is a bit more nuanced than what is happening here. Even if you have an unbiased estimate of the likelihood, that doesn't mean your gradient estimates are unbiased and so your dynamics are incorrect.

The approach taken in the PM-HMC paper is quite a bit more complicated. To avoid having a confusing/misleading example in the docs, it might be wiser to fit this model using MH, as in the PM-MH framework which is a valid "exact approximate" algorithm.

That said, you could stick with the current approach but I think you'd need to make it clear that this an approximate method.

gjgress commented 4 months ago

The discussion on pseudo-marginal samplers or sequential Monte Carlo methods is not something I'm qualified to comment on, nor implement myself. From the viewpoint of creating a tutorial, I would say that using either of those tools is outside the scope of this tutorial, and ought to be its own tutorial (if its even within the scope of Turing as a whole-- I could not find an implementation of either of these methods using Turing during my search).

Of course if it can be done it would be fantastic-- based on what others have said, it seems that except under particular conditions, it is generally bad form to do the method here, and so using this method without at least mentioning its approximate nature may be misleading to less experienced users trying to use Turing for their SDE problems.

In any case, there isn't more for me to add to this tutorial, as I am not knowledgeable enough on this to add that commentary to the tutorial.

yebai commented 4 months ago

Many thanks @gjgress for investigating the issue and the fixes to the tutorial. I agree that we seem have touched on a research-grade problem, which is great, but of course beyond the scope of a tutorial.

yebai commented 4 months ago

Even if you have an unbiased estimate of the likelihood, that doesn't mean your gradient estimates are unbiased and so your dynamics are incorrect.

For clarity, I am not sure this is incorrect either: The noise in the gradient might not matter as long as the MH step is correct, but of course, the resulting HMC might be suboptimal in terms of efficiency.