27#include <Skigen/Neighbors>
56 const int n =
static_cast<int>(features.rows());
59 return VectorXd::Ones(n);
63 Skigen::LocalOutlierFactor<double> lof(k);
65 return lof.lof_scores();
76 for (
int i = 0; i < info.
chs.size(); ++i) {
88 const int nCh = chIdx.size();
94 const int nFeatures = 3;
95 MatrixXd features(nCh, nFeatures);
97 for (
int i = 0; i < nCh; ++i) {
98 const RowVectorXd row = data.row(chIdx[i]);
99 const int nTimes =
static_cast<int>(row.size());
100 const double mean = row.mean();
103 double variance = (row.array() - mean).square().sum() /
static_cast<double>(nTimes);
104 double stdDev = std::sqrt(variance);
105 features(i, 0) = stdDev;
108 double m4 = (row.array() - mean).pow(4.0).sum() /
static_cast<double>(nTimes);
109 double kurt = (variance > 1e-30) ? m4 / (variance * variance) - 3.0 : 0.0;
110 features(i, 1) = kurt;
113 features(i, 2) = row.array().abs().maxCoeff();
117 for (
int f = 0; f < nFeatures; ++f) {
118 double fMean = features.col(f).mean();
119 double fStd = std::sqrt((features.col(f).array() - fMean).square().mean());
121 features.col(f) = (features.col(f).array() - fMean) / fStd;
130 QStringList badChannels;
131 for (
int i = 0; i < nCh; ++i) {
133 badChannels.append(info.
ch_names[chIdx[i]]);
Symbolic FIFF tag, block, value, unit and channel-type constants shared across FIFFLIB.
FIFF channel descriptor record (FIFF_CH_INFO): per-channel logical/scanner numbers,...
Full FIFF measurement metadata: everything from FIFFB_MEAS / FIFFB_MEAS_INFO needed to interpret a re...
Bad-channel detection via the Local Outlier Factor (LOF) algorithm.
FIFF file I/O, in-memory data structures and high-level readers/writers.
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
DSPSHARED_EXPORT Eigen::VectorXd computeLofScores(const Eigen::MatrixXd &features, int k)
Compute LOF scores for a feature matrix.
DSPSHARED_EXPORT QStringList findBadChannelsLof(const Eigen::MatrixXd &data, const FIFFLIB::FiffInfo &info, const LofBadChannelParams ¶ms=LofBadChannelParams())
Detect bad channels using Local Outlier Factor (LOF).
Full FIFF measurement info: per-channel descriptors, sampling and filter setup, projectors,...