alibi_detect.cd.tensorflow.lsdd_online module

class alibi_detect.cd.tensorflow.lsdd_online.LSDDDriftOnlineTF(x_ref, ert, window_size, preprocess_fn=None, x_ref_preprocessed=False, sigma=None, n_bootstraps=1000, n_kernel_centers=None, lambda_rd_max=0.2, verbose=True, input_shape=None, data_type=None)[source]

Bases: BaseMultiDriftOnline

__init__(x_ref, ert, window_size, preprocess_fn=None, x_ref_preprocessed=False, sigma=None, n_bootstraps=1000, n_kernel_centers=None, lambda_rd_max=0.2, verbose=True, input_shape=None, data_type=None)[source]

Online least squares density difference (LSDD) data drift detector using preconfigured thresholds. Motivated by Bu et al. (2017): https://ieeexplore.ieee.org/abstract/document/7890493 Modifications are made such that a desired ERT can be accurately targeted however.

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

  • ert (float) – The expected run-time (ERT) in the absence of drift. For the multivariate detectors, the ERT is defined as the expected run-time from t=0.

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

  • x_ref_preprocessed (bool) – Whether the given reference data x_ref has been preprocessed yet. If x_ref_preprocessed=True, only the test data x will be preprocessed at prediction time. If x_ref_preprocessed=False, the reference data will also be preprocessed.

  • sigma (Optional[ndarray]) – Optionally set the bandwidth of the Gaussian kernel used in estimating the LSDD. 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.

  • n_kernel_centers (Optional[int]) – The number of reference samples to use as centers in the Gaussian kernel model used to estimate LSDD. Defaults to 2*window_size.

  • lambda_rd_max (float) – The maximum relative difference between two estimates of LSDD that the regularization parameter lambda is allowed to cause. Defaults to 0.2 as in the paper.

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

online_state_keys: tuple = ('t', 'test_stats', 'drift_preds', 'test_window', 'k_xtc')
score(x_t)[source]

Compute the test-statistic (LSDD) between the reference window and test window.

Parameters:

x_t (Union[ndarray, Any]) – A single instance to be added to the test-window.

Return type:

float

Returns:

LSDD estimate between reference window and test window.