petab.parameter_mapping

Functions related to mapping parameter from model to parameter estimation problem

Functions

get_optimization_to_simulation_parameter_mapping(…) Create list of mapping dicts from PEtab-problem to SBML parameters.
get_parameter_mapping_for_condition(…) Create dictionary of parameter value and parameter scale mappings from PEtab-problem to SBML parameters for the given condition.
handle_missing_overrides(…) Find all observable parameters and noise parameters that were not mapped and set their mapping to np.nan.
merge_preeq_and_sim_pars(parameter_mappings, …) Merge preequilibration and simulation parameters and scales for a list of conditions while checking for compatibility.
merge_preeq_and_sim_pars_condition(…) Merge preequilibration and simulation parameters and scales for a single condition while checking for compatibility.
petab.parameter_mapping._apply_condition_parameters(par_mapping: Dict[str, Union[str, numbers.Number]], scale_mapping: Dict[str, str], condition_id: str, condition_df: pandas.core.frame.DataFrame, sbml_model: libsbml.Model) → None

Replace parameter IDs in parameter mapping dictionary by condition table parameter values (in-place).

Parameters:
  • par_mapping – see get_parameter_mapping_for_condition
  • condition_id – ID of condition to work on
  • condition_df – PEtab condition table
petab.parameter_mapping._apply_output_parameter_overrides(mapping: Dict[str, Union[str, numbers.Number]], cur_measurement_df: pandas.core.frame.DataFrame) → None

Apply output parameter overrides to the parameter mapping dict for a given condition as defined in the measurement table (observableParameter, noiseParameters).

Parameters:
  • mapping – parameter mapping dict as obtained from get_parameter_mapping_for_condition
  • cur_measurement_df – Subset of the measurement table for the current condition
petab.parameter_mapping._apply_overrides_for_observable(mapping: Dict[str, Union[str, numbers.Number]], observable_id: str, override_type: str, overrides: List[str]) → None

Apply parameter-overrides for observables and noises to mapping matrix.

Parameters:
  • mapping – mapping dict to which to apply overrides
  • observable_id – observable ID
  • override_type – ‘observable’ or ‘noise’
  • overrides – list of overrides for noise or observable parameters
petab.parameter_mapping._apply_parameter_table(par_mapping: Dict[str, Union[str, numbers.Number]], scale_mapping: Dict[str, str], parameter_df: Optional[pandas.core.frame.DataFrame] = None, scaled_parameters: bool = False, fill_fixed_parameters: bool = True) → None

Replace parameters from parameter table in mapping list for a given condition and set the corresponding scale.

Replace non-estimated parameters by nominalValues (un-scaled / lin-scaled), replace estimated parameters by the respective ID.

Parameters:
  • par_mapping – mapping dict obtained from get_parameter_mapping_for_condition
  • parameter_df – PEtab parameter table
petab.parameter_mapping._map_condition(packed_args)

Helper function for parallel condition mapping.

For arguments see get_optimization_to_simulation_parameter_mapping

petab.parameter_mapping._map_condition_arg_packer(simulation_conditions, measurement_df, condition_df, parameter_df, sbml_model, simulation_parameters, warn_unmapped, scaled_parameters, fill_fixed_parameters)

Helper function to pack extra arguments for _map_condition

petab.parameter_mapping._output_parameters_to_nan(mapping: Dict[str, Union[str, numbers.Number]]) → None

Set output parameters in mapping dictionary to nan

petab.parameter_mapping._perform_mapping_checks(measurement_df: pandas.core.frame.DataFrame) → None

Check for PEtab features which we can’t account for during parameter mapping.

petab.parameter_mapping.get_optimization_to_simulation_parameter_mapping(condition_df: pandas.core.frame.DataFrame, measurement_df: pandas.core.frame.DataFrame, parameter_df: Optional[pandas.core.frame.DataFrame] = None, observable_df: Optional[pandas.core.frame.DataFrame] = None, sbml_model: libsbml.Model = None, simulation_conditions: Optional[pandas.core.frame.DataFrame] = None, warn_unmapped: Optional[bool] = True, scaled_parameters: bool = False, fill_fixed_parameters: bool = True) → List[Tuple[Dict[str, Union[str, numbers.Number]], Dict[str, Union[str, numbers.Number]], Dict[str, str], Dict[str, str]]]

Create list of mapping dicts from PEtab-problem to SBML parameters.

Mapping can be performed in parallel. The number of threads is controlled by the environment variable with the name of petab.ENV_NUM_THREADS.

Parameters:
  • measurement_df, parameter_df, observable_df (condition_df,) – The dataframes in the PEtab format.
  • sbml_model – The sbml model with observables and noise specified according to the PEtab format.
  • simulation_conditions – Table of simulation conditions as created by petab.get_simulation_conditions.
  • warn_unmapped – If True, log warning regarding unmapped parameters
  • scaled_parameters – Whether parameter values should be scaled.
  • fill_fixed_parameters – Whether to fill in nominal values for fixed parameters (estimate=0 in parameters table).
Returns:

Parameter value and parameter scale mapping for all conditions.

The length of the returned array is the number of unique combinations of simulationConditionId``s and ``preequilibrationConditionId``s from the measurement table. Each entry is a tuple of four dicts of length equal to the number of model parameters. The first two dicts map simulation parameter IDs to optimization parameter IDs or values (where values are fixed) for preequilibration and simulation condition, respectively. The last two dicts map simulation parameter IDs to the parameter scale of the respective parameter, again for preequilibration and simulation condition. If no preequilibration condition is defined, the respective dicts will be empty. ``NaN is used where no mapping exists.

petab.parameter_mapping.get_parameter_mapping_for_condition(condition_id: str, is_preeq: bool, cur_measurement_df: pandas.core.frame.DataFrame, sbml_model: libsbml.Model, condition_df: pandas.core.frame.DataFrame, parameter_df: pandas.core.frame.DataFrame = None, simulation_parameters: Optional[Dict[str, str]] = None, warn_unmapped: bool = True, scaled_parameters: bool = False, fill_fixed_parameters: bool = True) → Tuple[Dict[str, Union[str, numbers.Number]], Dict[str, str]]

Create dictionary of parameter value and parameter scale mappings from PEtab-problem to SBML parameters for the given condition.

Parameters:
  • condition_id – Condition ID for which to perform mapping
  • is_preeq – If True, output parameters will not be mapped
  • cur_measurement_df – Measurement sub-table for current condition
  • condition_df – PEtab condition DataFrame
  • parameter_df – PEtab parameter DataFrame
  • sbml_model – The sbml model with observables and noise specified according to the PEtab format used to retrieve simulation parameter IDs.
  • simulation_parameters – Model simulation parameter IDs mapped to parameter values (output of petab.sbml.get_model_parameters(.., with_values=True)). Optional, saves time if precomputed.
  • warn_unmapped – If True, log warning regarding unmapped parameters
  • fill_fixed_parameters – Whether to fill in nominal values for fixed parameters (estimate=0 in parameters table).
Returns:

Tuple of two dictionaries. First dictionary mapping model parameter IDs to mapped parameters IDs to be estimated or to filled-in values in case of non-estimated parameters. Second dictionary mapping model parameter IDs to their scale. NaN is used where no mapping exists.

petab.parameter_mapping.handle_missing_overrides(mapping_par_opt_to_par_sim: Dict[str, Union[str, numbers.Number]], warn: bool = True, condition_id: str = None) → None

Find all observable parameters and noise parameters that were not mapped and set their mapping to np.nan.

Assumes that parameters matching “(noise|observable)Parameter[0-9]+_” were all supposed to be overwritten.

Parameters:
  • mapping_par_opt_to_par_sim – Output of get_parameter_mapping_for_condition
  • warn – If True, log warning regarding unmapped parameters
  • condition_id – Optional condition ID for more informative output
petab.parameter_mapping.merge_preeq_and_sim_pars(parameter_mappings: Iterable[Tuple[Dict[str, Union[str, numbers.Number]], Dict[str, Union[str, numbers.Number]]]], scale_mappings: Iterable[Tuple[Dict[str, str], Dict[str, str]]]) → Tuple[List[Tuple[Dict[str, Union[str, numbers.Number]], Dict[str, Union[str, numbers.Number]]]], List[Tuple[Dict[str, str], Dict[str, str]]]]

Merge preequilibration and simulation parameters and scales for a list of conditions while checking for compatibility.

Parameters:
  • parameter_mappings – As returned by petab.get_optimization_to_simulation_parameter_mapping
  • scale_mappings – As returned by petab.get_optimization_to_simulation_scale_mapping.
Returns:

The parameter and scale simulation mappings, modified and checked.

petab.parameter_mapping.merge_preeq_and_sim_pars_condition(condition_map_preeq: Dict[str, Union[str, numbers.Number]], condition_map_sim: Dict[str, Union[str, numbers.Number]], condition_scale_map_preeq: Dict[str, str], condition_scale_map_sim: Dict[str, str], condition: Any) → None

Merge preequilibration and simulation parameters and scales for a single condition while checking for compatibility.

This function is meant for the case where we cannot have different parameters (and scales) for preequilibration and simulation. Therefore, merge both and ensure matching scales and parameters. condition_map_sim and condition_scale_map_sim will ne modified in place.

Parameters:
  • condition_map_sim (condition_map_preeq,) – Parameter mapping as obtained from get_parameter_mapping_for_condition
  • condition_scale_map_sim (condition_scale_map_preeq,) – Parameter scale mapping as obtained from get_get_scale_mapping_for_condition
  • condition – Condition identifier for more informative error messages