alibi-detect icon indicating copy to clipboard operation
alibi-detect copied to clipboard

Add a drift detector base class

Open ascillitoe opened this issue 2 years ago • 0 comments

We should explore adding a base drift detector class. This could help with a number of issues:

  1. The preprocess methods are heavily duplicated across drift detectors (in cd.base):

         if self.preprocess_fn is not None:
             x = self.preprocess_fn(x)
             if not self.preprocess_at_init and not self.x_ref_preprocessed:
                 x_ref = self.preprocess_fn(self.x_ref)
             else:
                 x_ref = self.x_ref
             return x_ref, x  # type: ignore[return-value]
         else:
             return self.x_ref, x  # type: ignore[return-value]
    
  2. The preprocess logic in detector __init__ methods is heavily duplicated:

         # x_ref preprocessing
         self.preprocess_at_init = preprocess_at_init
         self.x_ref_preprocessed = x_ref_preprocessed
         if preprocess_fn is not None and not isinstance(preprocess_fn, Callable):  # type: ignore[arg-type]
             raise ValueError("`preprocess_fn` is not a valid Callable.")
         if self.preprocess_at_init and not self.x_ref_preprocessed and preprocess_fn is not None:
             self.x_ref = preprocess_fn(x_ref)
         else:
             self.x_ref = x_ref
    
  3. Some args/kwargs and methods are shared by all drift detectors i.e. input_shape and data_type. A base class would ensure these are included in new drift detectors (similar to an abstract method).

We should also check the super().__init__() calls in classes like MMDDrift. Some may not be neccesary.

ascillitoe avatar May 23 '22 08:05 ascillitoe