geoprior.models.forecast_tuner._base_tuner#

Base classes and utilities for hyperparameter tuning of PINN models.

Classes

PINNTunerBase([objective, max_trials, ...])

Base class for hyperparameter tuning of physics-informed models.

class geoprior.models.forecast_tuner._base_tuner.PINNTunerBase(objective='val_loss', max_trials=10, project_name='PINN_Tuning', directory='pinn_tuner_results', executions_per_trial=1, tuner_type='randomsearch', seed=None, overwrite_tuner=True, _logger=None, **tuner_kwargs)[source]#

Bases: HyperModel, BaseClass

Base class for hyperparameter tuning of physics-informed models.

This class wraps keras-tuner orchestration for GeoPrior PINN-style models. Subclasses are expected to implement build(hp).

Parameters:
  • objective (str or keras_tuner.Objective, default "val_loss") – Metric to optimize during the search.

  • max_trials (int, default 10) – Maximum number of hyperparameter trials to evaluate.

  • project_name (str, default "PINN_Tuning") – Project name used for tuner artifacts.

  • directory (str, default "pinn_tuner_results") – Root directory for tuner outputs.

  • executions_per_trial (int, default 1) – Number of repeated trainings per sampled hyperparameter set.

  • tuner_type ({"randomsearch", "bayesianoptimization", "hyperband"}, default "randomsearch") – Search backend used by keras-tuner.

  • seed (int or None, default None) – Random seed used for reproducibility.

  • overwrite_tuner (bool, default True) – Whether to overwrite an existing tuner project directory.

  • tuner_kwargs (dict) – Additional keyword arguments forwarded to the underlying tuner backend.

  • _logger (Logger | Callable[[str], None] | None)

Variables:
  • best_hps (keras_tuner.HyperParameters or None) – Best hyperparameters discovered during tuning.

  • best_model (tf.keras.Model or None) – Best compiled model recovered from the tuner.

  • tuner (keras_tuner.Tuner or None) – Underlying tuner instance.

  • tuning_summary (dict) – Compact summary of the completed tuning run.

__init__(objective='val_loss', max_trials=10, project_name='PINN_Tuning', directory='pinn_tuner_results', executions_per_trial=1, tuner_type='randomsearch', seed=None, overwrite_tuner=True, _logger=None, **tuner_kwargs)[source]#

Initialize the base class.

Parameters:
  • verbose (int, optional) – Verbosity level controlling logging (0 to 3). Defaults to 0.

  • objective (str | Objective)

  • max_trials (int)

  • project_name (str)

  • directory (str)

  • executions_per_trial (int)

  • tuner_type (str)

  • seed (int | None)

  • overwrite_tuner (bool)

  • _logger (Logger | Callable[[str], None] | None)

best_hps_: HyperParameters | None#
best_model_: Model | None#
tuner_: Tuner | None#
tuning_summary_: dict[str, Any]#
fixed_model_params: dict[str, Any]#
param_space_config: dict[str, Any]#
build(hp)[source]#

Builds and compiles the Keras model with hyperparameters.

This method must be overridden by subclasses (e.g., PIHALTuner) to define the specific model architecture (like PIHALNet), sample hyperparameters using the hp object based on self.param_space, and compile the model.

Args:

hp (kt.HyperParameters): Keras Tuner HyperParameters object.

Returns:

tf.keras.Model: The compiled Keras model.

Parameters:

hp (HyperParameters)

Return type:

Model

search(train_data, epochs, validation_data=None, callbacks=None, verbose=1, patience=10, **additional_search_kwargs)[source]#

Performs the hyperparameter search using Keras Tuner.

Parameters:
  • train_data (tf.data.Dataset) – Training dataset. Must yield tuples of (inputs_dict, targets_dict) compatible with the model’s train_step.

  • epochs (int) – Number of epochs to train each model during a trial.

  • validation_data (tf.data.Dataset or None, default None) – Validation dataset.

  • callbacks (list of tf.keras.callbacks.Callback or None, default None) – Keras callbacks for the search phase.

  • verbose (int, default 1) – Verbosity level for Keras Tuner search.

  • patience (int, default 10) – Early-stopping patience.

  • **additional_search_kwargs – Additional keyword arguments passed to the tuner search() method.

Returns:

  • best_model (tf.keras.Model or None) – Best model instance built with the best hyperparameters.

  • best_hps (keras_tuner.HyperParameters or None) – Best hyperparameters found.

  • tuner (keras_tuner.Tuner or None) – Tuner instance used for the search.

Return type:

tuple[Model | None, HyperParameters | None, Tuner | None]

help(**kwargs)#
my_params = PINNTunerBase(     objective='val_loss',     max_trials=10,     project_name='PINN_Tuning',     directory='pinn_tuner_results',     executions_per_trial=1,     tuner_type='randomsearch',     seed=None,     overwrite_tuner=True,     _logger=None )#