docstr: Online Fisher exact test (FET) data drift detector using preconfigured thresholds, which tests for a
  change in the mean of binary univariate data. This detector is an adaption of that proposed by
  :cite:t:`Ross2012b`.
  
  For multivariate data, the detector makes a correction similar to the Bonferroni correction used for
  the offline detector. Given :math:`d` features, the detector configures thresholds by
  targeting the :math:`1-\beta` quantile of test statistics over the simulated streams, where
  :math:`\beta = 1 - (1-(1/ERT))^{(1/d)}`. For the univariate case, this simplifies to
  :math:`\beta = 1/ERT`. At prediction time, drift is flagged if the test statistic of any feature stream
  exceed the thresholds.
  
  Note
  ----
  In the multivariate case, for the ERT to be accurately targeted the feature streams must be independent.
  
  Parameters
  ----------
  x_ref
      Data used as reference distribution.
  ert
      The expected run-time (ERT) in the absence of drift. For the univariate detectors, the ERT is defined
      as the expected run-time after the smallest window is full i.e. the run-time from t=min(windows_sizes).
  window_sizes
      window sizes for the sliding test-windows 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
      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.
  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.
  t_max
      Length of the streams to simulate when configuring thresholds. If `None`, this is set to
      2 * max(`window_sizes`) - 1.
  alternative
      Defines the alternative hypothesis. Options are 'greater' or 'less', which correspond to
      an increase or decrease in the mean of the Bernoulli stream.
  lam
      Smoothing coefficient used for exponential moving average.
  n_features
      Number of features used in the statistical test. No need to pass it if no preprocessing takes place.
      In case of a preprocessing step, this can also be inferred automatically but could be more
      expensive to compute.
  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","Fisher","exact","test","(","FET",")","data","drift","detector","using","preconfigured","thresholds",",","which","tests","for","a","change","in","the","mean","of","binary","univariate","data",".","This","detector","is","an","adaption","of","that","proposed","by",":","cite",":","t",":","`","Ross2012b","`",".","For","multivariate","data",",","the","detector","makes","a","correction","similar","to","the","Bonferroni","correction","used","for","the","offline","detector",".","Given",":","math",":","`","d","`","features",",","the","detector","configures","thresholds","by","targeting","the",":","math",":","`","1-\\beta","`","quantile","of","test","statistics","over","the","simulated","streams",",","where",":","math",":","`","\\beta","=","1","-","(","1-","(","1\/ERT",")",")","^","{","(","1\/d",")","}","`",".","For","the","univariate","case",",","this","simplifies","to",":","math",":","`","\\beta","=","1\/ERT","`",".","At","prediction","time",",","drift","is","flagged","if","the","test","statistic","of","any","feature","stream","exceed","the","thresholds",".","Note","--","--","In","the","multivariate","case",",","for","the","ERT","to","be","accurately","targeted","the","feature","streams","must","be","independent",".","Parameters","--","--","--","--","--","x_ref","Data","used","as","reference","distribution",".","ert","The","expected","run-time","(","ERT",")","in","the","absence","of","drift",".","For","the","univariate","detectors",",","the","ERT","is","defined","as","the","expected","run-time","after","the","smallest","window","is","full","i.e",".","the","run-time","from","t=min","(","windows_sizes",")",".","window_sizes","window","sizes","for","the","sliding","test-windows","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","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",".","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",".","t_max","Length","of","the","streams","to","simulate","when","configuring","thresholds",".","If","`","None","`",",","this","is","set","to","2","*","max","(","`","window_sizes","`",")","-","1.","alternative","Defines","the","alternative","hypothesis",".","Options","are","'greater","'","or","'less","'",",","which","correspond","to","an","increase","or","decrease","in","the","mean","of","the","Bernoulli","stream",".","lam","Smoothing","coefficient","used","for","exponential","moving","average",".","n_features","Number","of","features","used","in","the","statistical","test",".","No","need","to","pass","it","if","no","preprocessing","takes","place",".","In","case","of","a","preprocessing","step",",","this","can","also","be","inferred","automatically","but","could","be","more","expensive","to","compute",".","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_sizes: List[int],
      preprocess_fn: Optional[Callable] = None,
      x_ref_preprocessed: bool = False,
      n_bootstraps: int = 10000,
      t_max: Optional[int] = None,
      alternative: str = "greater",
      lam: float = 0.99,
      n_features: Optional[int] = None,
      verbose: bool = True,
      input_shape: Optional[tuple] = None,
      data_type: Optional[str] = None,
  ) -> None:
      """
      Online Fisher exact test (FET) data drift detector using preconfigured thresholds, which tests for a
      change in the mean of binary univariate data. This detector is an adaption of that proposed by
      :cite:t:`Ross2012b`.
  
      For multivariate data, the detector makes a correction similar to the Bonferroni correction used for
      the offline detector. Given :math:`d` features, the detector configures thresholds by
      targeting the :math:`1-\\beta` quantile of test statistics over the simulated streams, where
      :math:`\\beta = 1 - (1-(1/ERT))^{(1/d)}`. For the univariate case, this simplifies to
      :math:`\\beta = 1/ERT`. At prediction time, drift is flagged if the test statistic of any feature stream
      exceed the thresholds.
  
      Note
      ----
      In the multivariate case, for the ERT to be accurately targeted the feature streams must be independent.
  
      Parameters
      ----------
      x_ref
          Data used as reference distribution.
      ert
          The expected run-time (ERT) in the absence of drift. For the univariate detectors, the ERT is defined
          as the expected run-time after the smallest window is full i.e. the run-time from t=min(windows_sizes).
      window_sizes
          window sizes for the sliding test-windows 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
          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.
      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.
      t_max
          Length of the streams to simulate when configuring thresholds. If `None`, this is set to
          2 * max(`window_sizes`) - 1.
      alternative
          Defines the alternative hypothesis. Options are 'greater' or 'less', which correspond to
          an increase or decrease in the mean of the Bernoulli stream.
      lam
          Smoothing coefficient used for exponential moving average.
      n_features
          Number of features used in the statistical test. No need to pass it if no preprocessing takes place.
          In case of a preprocessing step, this can also be inferred automatically but could be more
          expensive to compute.
      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__(
          x_ref=x_ref,
          ert=ert,
          window_sizes=window_sizes,
          preprocess_fn=preprocess_fn,
          x_ref_preprocessed=x_ref_preprocessed,
          n_bootstraps=n_bootstraps,
          n_features=n_features,
          verbose=verbose,
          input_shape=input_shape,
          data_type=data_type,
      )
      # Set config
      self._set_config(locals())
  
      self.lam = lam
      if alternative.lower() not in ["greater", "less"]:
          raise ValueError(
              "`alternative` must be either 'greater' or 'less'."
          )
      self.alternative = alternative.lower()
  
      # Stream length
      if t_max is not None:
          if t_max < 2 * self.max_ws - 1:
              raise ValueError(
                  "`t_max` must be >= 2 * max(`window_sizes`) for the FETDriftOnline detector."
              )
      else:
          t_max = 2 * self.max_ws - 1
      self.t_max = t_max
  
      # Check data is only [False, True] or [0, 1]
      values = set(np.unique(self.x_ref))
      if not set(values).issubset(["0", "1", True, False]):
          raise ValueError(
              "The `x_ref` data must consist of only (0,1)'s or (False,True)'s for the "
              "FETDriftOnline detector."
          )
      if len(np.unique(self.x_ref.astype("int"))) == 1:
          raise ValueError(
              "The `x_ref` data consists of all 0's or all 1's. Thresholds cannot be configured."
          )
  
      # Configure thresholds and initialise detector
      self._initialise_state()
      self._configure_thresholds()
      self._configure_ref()
  
imports: from tqdm import tqdm
  import numpy
  from typing import Any, Callable, List, Optional, Union
  from alibi_detect.base import DriftConfigMixin
  from alibi_detect.cd.base_online import BaseUniDriftOnline
  from alibi_detect.utils.misc import quantile
  from scipy.stats import hypergeom
  import numba
  import warnings
label_desc: Use image node_id 1 to create a new FETDriftOnline object from inherited base classes: BaseUniDriftOnline, DriftConfigMixin with example: obj = FETDriftOnline(x_ref, ert, window_sizes, preprocess_fn, x_ref_preprocessed, n_bootstraps, t_max, alternative, lam, n_features, verbose, input_shape, data_type)