alibi_detect.cd.tensorflow.mmd_online module

class alibi_detect.cd.tensorflow.mmd_online.MMDDriftOnlineTF(x_ref, ert, window_size, preprocess_fn=None, kernel=<class 'alibi_detect.utils.tensorflow.kernels.GaussianRBF'>, sigma=None, n_bootstraps=1000, verbose=True, input_shape=None, data_type=None)[source]

Bases: alibi_detect.cd.base_online.BaseDriftOnline

__init__(x_ref, ert, window_size, preprocess_fn=None, kernel=<class 'alibi_detect.utils.tensorflow.kernels.GaussianRBF'>, sigma=None, n_bootstraps=1000, verbose=True, input_shape=None, data_type=None)[source]

Online maximum Mean Discrepancy (MMD) data drift detector using preconfigured thresholds.

Parameters
  • x_ref (Union[ndarray, list]) – Data used as reference distribution.

  • ert (float) – The expected run-time (ERT) in the absence of drift.

  • window_size (int) – The size of the sliding test-window used to compute the test-statistic. Smaller windows focus on responding quickly to severe drift, larger windows focus on ability to detect slight drift.

  • preprocess_fn (Optional[Callable]) – Function to preprocess the data before computing the data drift metrics.

  • kernel (Callable) – Kernel used for the MMD computation, defaults to Gaussian RBF kernel.

  • sigma (Optional[ndarray]) – Optionally set the GaussianRBF kernel bandwidth. Can also pass multiple bandwidth values as an array. The kernel evaluation is then averaged over those bandwidths. If sigma is not specified, the ‘median heuristic’ is adopted whereby sigma is set as the median pairwise distance between reference samples.

  • n_bootstraps (int) – The number of bootstrap simulations used to configure the thresholds. The larger this is the more accurately the desired ERT will be targeted. Should ideally be at least an order of magnitude larger than the ERT.

  • verbose (bool) – Whether or not to print progress during configuration.

  • input_shape (Optional[tuple]) – Shape of input data.

  • data_type (Optional[str]) – Optionally specify the data type (tabular, image or time-series). Added to metadata.

Return type

None

score(x_t)[source]

Compute the test-statistic (squared MMD) between the reference window and test window. If the test-window is not yet full then a test-statistic of None is returned.

Parameters

x_t (ndarray) – A single instance.

Return type

Optional[float]

Returns

Squared MMD estimate between reference window and test window.