petab_select.candidate_space

Classes and methods related to candidate spaces.

Functions

forward_inner(candidate_space, method_name)

Decorator to call the method of the inner space.

forward_super_and_inner(candidate_space, ...)

Decorator to call the method of both the super() and inner space.

method_to_candidate_space_class(method)

Get a candidate space class, given its method name.

Classes

BackwardCandidateSpace(*args[, ...])

The backward method class.

BruteForceCandidateSpace(*args, **kwargs)

The brute-force method class.

CandidateSpace(method, criterion[, ...])

A base class for collecting candidate models.

FamosCandidateSpace(*args[, ...])

The FAMoS method class.

ForwardCandidateSpace(*args[, ...])

The forward method class.

LateralCandidateSpace(*args[, max_steps])

Find models with the same number of estimated parameters.

class petab_select.candidate_space.BackwardCandidateSpace(*args, predecessor_model=None, max_steps=None, **kwargs)[source]

The backward method class.

__init__(*args, predecessor_model=None, max_steps=None, **kwargs)

See class attributes for arguments.

accept(model, distance)

Add a candidate model to the candidate space.

Parameters:
  • model (Model) – The model that will be added.

  • distance (None | float | int) – The distance of the model from the predecessor model.

Return type:

None

consider(model)

Add a candidate model, if it should be added.

Parameters:

model (Model | None) – The candidate model. This value may be None if the ModelSubspace decided to exclude the model that would have been sent.

Return type:

bool

Returns:

Whether it is OK to send additional models to the candidate space. For example, if the limit of the number of accepted models has been reached, then no further models should be sent.

distance(model)

Compute the distance between two models that are neighbors.

Parameters:

model (Model) – The candidate model.

Return type:

int

Returns:

The distance from self.predecessor_model to model, or None if the distance should not be computed.

distances_in_estimated_parameters(model, predecessor_model=None)

Distance between two models in model space, using different metrics.

All metrics are in terms of estimated parameters.

Metrics:
l1:

The L_1 distance between two models.

size:

The difference in the number of estimated parameters between two models.

Parameters:
  • model (Model) – The candidate model.

  • predecessor_model (Model | None) – See class attributes.

Return type:

dict[str, float | int]

Returns:

The distances between the models, as a dictionary, where a key is the name of the metric, and the value is the corresponding distance.

excluded(model_hash)

Check whether a model is excluded.

Parameters:

model – The model.

Return type:

bool

Returns:

True if the model is excluded, otherwise False.

get_excluded_hashes()

Get the excluded hashes.

Return type:

set[ModelHash]

Returns:

The hashes of excluded models.

get_iteration_calibrated_models(calibrated_models, reset=False)

Get all calibrated models for the current iteration.

The full list of models identified for calibration in an iteration of model selection may include models for which calibration results are already available. This combines the calibration results of the uncalibrated models, with the models that were already calibrated, to produce the full list of models that were identified for calibration in the current iteration.

Parameters:
  • calibrated_models (Models) – The calibration results for the uncalibrated models of this iteration. Keys are model hashes, values are models.

  • reset (bool) – Whether to remove the previously calibrated models from the candidate space, after they are used to produce the full list of calibrated models.

  • iteration – If provided, the iteration attribute of each model will be set to this.

Return type:

Models

Returns:

All calibrated models for the current iteration.

get_limit()

Get the limit on the number of accepted models.

Return type:

float | int

get_predecessor_model()

Get the predecessor model.

Return type:

str | Model

is_plausible(model)

Determine whether a candidate model is plausible.

A plausible model is one that could possibly be chosen by model selection method, in the absence of information about other models in the model space.

For example, given a forward selection method that starts with an initial model self.predecessor_model that has no estimated parameters, then only models with one or more estimated parameters are plausible.

Parameters:

model (Model) – The candidate model.

Return type:

bool

Returns:

True if model is plausible, else False.

n_accepted()

Get the current number of accepted models.

Return type:

int

Returns:

The number of models.

classmethod read_arguments_from_yaml_dict(yaml_dict)

Parse settings that were stored in YAML.

Parameters:

yaml_dict (dict[str, str]) – The information that was read from the YAML file. Keys are class attributes, values are the corresponding values.

Return type:

dict[str, str | Model]

Returns:

The settings, parsed into PEtab Select objects where possible.

reset(predecessor_model=None, excluded_hashes=None, limit=None)

Reset the candidate models, optionally reinitialize with a model.

Parameters:
  • predecessor_model (Model | None) – The initial model.

  • excluded_hashes (list[ModelHash] | None) – These hashes will extend the current excluded hashes.

  • limit (float | int) – The new upper limit of the number of models in this candidate space. Defaults to the previous limit.

Return type:

None

reset_accepted()

Reset the accepted models.

Return type:

None

set_excluded_hashes(hashes, extend=False)

Set the excluded hashes.

Parameters:
Return type:

None

