- tpcp.make_optimize_safe(self_optimize_method: Callable[[P], T]) Callable[[P], T] #
Apply a set of runtime checks to a custom
self_optimizemethod to prevent implementation errors.
The following things are checked:
self_optimizemethod must return
self(or at least an instance of the algorithm or pipeline).
self_optimizemethod must only modify input parameters of the pipeline and not any other attributes.
self_optimizemethod should modify at least one of the input parameters (this doesn’t raise an error, but just a warning).
In general, we recommend to just apply this decorator to all custom
self_optimizemethods. The runtime overhead is usually small enough to not make a difference.
The only execption are custom pipelines that you only optimize using the
Optimizewrapper. This wrapper will apply the same runtime checks anyway. However, it doesn’t hurt to apply it as decorator as well. We make sure that the cheks will still only be performed once.
>>> from tpcp import Algorithm, make_optimize_safe >>> class MyAlgorithm(Algorithm): ... def __init__(self, para_1: int = 4): ... self.para_1 = para_1 ... ... @make_optimize_safe ... def self_optimize(self, train_data, **kwargs): ... # find a better value for para_1 based on the provided trainings data ... better_value_for_para_1 = 5 ... self.para_1 = better_value_for_para_1 ... return self