Euclidean Alignment (EA)

Description

This module implements the Euclidean Alignment (EA) method, a spatial filtering technique used to align EEG data from different subjects or sessions to a common reference. This reduces inter-subject variability and improves the generalization of BCI models.

The EA method aligns EEG data by transforming it such that the reference matrix becomes an identity matrix. This is particularly useful for cross-subject or cross-session BCI applications.

Class

class bciflow.modules.sf.ea.ea[source]

Bases: object

target_transformation

List containing the reference matrix for each band of the target subject

Type:

list-like, size (n_bands)

calc_r(data)[source]

Computes the reference matrix for each frequency band.

Parameters:

data (array-like, shape (n_trials, n_bands, n_electodes, n_times)) – The input data from a subject.

Returns:

list_r – The list of reference matrix from the data.

Return type:

list-like, size (n_bands), containing array-like, shape (n_electodes, n_electodes)

fit(eegdata, source)[source]

Fits the EA method to the input data, calculating the transformation matrices.

Parameters:

eegdata (dict) – The input data.

Return type:

self

fit_transform(eegdata, source)[source]

Combines fitting and transforming into a single step.

Parameters:

eegdata (dict) – The input data.

Returns:

output – The transformed data.

Return type:

dict

full_r(data)[source]

This method call calc_r, and then raises all matrices to the power of -1/2, to transform the input data

Parameters:

data (array-like, shape (n_trials, n_bands, n_electodes, n_times)) – The input data from a subject.

Returns:

list_r_inv – The list of reference matrix to the power of -1/2 from the data.

Return type:

list-like, size (n_bands), containing array-like, shape (n_electodes, n_electodes)

transform(eegdata, source=None)[source]

This method aligns the target subject’s data by multiplying it by the reference matrix for each band.

Parameters:

eegdata (dict) – The input data.

Returns:

output – The transformed data.

Return type:

dict

verify_r(matrix, epsilon=1e-10)[source]

To check whether the Euclidean alignment was implemented correctly, it is necessary to check whether the data reference matrices after the transformation are equal to the identity matrix. Due to computational errors, all values less than epsilon are considered as 0

Parameters:
  • matrix (array-like, shape (n_electodes, n_electodes)) – A reference matrix.

  • epsilon (float) – Number used as parameter to determine whether the matrix and identity

Returns:

test – Validation of the matrix being identity or not

Return type:

bool

For more details on EA, refer to:
  • Zanini, P., et al. (2018). Euclidean Alignment for Brain-Computer Interfaces: A Comparative Study. IEEE Transactions on Neural Systems and Rehabilitation Engineering.