baybe.surrogates.utils.catch_constant_targets

baybe.surrogates.utils.catch_constant_targets(cls: type[Surrogate], std_threshold: float = 1e-06)[source]

Make a Surrogate class robustly handle constant training targets.

More specifically, “constant training targets” can mean either of:
  • The standard deviation of the training targets is below the given threshold.

  • There is only one target and the standard deviation cannot even be computed.

The modified class handles the above cases separately from “regular operation” by resorting to a baybe.surrogates.naive.MeanPredictionSurrogate, which is stored outside the model in a dictionary maintained by this decorator.

Parameters:
Returns:

The modified class.