HyperParams#

class openstef_core.mixins.predictor.HyperParams(**data: Any) None[source]

Bases: BaseConfig

Base configuration for model hyperparameters.

Serves as the foundation for model-specific hyperparameter configurations. Supports tuning ranges: pass a FloatRange, IntRange, or CategoricalRange as a field value at construction time and it will be extracted into _instance_ranges while the field keeps its declared default.

Example

>>> from typing import Annotated
>>> from openstef_core.mixins.param_ranges import FloatRange, IntRange
>>> class MyHP(HyperParams):
...     lr: Annotated[float, FloatRange(low=0.01, high=1.0)] = 0.3
...     depth: Annotated[int, IntRange(low=1, high=15)] = 6
>>> hp = MyHP(lr=FloatRange(low=0.001, high=0.5, tune=True))
>>> hp.lr  # field keeps its default
0.3
>>> hp.get_search_space()  # extracted range
{'lr': FloatRange(low=0.001, high=0.5, log=False, tune=True)}
Parameters:

data (Any)

get_search_space(include: set[str] | None = None) dict[str, TuningRange][source]

Merge instance and class-level ranges, returning only tune=True fields.

Parameters:
  • include (set[str] | None) – If given, restrict output to these field names.

  • include

Returns:

Mapping of field name to resolved TuningRange.

Raises:

KeyError – If include contains names not in the tunable space.

Return type:

dict[str, TypeAliasType]

get_tuning_overrides() dict[str, TuningRange][source]

Return the unresolved range overrides that were passed at construction time.

Return type:

dict[str, TypeAliasType]

clear_tuning_ranges() Self[source]

Clear any stored tuning range overrides from this hyperparameter config.

Return type:

Self

Returns:

self with _instance_ranges cleared.

materialize(update: dict[str, Any] | None = None) Self[source]

Return a copy with concrete values only and no stored tuning ranges.

Parameters:
  • update (dict[str, Any] | None) – Optional field updates to apply before clearing tuning metadata.

  • update

Returns:

Copy of self with _instance_ranges cleared.

Return type:

Self

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': False, 'extra': 'ignore', 'protected_namespaces': ()}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

  • self

  • context

Return type:

None