pypesto.select

Model Selection

Perform model selection with a PEtab Select problem.

class pypesto.select.Problem(petab_select_problem: Problem, model_postprocessor: Callable[[ModelProblem], None] | None = None)[source]

Bases: object

Handles use of a model selection algorithm.

Handles model selection. Usage involves initialisation with a model specifications file, and then calling the select() method to perform model selection with a specified algorithm and criterion.

calibrated_models

Storage for all calibrated models. A dictionary, where keys are model hashes, and values are petab_select.Model objects.

newly_calibrated_models

Storage for models that were calibrated in the previous iteration of model selection. Same type as calibrated_models.

method_caller

A MethodCaller, used to run a single iteration of a model selection method.

model_postprocessor

A method that is applied to each model after calibration.

petab_select_problem

A PEtab Select problem.

__init__(petab_select_problem: Problem, model_postprocessor: Callable[[ModelProblem], None] | None = None)[source]
create_method_caller(**kwargs) MethodCaller[source]

Create a method caller.

args and kwargs are passed to the MethodCaller constructor.

Returns:

A MethodCaller instance.

Return type:

MethodCaller

handle_select_kwargs(kwargs: Dict[str, Any])[source]

Check keyword arguments to select calls.

multistart_select(predecessor_models: Iterable[Model] | None = None, **kwargs) Tuple[Model, List[Model]][source]

Run an algorithm multiple times, with different predecessor models.

Note that the same method caller is currently shared between all calls. This may change when parallelization is implemented, but for now ensures that the same model isn’t calibrated twice. Could also be managed by sharing the same “calibrated_models” object (but then the same model could be repeatedly calibrated, if the calibrations start before any have stopped).

kwargs are passed to the MethodCaller constructor.

Parameters:

predecessor_models – The models that will be used as initial models. One “model selection iteration” will be run for each predecessor model.

Returns:

A 2-tuple, with the following values:

  1. the best model; and

  2. the best models (the best model at each iteration).

Return type:

tuple

select(**kwargs) Tuple[Model, Dict[str, Model], Dict[str, Model]][source]

Run a single iteration of a model selection algorithm.

The result is the selected model for the current run, independent of previous selected models.

kwargs are passed to the MethodCaller constructor.

Returns:

A 3-tuple, with the following values:

  1. the best model;

  2. all candidate models in this iteration, as a dict with model hashes as keys and models as values; and

  3. all candidate models from all iterations, as a dict with model hashes as keys and models as values.

Return type:

tuple

select_to_completion(**kwargs) List[Model][source]

Run an algorithm until an exception StopIteration is raised.

kwargs are passed to the MethodCaller constructor.

An exception StopIteration is raised by pypesto.select.method.MethodCaller.__call__ when no candidate models are found.

Returns:

The best models (the best model at each iteration).

Return type:

list

set_state(calibrated_models: Dict[str, Model], newly_calibrated_models: Dict[str, Model]) None[source]

Set the state of the problem.

See Problem attributes for argument documentation.

update_with_newly_calibrated_models(newly_calibrated_models: Dict[str, Model] | None = None) None[source]

Update the state of the problem with newly calibrated models.

Parameters:

newly_calibrated_models – See attributes of Problem.

pypesto.select.model_to_pypesto_problem(model: Model, objective: Objective | None = None, x_guesses: Iterable[Dict[str, float]] | None = None) Problem[source]

Create a pyPESTO problem from a PEtab Select model.

Parameters:
  • model – The model.

  • objective – The pyPESTO objective.

  • x_guesses – Startpoints to be used in the multi-start optimization. For example, this could be the maximum likelihood estimate from another model. Each dictionary has parameter IDs as keys, and parameter values as values. Values in x_guess for parameters that are not estimated will be ignored and replaced with their value from the PEtab Select model, if defined, else their nominal value in the PEtab parameters table.

Returns:

The pyPESTO select problem.

Return type:

Problem