class_docstr: AJDC algorithm.
  
  The approximate joint diagonalization of Fourier cospectral matrices (AJDC)
  [1]_ is a versatile tool for blind source separation (BSS) tasks based on
  Second-Order Statistics (SOS), estimating spectrally uncorrelated sources.
  
  It can be applied:
  
  * on a single subject, to solve the classical BSS problem [1]_,
  * on several subjects, to solve the group BSS (gBSS) problem [2]_,
  * on several experimental conditions (for eg, baseline versus task), to
    exploit the diversity of source energy between conditions in addition
    to generic coloration and time-varying energy [1]_.
  
  AJDC estimates Fourier cospectral matrices by the Welch's method, and
  applies a trace-normalization. If necessary, it averages cospectra across
  subjects, and concatenates them along experimental conditions.
  Then, a dimension reduction and a whitening are applied on cospectra.
  An approximate joint diagonalization (AJD) [3]_ allows to estimate the
  joint diagonalizer, not constrained to be orthogonal. Finally, forward and
  backward spatial filters are computed.
  
  Parameters
  ----------
  window : int, default=128
      The length of the FFT window used for spectral estimation.
  overlap : float, default=0.5
      The percentage of overlap between window.
  fmin : float | None, default=None
      The minimal frequency to be returned. Since BSS models assume zero-mean
      processes, the first cospectrum (0 Hz) must be excluded.
  fmax : float | None, default=None
      The maximal frequency to be returned.
  fs : float | None, default=None
      The sampling frequency of the signal.
  dim_red : None | dict, default=None
      Parameter for dimension reduction of cospectra, because Pham's AJD is
      sensitive to matrices conditioning.
  
      If ``None`` :
          no dimension reduction during whitening.
      If ``{'n_components': val}`` :
          dimension reduction defining the number of components;
          ``val`` must be an integer superior to 1.
      If ``{'expl_var': val}`` :
          dimension reduction selecting the number of components such that
          the amount of variance that needs to be explained is greater than
          the percentage specified by ``val``.
          ``val`` must be a float in (0,1], typically ``0.99``.
      If ``{'max_cond': val}`` :
          dimension reduction selecting the number of components such that
          the condition number of the mean matrix is lower than ``val``.
          This threshold has a physiological interpretation, because it can
          be viewed as the ratio between the power of the strongest component
          (usually, eye-blink source) and the power of the lowest component
          you don't want to keep (acquisition sensor noise).
          ``val`` must be a float strictly superior to 1, typically 100.
      If ``{'warm_restart': val}`` :
          dimension reduction defining the number of components from an
          initial joint diagonalizer, and then run AJD from this solution.
          ``val`` must be a square ndarray.
  verbose : bool, default=True
      Verbose flag.
  
  Attributes
  ----------
  n_channels_ : int
      If fit, the number of channels of the signal.
  freqs_ : ndarray, shape (n_freqs,)
      If fit, the frequencies associated to cospectra.
  n_sources_ : int
      If fit, the number of components of the source space.
  diag_filters_ : ndarray, shape ``(n_sources_, n_sources_)``
      If fit, the diagonalization filters, also called joint diagonalizer.
  forward_filters_ : ndarray, shape ``(n_sources_, n_channels_)``
      If fit, the spatial filters used to transform signal into source,
      also called deximing or separating matrix.
  backward_filters_ : ndarray, shape ``(n_channels_, n_sources_)``
      If fit, the spatial filters used to transform source into signal,
      also called mixing matrix.
  
  Notes
  -----
  .. versionadded:: 0.2.7
  
  See Also
  --------
  CospCovariances
  
  References
  ----------
  .. [1] `On the blind source separation of human electroencephalogram by
      approximate joint diagonalization of second order statistics
      <https://hal.archives-ouvertes.fr/hal-00343628>`_
      M. Congedo, C. Gouy-Pailler, C. Jutten. Clinical Neurophysiology,
      Elsevier, 2008, 119 (12), pp.2677-2686.
  .. [2] `Group indepedent component analysis of resting state EEG in large
      normative samples
      <https://hal.archives-ouvertes.fr/hal-00523200>`_
      M. Congedo, R. John, D. de Ridder, L. Prichep. International Journal of
      Psychophysiology, Elsevier, 2010, 78, pp.89-99.
  .. [3] `Joint approximate diagonalization of positive definite
      Hermitian matrices
      <https://epubs.siam.org/doi/10.1137/S089547980035689X>`_
      D.-T. Pham. SIAM Journal on Matrix Analysis and Applications, Volume 22
      Issue 4, 2000
docstr: Estimate explained variances of sources.
  
  Estimate explained variances of sources, see Appendix D in [1].
  
  Parameters
  ----------
  X : ndarray, shape (n_matrices, n_channels, n_times)
      Multi-channel time-series in channel space.
  
  Returns
  -------
  src_var : ndarray, shape (n_matrices, n_sources)
      Explained variance for each source.
docstr_tok: ["Estimate","explained","variances","of","sources",".","Estimate","explained","variances","of","sources",",","see","Appendix","D","in","[","1","]",".","Parameters","--","--","--","--","--","X",":","ndarray",",","shape","(","n_matrices",",","n_channels",",","n_times",")","Multi-channel","time-series","in","channel","space",".","Returns","--","--","--","-","src_var",":","ndarray",",","shape","(","n_matrices",",","n_sources",")","Explained","variance","for","each","source","."]
code: def get_src_expl_var(self, X):
      """Estimate explained variances of sources.
  
      Estimate explained variances of sources, see Appendix D in [1].
  
      Parameters
      ----------
      X : ndarray, shape (n_matrices, n_channels, n_times)
          Multi-channel time-series in channel space.
  
      Returns
      -------
      src_var : ndarray, shape (n_matrices, n_sources)
          Explained variance for each source.
      """
      if X.ndim != 3:
          raise ValueError("X must have 3 dimensions (Got %d)" % X.ndim)
      if X.shape[1] != self.n_channels_:
          raise ValueError(
              "X does not have the good number of channels. Should be %d but"
              " got %d." % (self.n_channels_, X.shape[1])
          )
  
      cov = est.Covariances().transform(X)
  
      src_var = np.zeros((X.shape[0], self.n_sources_))
      for s in range(self.n_sources_):
          src_var[:, s] = np.trace(
              self.backward_filters_[:, s]
              * self.forward_filters_[s].T
              * cov
              * self.forward_filters_[s]
              * self.backward_filters_[:, s].T,
              axis1=-2,
              axis2=-1,
          )
      return src_var
  
imports: import warnings
  import numpy
  from scipy.linalg import eigh, inv
  from sklearn.base import BaseEstimator, TransformerMixin
  from .utils.covariance import _check_cov_est_function, normalize, get_nondiag_weight
  from .utils.mean import mean_covariance
  from .utils.ajd import ajd_pham
  from .None import estimation
  from .preprocessing import Whitening
label_desc: Use image node_id 5 for calling the AJDC obj's underlying member method code with example usage: obj.get_src_expl_var(X) and returns: src_var