in src/entrypoint/gluonts_example/util.py [0:0]
def override_hp(hp: Dict[str, Any], metadata: MetaData) -> Dict[str, Any]:
"""Resolve values to inject to the estimator: is it the hp or the one from metadata.
This function:
- mitigates errors made by callers when inadvertantly specifies hyperparameters that shouldn't be done, e.g.,
the frequency should follow how the data prepared.
- uses some metadata values as defaults, unless stated otherwise by the hyperparameters.
"""
hp = hp.copy()
# Always use freq from dataset.
if "freq" in hp and hp["freq"] != metadata.freq:
freq_hp = hp["freq"]
logging.warning(f"freq: set freq='{metadata.freq}' from metadata; ignore '{freq_hp}' from hyperparam.")
hp["freq"] = metadata.freq
# Use prediction_length hyperparameters, but if not specified then fallbacks to the one from metadata.
if "prediction_length" not in hp:
hp["prediction_length"] = metadata.prediction_length
logging.warning(
"prediction_length: no hyperparam, so set " f"prediction_length={metadata.prediction_length} from metadata"
)
return hp