set_iteration_user_calibrated_models(user_calibrated_models)

Hide previously-calibrated models from the calibration tool.

This allows previously-calibrated model results, e.g. from a previous model selection job, to be re-used in this job. Calibrated models are stored here between model selection iterations, while the calibration tool calibrates the uncalibrated models of the iteration. The models are then combined as the full model calibration results for the iteration, with get_iteration_calibrated_models().

Parameters:

user_calibrated_models (Models | None) – The previously-calibrated models.

Return type:

None

set_limit(limit=None)

Set the limit on the number of accepted models.

Parameters:

limit (float | int) – The limit.

Return type:

None

set_predecessor_model(predecessor_model)

Set the predecessor model.

See class attributes for arguments.

update_after_calibration(*args, iteration_calibrated_models, **kwargs)

Do work in the candidate space after calibration.

For example, this is used by the FamosCandidateSpace to switch methods.

Different candidate spaces require different arguments. All arguments are here, to ensure candidate spaces can be switched easily and still receive sufficient arguments.

wrap_search_subspaces(search_subspaces)

Decorate the subspace searches of a model space.

Used by candidate spaces to perform changes that alter the search. See BidirectionalCandidateSpace for an example, where it’s used to switch directions.

Parameters:

search_subspaces (Callable[[], None]) – The method that searches the subspaces of a model space.

Return type:

Callable

Returns:

The wrapped search_subspaces.

write_summary_tsv(row)

Write the summary of the last iteration to a TSV file.

The destination is defined in self.summary_tsv.

Parameters:

row (list[Any]) – The row that will be written to disk.

class petab_select.candidate_space.BruteForceCandidateSpace(*args, **kwargs)[source]

The brute-force method class.

__init__(*args, **kwargs)[source]

See class attributes for arguments.

accept(model, distance)

Add a candidate model to the candidate space.

Parameters:
  • model (Model) – The model that will be added.

  • distance (None | float | int) – The distance of the model from the predecessor model.

Return type:

None

consider(model)

Add a candidate model, if it should be added.

Parameters:

model (Model | None) – The candidate model. This value may be None if the ModelSubspace decided to exclude the model that would have been sent.

Return type:

bool

Returns:

Whether it is OK to send additional models to the candidate space. For example, if the limit of the number of accepted models has been reached, then no further models should be sent.

distance(model)

Compute the distance between two models that are neighbors.

Parameters:

model (Model) – The candidate model.

Return type:

None | float | int

Returns:

The distance from self.predecessor_model to model, or None if the distance should not be computed.

distances_in_estimated_parameters(model, predecessor_model=None)

Distance between two models in model space, using different metrics.

All metrics are in terms of estimated parameters.

Metrics:
l1:

The L_1 distance between two models.

size:

The difference in the number of estimated parameters between two models.

Parameters:
  • model (Model) – The candidate model.

  • predecessor_model (Model | None) – See class attributes.

Return type:

dict[str, float | int]

Returns:

The distances between the models, as a dictionary, where a key is the name of the metric, and the value is the corresponding distance.

excluded(model_hash)

Check whether a model is excluded.

Parameters:

model – The model.

Return type:

bool

Returns:

True if the model is excluded, otherwise False.

get_excluded_hashes()

Get the excluded hashes.

Return type:

set[ModelHash]

Returns:

The hashes of excluded models.

get_iteration_calibrated_models(calibrated_models, reset=False)

Get all calibrated models for the current iteration.

The full list of models identified for calibration in an iteration of model selection may include models for which calibration results are already available. This combines the calibration results of the uncalibrated models, with the models that were already calibrated, to produce the full list of models that were identified for calibration in the current iteration.

Parameters:
  • calibrated_models (Models) – The calibration results for the uncalibrated models of this iteration. Keys are model hashes, values are models.

  • reset (bool) – Whether to remove the previously calibrated models from the candidate space, after they are used to produce the full list of calibrated models.

  • iteration – If provided, the iteration attribute of each model will be set to this.

Return type:

Models

Returns:

All calibrated models for the current iteration.

get_limit()

Get the limit on the number of accepted models.

Return type:

float | int

get_predecessor_model()

Get the predecessor model.

Return type:

str | Model

is_plausible(model)

Determine whether a candidate model is plausible.

A plausible model is one that could possibly be chosen by model selection method, in the absence of information about other models in the model space.

For example, given a forward selection method that starts with an initial model self.predecessor_model that has no estimated parameters, then only models with one or more estimated parameters are plausible.

Parameters:

model (Model) – The candidate model.

Return type:

bool

Returns:

True if model is plausible, else False.

n_accepted()

Get the current number of accepted models.

Return type:

int

Returns:

The number of models.

classmethod read_arguments_from_yaml_dict(yaml_dict)

Parse settings that were stored in YAML.

Parameters:

yaml_dict (dict[str, str]) – The information that was read from the YAML file. Keys are class attributes, values are the corresponding values.

Return type:

dict[str, str | Model]

Returns:

The settings, parsed into PEtab Select objects where possible.

reset(predecessor_model=None, excluded_hashes=None, limit=None)

Reset the candidate models, optionally reinitialize with a model.

Parameters:
  • predecessor_model (Model | None) – The initial model.

  • excluded_hashes (list[ModelHash] | None) – These hashes will extend the current excluded hashes.

  • limit (float | int) – The new upper limit of the number of models in this candidate space. Defaults to the previous limit.

Return type:

None

reset_accepted()

Reset the accepted models.

Return type:

None

set_excluded_hashes(hashes, extend=False)

Set the excluded hashes.

Parameters:
Return type:

None

set_iteration_user_calibrated_models(user_calibrated_models)

Hide previously-calibrated models from the calibration tool.

This allows previously-calibrated model results, e.g. from a previous model selection job, to be re-used in this job. Calibrated models are stored here between model selection iterations, while the calibration tool calibrates the uncalibrated models of the iteration. The models are then combined as the full model calibration results for the iteration, with get_iteration_calibrated_models().

Parameters:

user_calibrated_models (Models | None) – The previously-calibrated models.

Return type:

None

set_limit(limit=None)

Set the limit on the number of accepted models.

Parameters:

limit (float | int) – The limit.

Return type:

None

set_predecessor_model(predecessor_model)

Set the predecessor model.

See class attributes for arguments.

update_after_calibration(*args, iteration_calibrated_models, **kwargs)

Do work in the candidate space after calibration.

For example, this is used by the FamosCandidateSpace to switch methods.

Different candidate spaces require different arguments. All arguments are here, to ensure candidate spaces can be switched easily and still receive sufficient arguments.

wrap_search_subspaces(search_subspaces)

Decorate the subspace searches of a model space.

Used by candidate spaces to perform changes that alter the search. See BidirectionalCandidateSpace for an example, where it’s used to switch directions.

Parameters:

search_subspaces (Callable[[], None]) – The method that searches the subspaces of a model space.

Return type:

Callable

Returns:

The wrapped search_subspaces.

write_summary_tsv(row)

Write the summary of the last iteration to a TSV file.

The destination is defined in self.summary_tsv.

Parameters:

row (list[Any]) – The row that will be written to disk.

class petab_select.candidate_space.CandidateSpace(method, criterion, predecessor_model=None, excluded_hashes=None, limit=inf, summary_tsv=None, previous_predecessor_model=None, calibrated_models=None, iteration=0)[source]

A base class for collecting candidate models.

The intended use of subclasses is to identify suitable models in a model space, that will be provided to a model selection method for selection.

criterion

The criterion by which models are compared.

distances

The distances of all candidate models from the initial model.

predecessor_model

The model used for comparison, e.g. for stepwise methods.

previous_predecessor_model

The previous predecessor model.

excluded_hashes

A list of model hashes that will not be accepted into the candidate space. The hashes of accepted models are added to :attr:excluded_hashes.

governing_method

Used to store the search method that governs the choice of method during a search. In some cases, this is always the same as the method attribute. An example of a difference is in the bidirectional method, where governing_method stores the bidirectional method, whereas method may also store the forward or backward methods.

iteration

The iteration of model selection.

limit

A handler to limit the number of accepted models.

models

The current set of candidate models.

method

The model selection method of the candidate space.

predecessor_model

The model used for comparison, e.g. for stepwise methods.

previous_predecessor_model

The previous predecessor model.

retry_model_space_search_if_no_models

Whether a search with a candidate space should be repeated upon failure. Useful for the BidirectionalCandidateSpace, which switches directions upon failure.

summary_tsv

A string or pathlib.Path. A summary of the model selection progress will be written to this file.

calibrated_models

All models that have been calibrated across all iterations of model selection.

latest_iteration_calibrated_models

The calibrated models from the most recent iteration.

__init__(method, criterion, predecessor_model=None, excluded_hashes=None, limit=inf, summary_tsv=None, previous_predecessor_model=None, calibrated_models=None, iteration=0)[source]

See class attributes for arguments.

accept(model, distance)[source]

Add a candidate model to the candidate space.

Parameters:
  • model (Model) – The model that will be added.

  • distance (None | float | int) – The distance of the model from the predecessor model.

Return type:

None

consider(model)[source]

Add a candidate model, if it should be added.

Parameters:

model (Model | None) – The candidate model. This value may be None if the ModelSubspace decided to exclude the model that would have been sent.

Return type:

bool

Returns:

Whether it is OK to send additional models to the candidate space. For example, if the limit of the number of accepted models has been reached, then no further models should be sent.

distance(model)[source]

Compute the distance between two models that are neighbors.

Parameters:

model (Model) – The candidate model.

Return type:

None | float | int

Returns:

The distance from self.predecessor_model to model, or None if the distance should not be computed.

distances_in_estimated_parameters(model, predecessor_model=None)[source]

Distance between two models in model space, using different metrics.

All metrics are in terms of estimated parameters.

Metrics:
l1:

The L_1 distance between two models.

size:

The difference in the number of estimated parameters between two models.

Parameters:
  • model (Model) – The candidate model.

  • predecessor_model (Model | None) – See class attributes.

Return type:

dict[str, float | int]

Returns:

The distances between the models, as a dictionary, where a key is the name of the metric, and the value is the corresponding distance.

excluded(model_hash)[source]

Check whether a model is excluded.

Parameters:

model – The model.

Return type:

bool

Returns:

True if the model is excluded, otherwise False.

get_excluded_hashes()[source]

Get the excluded hashes.

Return type:

set[ModelHash]

Returns:

The hashes of excluded models.

get_iteration_calibrated_models(calibrated_models, reset=False)[source]

Get all calibrated models for the current iteration.

The full list of models identified for calibration in an iteration of model selection may include models for which calibration results are already available. This combines the calibration results of the uncalibrated models, with the models that were already calibrated, to produce the full list of models that were identified for calibration in the current iteration.

Parameters:
  • calibrated_models (Models) – The calibration results for the uncalibrated models of this iteration. Keys are model hashes, values are models.

  • reset (bool) – Whether to remove the previously calibrated models from the candidate space, after they are used to produce the full list of calibrated models.

  • iteration – If provided, the iteration attribute of each model will be set to this.

Return type:

Models

Returns:

All calibrated models for the current iteration.

get_limit()[source]

Get the limit on the number of accepted models.

Return type:

float | int

get_predecessor_model()[source]

Get the predecessor model.

Return type:

str | Model

is_plausible(model)[source]

Determine whether a candidate model is plausible.

A plausible model is one that could possibly be chosen by model selection method, in the absence of information about other models in the model space.

For example, given a forward selection method that starts with an initial model self.predecessor_model that has no estimated parameters, then only models with one or more estimated parameters are plausible.

Parameters:

model (Model) – The candidate model.

Return type:

bool

Returns:

True if model is plausible, else False.

n_accepted()[source]

Get the current number of accepted models.

Return type:

int

Returns:

The number of models.

classmethod read_arguments_from_yaml_dict(yaml_dict)[source]

Parse settings that were stored in YAML.

Parameters:

yaml_dict (dict[str, str]) – The information that was read from the YAML file. Keys are class attributes, values are the corresponding values.

Return type:

dict[str, str | Model]

Returns:

The settings, parsed into PEtab Select objects where possible.

reset(predecessor_model=None, excluded_hashes=None, limit=None)[source]

Reset the candidate models, optionally reinitialize with a model.

Parameters:
  • predecessor_model (Model | None) – The initial model.

  • excluded_hashes (list[ModelHash] | None) – These hashes will extend the current excluded hashes.

  • limit (float | int) – The new upper limit of the number of models in this candidate space. Defaults to the previous limit.

Return type:

None

reset_accepted()[source]

Reset the accepted models.

Return type:

None

set_excluded_hashes(hashes, extend=False)[source]

Set the excluded hashes.

Parameters:
Return type:

None

set_iteration_user_calibrated_models(user_calibrated_models)[source]

Hide previously-calibrated models from the calibration tool.

This allows previously-calibrated model results, e.g. from a previous model selection job, to be re-used in this job. Calibrated models are stored here between model selection iterations, while the calibration tool calibrates the uncalibrated models of the iteration. The models are then combined as the full model calibration results for the iteration, with get_iteration_calibrated_models().

Parameters:

user_calibrated_models (Models | None) – The previously-calibrated models.

Return type:

None

set_limit(limit=None)[source]

Set the limit on the number of accepted models.

Parameters:

limit (float | int) – The limit.

Return type:

None

set_predecessor_model(predecessor_model)[source]

Set the predecessor model.

See class attributes for arguments.

update_after_calibration(*args, iteration_calibrated_models, **kwargs)[source]

Do work in the candidate space after calibration.

For example, this is used by the FamosCandidateSpace to switch methods.

Different candidate spaces require different arguments. All arguments are here, to ensure candidate spaces can be switched easily and still receive sufficient arguments.

wrap_search_subspaces(search_subspaces)[source]

Decorate the subspace searches of a model space.

Used by candidate spaces to perform changes that alter the search. See BidirectionalCandidateSpace for an example, where it’s used to switch directions.

Parameters:

search_subspaces (Callable[[], None]) – The method that searches the subspaces of a model space.

Return type:

Callable

Returns:

The wrapped search_subspaces.

write_summary_tsv(row)[source]

Write the summary of the last iteration to a TSV file.

The destination is defined in self.summary_tsv.

Parameters:

row (list[Any]) – The row that will be written to disk.

class petab_select.candidate_space.FamosCandidateSpace(*args, predecessor_model=None, critical_parameter_sets=[], swap_parameter_sets=[], method_scheme=None, n_reattempts=0, consecutive_laterals=False, **kwargs)[source]

The FAMoS method class.

This candidate space implements and extends the original FAMoS algorithm (doi: 10.1371/journal.pcbi.1007230).

critical_parameter_sets

A list of lists, where each inner list contains parameter IDs. All models must estimate at least 1 parameter from each critical parameter set.

swap_parameter_sets

A list of lists, where each inner list contains parameter IDs. The lateral moves in FAMoS are constrained to be between parameters that exist in the same swap parameter set.

method_scheme

A dictionary that specifies how to switch between methods when the current method doesn’t produce a better model. Keys are n-tuples that described a pattern of length n methods. Values are methods. If the previous methods match the pattern in the key, then the method in the value will be used next. The order of the dictionary is important: only the first matched pattern will be used. Defaults to the method scheme described in the original FAMoS publication.

n_reattempts

Integer. The total number of times that a jump-to-most-distance action will be performed, triggered whenever the model selection would normally terminate. Defaults to no reattempts (0).

consecutive_laterals

Boolean. If True, the method will continue performing lateral moves while they produce better models. Otherwise, the method scheme will be applied after one lateral move.

__init__(*args, predecessor_model=None, critical_parameter_sets=[], swap_parameter_sets=[], method_scheme=None, n_reattempts=0, consecutive_laterals=False, **kwargs)[source]

See class attributes for arguments.

accept(model, distance)

Add a candidate model to the candidate space.

Parameters:
  • model (Model) – The model that will be added.

  • distance (None | float | int) – The distance of the model from the predecessor model.

Return type:

None

check_critical(model)[source]

Check if the model contains all necessary critical parameters

Return type:

bool

check_swap(model)[source]

Check if parameters that are swapped are contained in the same swap parameter set.

Return type:

bool

consider(model)[source]

Re-define consider of FAMoS to be the consider method of the inner_candidate_space. Update all the attributes changed in the consider method.

Return type:

bool

distance(model)

Compute the distance between two models that are neighbors.

Parameters:

model (Model) – The candidate model.

Return type:

None | float | int

Returns:

The distance from self.predecessor_model to model, or None if the distance should not be computed.

distances_in_estimated_parameters(model, predecessor_model=None)

Distance between two models in model space, using different metrics.

All metrics are in terms of estimated parameters.

Metrics:
l1:

The L_1 distance between two models.

size:

The difference in the number of estimated parameters between two models.

Parameters:
  • model (Model) – The candidate model.

  • predecessor_model (Model | None) – See class attributes.

Return type:

dict[str, float | int]

Returns:

The distances between the models, as a dictionary, where a key is the name of the metric, and the value is the corresponding distance.

excluded(model_hash)

Check whether a model is excluded.

Parameters:

model – The model.

Return type:

bool

Returns:

True if the model is excluded, otherwise False.

get_excluded_hashes()

Get the excluded hashes.

Return type:

set[ModelHash]

Returns:

The hashes of excluded models.

get_iteration_calibrated_models(calibrated_models, reset=False)

Get all calibrated models for the current iteration.

The full list of models identified for calibration in an iteration of model selection may include models for which calibration results are already available. This combines the calibration results of the uncalibrated models, with the models that were already calibrated, to produce the full list of models that were identified for calibration in the current iteration.

Parameters:
  • calibrated_models (Models) – The calibration results for the uncalibrated models of this iteration. Keys are model hashes, values are models.

  • reset (bool) – Whether to remove the previously calibrated models from the candidate space, after they are used to produce the full list of calibrated models.

  • iteration – If provided, the iteration attribute of each model will be set to this.

Return type:

Models

Returns:

All calibrated models for the current iteration.

get_limit()

Get the limit on the number of accepted models.

Return type:

float | int

get_most_distant()[source]

Get most distant model to all the checked models. We take models from the sorted list of best models (self.best_models) and construct complements of these models. For all these complements we compute the distance in number of different estimated parameters to all models from history. For each complement we take the minimum of these distances as it’s distance to history. Then we choose the complement model with the maximal distance to history.

TODO: Next we check if this model is contained in any subspace. If so we choose it. If not we choose the model in a subspace that has least distance to this complement model.

Return type:

Model

get_predecessor_model()

Get the predecessor model.

Return type:

str | Model

insert_model_into_best_models(model_to_insert)[source]

Inserts a model into the list of best_models which are sorted w.r.t. the criterion specified.

Return type:

None

is_plausible(model)[source]

Determine whether a candidate model is plausible.

A plausible model is one that could possibly be chosen by model selection method, in the absence of information about other models in the model space.

For example, given a forward selection method that starts with an initial model self.predecessor_model that has no estimated parameters, then only models with one or more estimated parameters are plausible.

Parameters:

model (Model) – The candidate model.

Return type:

bool

