PyStan ODE Example

Anyone has any example for ODE models in PyStan?


Hey, I think ODE models in Stan are just custom functions living in the functions blocks. You can then call the solver from generated quantities for example. There are some examples in the documentation section here:

I don’t think any part of it is specific to R / Python. You’d run it like any other model from pystan (e.g. by calling “sample” and telling it not to sample).

I think some of the ODE solver stuff in PyStan has been difficult for the maintainers to support (ODE in PyStan: 'Failed to parse Stan model')

You might try cmdstanpy: which is a different interface which might be easier.

As @emiruz says, the Stan part of ODE modeling should be the same across the Python/R interfaces (as long as you’re able to get PyStan with the appropriate ODE solver). Here’s a nice example of using ODEs in Rstan:

edit: Pystan might support the rk45 solver without these difficulties, I’m not sure, maybe @ahartikainen would know.

Installing latest pystan with ode support: