Skip to content

fit

The fit settings, the metadata check and the sampling sites of the models.

The models of pkdb_models share their fit settings apart from the integrator tolerances (default_fit_settings). Every mapping_collections.py checks the type of the metadata of a mapping (mapping_metadata) and selects the training data by the values of the metadata (metadata_filter, the filter of sbmlsim.fit.filters for PKPDMappingMetaData). The other filters, the selection of the mappings, the start of a fit, the fixed adopted fits and the records of the adopted fits are those of sbmlsim.fit (sbmlsim.fit.filters, sbmlsim.fit.helpers.select_mappings, sbmlsim.fit.project_fits, sbmlsim.fit.records).

default_fit_settings

default_fit_settings(
    absolute_tolerance, relative_tolerance=1e-06
)

Get the settings of the fits of a model.

Normalized residuals with a linear loss; the curves are weighted by the weights of their mappings and by their number of points, the points by their errors (a mapping without errors is weighted with a CV of 0.5); the integrator takes variable steps; a data point at the time of a change after the start is compared with the state before the change (data_at_change), sbmlsim's default, written out so that a change of the default does not change the fits.

Parameters:

Name Type Description Default
absolute_tolerance float | AbsoluteTolerance

the absolute tolerance of the integrator, one value or an AbsoluteTolerance per kind and state.

required
relative_tolerance float

the relative tolerance of the integrator.

1e-06

Returns:

Type Description
FitSettings

The settings, stored with the result of a fit and read back by its report.

mapping_metadata

mapping_metadata(
    fit_mapping: FitMapping,
) -> PKPDMappingMetaData
mapping_metadata(
    fit_mapping: FitMapping, metadata_type: type[M]
) -> M
mapping_metadata(
    fit_mapping, metadata_type=PKPDMappingMetaData
)

Get the metadata of a fit mapping, checked against the type of the model.

Parameters:

Name Type Description Default
fit_mapping FitMapping

the fit mapping.

required
metadata_type type[MappingMetaData]

the metadata class, PKPDMappingMetaData unless a model extends it.

PKPDMappingMetaData

Returns:

Type Description
MappingMetaData

The metadata.

Raises:

Type Description
TypeError

if the mapping has no metadata of the type.

metadata_filter

metadata_filter(
    metadata_type=PKPDMappingMetaData,
    /,
    *,
    excluded=None,
    **allowed,
)

Build a filter of fit mappings by the values of their PK metadata.

The filter of sbmlsim.fit.filters.metadata_filter with the metadata of the models, PKPDMappingMetaData; the sampling site it compares is the resolved one (PKPDMappingMetaData.filter_value).

# not executed
filter_control = metadata_filter(
    route={Route.PO, Route.IV},
    coadministration={Coadministration.NONE},
    excluded={"dosing": {Dosing.MULTIPLE}},
)

Parameters:

Name Type Description Default
metadata_type type[PKPDMappingMetaData]

the metadata class, PKPDMappingMetaData unless a model extends it; positional only.

PKPDMappingMetaData
excluded Mapping[str, Collection[Hashable]] | None

the fields with the values a mapping must not have.

None
**allowed Collection[Hashable]

the fields with the values a mapping must have.

{}

Returns:

Type Description
MetadataFilter

The filter, called by the selection of the mappings of a fit.

Raises:

Type Description
TypeError

if the metadata class is no dataclass (or an instance of one), has no field of a given name, or the values of a field are not a collection (a single value, also a string or None).

ValueError

for a filter without clauses, with an empty set of allowed values, which would select nothing, or with an empty set of excluded values, which would exclude nothing.

check_sampling_sites

check_sampling_sites(
    fit_mappings, sites, metadata_type=PKPDMappingMetaData
)

Check the sampling site of the mappings against their observable.

Parameters:

Name Type Description Default
fit_mappings FitMappings | Iterable[FitMapping]

the fit mappings, or the instantiated experiments of a model (FitMappings, every fit mapping of every experiment).

required
sites Mapping[str, SamplingSite]

the sampling site of every observable by observable id, e.g. Carm_hctz is ARM_VEIN and Aurine_hctz is NOT_APPLICABLE.

required
metadata_type type[PKPDMappingMetaData]

the metadata class, PKPDMappingMetaData unless a model extends it.

PKPDMappingMetaData

Returns:

Type Description
list[str]

One problem per mapping whose site differs from the site of its

list[str]

observable or whose observable is not in sites; empty if all fit.