v2.0.0
Loading...
Searching...
No Matches
DECODINGLIB::DecodingCsp Class Reference

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

Detailed Description

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.

  1. After fit the class works as a deterministic feature extractor: transform reduces an epoch tensor either to one log-power (or z-scored) value per component (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.

See also
DECODINGLIB, mne.decoding.CSP

Definition at line 95 of file decoding_csp.h.

Member Enumeration Documentation

◆ TransformMode

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 102 of file decoding_csp.h.

Constructor & Destructor Documentation

◆ DecodingCsp()

DecodingCsp::DecodingCsp ( int nComponents = 4,
TransformMode transformInto = TransformMode::AveragePower,
bool useLog = true )
explicit

Constructs a CSP decoder.

Parameters
[in]nComponentsNumber of CSP components (split between classes). Default: 4.
[in]transformIntoFeature extraction mode. Default: AveragePower.
[in]useLogIf 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.

Member Function Documentation

◆ filters()

const MatrixXd & DecodingCsp::filters ( ) const
Returns
Spatial filters (n_components × n_channels).

Definition at line 261 of file decoding_csp.cpp.

◆ fit()

void DecodingCsp::fit ( const std::vector< Eigen::MatrixXd > & epochs,
const Eigen::VectorXi & y )

Fit CSP from labelled epoch data (binary classification).

Parameters
[in]epochsVector of epoch matrices, each (n_channels × n_times).
[in]yClass label for each epoch (must contain exactly 2 unique values).

Definition at line 73 of file decoding_csp.cpp.

◆ fitTransform()

MatrixXd DecodingCsp::fitTransform ( const std::vector< Eigen::MatrixXd > & epochs,
const Eigen::VectorXi & y )

Fit and transform in one step.

Parameters
[in]epochsEpoch data.
[in]yClass labels.
Returns
Feature matrix (same as transform output).

Definition at line 229 of file decoding_csp.cpp.

◆ inverseTransform()

MatrixXd DecodingCsp::inverseTransform ( const Eigen::MatrixXd & X) const

Project CSP power features back to sensor space.

Only valid when transformInto == AveragePower.

Parameters
[in]XFeature matrix (n_epochs × n_components).
Returns
Sensor-space projection (n_epochs × n_channels × n_components). Stored as (n_epochs, n_channels * n_components) flattened.

Definition at line 238 of file decoding_csp.cpp.

◆ isFitted()

bool DecodingCsp::isFitted ( ) const
Returns
True if the model has been fitted.

Definition at line 301 of file decoding_csp.cpp.

◆ mean()

const VectorXd & DecodingCsp::mean ( ) const
Returns
Mean band power per component (computed during fit).

Definition at line 281 of file decoding_csp.cpp.

◆ patterns()

const MatrixXd & DecodingCsp::patterns ( ) const
Returns
Spatial patterns (n_channels × n_components).

Definition at line 271 of file decoding_csp.cpp.

◆ stddev()

const VectorXd & DecodingCsp::stddev ( ) const
Returns
Standard deviation of band power per component (computed during fit).

Definition at line 291 of file decoding_csp.cpp.

◆ transform()

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).

Parameters
[in]epochsVector of epoch matrices, each (n_channels × n_times).
Returns
Feature matrix.

Definition at line 191 of file decoding_csp.cpp.


The documentation for this class was generated from the following files: