fit¶
The fit settings, the metadata filters and the selection of the mappings.
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), reads the observable of
a mapping (observable_id) and selects the training data by the values of the
metadata (metadata_filter) or the observable (observable_filter).
select_mappings selects the data of a fit with the paths of the model object,
see sbmlsim.fit.helpers.FitMappings.select for the filters, outliers and
validation data.
MetadataFilter
dataclass
¶
A filter of fit mappings by the values of their metadata.
A mapping passes when every allowed field has one of its values and no
excluded field has one of its values. Build it with metadata_filter.
Attributes:
| Name | Type | Description |
|---|---|---|
metadata_type |
type[MappingMetaData]
|
the metadata class of the model. |
allowed |
tuple[tuple[str, frozenset[Hashable]], ...]
|
the fields with the values a mapping must have. |
excluded |
tuple[tuple[str, frozenset[Hashable]], ...]
|
the fields with the values a mapping must not have. |
ObservableFilter
dataclass
¶
A filter of fit mappings by their observable, see observable_id.
Attributes:
| Name | Type | Description |
|---|---|---|
observables |
frozenset[str]
|
the ids of the observables a mapping may have, the index
of the data ( |
default_fit_settings
¶
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 |
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
¶
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[M]
|
the metadata class of the model. |
required |
Returns:
| Type | Description |
|---|---|
M
|
The metadata. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if the mapping has no metadata of the type. |
observable_id
¶
Get the observable of a fit mapping, the index of its data.
The index of the y data of the observable (sbmlsim.data.Data.index): the
selection without the brackets of a concentration, Cve_hctz for
[Cve_hctz], Aurine_hctz for Aurine_hctz. sbmlsim 0.9 writes the
concentration into the id of the data (<task>__conc__Cve_hctz), so the
id is no longer read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit_mapping
|
FitMapping
|
the fit mapping. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The id of the observable, e.g. |
metadata_filter
¶
Build a filter of fit mappings by the values of their metadata.
# not executed
filter_control = metadata_filter(
HctzMappingMetaData,
route={Route.PO, Route.IV},
coadministration={Coadministration.NONE},
excluded={"dosing": {Dosing.MULTIPLE}},
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata_type
|
type[MappingMetaData]
|
the metadata class of the model, a dataclass. |
required |
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 |
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. |
observable_filter
¶
Build a filter of fit mappings by their observable, e.g. the PK data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observables
|
Collection[str]
|
the ids of the observables, the index of the data
( |
required |
Returns:
| Type | Description |
|---|---|
ObservableFilter
|
The filter. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if the observables are a single id or not a collection. |
ValueError
|
for no observables, which would select nothing. |
select_mappings
¶
Select the data of a fit of a model, see sbmlsim.fit.helpers.FitMappings.
The experiments are created with the paths of the model object; the counts of the selected mappings per experiment and kind are printed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PKPDModel
|
the model object. |
required |
experiment_classes
|
Iterable[type[SimulationExperiment]]
|
the experiments with the fit mappings. |
required |
filters
|
MappingFilter | Iterable[MappingFilter]
|
the filters of the training data. |
()
|
outliers
|
Iterable[str]
|
the keys of the training data which is not usable. |
()
|
validation
|
Iterable[str] | MappingFilter
|
the keys or a filter of the validation data. |
()
|
Returns:
| Type | Description |
|---|---|
dict[str, list[FitMappingCollection]]
|
The fit mapping collections of all kinds by experiment id. |