sebapersson / PEtab.jl

Create parameter estimation problems for ODE models
https://sebapersson.github.io/PEtab.jl/stable/
MIT License
38 stars 6 forks source link

Fitting large ODE model #236

Open NikosMemmos opened 2 days ago

NikosMemmos commented 2 days ago

Hi,

I am trying to replicate the following paper: https://www.nature.com/articles/s41598-01

Here are the codes I have for parameter fitting. The last version of PEtab worked ok but I cannot reproduce what I was doing in the current one. I also used the original published model to generate some artificial data but I was not able to capture the behavior

nfat_model.zip

sebapersson commented 1 day ago

This proved to be an interesting problem. You get the error because the event handling in SciMLSensitivity has changed, which is bug (I actually do not test PEtab.jl for the setting adjoint with events which I should).

Regardless, after doing some benchmarks, I do not think gradient_method = :Adjoint is the configuration you should use. You have a relatively large stiff models, for these adjoint methods in Julia are not super reliable (you often get gradient computation failures, which can be detrimental). Moreover, your problem is not that large so that adjoint must be used, as it takes around (only) 2 seconds to compute the gradient with forward methods. Therefore, I would use a setup like:

petab_problem = PEtabODEProblem(petab_model,
                                gradient_method = :ForwardEquations,
                                sensealg = :ForwardDiff,
                                hessian_method = :GaussNewton,
                                reuse_sensitivities = true,
                                odesolver=ODESolver(QNDF() , abstol=1e-3, reltol=1e-6),
                                sparse_jacobian = false, verbose = true)

The sparse_jacobian = false is needed here to have forward gradients working (I missed fixing this when setting default options, so when you build the problem you get sparse_jacobian = true by default, hence strange results with ForwardDiff). In particular, I recomend using this setting together with Fides https://sebapersson.github.io/PEtab.jl/stable/pest_algs/#Fides (if you cannot install Fides consider Ipopt with BFGS Hessian). This is because the Gauss-Newton Hessian is often the best approximation you can use if you have a trust-region method, and in my experience, Fides is a good trust-region implementation.

Hope this helps!