Common Spatial Patterns decoder for two-class discriminative spatial filtering. More...
#include <decoding_csp.h>
Public Types | |
| enum class | TransformMode { AveragePower , CspSpace } |
Public Member Functions | |
| DecodingCsp (int nComponents=4, TransformMode transformInto=TransformMode::AveragePower, bool useLog=true) | |
| void | fit (const std::vector< Eigen::MatrixXd > &epochs, const Eigen::VectorXi &y) |
| Eigen::MatrixXd | transform (const std::vector< Eigen::MatrixXd > &epochs) const |
| Eigen::MatrixXd | fitTransform (const std::vector< Eigen::MatrixXd > &epochs, const Eigen::VectorXi &y) |
| Eigen::MatrixXd | inverseTransform (const Eigen::MatrixXd &X) const |
| const Eigen::MatrixXd & | filters () const |
| const Eigen::MatrixXd & | patterns () const |
| const Eigen::VectorXd & | mean () const |
| const Eigen::VectorXd & | stddev () const |
| bool | isFitted () const |
Common Spatial Patterns decoder for two-class discriminative spatial filtering.
Estimates the joint diagonaliser of two class-conditional covariance matrices estimated from labelled, band-passed epochs and exposes the top and bottom n_components eigenvectors as a bank of spatial filters; the corresponding patterns (the columns of the pseudoinverse of the filter matrix) describe the sensor-space activity that each filter is sensitive to and are what should be plotted as topographies for neurophysiological interpretation, as discussed by Haufe et al.
AveragePower, the standard input to an LDA / logistic-regression classifier) or to the full time-resolved projection (CspSpace, useful for downstream Riemannian or deep-learning stages).The implementation expects exactly two unique class labels in y and epochs already restricted to the discriminative frequency band (e.g. 8–30 Hz for sensorimotor rhythms); no regularisation is applied to the covariance estimate, so callers should ensure enough trials per class to avoid the ill-conditioned regime that motivates the regularised variants of Lotte & Guan 2011. inverseTransform provides the closed-form back-projection of a power-feature vector into sensor space, which is what the application layer uses to render CSP topographies side-by-side with the discriminative scores.
mne.decoding.CSP Definition at line 98 of file decoding_csp.h.
|
strong |
Transform mode for the CSP output.
| Enumerator | |
|---|---|
| AveragePower | Return average band power per component (n_epochs × n_components). |
| CspSpace | Return data projected into CSP space (n_epochs × n_components × n_times). |
Definition at line 105 of file decoding_csp.h.
|
explicit |
Constructs a CSP decoder.
| [in] | nComponents | Number of CSP components (split between classes). Default: 4. |
| [in] | transformInto | Feature extraction mode. Default: AveragePower. |
| [in] | useLog | If true (default) and transformInto == AveragePower, apply log transform; otherwise z-score features using mean_ and std_. |
Definition at line 62 of file decoding_csp.cpp.
| const MatrixXd & DecodingCsp::filters | ( | ) | const |
Definition at line 258 of file decoding_csp.cpp.
| void DecodingCsp::fit | ( | const std::vector< Eigen::MatrixXd > & | epochs, |
| const Eigen::VectorXi & | y ) |
Fit CSP from labelled epoch data (binary classification).
| [in] | epochs | Vector of epoch matrices, each (n_channels × n_times). |
| [in] | y | Class label for each epoch (must contain exactly 2 unique values). |
Definition at line 73 of file decoding_csp.cpp.
| MatrixXd DecodingCsp::fitTransform | ( | const std::vector< Eigen::MatrixXd > & | epochs, |
| const Eigen::VectorXi & | y ) |
Fit and transform in one step.
| [in] | epochs | Epoch data. |
| [in] | y | Class labels. |
Definition at line 226 of file decoding_csp.cpp.
| MatrixXd DecodingCsp::inverseTransform | ( | const Eigen::MatrixXd & | X | ) | const |
Project CSP power features back to sensor space.
Only valid when transformInto == AveragePower.
| [in] | X | Feature matrix (n_epochs × n_components). |
Definition at line 235 of file decoding_csp.cpp.
| bool DecodingCsp::isFitted | ( | ) | const |
Definition at line 298 of file decoding_csp.cpp.
| const VectorXd & DecodingCsp::mean | ( | ) | const |
Definition at line 278 of file decoding_csp.cpp.
| const MatrixXd & DecodingCsp::patterns | ( | ) | const |
Definition at line 268 of file decoding_csp.cpp.
| const VectorXd & DecodingCsp::stddev | ( | ) | const |
Definition at line 288 of file decoding_csp.cpp.
| MatrixXd DecodingCsp::transform | ( | const std::vector< Eigen::MatrixXd > & | epochs | ) | const |
Transform epoch data using the fitted CSP filters.
When transformInto == AveragePower, returns (n_epochs × n_components) with log-transformed or z-scored mean band power.
When transformInto == CspSpace, returns a matrix where each n_components rows correspond to one epoch's CSP-space projection. The shape is (n_epochs * n_components, n_times).
| [in] | epochs | Vector of epoch matrices, each (n_channels × n_times). |
Definition at line 187 of file decoding_csp.cpp.