class_docstr: Implementation of the Xdawn Algorithm.
  
  Xdawn :footcite:`RivetEtAl2009,RivetEtAl2011` is a spatial
  filtering method designed to improve the signal to signal + noise
  ratio (SSNR) of the ERP responses. Xdawn was originally designed for
  P300 evoked potential by enhancing the target response with respect
  to the non-target response. This implementation is a generalization
  to any type of ERP.
  
  Parameters
  ----------
  n_components : int, (default 2)
      The number of components to decompose the signals.
  signal_cov : None | Covariance | ndarray, shape (n_channels, n_channels)
      (default None). The signal covariance used for whitening of the data.
      if None, the covariance is estimated from the epochs signal.
  correct_overlap : 'auto' or bool (default 'auto')
      Compute the independent evoked responses per condition, while
      correcting for event overlaps if any. If 'auto', then
      overlapp_correction = True if the events do overlap.
  reg : float | str | None (default None)
      If not None (same as ``'empirical'``, default), allow
      regularization for covariance estimation.
      If float, shrinkage is used (0 <= shrinkage <= 1).
      For str options, ``reg`` will be passed as ``method`` to
      :func:`mne.compute_covariance`.
  
  Attributes
  ----------
  filters_ : dict of ndarray
      If fit, the Xdawn components used to decompose the data for each event
      type, else empty. For each event type, the filters are in the rows of
      the corresponding array.
  patterns_ : dict of ndarray
      If fit, the Xdawn patterns used to restore the signals for each event
      type, else empty.
  evokeds_ : dict of Evoked
      If fit, the evoked response for each event type.
  event_id_ : dict
      The event id.
  correct_overlap_ : bool
      Whether overlap correction was applied.
  
  See Also
  --------
  mne.decoding.CSP, mne.decoding.SPoC
  
  Notes
  -----
  .. versionadded:: 0.10
  
  References
  ----------
  .. footbibliography::
docstr: Fit Xdawn from epochs.
  
  Parameters
  ----------
  epochs : instance of Epochs
      An instance of Epoch on which Xdawn filters will be fitted.
  y : ndarray | None (default None)
      If None, used epochs.events[:, 2].
  
  Returns
  -------
  self : instance of Xdawn
      The Xdawn instance.
docstr_tok: ["Fit","Xdawn","from","epochs",".","Parameters","--","--","--","--","--","epochs",":","instance","of","Epochs","An","instance","of","Epoch","on","which","Xdawn","filters","will","be","fitted",".","y",":","ndarray","|","None","(","default","None",")","If","None",",","used","epochs.events","[",":",",","2","]",".","Returns","--","--","--","-","self",":","instance","of","Xdawn","The","Xdawn","instance","."]
code: def fit(self, epochs, y=None):
      """Fit Xdawn from epochs.
  
      Parameters
      ----------
      epochs : instance of Epochs
          An instance of Epoch on which Xdawn filters will be fitted.
      y : ndarray | None (default None)
          If None, used epochs.events[:, 2].
  
      Returns
      -------
      self : instance of Xdawn
          The Xdawn instance.
      """
      # Check data
      if not isinstance(epochs, BaseEpochs):
          raise ValueError("epochs must be an Epochs object.")
      picks = _pick_data_channels(epochs.info)
      use_info = pick_info(epochs.info, picks)
      X = epochs.get_data(picks)
      y = epochs.events[:, 2] if y is None else y
      self.event_id_ = epochs.event_id
  
      # Check that no baseline was applied with correct overlap
      correct_overlap = self.correct_overlap
      if correct_overlap == "auto":
          # Events are overlapped if the minimal inter-stimulus
          # interval is smaller than the time window.
          isi = np.diff(np.sort(epochs.events[:, 0]))
          window = int(
              (epochs.tmax - epochs.tmin) * epochs.info["sfreq"]
          )
          correct_overlap = isi.min() < window
  
      if epochs.baseline and correct_overlap:
          raise ValueError(
              "Cannot apply correct_overlap if epochs"
              " were baselined."
          )
  
      events, tmin, sfreq = None, 0.0, 1.0
      if correct_overlap:
          events = epochs.events
          tmin = epochs.tmin
          sfreq = epochs.info["sfreq"]
      self.correct_overlap_ = correct_overlap
  
      # Note: In this original version of Xdawn we compute and keep all
      # components. The selection comes at transform().
      n_components = X.shape[1]
  
      # Main fitting function
      filters, patterns, evokeds = _fit_xdawn(
          X,
          y,
          n_components=n_components,
          reg=self.reg,
          signal_cov=self.signal_cov,
          events=events,
          tmin=tmin,
          sfreq=sfreq,
          method_params=self.method_params,
          info=use_info,
      )
  
      # Re-order filters and patterns according to event_id
      filters = filters.reshape(-1, n_components, filters.shape[-1])
      patterns = patterns.reshape(-1, n_components, patterns.shape[-1])
      self.filters_, self.patterns_, self.evokeds_ = (
          dict(),
          dict(),
          dict(),
      )
      idx = np.argsort([value for _, value in epochs.event_id.items()])
      for eid, this_filter, this_pattern, this_evo in zip(
          epochs.event_id, filters[idx], patterns[idx], evokeds[idx]
      ):
          self.filters_[eid] = this_filter
          self.patterns_[eid] = this_pattern
          n_events = len(epochs[eid])
          evoked = EvokedArray(
              this_evo,
              use_info,
              tmin=epochs.tmin,
              comment=eid,
              nave=n_events,
          )
          self.evokeds_[eid] = evoked
      return self
  
imports: import numpy
  from scipy import linalg
  from .._fiff.pick import _pick_data_channels, pick_info
  from ..cov import Covariance, _regularized_covariance
  from ..decoding import BaseEstimator, TransformerMixin
  from ..epochs import BaseEpochs
  from ..evoked import Evoked, EvokedArray
  from ..io import BaseRaw
  from ..utils import _check_option, logger
label_desc: Use image node_id 2 for calling the Xdawn obj's underlying member method code with example usage: obj.fit(epochs, y) and returns: self