v2.0.0
Loading...
Searching...
No Matches
sts_source_metrics.cpp
Go to the documentation of this file.
1//=============================================================================================================
20
21//=============================================================================================================
22// INCLUDES
23//=============================================================================================================
24
25#include "sts_source_metrics.h"
26
27//=============================================================================================================
28// STL INCLUDES
29//=============================================================================================================
30
31#include <cmath>
32
33//=============================================================================================================
34// USED NAMESPACES
35//=============================================================================================================
36
37using namespace STSLIB;
38using namespace Eigen;
39
40//=============================================================================================================
41// DEFINE MEMBER METHODS
42//=============================================================================================================
43
45 const Vector3d& truePos,
46 const Vector3d& estimatedPos)
47{
48 return (truePos - estimatedPos).norm();
49}
50
51//=============================================================================================================
52
54 const VectorXd& sourceAmplitudes,
55 const MatrixXd& sourcePositions,
56 int peakIndex)
57{
58 int nSources = sourceAmplitudes.size();
59 Vector3d peakPos = sourcePositions.row(peakIndex);
60
61 double weightedSum = 0.0;
62 double totalWeight = 0.0;
63
64 for (int k = 0; k < nSources; ++k) {
65 double absAmp = std::abs(sourceAmplitudes(k));
66 double dist = (sourcePositions.row(k).transpose() - peakPos).norm();
67 weightedSum += dist * absAmp;
68 totalWeight += absAmp;
69 }
70
71 if (totalWeight < 1e-10) {
72 return 0.0;
73 }
74
75 return weightedSum / totalWeight;
76}
77
78//=============================================================================================================
79
80int StatsSourceMetrics::findPeakIndex(const VectorXd& sourceAmplitudes)
81{
82 int peakIdx = 0;
83 sourceAmplitudes.cwiseAbs().maxCoeff(&peakIdx);
84 return peakIdx;
85}
Peak localisation error and spatial dispersion metrics for evaluating distributed M/EEG inverse solut...
Statistical testing (t-tests, F-tests, cluster permutation, multiple comparison correction).
static double peakLocalizationError(const Eigen::Vector3d &truePos, const Eigen::Vector3d &estimatedPos)
static double spatialDispersion(const Eigen::VectorXd &sourceAmplitudes, const Eigen::MatrixXd &sourcePositions, int peakIndex)
static int findPeakIndex(const Eigen::VectorXd &sourceAmplitudes)