ICA
Namespace: RTPROCESSINGLIB · Library: DSP Library
mne.preprocessing.ICA (fastica) in MNE-Python.
#include <dsp/ica.h>
class UTILSLIB::ICA
Independent Component Analysis using the FastICA algorithm (deflationary, logcosh nonlinearity).
const IcaResult ica = ICA::run(mixed, 3); // FastICA, logcosh, fixed seed
const MatrixXd cleaned = ICA::excludeComponents(mixed, ica, {0}); // drop component 0, back-project the rest
Static Methods
run(matData, nComponents, maxIter, tol, randomSeed)
Fit FastICA on the given data matrix.
Parameters:
-
matData : const Eigen::MatrixXd & Input data (n_channels x n_samples). Each row is one sensor channel.
-
nComponents : int Number of independent components to extract. Pass -1 (default) to use all channels.
-
maxIter : int Maximum iterations per component (default 200).
-
tol : double Convergence tolerance on |w_new · w_old| - 1 (default 1e-4).
-
randomSeed : int Seed for the random weight initialisation (default 42).
Returns:
applyUnmixing(matData, result)
Project new data through a previously fitted unmixing matrix.
The same mean centering as during fitting is applied.
Parameters:
-
matData : const Eigen::MatrixXd & New data (n_channels x n_samples), same channel order as training data.
-
result : const IcaResult & Result from a previous
ICA::run()call.
Returns:
- Eigen::MatrixXd — Source matrix (n_components x n_samples).
excludeComponents(matData, result, excludedComponents)
Reconstruct sensor-space data after suppressing selected components.
The excluded component(s) are zeroed in source space before back-projection.
Parameters:
-
matData : const Eigen::MatrixXd & Original sensor data (n_channels x n_samples).
-
result : const IcaResult & Result from
ICA::run()on matData (or a representative segment). -
excludedComponents : const QVector< int > & 0-based indices of components to suppress (e.g. ECG, EOG artifacts).
Returns:
- Eigen::MatrixXd — Cleaned sensor data (n_channels x n_samples).
Example
- Full source:
src/examples/ex_dsp_preprocessing/main.cpp - Build target:
ex_dsp_preprocessing(runs under CTest)
Used in examples
ex_dsp_preprocessing
Preprocessing tools of the dsp library on synthetic data with a known ground truth.
const IcaResult ica = ICA::run(mixed, 3); // FastICA, logcosh, fixed seed
const MatrixXd cleaned = ICA::excludeComponents(mixed, ica, {0}); // drop component 0, back-project the rest
ok &= expect(worstRecovery(ica.matSources, sources) > 0.99, QString("FastICA recovers all sources (worst |r| %1)").arg(worstRecovery(ica.matSources, sources)));
ok &= expect((mixed - cleaned - ica.matMixing.col(0) * ica.matSources.row(0)).cwiseAbs().maxCoeff() < 1e-9,
"excluding a component removes exactly its back-projection");
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>