make_optimize_safe#

tpcp.make_optimize_safe(self_optimize_method: Callable[[P], T]) Callable[[P], T][source]#

Apply a set of runtime checks to a custom self_optimize method to prevent implementation errors.

The following things are checked:

  • The self_optimize method must return self (or at least an instance of the algorithm or pipeline).

  • The self_optimize method must only modify input parameters of the pipeline and not any other attributes.

  • The self_optimize method 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_optimize methods. The runtime overhead is usually small enough to not make a difference.

The only execption are custom pipelines that you only optimize using the Optimize wrapper. 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.

Examples

>>> 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

Examples using tpcp.make_optimize_safe#

Algorithms - A real world example: QRS-Detection

Algorithms - A real world example: QRS-Detection

The final QRS detection algorithms

The final QRS detection algorithms

Optimizable Pipelines

Optimizable Pipelines

Tensorflow/Keras

Tensorflow/Keras

Optimization Info

Optimization Info