55 init(p_pFwd, p_bSparsed, p_iN, p_dThr);
68 return "Powell RAP MUSIC";
93 throw std::logic_error(
"RAP MUSIC was not initialized");
98 throw std::invalid_argument(
"Lead field channels do not match number of measurement channels");
114 int t_r =
calcPhi_s( p_matMeasurement, t_pMatPhi_s);
116 int t_iMaxSearch =
m_iN < t_r ?
m_iN : t_r;
119 qDebug() <<
"Warning: Rank " << t_r <<
" of the measurement data is smaller than the " <<
m_iN;
120 qDebug() <<
" sources to find.";
121 qDebug() <<
" Searching now for " << t_iMaxSearch <<
" correlated sources.";
128 t_matOrthProj.setIdentity();
132 t_matA_k_1.setZero();
148 p_RapDipoles.clear();
150 qDebug() <<
"##### Calculation of PWL RAP MUSIC started ######\n\n";
152 MatrixXT t_matProj_Phi_s(t_matOrthProj.rows(), t_pMatPhi_s->cols());
156 for (
int r = 0; r < t_iMaxSearch; ++r) {
157 t_matProj_Phi_s = t_matOrthProj * (*t_pMatPhi_s);
164 Eigen::JacobiSVD<MatrixXT> t_svdProj_Phi_S(t_matProj_Phi_s, Eigen::ComputeThinU);
166 useFullRank(t_svdProj_Phi_S.matrixU(), t_svdProj_Phi_S.singularValues().asDiagonal(), t_matU_B);
174 clock_t start_subcorr, end_subcorr;
175 start_subcorr = clock();
179 double t_val_roh_k = 0.0;
182 int t_iCurrentRow = 2;
187 int t_iMaxIdx_old = -1;
197 while (t_iMaxFound == 0) {
200#pragma omp parallel num_threads(m_iMaxNumThreads)
206 for (
int i = 0; i < t_iNumVecElements; i++) {
207 int k = t_pVecIdxElements(i);
210 MatrixX6T t_matProj_G(t_matProj_LeadField.rows(), 6);
239 VectorXT::Index t_iMaxIdx;
241 t_val_roh_k = t_vecRoh.maxCoeff(&t_iMaxIdx);
243 if (
static_cast<int>(t_iMaxIdx) == t_iMaxIdx_old) {
247 t_iMaxIdx_old = t_iMaxIdx;
254 if (t_iIdx1 == t_iCurrentRow)
255 t_iCurrentRow = t_iIdx2;
257 t_iCurrentRow = t_iIdx1;
263 end_subcorr = clock();
265 float t_fSubcorrElapsedTime = (
static_cast<float>(end_subcorr - start_subcorr) /
static_cast<float>(CLOCKS_PER_SEC)) * 1000.0f;
266 qDebug() <<
"Time Elapsed: " << t_fSubcorrElapsedTime <<
" ms";
269 qDebug() <<
"Iteration: " << r + 1 <<
" of " << t_iMaxSearch
270 <<
"; Correlation: " << t_val_roh_k <<
"; Position (Idx+1): " << t_iIdx1 + 1 <<
" - " << t_iIdx2 + 1 <<
"\n\n";
276 MatrixX6T t_matProj_G_k_1(t_matOrthProj.rows(), t_matG_k_1.cols());
277 t_matProj_G_k_1 = t_matOrthProj * t_matG_k_1;
291 qDebug() <<
"Searching stopped, last correlation " << t_val_roh_k;
292 qDebug() <<
" is smaller then the given threshold " <<
m_dThreshold;
306 qDebug() <<
"##### Calculation of PWL RAP MUSIC completed ######";
310 float t_fElapsedTime = (
static_cast<float>(end - start) /
static_cast<float>(CLOCKS_PER_SEC)) * 1000.0f;
311 qDebug() <<
"Total Time Elapsed: " << t_fElapsedTime <<
" ms";
316 return p_SourceEstimate;
323 return p_iRow * p_iNumPoints - (((p_iRow - 1) * p_iRow) / 2);
335 if (p_pVecElements.size() != p_iNumPoints)
336 p_pVecElements.resize(p_iNumPoints);
339 for (
int i = 0; i <= p_iRow; ++i)
344 int length = p_iNumPoints - p_iRow;
346 for (
int i = p_iRow; i < p_iRow + length; ++i)
348 p_pVecElements(i) = off + k;
Powell-accelerated RAP-MUSIC variant — replaces the exhaustive pair scan with a Powell line-search re...
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O, in-memory data structures and high-level readers/writers.
Inverse source estimation (MNE, dSPM, sLORETA, dipole fitting).
Single averaged evoked response: time axis, data, baseline, channel info and averaging metadata.
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.
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)
In-memory representation of an -fwd.fif forward solution.