Data2Dynamics / d2d

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

fitting history log #138

Closed plakrisenko closed 5 years ago

plakrisenko commented 5 years ago

Hello! I was looking through fitting history log (ar.fit_hist), and it seems that if a particular fit stopped with the exit flag "NaN", than for this fit the information about the previous successful fit is being written in ar.fit_hist. For example, I ran arFitLHS(10, init_seed, true), and got ar.exitflag = [0, NaN, 3, NaN, NaN, 3, 3, NaN, 0, NaN]. In this case, ar.fit_hist(2).hist is the same as ar.fit_hist(1).hist, ar.fit_hist(4).hist and ar.fit_hist(5).hist are the same as ar.fit_hist(3).hist, ar.fit_hist(8).hist is the same as ar.fit_hist(7).hist and ar.fit_hist(10).hist is the same as ar.fit_hist(9).hist.

Actually, I wanted to have a look at fitting history for unsuccessful fits, those that stopped with the exit flag "NaN", as I know that some optimization steps were performed. So, it would be perfect if you could log this information. However, having no information in the corresponding entries in ar.fit_hist for unsuccessful fits would also be better, I think.

clemenskreutz commented 5 years ago

Dear Polina.

Thanks for this hint.

ar.fit_hist is now properly initialized to guarantee that no information from previous fits are contained in case of unsuccessful, i.e. not properly finshed fits.

We can only store information which is by default provided by the opimizer. We cannot change Matlab's optimization algorithms to provide more information. But you can do it by yourself: If you use lsqnonlin (=D2D default), then you have to edit snls.m. You can add some lines within the "main loop". Use the variable global fit to store extra information. It is even possible to store the current ar struct via:

global fit
global ar
if ~isfield(fit,'current_ar')
  fit.current_ar = [];
end
fit.current_ar = ar;  

This possibility is actually the reason, why we work with a global variable in arFit.m to store information about individual fits.

Another less informative option is setting ar.config.optim.Display='iter';