Skip to content
 

Working Stiff

After a challenging development process we are happy to announce that Stan finally supports stiff ODE systems, removing one of the key obstacles in fields such as pharmacometrics and ecology.  For the experts, we’ve incorporated CVODE 2.8.2 into Stan and exposed the backward-differentiation formula solver using Newton iterations and a banded Jacobian computed exactly using our autodiff.

Right now the code is available on the develop branches of the Stan library and the CmdStan interface, with more interface support hopefully coming soon.  All you have to do is download develop from GitHub and compile your model — the CVODE library will automatically compile and install.

The new solver is used similarly to the current integrate_ode function in Stan, only you have to explicitly specify the relative and absolute tolerances and the maximum number of steps,

 integrate_ode_cvode(ode, y0, t0, ts, theta, x_real, x_int,
                     rel_tol, abs_tol, max_num_steps)

Be warned that these arguments can have a strong influence on the overall performance of the integrator, so care must be taken in choosing values that ensure accurate solutions. We’ve found that rel_tol = abs_tol = 1e-10 and max_num_steps = 1e8 have worked well for our tests.

If you get a chance to play around with the new solver then do let us know how it performs.  Without your feedback, both positive and negative, we can’t make Stan better!

6 Comments

  1. ojm says:

    Cool! Do you know anyone who’s worked with PDEs and Stan? Eg seni-discretised first and solved (or amy other way).

Leave a Reply