code: def covariance_sch(X):
      r"""Schaefer-Strimmer shrunk covariance estimator.
  
      Shrinkage covariance estimator [1]_:
  
      .. math::
          C = (1 - \gamma) C_\text{scm} + \gamma T
  
      where :math:`T` is the diagonal target matrix:
  
      .. math::
          T[i,j] = \{ C_\text{scm}[i,i] \ \text{if} i = j, 0 \text{otherwise} \}
  
      Note that the optimal :math:`\gamma` is estimated by the authors' method.
  
      Parameters
      ----------
      X : ndarray, shape (n_channels, n_times)
          Multi-channel time-series, real-valued.
  
      Returns
      -------
      cov : ndarray, shape (n_channels, n_channels)
          Schaefer-Strimmer shrunk covariance matrix.
  
      Notes
      -----
      .. versionadded:: 0.3
  
      References
      ----------
      .. [1] `A shrinkage approach to large-scale covariance estimation and
          implications for functional genomics
          <http://doi.org/10.2202/1544-6115.1175>`_
          J. Schafer, and K. Strimmer. Statistical Applications in Genetics and
          Molecular Biology, Volume 4, Issue 1, 2005.
      """
      _, n_times = X.shape
      X_c = X - X.mean(axis=1, keepdims=True)
      C_scm = X_c @ X_c.T / n_times
  
      # Compute optimal gamma, the weigthing between SCM and shrinkage estimator
      R = n_times / (
          (n_times - 1.0) * np.outer(X.std(axis=1), X.std(axis=1))
      )
      R *= C_scm
      var_R = (X_c**2) @ (X_c**2).T - 2 * C_scm * (X_c @ X_c.T)
      var_R += n_times * C_scm**2
      Xvar = np.outer(X.var(axis=1), X.var(axis=1))
      var_R *= n_times / ((n_times - 1) ** 3 * Xvar)
      R -= np.diag(np.diag(R))
      var_R -= np.diag(np.diag(var_R))
      gamma = max(0, min(1, var_R.sum() / (R**2).sum()))
  
      sigma = (1.0 - gamma) * (n_times / (n_times - 1.0)) * C_scm
      shrinkage = (
          gamma * (n_times / (n_times - 1.0)) * np.diag(np.diag(C_scm))
      )
      return sigma + shrinkage
  
imports: import warnings
  from functools import wraps
  import numpy
  from scipy.linalg import block_diag
  from scipy.stats import chi2
  from sklearn.covariance import oas, ledoit_wolf, fast_mcd
  from .distance import distance_mahalanobis
  from .test import is_square, is_real_type
label_desc: Use image node_id 9 for calling a global function with example usage: covariance_sch(X) and returns: unknown