ICB-DCM / pyPESTO

python Parameter EStimation TOolbox
https://pypesto.readthedocs.io
BSD 3-Clause "New" or "Revised" License
216 stars 47 forks source link

Make spline parameters available for user for non-linear semi-quantitative data #1308

Closed arrjon closed 4 months ago

arrjon commented 6 months ago

Feature description When performing hierarchical approximation using splines as the observable mapping one should include spline knots and values for each observable in the result.optimize_result object.

Motivation/Application When using non-linear semi-quantitative data and a spline appoximation for the observabale mapping one might like to use this mapping further. For example, in the function pypesto.visualize.plot_splines_from_pypesto_result these values are extracted but not given to the user.

Doresic commented 6 months ago

Thanks for the issue!

True, this is a nice addition to the module. A user should be able to access the spline mapping after it's optimized. It was previously in result.optimize_result.list[i].inner_parameter_values, but I decided to remove it. The reason was the large amount of spline parameters one can have in a relatively simple model, making it hard to find other inner parameters in the same object like noise, scaling, and offset.

I'll think of another solution, probably a function similar to plot_splines_from_pypesto_result, that would extract and return the spline parameters for one or all semiquantitative observables. Might be cleaner, but on the other hand it seems logical that it should be in result.optimize_result somewhere

Will think of some solutions and ask for a discussion of the solutions.

arrjon commented 6 months ago

Is the spline mapping saved somewhere? In other words, if I load a result and create the same petab problem, will I get the same results? I noticed that for the same petab problem after loading sometimes the values (but not the knot points) of the spline changed a bit (at least the ones used in the plot_splines_from_pypesto_result function).

Doresic commented 6 months ago

(We discussed this, but I'll add it here too to remain documented) Yes, that can happen. The optimization of an inner problem requires an initialization of inner parameters. The inner problem is solved during optimization for each trial parameter vector of outer parameters (mechanistic parameters). To make the inner optimization more efficient and "continuous", the initial inner optimization values are given by the end values of the previous inner optimization. These are saved in the inner problem object.

However, if the optimization finishes, the result is saved, and then loaded with a brand new inner problem object the new inner problem will not have any end values of a previous inner optimization. So the inner solver will choose the default inner values.

This can cause what you observe, the spline knot points to have values a bit different than before (the inner problem is not strictly convex, but only convex, so this can occur).