class_docstr: Stretch data for transfer learning.
  
  Change the dispersion of the datapoints around their geometric mean
  for each dataset so that they all have the same desired value.
  
  .. note::
     Using .fit() and then .transform() will give different results than
     .fit_transform(). In fact, .fit_transform() should be applied on the
     training dataset (target and source) and .transform() on the test
     partition of the target dataset.
  
  Parameters
  ----------
  target_domain : str
      Domain to consider as target.
  dispersion : float, default=1.0
      Target value for the dispersion of the data points.
  centered_data : bool, default=False
      Whether the data has been re-centered to the Identity beforehand.
  metric : str, default='riemann'
      The metric for calculating the dispersion can be: 'ale', 'alm',
      'euclid', 'harmonic', 'identity', 'kullback_sym', 'logdet',
      'logeuclid', 'riemann', 'wasserstein', or a callable function.
  
  Attributes
  ----------
  dispersions_ : dict
      Dictionary with key=domain_name and value=domain_dispersion.
  
  References
  ----------
  .. [1] `Riemannian Procrustes analysis: transfer learning for
      brain-computer interfaces
      <https://hal.archives-ouvertes.fr/hal-01971856>`_
      PLC Rodrigues et al, IEEE Transactions on Biomedical Engineering,
      vol. 66, no. 8, pp. 2390-2401, December, 2018
  
  Notes
  -----
  .. versionadded:: 0.4
class_docstr_tok: ["Stretch","data","for","transfer","learning",".","Change","the","dispersion","of","the","datapoints","around","their","geometric","mean","for","each","dataset","so","that","they","all","have","the","same","desired","value",".","..","note",":",":","Using",".fit","(",")","and","then",".transform","(",")","will","give","different","results","than",".fit_transform","(",")",".","In","fact",",",".fit_transform","(",")","should","be","applied","on","the","training","dataset","(","target","and","source",")","and",".transform","(",")","on","the","test","partition","of","the","target","dataset",".","Parameters","--","--","--","--","--","target_domain",":","str","Domain","to","consider","as","target",".","dispersion",":","float",",","default=1.0","Target","value","for","the","dispersion","of","the","data","points",".","centered_data",":","bool",",","default=False","Whether","the","data","has","been","re-centered","to","the","Identity","beforehand",".","metric",":","str",",","default='riemann'","The","metric","for","calculating","the","dispersion","can","be",":","'ale","'",",","'alm","'",",","'euclid","'",",","'harmonic","'",",","'identity","'",",","'kullback_sym","'",",","'logdet","'",",","'logeuclid","'",",","'riemann","'",",","'wasserstein","'",",","or","a","callable","function",".","Attributes","--","--","--","--","--","dispersions_",":","dict","Dictionary","with","key=domain_name","and","value=domain_dispersion",".","References","--","--","--","--","--","..","[","1","]","`","Riemannian","Procrustes","analysis",":","transfer","learning","for","brain-computer","interfaces","<","https",":","\/\/hal.archives-ouvertes.fr\/hal-01971856",">","`","_","PLC","Rodrigues","et","al",",","IEEE","Transactions","on","Biomedical","Engineering",",","vol",".","66",",","no",".","8",",","pp",".","2390-2401",",","December",",","2018","Notes","--","--","-","..","versionadded",":",":","0.4"]
docstr: Fit TLStretch.
  
  Calculate the dispersion around the mean for each domain.
  
  Parameters
  ----------
  X : ndarray, shape (n_matrices, n_channels, n_channels)
      Set of SPD matrices.
  y_enc : ndarray, shape (n_matrices,)
      Extended labels for each matrix.
  sample_weight : None | ndarray, shape (n_matrices,), default=None
      Weights for each matrix. If None, it uses equal weights.
  
  Returns
  -------
  self : TLStretch instance
      The TLStretch instance.
docstr_tok: ["Fit","TLStretch",".","Calculate","the","dispersion","around","the","mean","for","each","domain",".","Parameters","--","--","--","--","--","X",":","ndarray",",","shape","(","n_matrices",",","n_channels",",","n_channels",")","Set","of","SPD","matrices",".","y_enc",":","ndarray",",","shape","(","n_matrices",",",")","Extended","labels","for","each","matrix",".","sample_weight",":","None","|","ndarray",",","shape","(","n_matrices",",",")",",","default=None","Weights","for","each","matrix",".","If","None",",","it","uses","equal","weights",".","Returns","--","--","--","-","self",":","TLStretch","instance","The","TLStretch","instance","."]
code: def fit(self, X, y_enc, sample_weight=None):
      """Fit TLStretch.
  
      Calculate the dispersion around the mean for each domain.
  
      Parameters
      ----------
      X : ndarray, shape (n_matrices, n_channels, n_channels)
          Set of SPD matrices.
      y_enc : ndarray, shape (n_matrices,)
          Extended labels for each matrix.
      sample_weight : None | ndarray, shape (n_matrices,), default=None
          Weights for each matrix. If None, it uses equal weights.
  
      Returns
      -------
      self : TLStretch instance
          The TLStretch instance.
      """
      _, _, domains = decode_domains(X, y_enc)
      n_matrices, n_channels, _ = X.shape
      sample_weight = check_weights(sample_weight, n_matrices)
  
      self._means, self.dispersions_ = {}, {}
      for d in np.unique(domains):
          idx = domains == d
          sample_weight_d = check_weights(
              sample_weight[idx], np.sum(idx)
          )
          if self.centered_data:
              self._means[d] = np.eye(n_channels)
          else:
              self._means[d] = mean_riemann(
                  X[idx], sample_weight=sample_weight_d
              )
          dist = distance(
              X[idx],
              self._means[d],
              metric=self.metric,
              squared=True,
          )
          self.dispersions_[d] = np.sum(
              sample_weight_d * np.squeeze(dist)
          )
  
      return self
  
imports: import numpy
  from joblib import Parallel, delayed
  from sklearn.base import BaseEstimator, TransformerMixin, is_classifier, is_regressor
  from sklearn.pipeline import Pipeline
  from sklearn.metrics import accuracy_score, r2_score
  from ..utils.mean import mean_covariance, mean_riemann
  from ..utils.distance import distance
  from ..utils.base import invsqrtm, powm, sqrtm
  from ..utils.geodesic import geodesic
  from ..utils.utils import check_weights
  from ._rotate import _get_rotation_matrix
  from ..classification import MDM, _check_metric
  from ..preprocessing import Whitening
  from ._tools import decode_domains
label_desc: Use image node_id 2 for calling the TLStretch obj's underlying member method code with example usage: obj.fit(X, y_enc, sample_weight) and returns: self