Model Mixins#
Mixin classes to enhance functionality of models.
- class lymph.mixins.NamedParamsMixin[source]#
Bases:
objectAllow defining a
named_paramssubset of params to set and get.- property named_params: Sequence[str]#
Sequence of parameter names that may be changed.
Only parameter names are allowed that would also be recognized by the
set_params()method. For example,"TtoII_spread"or"late_p"could be valid named parameters. Even global parameters like"spread"work.Warning
The order is important: If the
named_paramsare set to e.g.["TtoII_spread", "spread"], then the"spread"parameter will override the"TtoII_spread".This exists for reproducibility reasons: It allows for a subset of parameters to be set via a special method (
set_named_params()). Subsequently, only these parameters can be set via that method, both using positional and keyword arguments.A use case for this is parameter sampling. E.g., someone samples only a subset of parameters and stores these as an unnamed array along with a list of the parameters names they correspond to. Without the
named_paramsand theset_named_params()method, it would be tricky to load those values back into the model.See also
This issue on GitHub provides more information for the rationale behind this mixin.
- get_named_params(as_dict: bool = True) Iterable[float] | dict[str, float][source]#
Get the values of the
named_params.Note
Unlike the general
get_params()method, this method does not support the keyword argumentas_flat. The returned dictionary (ifas_dict=True) will always be flat.
- set_named_params(*args, **kwargs) None[source]#
Set the values of the
named_params.Note
Positional arguments are overwritten by keyword arguments, which must only contain keys that are in
named_params.