Data2Dynamics / d2d

a modeling environment tailored to parameter estimation in dynamical systems
https://github.com/Data2Dynamics/d2d
57 stars 29 forks source link

Different behavior depending on the method of setting model parameters #146

Closed gdudziuk closed 4 years ago

gdudziuk commented 4 years ago

System information

Issue description

I attach code which compare two different ways of setting up the same model with the same known parameters:

  1. Assigning model parameters via arSetPars in the setup script (cf. Setup_A.m and Models/hsr_A.def in the attached files).
  2. Assigning model parameters in the CONDITIONS section of the model definition file (cf. Setup_B.m and Models/hsr_B.def in the attached files).

The attached scripts set up the model, compile it and try to plot its solutions by a call to arPlot.

With the method 1. (call Setup_A to reproduce), arPlot experiences problems with the convergence of the ODE solver and returns the following error:

The following error was reported during thread evaluation: Error code -1 in module CVODES and function CVode:
At t = 1.23064e-09, mxstep steps taken before reaching tout.
cvodes failed at CV_TOO_MUCH_WORK for model 1, condition 1. Trying arCheckSimu could be an option.
total chi^2 = 0, 0 data points, 27 free parameters, data chi^2 = 0

Possibly, the solver tolerances require some tweaking but I have not managed to get things work.

With the method 2. (call Setup_B to reproduce) there are no problems with running arPlot and the default tolerances were just fine. I other words, things work "out of the box".

To my understanding, both methods of implementing a model with known parameters should result in the same ODE system, so the ODE solver should be able to deal with it for both methods (or for neither of them). This is not the case, which suggests that there may exist some essential differences in the compiled mex files which impact the performance of the ODE solver. It may be a bug, so hereby I report.

Attachment code.zip

rengesser commented 4 years ago

Hi Grzegorz,

some of your parameters (k1, l1, k2, k5, k6, k8 and k10) in Setup_A are defined in log10 space which is indicated by the fourth function parameter. For these parameters, you also have to define the value of the parameter in log10 space, e.g. change arSetPars('k8', 9.60678189e+01, 1, 1, 0.0, 1.0e+100) to arSetPars('k8', log10(9.60678189e+01), 1, 1, 0.0, 1.0e+100) in order to correctly assign the value of k8. In your current implementation the value of k8 would be 10^(9.60678189e+01) which is very high and typically leads to problems in the ODE integration, since the ODE system becomes too stiff.

Additionally you should also define the upper and lower bounds in log10 space for these values. I also recommend to use lower values for the upper bound, since during fitting it can happen that the upper bound (in your case 1e+100) is reached, leading again to problems with the integration of the ODE.

gdudziuk commented 4 years ago

some of your parameters (k1, l1, k2, k5, k6, k8 and k10) in Setup_A are defined in log10 space which is indicated by the fourth function parameter. For these parameters, you also have to define the value of the parameter in log10 space

Ah, that's it. So—contrary to what I have said—the attached models does not have the same parameters, and consequently the resulting ODE systems are different. Thanks for your help in identifying this. After setting the scale for all parameters to normal, Setup_A produces plots as Setup_B, i.e. everything works as expected.

gdudziuk commented 4 years ago

By the way, except the GitHub issues, is there any place to ask questions concerning d2d? The README of the project states that

for support issues, please use the issues and forum

but I can't find the forum anywhere.