Handling events when using ode integrator

Hi there!

I was wondering if anyone knew about how to handle events when using one of the ode integrators such as integrate_ode_bdf in stan?

In many (all?) environments, ode solvers do not test conditions in the specified function at all times (this is related to algorithm efficiency), hence you cannot simply add an event via a condition in the function (e.g. at time t=300, change variable X value to 0.0).

There are ways of handling this. For instance in deSolve in r, you can define events that you then feed to the solver.

I cannot find information about this topic in STAN online. This is the closest I gan get to the topic, and I still do not understand if/how this should be handled in STAN.

Events is really something we use all the times in our models and would be a shame if there wasnt a way of handling them in STAN. Please let me if you have some insight about that

Thanks

Gianni

You have to stop and restart the integrator yourself. This functionality is not available for now. An alternative is to put any discontinuity into the ode rhs and integrate brute force over it…not ideal, but can work.

Hi,
If you’re modeling clinical events, as might arise in pharmacometrics, you could consider Torsten (https://github.com/metrumresearchgroup/Torsten). It couples Stan’s ode integrators with an event handler (by doing under the hood what @wds15 describes).

@yizhang can probably give you additional pointers.