docstr: 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
  We have made modifications such that a desired ERT can be accurately targeted however.
  
  Parameters
  ----------
  x_ref
      Data used as reference distribution.
  ert
      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
      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.
  backend
      Backend used for the LSDD implementation and configuration.
  preprocess_fn
      Function to preprocess the data before computing the data drift metrics.
  x_ref_preprocessed
      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
      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
      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
      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
      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.
  device
      Device type used. The default tries to use the GPU and falls back on CPU if needed.
      Can be specified by passing either ``'cuda'``, ``'gpu'``, ``'cpu'`` or an instance of
      ``torch.device``. Only relevant for 'pytorch' backend.
  verbose
      Whether or not to print progress during configuration.
  input_shape
      Shape of input data.
  data_type
      Optionally specify the data type (tabular, image or time-series). Added to metadata.
docstr_tok: ["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","We","have","made","modifications","such","that","a","desired","ERT","can","be","accurately","targeted","however",".","Parameters","--","--","--","--","--","x_ref","Data","used","as","reference","distribution",".","ert","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","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",".","backend","Backend","used","for","the","LSDD","implementation","and","configuration",".","preprocess_fn","Function","to","preprocess","the","data","before","computing","the","data","drift","metrics",".","x_ref_preprocessed","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","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","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","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","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",".","device","Device","type","used",".","The","default","tries","to","use","the","GPU","and","falls","back","on","CPU","if","needed",".","Can","be","specified","by","passing","either","``","'cuda","'","``",",","``","'gpu","'","``",",","``","'cpu","'","``","or","an","instance","of","``","torch.device","``",".","Only","relevant","for","'pytorch","'","backend",".","verbose","Whether","or","not","to","print","progress","during","configuration",".","input_shape","Shape","of","input","data",".","data_type","Optionally","specify","the","data","type","(","tabular",",","image","or","time-series",")",".","Added","to","metadata","."]
code: def __init__(
      self,
      x_ref: Union[np.ndarray, list],
      ert: float,
      window_size: int,
      backend: str = "tensorflow",
      preprocess_fn: Optional[Callable] = None,
      x_ref_preprocessed: bool = False,
      sigma: Optional[np.ndarray] = None,
      n_bootstraps: int = 1000,
      n_kernel_centers: Optional[int] = None,
      lambda_rd_max: float = 0.2,
      device: TorchDeviceType = None,
      verbose: bool = True,
      input_shape: Optional[tuple] = None,
      data_type: Optional[str] = None,
  ) -> None:
      """
      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
      We have made modifications such that a desired ERT can be accurately targeted however.
  
      Parameters
      ----------
      x_ref
          Data used as reference distribution.
      ert
          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
          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.
      backend
          Backend used for the LSDD implementation and configuration.
      preprocess_fn
          Function to preprocess the data before computing the data drift metrics.
      x_ref_preprocessed
          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
          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
          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
          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
          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.
      device
          Device type used. The default tries to use the GPU and falls back on CPU if needed.
          Can be specified by passing either ``'cuda'``, ``'gpu'``, ``'cpu'`` or an instance of
          ``torch.device``. Only relevant for 'pytorch' backend.
      verbose
          Whether or not to print progress during configuration.
      input_shape
          Shape of input data.
      data_type
          Optionally specify the data type (tabular, image or time-series). Added to metadata.
      """
      super().__init__()
  
      # Set config
      self._set_config(locals())
  
      backend = backend.lower()
      BackendValidator(
          backend_options={
              Framework.TENSORFLOW: [Framework.TENSORFLOW],
              Framework.PYTORCH: [Framework.PYTORCH],
          },
          construct_name=self.__class__.__name__,
      ).verify_backend(backend)
  
      kwargs = locals()
      args = [kwargs["x_ref"], kwargs["ert"], kwargs["window_size"]]
      pop_kwargs = [
          "self",
          "x_ref",
          "ert",
          "window_size",
          "backend",
          "__class__",
      ]
      [kwargs.pop(k, None) for k in pop_kwargs]
  
      if backend == Framework.TENSORFLOW:
          kwargs.pop("device", None)
          self._detector = LSDDDriftOnlineTF(*args, **kwargs)
      else:
          self._detector = LSDDDriftOnlineTorch(*args, **kwargs)  # type: ignore
      self.meta = self._detector.meta
  
file_path: alibi-detect/alibi_detect/cd/lsdd_online.py
imports: import os
  import numpy
  from typing import Any, Callable, Dict, Optional, Union
  from alibi_detect.utils.frameworks import has_pytorch, has_tensorflow, BackendValidator, Framework
  from alibi_detect.base import DriftConfigMixin
  from alibi_detect.utils._types import TorchDeviceType
label_desc: Use image node_id 1 to create a new LSDDDriftOnline object from inherited base classes: DriftConfigMixin with example: obj = LSDDDriftOnline(x_ref, ert, window_size, backend, preprocess_fn, x_ref_preprocessed, sigma, n_bootstraps, n_kernel_centers, lambda_rd_max, device, verbose, input_shape, data_type)