72 init(p_pFwd, p_bSparsed, p_iN, p_dThr);
85 return "Powell RAP MUSIC";
111 throw std::logic_error(
"RAP MUSIC was not initialized");
117 throw std::invalid_argument(
"Lead field channels do not match number of measurement channels");
133 int t_r =
calcPhi_s(p_matMeasurement, t_pMatPhi_s);
135 int t_iMaxSearch =
m_iN < t_r ?
m_iN : t_r;
139 qDebug() <<
"Warning: Rank " << t_r <<
" of the measurement data is smaller than the " <<
m_iN;
140 qDebug() <<
" sources to find.";
141 qDebug() <<
" Searching now for " << t_iMaxSearch <<
" correlated sources.";
148 t_matOrthProj.setIdentity();
152 t_matA_k_1.setZero();
168 p_RapDipoles.clear();
170 qDebug() <<
"##### Calculation of PWL RAP MUSIC started ######\n\n";
172 MatrixXT t_matProj_Phi_s(t_matOrthProj.rows(), t_pMatPhi_s->cols());
176 for(
int r = 0; r < t_iMaxSearch ; ++r)
178 t_matProj_Phi_s = t_matOrthProj*(*t_pMatPhi_s);
185 Eigen::JacobiSVD< MatrixXT > t_svdProj_Phi_S(t_matProj_Phi_s, Eigen::ComputeThinU);
187 useFullRank(t_svdProj_Phi_S.matrixU(), t_svdProj_Phi_S.singularValues().asDiagonal(), t_matU_B);
195 clock_t start_subcorr, end_subcorr;
196 start_subcorr = clock();
201 int t_iCurrentRow = 2;
206 int t_iMaxIdx_old = -1;
216 while(t_iMaxFound == 0)
221 #pragma omp parallel num_threads(m_iMaxNumThreads)
227 for(
int i = 0; i < t_iNumVecElements; i++)
229 int k = t_pVecIdxElements(i);
232 MatrixX6T t_matProj_G(t_matProj_LeadField.rows(),6);
261 VectorXT::Index t_iMaxIdx;
263 t_val_roh_k = t_vecRoh.maxCoeff(&t_iMaxIdx);
265 if(
static_cast<int>(t_iMaxIdx) == t_iMaxIdx_old)
272 t_iMaxIdx_old = t_iMaxIdx;
279 if(t_iIdx1 == t_iCurrentRow)
280 t_iCurrentRow = t_iIdx2;
282 t_iCurrentRow = t_iIdx1;
288 end_subcorr = clock();
290 float t_fSubcorrElapsedTime = (
static_cast<float>(end_subcorr-start_subcorr) /
static_cast<float>(CLOCKS_PER_SEC) ) * 1000.0f;
291 qDebug() <<
"Time Elapsed: " << t_fSubcorrElapsedTime <<
" ms";
294 qDebug() <<
"Iteration: " << r+1 <<
" of " << t_iMaxSearch
295 <<
"; Correlation: " << t_val_roh_k<<
"; Position (Idx+1): " << t_iIdx1+1 <<
" - " << t_iIdx2+1 <<
"\n\n";
301 MatrixX6T t_matProj_G_k_1(t_matOrthProj.rows(), t_matG_k_1.cols());
302 t_matProj_G_k_1 = t_matOrthProj * t_matG_k_1;
317 qDebug() <<
"Searching stopped, last correlation " << t_val_roh_k;
318 qDebug() <<
" is smaller then the given threshold " <<
m_dThreshold;
332 qDebug() <<
"##### Calculation of PWL RAP MUSIC completed ######";
336 float t_fElapsedTime = (
static_cast<float>(end-start) /
static_cast<float>(CLOCKS_PER_SEC) ) * 1000.0f;
337 qDebug() <<
"Total Time Elapsed: " << t_fElapsedTime <<
" ms";
342 return p_SourceEstimate;
350 return p_iRow*p_iNumPoints - (( (p_iRow-1)*p_iRow) / 2);
363 if (p_pVecElements.size() != p_iNumPoints)
364 p_pVecElements.resize(p_iNumPoints);
367 for(
int i = 0; i <= p_iRow; ++i)
372 int length = p_iNumPoints - p_iRow;
374 for(
int i = p_iRow; i < p_iRow+length; ++i)
376 p_pVecElements(i) = off+k;
InvPwlRapMusic algorithm class declaration.
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
Inverse source estimation (MNE, dSPM, sLORETA, dipole fitting).
Pair of correlated dipole indices and orientations found by the RAP MUSIC scanning step.
static int PowellOffset(int p_iRow, int p_iNumPoints)
virtual InvSourceEstimate calculateInverse(const FIFFLIB::FiffEvoked &p_fiffEvoked, bool pick_normal=false)
static void PowellIdxVec(int p_iRow, int p_iNumPoints, Eigen::VectorXi &p_pVecElements)
virtual const char * getName() const
virtual ~InvPwlRapMusic()
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)
virtual InvSourceEstimate calculateInverse(const FIFFLIB::FiffEvoked &p_fiffEvoked, bool pick_normal=false)
static void insertSource(int p_iDipoleIdx1, int p_iDipoleIdx2, const Vector6T &p_vec_phi_k_1, double p_valCor, QList< InvDipolePair< double > > &p_RapDipoles)
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, Eigen::Dynamic, 1 > VectorXT
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
std::vector< Pair > m_ppPairIdxCombinations
static void getGainMatrixPair(const MatrixXT &p_matGainMarix, MatrixX6T &p_matGainMarix_Pair, int p_iIdx1, int p_iIdx2)
int m_iNumLeadFieldCombinations
static double subcorr(MatrixX6T &p_matProj_G, const MatrixXT &p_pMatU_B)