pypesto.select

Model Selection

Perform model selection with a PEtab Select problem.

class pypesto.select.ModelProblem[source]

Bases: object

Handles all required calibration tasks on a model.

Handles the creation, estimation, and evaluation of a model. Here, a model is a PEtab problem that is patched with a dictionary of custom parameter values (which may specify that the parameter should be estimated). Evaluation refers to criterion values such as AIC.

best_start

The best start from a pyPESTO optimize result.

criterion

The criterion that should be computed after the model is calibrated.

minimize_method

The optimization method, which should take a :class:Problem as its only required positional argument, and return a :class:Result that contains an :class:OptimizerResult. Other arguments can be provided as keyword arguments, via minimize_options.

minimize_options

Keyword argument options that will be passed on to minimize_method.

minimize_result

A pyPESTO result with an optimize result.

model

A PEtab Select model.

model_id

The ID of the PEtab Select model.

objective_customizer

A method that takes a pypesto.objective.AmiciObjective as input, and makes changes to the objective in-place.

postprocessor

A method that takes a ModelSelectionProblem as input. For example, this can be a function that generates a waterfall plot. This postprocessor is applied at the end of the ModelProblem.set_result() method.

pypesto_problem

The pyPESTO problem for the model.

valid

If False, the model will not be tested.

x_guess

A single startpoint, that will be used as one of the startpoints in the multi-start optimization.

__init__(model, criterion, valid=True, autorun=True, x_guess=None, minimize_options=None, objective_customizer=None, postprocessor=None, model_to_pypesto_problem_method=None, minimize_method=None)[source]

Construct then calibrate a model problem.

See the class documentation for documentation of most parameters.

Parameters:
minimize()[source]

Optimize the model.

Return type:

Result

Returns:

The optimization result.

set_result(result)[source]

Postprocess a result.

Parameters:

result (Result) – A pyPESTO result with an optimize result.

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

All calibrated models.

Type:

petab_select.Models

newly_calibrated_models

All models that were calibrated in the latest iteration of model selection.

Type:

petab_select.Models

method_caller

Used to run a single iteration of a model selection method.

Type:

pypesto.select.method.MethodCaller

model_problem_options

Keyword arguments, passed to the constructor of ModelProblem.

Type:

dict[str, Any]

petab_select_problem

A PEtab Select problem.

Type:

petab_select.Problem

__init__(petab_select_problem, model_postprocessor=None, model_problem_options=None)[source]
Parameters:
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 (Models) – 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, Models]

Returns:

A 2-tuple, with the following values from this iteration

  1. the best model; and

  2. all models.

select_to_completion(**kwargs)[source]

Perform model selection until the method terminates.

kwargs are passed to the MethodCaller constructor.

Return type:

Models

Returns:

All models.

set_state(calibrated_models, newly_calibrated_models)[source]

Set the state of the problem.

See Problem attributes for argument documentation.

Return type:

None

Parameters:
  • calibrated_models (Models)

  • newly_calibrated_models (Models)

update_with_newly_calibrated_models(newly_calibrated_models=None)[source]

Update the state of the problem with newly calibrated models.

Parameters:

newly_calibrated_models (Models | None) – See attributes of Problem.

Return type:

None

class pypesto.select.SacessMinimizeMethod[source]

Bases: object

Create a minimize method for SaCeSS that adapts to each problem.

When a pyPESTO SaCeSS optimizer is created, it takes the problem dimension as input. Hence, an optimizer needs to be constructed for each problem. Objects of this class act like a minimize method for model selection, but a new problem-specific SaCeSS optimizer will be created every time a model is minimized.

Instance attributes correspond to pyPESTO’s SaCeSS optimizer, and are documented there. Extra keyword arguments supplied to the constructor will be passed on to the constructor of the SaCeSS optimizer, for example, max_walltime_s can be specified in this way. If specified, tmpdir will be treated as a parent directory.

__call__(problem, model_hash, **minimize_options)[source]

Create then run a problem-specific sacess optimizer.

Parameters:
  • problem (Problem) – The pyPESTO problem for the model.

  • model_hash (ModelHash) – The model hash.

  • minimize_options – Passed to SacessOptimizer.minimize().

Returns:

The output from SacessOptimizer.minimize().

__init__(num_workers, local_optimizer=None, tmpdir=None, save_history=False, **optimizer_kwargs)[source]

Construct a minimize-like object.

Parameters:
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.