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 as an additional temporary attribute in its objects.

Parameters:
Raises:

ValueError – If the class already contains an attribute with the same name as the temporary attribute to be added.

Returns:

The modified class.