v2.0.0
Loading...
Searching...
No Matches
rapmusic.h
Go to the documentation of this file.
1//=============================================================================================================
35
36#ifndef RAPMUSIC_H
37#define RAPMUSIC_H
38
39//=============================================================================================================
40// INCLUDES
41//=============================================================================================================
42
43#include "../inverse_global.h"
45
46#include "dipole.h"
47
50#include <time.h>
51
52#include <QVector>
53
54//=============================================================================================================
55// EIGEN INCLUDES
56//=============================================================================================================
57
58#include <Eigen/Core>
59#include <Eigen/SVD>
60#include <Eigen/LU>
61
62//=============================================================================================================
63// DEFINE NAMESPACE INVERSELIB
64//=============================================================================================================
65
66namespace INVERSELIB
67{
68
69//=============================================================================================================
70// SOME DEFINES
71//=============================================================================================================
72
73#define NOT_TRANSPOSED 0
74#define IS_TRANSPOSED 1
75
76//=============================================================================================================
82typedef struct Pair
83{
84 int x1;
85 int x2;
87
88//=============================================================================================================
95{
96public:
97 typedef QSharedPointer<RapMusic> SPtr;
98 typedef QSharedPointer<const RapMusic> ConstSPtr;
99
100 //*********************************************************************************************************
101 //=========================================================================================================
102 // TYPEDEFS
103 //=========================================================================================================
104
105 typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> MatrixXT;
107 typedef Eigen::Matrix<double, Eigen::Dynamic, 6> MatrixX6T;
109 typedef Eigen::Matrix<double, 6, Eigen::Dynamic> Matrix6XT;
111 typedef Eigen::Matrix<double, 6, 6> Matrix6T;
113 typedef Eigen::Matrix<double, Eigen::Dynamic, 1> VectorXT;
115 typedef Eigen::Matrix<double, 6, 1> Vector6T;
117
118 //=========================================================================================================
122 RapMusic();
123
124 //=========================================================================================================
134 RapMusic(MNELIB::MNEForwardSolution& p_pFwd, bool p_bSparsed, int p_iN = 2, double p_dThr = 0.5);
135
136 virtual ~RapMusic();
137
138 //=========================================================================================================
149 bool init(MNELIB::MNEForwardSolution& p_pFwd, bool p_bSparsed = false, int p_iN = 2, double p_dThr = 0.5);
150
151 virtual MNELIB::MNESourceEstimate calculateInverse(const FIFFLIB::FiffEvoked &p_fiffEvoked, bool pick_normal = false);
152
153 virtual MNELIB::MNESourceEstimate calculateInverse(const Eigen::MatrixXd &data, float tmin, float tstep, bool pick_normal = false) const;
154
155 virtual MNELIB::MNESourceEstimate calculateInverse(const Eigen::MatrixXd& p_matMeasurement, QList< DipolePair<double> > &p_RapDipoles) const;
156
157 virtual const char* getName() const;
158
159 virtual const MNELIB::MNESourceSpaces& getSourceSpace() const;
160
161 //=========================================================================================================
168 void setStcAttr(int p_iSampStcWin, float p_fStcOverlap);
169
170protected:
171 //=========================================================================================================
180 int calcPhi_s(const MatrixXT& p_matMeasurement, MatrixXT* &p_pMatPhi_s) const;
181
182 //=========================================================================================================
195 static double subcorr(MatrixX6T& p_matProj_G, const MatrixXT& p_pMatU_B);
196
197 //=========================================================================================================
213 static double subcorr(MatrixX6T& p_matProj_G, const MatrixXT& p_matU_B, Vector6T& p_vec_phi_k_1);
214
215 //=========================================================================================================
225 static void calcA_k_1( const MatrixX6T& p_matG_k_1,
226 const Vector6T& p_matPhi_k_1,
227 const int p_iIdxk_1,
228 MatrixXT& p_matA_k_1);
229
230 //=========================================================================================================
237 void calcOrthProj(const MatrixXT& p_matA_k_1, MatrixXT& p_matOrthProj) const;
238
239 //=========================================================================================================
250 void calcPairCombinations( const int p_iNumPoints,
251 const int p_iNumCombinations,
252 Pair** p_ppPairIdxCombinations) const;
253
254 //=========================================================================================================
270 static void getPointPair(const int p_iPoints, const int p_iCurIdx, int &p_iIdx1, int &p_iIdx2);
271
272 //=========================================================================================================
281 static void getGainMatrixPair( const MatrixXT& p_matGainMarix,
282 MatrixX6T& p_matGainMarix_Pair,
283 int p_iIdx1, int p_iIdx2);
284
285 //=========================================================================================================
295 static void insertSource( int p_iDipoleIdx1, int p_iDipoleIdx2,
296 const Vector6T &p_vec_phi_k_1,
297 double p_valCor,
298 QList< DipolePair<double> > &p_RapDipoles);
299
301
302 int m_iN;
306
310
312
314
316
317 //Stc stuff
320
321 //=========================================================================================================
329 static inline int getRank(const MatrixXT& p_matSigma);
330
331 //=========================================================================================================
341 static inline int useFullRank( const MatrixXT& p_Mat,
342 const MatrixXT& p_matSigma_src,
343 MatrixXT& p_matFull_Rank,
344 int type = NOT_TRANSPOSED);
345
346 //=========================================================================================================
353 static inline MatrixXT makeSquareMat(const MatrixXT& p_matF);
354};
355
356//=============================================================================================================
357// INLINE DEFINITIONS
358//=============================================================================================================
359
360inline int RapMusic::getRank(const MatrixXT& p_matSigma)
361{
362 int t_iRank;
363 //if once a singularvalue is smaller than epsilon = 10^-5 the following values are also smaller
364 // -> because Singular values are ordered
365 for(t_iRank = p_matSigma.rows()-1; t_iRank > 0; t_iRank--)
366 if (p_matSigma(t_iRank, t_iRank) > 0.00001)
367 break;
368
369 t_iRank++;//rank corresponding to epsilon
370
371 return t_iRank;
372}
373
374//=============================================================================================================
375
376inline int RapMusic::useFullRank( const MatrixXT& p_Mat,
377 const MatrixXT& p_matSigma_src,
378 MatrixXT& p_matFull_Rank,
379 int type)
380{
381 int rank = getRank(p_matSigma_src);
382
383 if (type == NOT_TRANSPOSED)
384 p_matFull_Rank = p_Mat.block(0,0,p_Mat.rows(),rank);
385 else
386 p_matFull_Rank = p_Mat.block(0,0,rank,p_Mat.cols());
387
388 return rank;
389}
390
391//=============================================================================================================
392
394{
395 //Make rectangular - p_matF*p_matF^T
396 //MatrixXT FFT = p_matF*p_matF.transpose();
397
398 MatrixXT mat = p_matF.transpose();
399
400 return p_matF*mat;
401}
402} //NAMESPACE
403
404#endif // RAPMUSIC_H
MNEForwardSolution class declaration, which provides the forward solution including the source space ...
MNESourceEstimate class declaration.
#define NOT_TRANSPOSED
Definition pwlrapmusic.h:73
ToDo Documentation...
Contains declaration of IIinverseAlgorithm interface class.
inverse library export/import macros.
#define INVERSESHARED_EXPORT
Inverse source estimation (MNE, dSPM, sLORETA, dipole fitting).
struct INVERSELIB::Pair Pair
Index pair representing two grid points evaluated together in the RAP MUSIC subspace scan.
Inverse algorithm interface.
Pair of correlated dipole indices and orientations found by the RAP MUSIC scanning step.
Definition dipole.h:59
Index pair representing two grid points evaluated together in the RAP MUSIC subspace scan.
Definition rapmusic.h:83
static double subcorr(MatrixX6T &p_matProj_G, const MatrixXT &p_pMatU_B)
Definition rapmusic.cpp:616
Eigen::Matrix< double, 6, 6 > Matrix6T
Definition rapmusic.h:111
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorXT
Definition rapmusic.h:113
Eigen::Matrix< double, Eigen::Dynamic, 6 > MatrixX6T
Definition rapmusic.h:107
bool init(MNELIB::MNEForwardSolution &p_pFwd, bool p_bSparsed=false, int p_iN=2, double p_dThr=0.5)
Definition rapmusic.cpp:109
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixXT
Definition rapmusic.h:105
virtual MNELIB::MNESourceEstimate calculateInverse(const Eigen::MatrixXd &data, float tmin, float tstep, bool pick_normal=false) const
virtual MNELIB::MNESourceEstimate calculateInverse(const Eigen::MatrixXd &p_matMeasurement, QList< DipolePair< double > > &p_RapDipoles) const
virtual const char * getName() const
Definition rapmusic.cpp:192
static void getPointPair(const int p_iPoints, const int p_iCurIdx, int &p_iIdx1, int &p_iIdx2)
Definition rapmusic.cpp:829
QSharedPointer< RapMusic > SPtr
Definition rapmusic.h:97
int m_iNumLeadFieldCombinations
Definition rapmusic.h:309
static void insertSource(int p_iDipoleIdx1, int p_iDipoleIdx2, const Vector6T &p_vec_phi_k_1, double p_valCor, QList< DipolePair< double > > &p_RapDipoles)
Definition rapmusic.cpp:852
void calcOrthProj(const MatrixXT &p_matA_k_1, MatrixXT &p_matOrthProj) const
Definition rapmusic.cpp:761
void setStcAttr(int p_iSampStcWin, float p_fStcOverlap)
Definition rapmusic.cpp:885
Pair ** m_ppPairIdxCombinations
Definition rapmusic.h:311
static MatrixXT makeSquareMat(const MatrixXT &p_matF)
Definition rapmusic.h:393
virtual MNELIB::MNESourceEstimate calculateInverse(const FIFFLIB::FiffEvoked &p_fiffEvoked, bool pick_normal=false)
Definition rapmusic.cpp:206
Eigen::Matrix< double, 6, Eigen::Dynamic > Matrix6XT
Definition rapmusic.h:109
virtual const MNELIB::MNESourceSpaces & getSourceSpace() const
Definition rapmusic.cpp:199
void calcPairCombinations(const int p_iNumPoints, const int p_iNumCombinations, Pair **p_ppPairIdxCombinations) const
Definition rapmusic.cpp:799
static int useFullRank(const MatrixXT &p_Mat, const MatrixXT &p_matSigma_src, MatrixXT &p_matFull_Rank, int type=NOT_TRANSPOSED)
Definition rapmusic.h:376
MNELIB::MNEForwardSolution m_ForwardSolution
Definition rapmusic.h:300
static void getGainMatrixPair(const MatrixXT &p_matGainMarix, MatrixX6T &p_matGainMarix_Pair, int p_iIdx1, int p_iIdx2)
Definition rapmusic.cpp:841
int calcPhi_s(const MatrixXT &p_matMeasurement, MatrixXT *&p_pMatPhi_s) const
Definition rapmusic.cpp:587
QSharedPointer< const RapMusic > ConstSPtr
Definition rapmusic.h:98
static int getRank(const MatrixXT &p_matSigma)
Definition rapmusic.h:360
Eigen::Matrix< double, 6, 1 > Vector6T
Definition rapmusic.h:115
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)
Definition rapmusic.cpp:746
Source Space descritpion.