pymc-devs / pymc-examples

Examples of PyMC models, including a library of Jupyter notebooks.
https://www.pymc.io/projects/examples/en/latest/
MIT License
280 stars 243 forks source link

ODE Notebooks Cleanup #502

Open gbrunkhorst opened 1 year ago

gbrunkhorst commented 1 year ago

ODE Notebooks

URLS

Issue description

I'm suggesting we delete these three notebooks, and salvage three very short ODE examples that are not covered elsewhere (Fitzhugh-Nagumo model, enzymatic reaction, SIR model).

The main issue with these notebooks is that they are not very relevant for someone trying to perform inference on an ODE. The notebook Lotka-Volterra with manual gradients is very long and isn't a method that people should implement on their own. pymc3.ode: Shapes and benchmarking is more about profiling than ODEs, and GSoC 2019: Introduction of pymc3.ode API focuses only on the pymc.ODE module, which is very slow.

More Background I am working on updating the ODE notebooks. After taking stock of the existing examples, I developed a new notebook that covers multiple methods for performing inference on ODEs (draft here)

It seems like the state-of-the-art for ODEs is moving on from the old example notebooks. The cutting edge is likely sunode or diffrax (or DifferentialEquations.jl) which all use autodifferentiation. Pymc.ODE is slow and should probably not be highlighted too much in the docs.

However, I did find that the Scipy ODE solver combined with non-gradient-based inference (e.g., DEMetropolis) was relatively simple and effective!

Proposed solution

Based on this information, I suggest to moving the Fitzhugh-Nagumo model, enzymatic reaction model, and SIR models into new short notebooks that just perform inference using Scipy and DEMetropolis.

Also note that pymc3.ode: Shapes and benchmarking is mostly about timing code and inspecting computational graphs, not ODEs. If there is valuable information in this notebook, then it should be moved to the "How to" folder of the PyMC examples (and needs a lot more text explaining what problem it is solving).

I can rework the existing notebooks once the broader team chimes in.

michaelosthege commented 1 year ago

Generally I agree, however I am concerned that we might end up with a gap of explanatory content when jumping to the easy-to-use "blackbox" solution right away. On the other hand that's something that should be covered by a blog post rather than a notebook in the documentation..

jucor commented 9 months ago

Thanks @gbrunkhorst for the new notebook, very helpful! Unfortunately, its call to SMC sampler (which is the very reason I went there) at line:

 trace_SMC_like = pm.sample_smc(draws)

throws the following error:

AttributeError: module '__main__' has no attribute 'pytensor_forward_model_matrix'

Would you be able to help, please?

jucor commented 9 months ago

I have opened an issue for that bug at https://github.com/pymc-devs/pymc/issues/7078