petab_select.analyze

Methods to analyze results of model selection.

Functions

compute_weights(models, criterion[, as_dict])

Compute criterion weights.

get_best(models, criterion[, compare, ...])

Get the best model.

get_best_by_iteration(models, *args, **kwargs)

Get the best model of each iteration.

get_graph(models[, labels])

Get a graph representation of the models in terms of their ancestry.

get_parameter_changes(models[, as_dict])

Get the differences in parameters betweem models and their predecessors.

group_by_iteration(models[, sort])

Group models by their iteration.

group_by_predecessor_model(models)

Group models by their predecessor model.

petab_select.analyze.compute_weights(models, criterion, as_dict=False)[source]

Compute criterion weights.

N.B.: regardless of the criterion, the formula used is the Akaike weights formula, but with criterion values instead of the AIC.

Parameters:
  • models (Models) – The models.

  • criterion (Criterion) – The criterion.

  • as_dict (bool) – Whether to return a dictionary, with model hashes for keys.

Return type:

list[float] | dict[ModelHash, float]

Returns:

The criterion weights.

petab_select.analyze.get_best_by_iteration(models, *args, **kwargs)[source]

Get the best model of each iteration.

See :func:get_best for additional required arguments.

Parameters:
  • models (Models) – The models.

  • *args – Forwarded to :func:get_best.

  • **kwargs

    Forwarded to :func:get_best.

Return type:

dict[int, Models]

Returns:

The strictly improving models. Keys are iteration, values are models.

petab_select.analyze.get_graph(models, labels=None)[source]

Get a graph representation of the models in terms of their ancestry.

Edges connect models with their predecessor models.

Parameters:
  • models (Models) – The models.

  • labels (dict[ModelHash, str]) – Alternative labels for the models. Keys are model hashes, values are the labels.

Return type:

DiGraph

Returns:

The graph.

petab_select.analyze.get_parameter_changes(models, as_dict=False)[source]

Get the differences in parameters betweem models and their predecessors.

Parameters:
  • models (Models) – The models.

  • as_dict (bool) – Whether to return a dictionary, with model hashes for keys.

Return type:

dict[ModelHash, list[tuple[set[str], set[str]]]] | list[tuple[set[str], set[str]]]

Returns:

The parameter changes. Each model has a 2-tuple of sets of parameters. The first and second sets are the added and removed parameters, respectively. If the predecessor model is undefined (e.g. the VIRTUAL_INITIAL_MODEL), then both sets will be empty.

petab_select.analyze.group_by_iteration(models, sort=True)[source]

Group models by their iteration.

Parameters:
  • models (Models) – The models.

  • sort (bool) – Whether to sort the iterations.

Return type:

dict[int | None, Models]

Returns:

Key is iteration, value is models.

petab_select.analyze.group_by_predecessor_model(models)[source]

Group models by their predecessor model.

Parameters:

models (Models) – The models.

Return type:

dict[ModelHash, Models]

Returns:

Key is predecessor model hash, value is models.