Animating MCMC with Python

Hi everyone,

I am currently running an MCMC model with non-linear ODEs with so many parameters and have been having some difficulties in getting results that I expected. I am thinking that it would be very helpful if there is any way to visualize/animate the algorithm during the fitting processes (if anything goes weird I can terminate the model quickly rather than wait for multiple hours only to find disappointing results). I have been trying to find anyway to do this in Python (because I’m currently using PyStan for the interface), but has not been able to do so.

What I’m looking is something similar to what some other people do here but with PyMC3 (Animations of Metropolis, Gibbs and Slice Sampler dynamics — Computational Statistics in Python 0.1 documentation), and potentially how the model fits the data trace (which I believe can easily be done if I can access the samples in real time).

Any idea how I can do this with Stan? Because I’m not planning to switch to PyMC3 for the ODE solver speed issue. Is there anyway to access the samples in real time with Stan?

Thanks!

1 Like

There are couple options:

  • using cmdstan (cmdstanpy) + reading csv files on the fly
  • pystan (you need to edit source code so you can tap in to the process while it runs)
4 Likes

Also, note that the actual hamiltonian dynamics that occur within a sampling step are not accessible outside of cmdstan.

2 Likes

those aren’t accessible in CmdStan either. the Stan I/O is very limited, and the Stan algorithms don’t report on each leapfrog step.

1 Like

Oops, yeah, that’s what I intended to convey.