Returns:

True if model is plausible, else False.

jump_to_most_distant()[source]

Jump to most distant model with respect to the history of all calibrated models.

n_accepted()

Get the current number of accepted models.

Return type:

int

Returns:

The number of models.

classmethod read_arguments_from_yaml_dict(yaml_dict)[source]

Parse settings that were stored in YAML.

Parameters:

yaml_dict – The information that was read from the YAML file. Keys are class attributes, values are the corresponding values.

Return type:

dict

Returns:

The settings, parsed into PEtab Select objects where possible.

reset(predecessor_model=None, excluded_hashes=None, limit=None)

Reset the candidate models, optionally reinitialize with a model.

Parameters:
  • predecessor_model (Model | None) – The initial model.

  • excluded_hashes (list[ModelHash] | None) – These hashes will extend the current excluded hashes.

  • limit (float | int) – The new upper limit of the number of models in this candidate space. Defaults to the previous limit.

Return type:

None

reset_accepted()

Reset the accepted models.

Return type:

None

set_excluded_hashes(hashes, extend=False)

Set the excluded hashes.

Parameters:
Return type:

None

set_iteration_user_calibrated_models(user_calibrated_models)

Hide previously-calibrated models from the calibration tool.

This allows previously-calibrated model results, e.g. from a previous model selection job, to be re-used in this job. Calibrated models are stored here between model selection iterations, while the calibration tool calibrates the uncalibrated models of the iteration. The models are then combined as the full model calibration results for the iteration, with get_iteration_calibrated_models().

Parameters:

user_calibrated_models (Models | None) – The previously-calibrated models.

Return type:

None

set_limit(limit=None)

Set the limit on the number of accepted models.

Parameters:

limit (float | int) – The limit.

Return type:

None

set_predecessor_model(predecessor_model)

Set the predecessor model.

See class attributes for arguments.

switch_inner_candidate_space(excluded_hashes)[source]

Switch the inner candidate space to match the current method.

Parameters:

excluded_hashes (list[ModelHash]) – Hashes of excluded models.

switch_method()[source]

Switch to the next method with respect to the history of methods used and the switching scheme in self.method_scheme.

Return type:

None

update_after_calibration(*args, iteration_calibrated_models, **kwargs)[source]

See CandidateSpace.update_after_calibration.

Return type:

None

update_from_iteration_calibrated_models(iteration_calibrated_models)[source]

Update self.best_models with the latest iteration_calibrated_models and determine if there was a new best model. If so, return False. True otherwise.

Return type:

bool

update_method(method)[source]

Update self.method to method.

wrap_search_subspaces(search_subspaces)[source]

Decorate the subspace searches of a model space.

Used by candidate spaces to perform changes that alter the search. See BidirectionalCandidateSpace for an example, where it’s used to switch directions.

Parameters:

search_subspaces – The method that searches the subspaces of a model space.

Returns:

The wrapped search_subspaces.

write_summary_tsv(row)

Write the summary of the last iteration to a TSV file.

The destination is defined in self.summary_tsv.

Parameters:

row (list[Any]) – The row that will be written to disk.

class petab_select.candidate_space.ForwardCandidateSpace(*args, predecessor_model=None, max_steps=None, **kwargs)[source]

The forward method class.

direction

1 for the forward method, -1 for the backward method.

max_steps

Maximum number of steps forward in a single iteration of forward selection. Defaults to no maximum (None).

__init__(*args, predecessor_model=None, max_steps=None, **kwargs)[source]

See class attributes for arguments.

accept(model, distance)

Add a candidate model to the candidate space.

Parameters:
  • model (Model) – The model that will be added.

  • distance (None | float | int) – The distance of the model from the predecessor model.

Return type:

None

consider(model)

Add a candidate model, if it should be added.

Parameters:

model (Model | None) – The candidate model. This value may be None if the ModelSubspace decided to exclude the model that would have been sent.

Return type:

bool

Returns:

Whether it is OK to send additional models to the candidate space. For example, if the limit of the number of accepted models has been reached, then no further models should be sent.

distance(model)[source]

Compute the distance between two models that are neighbors.

Parameters:

model (Model) – The candidate model.

Return type:

int

Returns:

The distance from self.predecessor_model to model, or None if the distance should not be computed.

distances_in_estimated_parameters(model, predecessor_model=None)

Distance between two models in model space, using different metrics.

All metrics are in terms of estimated parameters.

Metrics:
l1:

The L_1 distance between two models.

size:

The difference in the number of estimated parameters between two models.

Parameters:
  • model (Model) – The candidate model.

  • predecessor_model (Model | None) – See class attributes.

Return type:

dict[str, float | int]

Returns:

The distances between the models, as a dictionary, where a key is the name of the metric, and the value is the corresponding distance.

excluded(model_hash)

Check whether a model is excluded.

Parameters:

model – The model.

Return type:

bool

Returns:

