v2.0.0
Loading...
Searching...
No Matches
inv_rap_music.h
Go to the documentation of this file.
1//=============================================================================================================
35
36#ifndef INV_RAP_MUSIC_H
37#define INV_RAP_MUSIC_H
38
39//=============================================================================================================
40// INCLUDES
41//=============================================================================================================
42
43#include "../inv_global.h"
44
45#include "inv_dipole.h"
46
49#include <time.h>
50
51#include <QVector>
52
53//=============================================================================================================
54// EIGEN INCLUDES
55//=============================================================================================================
56
57#include <Eigen/Core>
58#include <Eigen/SVD>
59#include <Eigen/LU>
60
61//=============================================================================================================
62// DEFINE NAMESPACE INVLIB
63//=============================================================================================================
64
65namespace INVLIB
66{
67
68//=============================================================================================================
69// SOME DEFINES
70//=============================================================================================================
71
72#define NOT_TRANSPOSED 0
73#define IS_TRANSPOSED 1
74
75//=============================================================================================================
81typedef struct Pair
82{
83 int x1;
84 int x2;
86
87//=============================================================================================================
100{
101public:
102 typedef QSharedPointer<InvRapMusic> SPtr;
103 typedef QSharedPointer<const InvRapMusic> ConstSPtr;
104
105 //*********************************************************************************************************
106 //=========================================================================================================
107 // TYPEDEFS
108 //=========================================================================================================
109
110 typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> MatrixXT;
112 typedef Eigen::Matrix<double, Eigen::Dynamic, 6> MatrixX6T;
114 typedef Eigen::Matrix<double, 6, Eigen::Dynamic> Matrix6XT;
116 typedef Eigen::Matrix<double, 6, 6> Matrix6T;
118 typedef Eigen::Matrix<double, Eigen::Dynamic, 1> VectorXT;
120 typedef Eigen::Matrix<double, 6, 1> Vector6T;
122
123 //=========================================================================================================
127 InvRapMusic();
128
129 //=========================================================================================================
139 InvRapMusic(MNELIB::MNEForwardSolution& p_pFwd, bool p_bSparsed, int p_iN = 2, double p_dThr = 0.5);
140
141 virtual ~InvRapMusic();
142
143 //=========================================================================================================
154 bool init(MNELIB::MNEForwardSolution& p_pFwd, bool p_bSparsed = false, int p_iN = 2, double p_dThr = 0.5);
155
156 virtual InvSourceEstimate calculateInverse(const FIFFLIB::FiffEvoked &p_fiffEvoked, bool pick_normal = false);
157
158 virtual InvSourceEstimate calculateInverse(const Eigen::MatrixXd &data, float tmin, float tstep, bool pick_normal = false) const;
159
160 virtual InvSourceEstimate calculateInverse(const Eigen::MatrixXd& p_matMeasurement, QList< InvDipolePair<double> > &p_RapDipoles) const;
161
162 virtual const char* getName() const;
163
164 virtual const MNELIB::MNESourceSpaces& getSourceSpace() const;
165
166 //=========================================================================================================
173 void setStcAttr(int p_iSampStcWin, float p_fStcOverlap);
174
175protected:
176 //=========================================================================================================
185 int calcPhi_s(const MatrixXT& p_matMeasurement, MatrixXT* &p_pMatPhi_s) const;
186
187 //=========================================================================================================
200 static double subcorr(MatrixX6T& p_matProj_G, const MatrixXT& p_pMatU_B);
201
202 //=========================================================================================================
218 static double subcorr(MatrixX6T& p_matProj_G, const MatrixXT& p_matU_B, Vector6T& p_vec_phi_k_1);
219
220 //=========================================================================================================
230 static void calcA_k_1( const MatrixX6T& p_matG_k_1,
231 const Vector6T& p_matPhi_k_1,
232 const int p_iIdxk_1,
233 MatrixXT& p_matA_k_1);
234
235 //=========================================================================================================
242 void calcOrthProj(const MatrixXT& p_matA_k_1, MatrixXT& p_matOrthProj) const;
243
244 //=========================================================================================================
255 void calcPairCombinations( const int p_iNumPoints,
256 const int p_iNumCombinations,
257 Pair** p_ppPairIdxCombinations) const;
258
259 //=========================================================================================================
275 static void getPointPair(const int p_iPoints, const int p_iCurIdx, int &p_iIdx1, int &p_iIdx2);
276
277 //=========================================================================================================
286 static void getGainMatrixPair( const MatrixXT& p_matGainMarix,
287 MatrixX6T& p_matGainMarix_Pair,
288 int p_iIdx1, int p_iIdx2);
289
290 //=========================================================================================================
300 static void insertSource( int p_iDipoleIdx1, int p_iDipoleIdx2,
301 const Vector6T &p_vec_phi_k_1,
302 double p_valCor,
303 QList< InvDipolePair<double> > &p_RapDipoles);
304
306
307 int m_iN;
311
315
317
319
321
322 //Stc stuff
325
326 //=========================================================================================================
334 static inline int getRank(const MatrixXT& p_matSigma);
335
336 //=========================================================================================================
346 static inline int useFullRank( const MatrixXT& p_Mat,
347 const MatrixXT& p_matSigma_src,
348 MatrixXT& p_matFull_Rank,
349 int type = NOT_TRANSPOSED);
350
351 //=========================================================================================================
358 static inline MatrixXT makeSquareMat(const MatrixXT& p_matF);
359};
360
361//=============================================================================================================
362// INLINE DEFINITIONS
363//=============================================================================================================
364
365inline int InvRapMusic::getRank(const MatrixXT& p_matSigma)
366{
367 int t_iRank;
368 //if once a singularvalue is smaller than epsilon = 10^-5 the following values are also smaller
369 // -> because Singular values are ordered
370 for(t_iRank = p_matSigma.rows()-1; t_iRank > 0; t_iRank--)
371 if (p_matSigma(t_iRank, t_iRank) > 0.00001)
372 break;
373
374 t_iRank++;//rank corresponding to epsilon
375
376 return t_iRank;
377}
378
379//=============================================================================================================
380
381inline int InvRapMusic::useFullRank( const MatrixXT& p_Mat,
382 const MatrixXT& p_matSigma_src,
383 MatrixXT& p_matFull_Rank,
384 int type)
385{
386 int rank = getRank(p_matSigma_src);
387
388 if (type == NOT_TRANSPOSED)
389 p_matFull_Rank = p_Mat.block(0,0,p_Mat.rows(),rank);
390 else
391 p_matFull_Rank = p_Mat.block(0,0,rank,p_Mat.cols());
392
393 return rank;
394}
395
396//=============================================================================================================
397
399{
400 //Make rectangular - p_matF*p_matF^T
401 //MatrixXT FFT = p_matF*p_matF.transpose();
402
403 MatrixXT mat = p_matF.transpose();
404
405 return p_matF*mat;
406}
407} //NAMESPACE
408
409#endif // INV_RAP_MUSIC_H
InvDipole class declaration for RAP MUSIC dipole results.
#define NOT_TRANSPOSED
InvSourceEstimate class declaration.
inverse library export/import macros.
#define INVSHARED_EXPORT
Definition inv_global.h:52
MNEForwardSolution class declaration.
Inverse source estimation (MNE, dSPM, sLORETA, dipole fitting).
struct INVLIB::Pair Pair
Index pair representing two grid points evaluated together in the RAP MUSIC subspace scan.
Pair of correlated dipole indices and orientations found by the RAP MUSIC scanning step.
Definition inv_dipole.h:59
Index pair representing two grid points evaluated together in the RAP MUSIC subspace scan.
Eigen::Matrix< double, 6, 1 > Vector6T
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
Pair ** m_ppPairIdxCombinations
void calcPairCombinations(const int p_iNumPoints, const int p_iNumCombinations, Pair **p_ppPairIdxCombinations) const
virtual const MNELIB::MNESourceSpaces & getSourceSpace() const
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
Source Space descritpion.