v2.0.0
Loading...
Searching...
No Matches
inv_rap_music.h
Go to the documentation of this file.
1//=============================================================================================================
23
24#ifndef INV_RAP_MUSIC_H
25#define INV_RAP_MUSIC_H
26
27//=============================================================================================================
28// INCLUDES
29//=============================================================================================================
30
31#include "../inv_global.h"
32
33#include "inv_dipole.h"
34
37#include <time.h>
38
39#include <QVector>
40
41#include <vector>
42
43//=============================================================================================================
44// EIGEN INCLUDES
45//=============================================================================================================
46
47#include <Eigen/Core>
48#include <Eigen/SVD>
49#include <Eigen/LU>
50
51//=============================================================================================================
52// DEFINE NAMESPACE INVLIB
53//=============================================================================================================
54
55namespace INVLIB
56{
57
58//=============================================================================================================
59// SOME DEFINES
60//=============================================================================================================
61
62#define NOT_TRANSPOSED 0
63#define IS_TRANSPOSED 1
64
65//=============================================================================================================
71struct Pair
72{
73 int x1;
74 int x2;
75};
76
77//=============================================================================================================
92{
93public:
94 typedef QSharedPointer<InvRapMusic> SPtr;
95 typedef QSharedPointer<const InvRapMusic> ConstSPtr;
96
97 //*********************************************************************************************************
98 //=========================================================================================================
99 // TYPEDEFS
100 //=========================================================================================================
101
102 typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> MatrixXT;
104 typedef Eigen::Matrix<double, Eigen::Dynamic, 6> MatrixX6T;
106 typedef Eigen::Matrix<double, 6, Eigen::Dynamic> Matrix6XT;
108 typedef Eigen::Matrix<double, 6, 6> Matrix6T;
110 typedef Eigen::Matrix<double, Eigen::Dynamic, 1> VectorXT;
112 typedef Eigen::Matrix<double, 6, 1> Vector6T;
114
115 //=========================================================================================================
119 InvRapMusic();
120
121 //=========================================================================================================
131 InvRapMusic(MNELIB::MNEForwardSolution& p_pFwd, bool p_bSparsed, int p_iN = 2, double p_dThr = 0.5);
132
133 virtual ~InvRapMusic();
134
135 //=========================================================================================================
146 bool init(MNELIB::MNEForwardSolution& p_pFwd, bool p_bSparsed = false, int p_iN = 2, double p_dThr = 0.5);
147
148 virtual InvSourceEstimate calculateInverse(const FIFFLIB::FiffEvoked& p_fiffEvoked, bool pick_normal = false);
149
150 virtual InvSourceEstimate calculateInverse(const Eigen::MatrixXd& data, float tmin, float tstep, bool pick_normal = false) const;
151
152 virtual InvSourceEstimate calculateInverse(const Eigen::MatrixXd& p_matMeasurement, QList<InvDipolePair<double>>& p_RapDipoles) const;
153
154 virtual const char* getName() const;
155
156 virtual const MNELIB::MNESourceSpaces& getSourceSpace() const;
157
158 //=========================================================================================================
165 void setStcAttr(int p_iSampStcWin, float p_fStcOverlap);
166
167protected:
168 //=========================================================================================================
177 int calcPhi_s(const MatrixXT& p_matMeasurement, MatrixXT*& p_pMatPhi_s) const;
178
179 //=========================================================================================================
192 static double subcorr(MatrixX6T& p_matProj_G, const MatrixXT& p_pMatU_B);
193
194 //=========================================================================================================
210 static double subcorr(MatrixX6T& p_matProj_G, const MatrixXT& p_matU_B, Vector6T& p_vec_phi_k_1);
211
212 //=========================================================================================================
222 static void calcA_k_1(const MatrixX6T& p_matG_k_1,
223 const Vector6T& p_matPhi_k_1,
224 const int p_iIdxk_1,
225 MatrixXT& p_matA_k_1);
226
227 //=========================================================================================================
234 void calcOrthProj(const MatrixXT& p_matA_k_1, MatrixXT& p_matOrthProj) const;
235
236 //=========================================================================================================
247 void calcPairCombinations(const int p_iNumPoints,
248 const int p_iNumCombinations,
249 std::vector<Pair>& p_pairIdxCombinations) const;
250
251 //=========================================================================================================
267 static void getPointPair(const int p_iPoints, const int p_iCurIdx, int& p_iIdx1, int& p_iIdx2);
268
269 //=========================================================================================================
278 static void getGainMatrixPair(const MatrixXT& p_matGainMarix,
279 MatrixX6T& p_matGainMarix_Pair,
280 int p_iIdx1, int p_iIdx2);
281
282 //=========================================================================================================
292 static void insertSource(int p_iDipoleIdx1, int p_iDipoleIdx2,
293 const Vector6T& p_vec_phi_k_1,
294 double p_valCor,
295 QList<InvDipolePair<double>>& p_RapDipoles);
296
298
299 int m_iN;
303
307
308 std::vector<Pair> m_ppPairIdxCombinations;
309
311
313
314 //Stc stuff
317
318 //=========================================================================================================
326 static inline int getRank(const MatrixXT& p_matSigma);
327
328 //=========================================================================================================
340 static inline int useFullRank(const MatrixXT& p_Mat,
341 const MatrixXT& p_matSigma_src,
342 MatrixXT& p_matFull_Rank,
343 int type = NOT_TRANSPOSED);
344
345 //=========================================================================================================
352 static inline MatrixXT makeSquareMat(const MatrixXT& p_matF);
353};
354
355//=============================================================================================================
356// INLINE DEFINITIONS
357//=============================================================================================================
358
359inline int InvRapMusic::getRank(const MatrixXT& p_matSigma)
360{
361 int t_iRank;
362 //if once a singularvalue is smaller than epsilon = 10^-5 the following values are also smaller
363 // -> because Singular values are ordered
364 for (t_iRank = p_matSigma.rows() - 1; t_iRank > 0; t_iRank--)
365 if (p_matSigma(t_iRank, t_iRank) > 0.00001)
366 break;
367
368 t_iRank++; //rank corresponding to epsilon
369
370 return t_iRank;
371}
372
373//=============================================================================================================
374
375inline int InvRapMusic::useFullRank(const MatrixXT& p_Mat,
376 const MatrixXT& p_matSigma_src,
377 MatrixXT& p_matFull_Rank,
378 int type)
379{
380 int rank = getRank(p_matSigma_src);
381
382 if (type == NOT_TRANSPOSED)
383 p_matFull_Rank = p_Mat.block(0, 0, p_Mat.rows(), rank);
384 else
385 p_matFull_Rank = p_Mat.block(0, 0, rank, p_Mat.cols());
386
387 return rank;
388}
389
390//=============================================================================================================
391
393{
394 //Make rectangular - p_matF*p_matF^T
395 //MatrixXT FFT = p_matF*p_matF.transpose();
396
397 MatrixXT mat = p_matF.transpose();
398
399 return p_matF * mat;
400}
401} //NAMESPACE
402
403#endif // INV_RAP_MUSIC_H
Templated dipole and dipole-pair value types used by the RAP-MUSIC scanning algorithm.
#define NOT_TRANSPOSED
INVLIB library export/import macros, build-info accessors, and namespace docstring for the inverse-so...
#define INVSHARED_EXPORT
Definition inv_global.h:38
InvSourceEstimate value type — central source-space data container produced by every INVLIB inverse s...
Forward solution (gain matrix mapping source dipoles to sensor measurements).
Inverse source estimation (MNE, dSPM, sLORETA, dipole fitting).
Single averaged evoked response: time axis, data, baseline, channel info and averaging metadata.
Definition fiff_evoked.h:77
Source-space inverse-solution container with dense grid plus optional focal-dipole,...
Pair of correlated dipole indices and orientations found by the RAP MUSIC scanning step.
Definition inv_dipole.h:62
Index pair representing two grid points evaluated together in the RAP MUSIC subspace scan.
Eigen::Matrix< double, 6, 1 > Vector6T
void calcPairCombinations(const int p_iNumPoints, const int p_iNumCombinations, std::vector< Pair > &p_pairIdxCombinations) const
static void calcA_k_1(const MatrixX6T &p_matG_k_1, const Vector6T &p_matPhi_k_1, const int p_iIdxk_1, MatrixXT &p_matA_k_1)
static void getPointPair(const int p_iPoints, const int p_iCurIdx, int &p_iIdx1, int &p_iIdx2)
virtual InvSourceEstimate calculateInverse(const FIFFLIB::FiffEvoked &p_fiffEvoked, bool pick_normal=false)
static int getRank(const MatrixXT &p_matSigma)
virtual const char * getName() const
static MatrixXT makeSquareMat(const MatrixXT &p_matF)
static void insertSource(int p_iDipoleIdx1, int p_iDipoleIdx2, const Vector6T &p_vec_phi_k_1, double p_valCor, QList< InvDipolePair< double > > &p_RapDipoles)
void setStcAttr(int p_iSampStcWin, float p_fStcOverlap)
bool init(MNELIB::MNEForwardSolution &p_pFwd, bool p_bSparsed=false, int p_iN=2, double p_dThr=0.5)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixXT
Eigen::Matrix< double, 6, 6 > Matrix6T
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorXT
QSharedPointer< InvRapMusic > SPtr
virtual InvSourceEstimate calculateInverse(const Eigen::MatrixXd &p_matMeasurement, QList< InvDipolePair< double > > &p_RapDipoles) const
void calcOrthProj(const MatrixXT &p_matA_k_1, MatrixXT &p_matOrthProj) const
int calcPhi_s(const MatrixXT &p_matMeasurement, MatrixXT *&p_pMatPhi_s) const
static int useFullRank(const MatrixXT &p_Mat, const MatrixXT &p_matSigma_src, MatrixXT &p_matFull_Rank, int type=NOT_TRANSPOSED)
Eigen::Matrix< double, Eigen::Dynamic, 6 > MatrixX6T
MNELIB::MNEForwardSolution m_ForwardSolution
virtual const MNELIB::MNESourceSpaces & getSourceSpace() const
std::vector< Pair > m_ppPairIdxCombinations
Eigen::Matrix< double, 6, Eigen::Dynamic > Matrix6XT
virtual InvSourceEstimate calculateInverse(const Eigen::MatrixXd &data, float tmin, float tstep, bool pick_normal=false) const
static void getGainMatrixPair(const MatrixXT &p_matGainMarix, MatrixX6T &p_matGainMarix_Pair, int p_iIdx1, int p_iIdx2)
static double subcorr(MatrixX6T &p_matProj_G, const MatrixXT &p_pMatU_B)
QSharedPointer< const InvRapMusic > ConstSPtr
In-memory representation of an -fwd.fif forward solution.
List of MNESourceSpace objects forming a subject source space.