Smooth Transition to PyMC3

Hello

I am currently in the process of migrating from Stan to PyMC3 for my Bayesian modeling projects. I have faced a few issues that I need some guidance on.

I have been using Stan for Bayesian modeling for the past couple of years, primarily for hierarchical modeling and Bayesian inference. Now, I am exploring PyMC3 due to its flexibility and ease of use in Python; but I am facing some specific challenges in the transition.

I am accustomed to specifying models using a different syntax and structure compared to PyMC3. I am looking for guidance on how to effectively translate my model specifications to PyMC3 syntax, especially for complex hierarchical models.

Stan offers a wide range of built-in distributions for priors. I am trying to understand the equivalent priors in PyMC3 and how to specify them effectively to maintain model consistency.

I am also interested in understanding any differences in parameter estimation techniques between Stan and PyMC3.

Are there specific strategies or best practices I should be aware of when using PyMC3 for parameter tuning and convergence diagnostics? Checked https://discourse.pymc.io/t/porting-stan-model-to-pymc/10055-react native discussions but still need help .

Your advice could help me ensure a smooth transition and enhance my Bayesian modeling capabilities.

Thank you in advance for your help and suggestions!

Best regards, :slightly_smiling_face:
boblewis

My first suggestion is to use PyMC not the old PyMC3 (maybe you were intending to use that, but just appended the sticky 3 in your message).

I would imagine the easiest way to check if they match exactly is to evaluate the logp of the Stan and PyMC models at the same point? With pymc you can do that via model.compile_logp()(model.initial_point()). You can check how initial_point looks like to use the same in Stan or to provide your own to PyMC.

I don’t know how to evaluate the logp of Stan at a specific point but it must be possible?

The other thing is Stan by default excludes normalization terms, whereas PyMC does not, so you have to tell Stan to not do that, or the logps will differ even if the models are completely equivalent.

Also the default transforms applied by PyMC and Stan may be slightly different and therefore have different jacobian corrections. But in most cases I imagine they will be the same and not a source of differences (could be very wrong)