True if the model is excluded, otherwise False.

get_excluded_hashes()

Get the excluded hashes.

Return type:

set[ModelHash]

Returns:

The hashes of excluded models.

get_iteration_calibrated_models(calibrated_models, reset=False)

Get all calibrated models for the current iteration.

The full list of models identified for calibration in an iteration of model selection may include models for which calibration results are already available. This combines the calibration results of the uncalibrated models, with the models that were already calibrated, to produce the full list of models that were identified for calibration in the current iteration.

Parameters:
  • calibrated_models (Models) – The calibration results for the uncalibrated models of this iteration. Keys are model hashes, values are models.

  • reset (bool) – Whether to remove the previously calibrated models from the candidate space, after they are used to produce the full list of calibrated models.

  • iteration – If provided, the iteration attribute of each model will be set to this.

Return type:

Models

Returns:

All calibrated models for the current iteration.

get_limit()

Get the limit on the number of accepted models.

Return type:

float | int

get_predecessor_model()

Get the predecessor model.

Return type:

str | Model

is_plausible(model)[source]

Determine whether a candidate model is plausible.

A plausible model is one that could possibly be chosen by model selection method, in the absence of information about other models in the model space.

For example, given a forward selection method that starts with an initial model self.predecessor_model that has no estimated parameters, then only models with one or more estimated parameters are plausible.

Parameters:

model (Model) – The candidate model.

Return type:

bool

Returns:

True if model is plausible, else False.

n_accepted()

Get the current number of accepted models.

Return type:

int

Returns:

The number of models.

classmethod read_arguments_from_yaml_dict(yaml_dict)

Parse settings that were stored in YAML.

Parameters:

yaml_dict (dict[str, str]) – The information that was read from the YAML file. Keys are class attributes, values are the corresponding values.

Return type:

dict[str, str | Model]

Returns:

The settings, parsed into PEtab Select objects where possible.

reset(predecessor_model=None, excluded_hashes=None, limit=None)

Reset the candidate models, optionally reinitialize with a model.

Parameters:
  • predecessor_model (Model | None) – The initial model.

  • excluded_hashes (list[ModelHash] | None) – These hashes will extend the current excluded hashes.

  • limit (float | int) – The new upper limit of the number of models in this candidate space. Defaults to the previous limit.

Return type:

None

reset_accepted()

Reset the accepted models.

Return type:

None

set_excluded_hashes(hashes, extend=False)

Set the excluded hashes.

Parameters:
Return type:

None

set_iteration_user_calibrated_models(user_calibrated_models)

Hide previously-calibrated models from the calibration tool.

This allows previously-calibrated model results, e.g. from a previous model selection job, to be re-used in this job. Calibrated models are stored here between model selection iterations, while the calibration tool calibrates the uncalibrated models of the iteration. The models are then combined as the full model calibration results for the iteration, with get_iteration_calibrated_models().

Parameters:

user_calibrated_models (Models | None) – The previously-calibrated models.

Return type:

None

set_limit(limit=None)

Set the limit on the number of accepted models.

Parameters:

limit (float | int) – The limit.

Return type:

None

set_predecessor_model(predecessor_model)

Set the predecessor model.

See class attributes for arguments.

update_after_calibration(*args, iteration_calibrated_models, **kwargs)

Do work in the candidate space after calibration.

For example, this is used by the FamosCandidateSpace to switch methods.

Different candidate spaces require different arguments. All arguments are here, to ensure candidate spaces can be switched easily and still receive sufficient arguments.

wrap_search_subspaces(search_subspaces)

Decorate the subspace searches of a model space.

Used by candidate spaces to perform changes that alter the search. See BidirectionalCandidateSpace for an example, where it’s used to switch directions.

Parameters:

search_subspaces (Callable[[], None]) – The method that searches the subspaces of a model space.

Return type:

Callable

Returns:

The wrapped search_subspaces.

write_summary_tsv(row)

Write the summary of the last iteration to a TSV file.

The destination is defined in self.summary_tsv.

Parameters:

row (list[Any]) – The row that will be written to disk.

class petab_select.candidate_space.LateralCandidateSpace(*args, max_steps=None, **kwargs)[source]

Find models with the same number of estimated parameters.

__init__(*args, max_steps=None, **kwargs)[source]
Additional args:
max_number_of_steps:

Maximal allowed number of swap moves. If 0 then there is no maximum.

accept(model, distance)

Add a candidate model to the candidate space.

Parameters:
  • model (Model) – The model that will be added.

  • distance (None | float | int) – The distance of the model from the predecessor model.

Return type:

None

consider(model)

Add a candidate model, if it should be added.

Parameters:

model (Model | None) – The candidate model. This value may be None if the ModelSubspace decided to exclude the model that would have been sent.

Return type:

bool

Returns:

Whether it is OK to send additional models to the candidate space. For example, if the limit of the number of accepted models has been reached, then no further models should be sent.

