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.

Parameters:

hypers_cls (Type[HypersType]) – The class defining the hyperparameters.

Returns:

A list with the names of the hyperparameters.

Return type:

list[str]

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.

Parameters:

hypers_cls (Type[HypersType]) – The class defining the hyperparameters.

Returns:

A dict with the default hyperparameters.

Return type:

dict

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.

Parameters:
  • hypers_cls (Type) – The hypers class whose defaults to overwrite.

  • new_defaults (dict) – A dict with the new default hyperparameters.

Return type:

None