Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select: use petab_select method to set estimated parameters #1287

Merged
merged 9 commits into from
Feb 5, 2024
16 changes: 16 additions & 0 deletions pypesto/select/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ def correct_x_guesses(
should be corrected by replacing them with
- their corresponding values in `row` if possible, else
- their corresponding nominal values in the `petab_problem.parameter_df`.

Parameters
----------
x_guesses:
The startpoints to correct.
model:
The startpoints will be corrected to match this model.
petab_problem:
The model's corresponding PEtab problem. If this is not provided,
it will be created from the `model`.
hierarchical:
Whether hierarchical optimization is used.

Returns
-------
The corrected startpoint guesses.
"""
# TODO reconsider whether correcting is a good idea (`x_guess` is no longer
# the latest MLE then). Similar todo exists in
Expand Down
16 changes: 11 additions & 5 deletions pypesto/select/model_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,22 @@ def set_result(self, result: Result):
self.model.set_criterion(Criterion.NLLH, float(self.best_start.fval))
self.model.compute_criterion(criterion=self.criterion)

self.model.estimated_parameters = {
estimated_parameters = {
id: float(value)
for index, (id, value) in enumerate(
zip(
self.pypesto_problem.x_names,
self.best_start.x,
)
dict(
zip(
self.pypesto_problem.x_names,
self.best_start.x,
)
).items()
dilpath marked this conversation as resolved.
Show resolved Hide resolved
)
if index in self.pypesto_problem.x_free_indices
}
self.model.set_estimated_parameters(
estimated_parameters=estimated_parameters,
scaled=True,
)

if self.postprocessor is not None:
self.postprocessor(self)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ select =
# Remove when vis is moved to PEtab Select version
networkx >= 2.5.1
# End remove
petab-select >= 0.1.8
petab-select >= 0.1.12
test =
pytest >= 5.4.3
pytest-cov >= 2.10.0
Expand Down
24 changes: 13 additions & 11 deletions test/select/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
from pypesto.select import model_problem
from pypesto.select.misc import correct_x_guesses

# Options sent to `pypesto.optimize.optimize.minimize`, to reduce run time.
minimize_options = {
'engine': pypesto.engine.MultiProcessEngine(),
'n_starts': 20,
'filename': None,
'progress_bar': False,
model_problem_options = {
# Options sent to `pypesto.optimize.optimize.minimize`, to reduce run time.
'minimize_options': {
'engine': pypesto.engine.MultiProcessEngine(),
'n_starts': 20,
'filename': None,
'progress_bar': False,
}
}
# Tolerances for the differences between expected and test values.
tolerances = {
Expand Down Expand Up @@ -137,7 +139,7 @@ def test_problem_select(pypesto_select_problem):
for expected_result in expected_results:
best_model, _ = pypesto_select_problem.select(
criterion=criterion,
minimize_options=minimize_options,
model_problem_options=model_problem_options,
predecessor_model=best_model,
candidate_space=candidate_space,
)
Expand Down Expand Up @@ -186,7 +188,7 @@ def test_problem_select_to_completion(pypesto_select_problem):
criterion=Criterion.BIC,
select_first_improvement=True,
startpoint_latest_mle=True,
minimize_options=minimize_options,
model_problem_options=model_problem_options,
candidate_space=candidate_space,
)

Expand Down Expand Up @@ -258,7 +260,7 @@ def test_problem_multistart_select(pypesto_select_problem, initial_models):
method=Method.FORWARD,
criterion=criterion,
predecessor_models=initial_models,
minimize_options=minimize_options,
model_problem_options=model_problem_options,
)

expected_best_model_subspace_id = 'M1_3'
Expand Down Expand Up @@ -336,7 +338,7 @@ def test_postprocessors(petab_select_problem):
best_model_1, newly_calibrated_models_1 = pypesto_select_problem.select(
method=Method.FORWARD,
criterion=Criterion.AIC,
minimize_options=minimize_options,
model_problem_options=model_problem_options,
)

expected_newly_calibrated_models_subspace_ids = ['M1_0']
Expand Down Expand Up @@ -403,7 +405,7 @@ def test_vis(pypesto_select_problem):
best_models = pypesto_select_problem.select_to_completion(
method=Method.FORWARD,
criterion=criterion,
minimize_options=minimize_options,
model_problem_options=model_problem_options,
)
labels = {
model.get_hash(): model.model_subspace_id
Expand Down
Loading