distance(model)

Compute the distance between two models that are neighbors.

Parameters:

model (Model) – The candidate model.

Return type:

None | float | int

Returns:

The distance from self.predecessor_model to model, or None if the distance should not be computed.

distances_in_estimated_parameters(model, predecessor_model=None)

Distance between two models in model space, using different metrics.

All metrics are in terms of estimated parameters.

Metrics:
l1:

The L_1 distance between two models.

size:

The difference in the number of estimated parameters between two models.

Parameters:
  • model (Model) – The candidate model.

  • predecessor_model (Model | None) – See class attributes.

Return type:

dict[str, float | int]

Returns:

The distances between the models, as a dictionary, where a key is the name of the metric, and the value is the corresponding distance.

excluded(model_hash)

Check whether a model is excluded.

Parameters:

model – The model.

Return type:

bool

Returns:

True if the model is excluded, otherwise False.

get_excluded_hashes()

Get the excluded hashes.

Return type:

set[ModelHash]

Returns:

The hashes of excluded models.

get_iteration_calibrated_models(calibrated_models, reset=False)

Get all calibrated models for the current iteration.

The full list of models identified for calibration in an iteration of model selection may include models for which calibration results are already available. This combines the calibration results of the uncalibrated models, with the models that were already calibrated, to produce the full list of models that were identified for calibration in the current iteration.

Parameters:
  • calibrated_models (Models) – The calibration results for the uncalibrated models of this iteration. Keys are model hashes, values are models.

  • reset (bool) – Whether to remove the previously calibrated models from the candidate space, after they are used to produce the full list of calibrated models.

  • iteration – If provided, the iteration attribute of each model will be set to this.

Return type:

Models

Returns:

All calibrated models for the current iteration.

get_limit()

Get the limit on the number of accepted models.

Return type:

float | int

get_predecessor_model()

Get the predecessor model.

Return type:

str | Model

is_plausible(model)[source]

Determine whether a candidate model is plausible.

A plausible model is one that could possibly be chosen by model selection method, in the absence of information about other models in the model space.

For example, given a forward selection method that starts with an initial model self.predecessor_model that has no estimated parameters, then only models with one or more estimated parameters are plausible.

Parameters:

model (Model) – The candidate model.

Return type:

bool

Returns:

True if model is plausible, else False.

n_accepted()

Get the current number of accepted models.

Return type:

int

Returns:

The number of models.

classmethod read_arguments_from_yaml_dict(yaml_dict)

Parse settings that were stored in YAML.

Parameters:

yaml_dict (dict[str, str]) – The information that was read from the YAML file. Keys are class attributes, values are the corresponding values.

Return type:

dict[str, str | Model]

Returns:

The settings, parsed into PEtab Select objects where possible.

reset(predecessor_model=None, excluded_hashes=None, limit=None)

Reset the candidate models, optionally reinitialize with a model.

Parameters:
  • predecessor_model (Model | None) – The initial model.

  • excluded_hashes (list[ModelHash] | None) – These hashes will extend the current excluded hashes.

  • limit (float | int) – The new upper limit of the number of models in this candidate space. Defaults to the previous limit.

Return type:

None

reset_accepted()

Reset the accepted models.

Return type:

None

set_excluded_hashes(hashes, extend=False)

Set the excluded hashes.

Parameters:
Return type:

None

set_iteration_user_calibrated_models(user_calibrated_models)

Hide previously-calibrated models from the calibration tool.

This allows previously-calibrated model results, e.g. from a previous model selection job, to be re-used in this job. Calibrated models are stored here between model selection iterations, while the calibration tool calibrates the uncalibrated models of the iteration. The models are then combined as the full model calibration results for the iteration, with get_iteration_calibrated_models().

Parameters:

user_calibrated_models (Models | None) – The previously-calibrated models.

Return type:

None

set_limit(limit=None)

Set the limit on the number of accepted models.

Parameters:

limit (float | int) – The limit.

Return type:

None

set_predecessor_model(predecessor_model)

Set the predecessor model.

See class attributes for arguments.

update_after_calibration(*args, iteration_calibrated_models, **kwargs)

Do work in the candidate space after calibration.

For example, this is used by the FamosCandidateSpace to switch methods.

Different candidate spaces require different arguments. All arguments are here, to ensure candidate spaces can be switched easily and still receive sufficient arguments.

wrap_search_subspaces(search_subspaces)

Decorate the subspace searches of a model space.

Used by candidate spaces to perform changes that alter the search. See BidirectionalCandidateSpace for an example, where it’s used to switch directions.

Parameters:

search_subspaces (Callable[[], None]) – The method that searches the subspaces of a model space.

Return type:

Callable

Returns:

The wrapped search_subspaces.

write_summary_tsv(row)

Write the summary of the last iteration to a TSV file.

The destination is defined in self.summary_tsv.

Parameters:

row (list[Any]) – The row that will be written to disk.