metabci.brainda.algorithms.transfer_learning.mekt module

Manifold Embedded Knowledge Transfer. Modified from https://github.com/chamwen/MEKT.git

class metabci.brainda.algorithms.transfer_learning.mekt.MEKT(subspace_dim: int = 10, max_iter: int = 5, alpha: float = 0.01, beta: float = 0.1, rho: float = 20, k: int = 10, t: int = 1, covariance_type='lwf')[source]

Bases: BaseEstimator, TransformerMixin

Manifold Embedded Knowledge Transfer(MEKT)

fit_transform(Xs, ys, Xt)[source]

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Input samples.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).

  • **fit_params (dict) – Additional fit parameters.

Returns:

X_new – Transformed array.

Return type:

ndarray array of shape (n_samples, n_features_new)

metabci.brainda.algorithms.transfer_learning.mekt.anova_dimension_reduction(Xs, ys, d)[source]

Dimension reduction in MEKT.

MEKT use len(ys) as d

Parameters:
  • Xs (ndarray) – features, shape (n_trials, n_features)

  • ys (ndarray) – labels, shape (n_trials,)

  • d (int) – reduce to dimension d

Returns:

f_ix – the index of selected features, shape (d,)

Return type:

ndarray

metabci.brainda.algorithms.transfer_learning.mekt.choose_multiple_subjects(Xs, Xt, ys, y_subjects, k=1)[source]

choose k most appropriate subjects according to dte.

Parameters:
  • Xs (ndarray) – source features, shape (n_trials*n_subjects, n_features)

  • Xt (ndarray) – target features, shape (n_trials, n_features)

  • ys (ndarray) – source labels, shape (n_trials*n_subjects, n_features)

  • y_subjects (ndarray) – subject labels, shape (n_trials*n_subjects,)

  • k (int, optional) – k subjects, by default 1

Returns:

  • subject_ix (ndarray) – selected subject boolean index, shape (n_trials*n_subjects,)

  • subjects (ndarray) – selected subject ids, shape (k,)

metabci.brainda.algorithms.transfer_learning.mekt.dte(Xs, Xt, ys)[source]

Domain Transferiability Estimation

Parameters: Xs: ndarray

source features, shape (n_source_trials, n_features)

Xt: ndarray

target features, shape (n_traget_trials, n_features)

ys: ndarray

source labels, shape (n_source_trials,)

metabci.brainda.algorithms.transfer_learning.mekt.graph_laplacian(Xs, k=10, t=1)[source]

Graph Laplacian Matrix.

Currently with heat kernel implemented.

Parameters:
  • Xs (ndarray) – features, shape (n_trials, n_samples)

  • k (int, optional) – k nearest neighbors, by default 10

  • t (int, optional) – heat kernel parameter, by default 1

Returns:

  • L (ndarray) – unnormalized laplacian kernel, shape (n_trials, n_trials)

  • D (ndarray) – degree matrix, L = D - W, shape (n_trials, n_trials)

metabci.brainda.algorithms.transfer_learning.mekt.mekt_feature(X, covariance_type)[source]
Covariance Matrix Centroid Alignment and Tangent Space Feature Extraction.

Parameters

Returns:

featureX – feature of X, shape (n_trials, n_feature)

Return type:

ndarray

metabci.brainda.algorithms.transfer_learning.mekt.mekt_kernel(Xs, Xt, ys, d=10, max_iter=5, alpha=0.01, beta=0.1, rho=20, k=10, t=1)[source]

Manifold Embedding Knowledge Transfer.

Parameters:
  • Xs (ndarray) – source features, shape (n_source_trials, n_features)

  • Xt (ndarray) – target features, shape (n_target_trials, n_features)

  • ys (ndarray) – source labels, shape (n_source_trials,)

  • d (int, optional) – selected d projection vectors, by default 10

  • max_iter (int, optional) – max iterations, by default 5

  • alpha (float, optional) – regularized term for source domain discriminability, by default 0.01

  • beta (float, optional) – regularized term for target domain locality, by default 0.1

  • rho (int, optional) – regularized term for parameter transfer, by default 20

  • k (int, optional) – number of nearest neighbors

  • t (int, optional) – heat kernel parameter

Returns:

  • A (ndarray) – projection matrix for source, shape (n_features, d)

  • B (ndarray) – projection matrix for target, shape (n_features, d)

metabci.brainda.algorithms.transfer_learning.mekt.scatter_matrix(X, y)[source]

Compute between-class scatter matrix.

Parameters:
  • X (ndarray) – features, shape (n_trials, n_features)

  • y (ndarray) – labels, shape (n_trials,)

Returns:

Sb – between-class scatter matrix, shape (n_features, n_features)

Return type:

ndarray

metabci.brainda.algorithms.transfer_learning.mekt.source_discriminability(Xs, ys)[source]

Source features discriminability.

Parameters:
  • Xs (ndarray) – source features, shape (n_trials, n_features)

  • ys (ndarray) – labels, shape (n_trials)

Returns:

  • Sw (ndarray) – within-class scatter matrix, shape (n_features, n_features)

  • Sb (ndarray) – between-class scatter matrix, shape (n_features, n_features)