Hyperparameters¶
Functions to handle the definition and manipulation of hyperparameters
- metatrain.utils.hypers.get_hypers_list(hypers_cls: Type[HypersType]) list[str][source]¶
Get the list of hyperparameter names defined in a TypedDict hypers class.
Inheritance of parameters is allowed from parent classes, but make sure that the parent classes only contain hyperparameters as attributes! (i.e., no methods allowed). Private attributes (starting with “_”) are not considered as hyperparameters, so one can have arbitrary private methods or attributes in the class and its parents, although this is not recommended.
- metatrain.utils.hypers.init_with_defaults(hypers_cls: Type[HypersType]) dict[source]¶
Initialize a TypedDict hypers class with its default values.
Inheritance of parameters is allowed from parent classes, but make sure that the parent classes only contain hyperparameters as attributes! (i.e., no methods allowed). Private attributes (starting with “_”) are not considered as hyperparameters, so one can have arbitrary private methods or attributes in the class and its parents, although this is not recommended.
- metatrain.utils.hypers.overwrite_defaults(hypers_cls: Type, new_defaults: dict) None[source]¶
Overwrite the default hyperparameters.
This function does not check that the new defaults correspond to valid hyperparameters of the given hypers class. If the new defaults contain keys that are not hyperparameters of the class, they will simply be ignored.
- metatrain.utils.hypers.get_hypers_diff(old_hypers: Mapping[str, Any], new_hypers: Mapping[str, Any], default_hypers: Mapping[str, Any] | None = None) dict[str, tuple[Any, Any]][source]¶
Get the difference between two hypers dictionaries.
- Parameters:
- Returns:
A dict with the hyperparameters that are different in the new hypers compared to the old hypers. It is assumed that every key in the new hypers is also present in the old hypers.
- Return type:
- metatrain.utils.hypers.raise_hypers_mismatch(hypers_diff: Mapping[str, tuple[Any, Any]]) None[source]¶
Raise an error if the hypers diff is not empty.
The error shows a report of the mismatched hyperparameters.