pypesto.select

Model Selection

Perform model selection with a PEtab Select problem.

class pypesto.select.Problem[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_problem_options

Passed to the constructor of :class:ModelProblem.

petab_select_problem

A PEtab Select problem.

__init__(petab_select_problem, model_postprocessor=None, model_problem_options=None)[source]
Parameters:
  • petab_select_problem (Problem) –

  • model_postprocessor (Callable[[ModelProblem], None] | None) –

  • model_problem_options (dict) –

create_method_caller(**kwargs)[source]

Create a method caller.

kwargs are passed to the MethodCaller constructor.

Return type:

MethodCaller

Returns:

A MethodCaller instance.

handle_select_kwargs(kwargs)[source]

Check keyword arguments to select calls.

Parameters:

kwargs (dict[str, Any]) –

multistart_select(predecessor_models=None, **kwargs)[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 (Iterable[Model]) – The models that will be used as initial models. One “model selection iteration” will be run for each predecessor model.

Return type:

tuple[Model, list[Model]]

Returns:

A 2-tuple, with the following values

  1. the best model; and

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

select(**kwargs)[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.

Return type:

tuple[Model, dict[str, Model], dict[str, Model]]

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.

select_to_completion(**kwargs)[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.

Return type:

list[Model]

Returns:

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

set_state(calibrated_models, newly_calibrated_models)[source]

Set the state of the problem.

See Problem attributes for argument documentation.

Return type:

None

Parameters:
update_with_newly_calibrated_models(newly_calibrated_models=None)[source]

Update the state of the problem with newly calibrated models.

Parameters:

newly_calibrated_models (Optional[dict[str, Model]]) – See attributes of Problem.

Return type:

None

pypesto.select.model_to_pypesto_problem(model, objective=None, x_guesses=None, hierarchical=False)[source]

Create a pyPESTO problem from a PEtab Select model.

Parameters:
  • model (Model) – The model.

  • objective (Objective) – The pyPESTO objective.

  • x_guesses (Iterable[dict[str, float]]) – 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.

  • hierarchical (bool) – Whether the problem involves hierarchical optimization.

Return type:

Problem

Returns:

The pyPESTO select problem.