ICB-DCM / pyPESTO

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

Pypesto Optimization ignores bounds #881

Closed shoepfl closed 2 years ago

shoepfl commented 2 years ago

I recently found that the parameter estimation of the ICG PEtab model resulted in parameters that violate the bounds given in the PEtab parameter table.

The PEtab problem I used is: icg_sd.omex.zip

And I used the following code that produced the error:

import pypesto import pypesto.petab import pypesto.optimize as optimize import pypesto.store as store

pypesto_importer = pypesto.petab.PetabImporter.from_yaml(yaml_file) pypesto_problem = pypesto_importer.create_problem()

optimizer = optimize.ScipyDifferentialEvolutionOptimizer(options = {'strategy':'best1bin', 'maxiter':8000 ,'mutation':(0.2, 1), 'recombination':0.7, 'popsize':70, 'init':'latinhypercube', 'polish':True, 'workers' : 8})

n_starts = 10 result = optimize.minimize(pypesto_problem, optimizer=optimizer, n_starts=n_starts)

store.save_to_hdf5.write_result(result, os.path.join(Path , M + '_Pypesto_Parameters.hdf5'), overwrite= True)

dilpath commented 2 years ago

What result do you expect, and what result do you see? pyPESTO returns parameters on parameter scale, which is log according to your PEtab parameters table. If you unscale the parameters, are they as expected?

dilpath commented 2 years ago

The parameters plot can be used as a diagnostic here to visualize parameter values and their optimization bounds, on parameter scale.

e.g. see usage of visualize.parameters in https://github.com/ICB-DCM/pyPESTO/blob/main/doc/example/rosenbrock.ipynb

shoepfl commented 2 years ago

Sorry i forgot to add the estimated parameter vector, the problem is that the unscaled parameters are outside the bounds we defined.

For example for LI__ICGLI2BI_Vmax, which should have a lower bound of 1e-05 and a upper bound of 10.0 according to the parameter table, however the actual value is much lower. I attached the visualization as you suggested, there it is also visible that the lower bound is 1e-12. icg_sd_parameter_visualization

dilpath commented 2 years ago

Ah, the lower bound for LI__ICGLI2BI_Vmax in the plot is close to -12 on log-scale, which is the lower bound 1e-5 on log-scale (i.e. log(1e-5) = -11.5), which appears to be the lower bound for in your plot. To get the values on linear scale, you would need to unscale, e.g.:

import petab
petab_problem = petab.Problem.from_yaml(yaml_file)
unscaled_optimum = petab_problem.unscale_parameters(dict(zip(
    pypesto_problem.x_names,
    result.optimize_result.list[0].x,
))
shoepfl commented 2 years ago

Okay thanks for the help - maybe that needs more clairification in the PEtab documentation as the description for the bounds state there: "Must be provided in linear space, independent of parameterScale."

from this at least it is confusing when I have to give the bounds in linear scale explicitly but indeed the log of them are taken as boundaries. But thats probably a topic for the PEtab implementation so I will shift the discussion to there.

Thanks for your help!

yannikschaelte commented 2 years ago

Closing here as this concerns the petab documentation