v2.0.0
Loading...
Searching...
No Matches
mne_inverse_operator.h
Go to the documentation of this file.
1//=============================================================================================================
27
28#ifndef MNE_INVERSE_OPERATOR_H
29#define MNE_INVERSE_OPERATOR_H
30
31//=============================================================================================================
32// INCLUDES
33//=============================================================================================================
34
35#include "mne_global.h"
36#include "mne_source_spaces.h"
38
39#include <fiff/fiff_types.h>
41#include <fiff/fiff_proj.h>
42#include <fiff/fiff_cov.h>
43#include <fiff/fiff_info.h>
44
45//=============================================================================================================
46// EIGEN INCLUDES
47//=============================================================================================================
48
49#include <Eigen/Core>
50
51//=============================================================================================================
52// QT INCLUDES
53//=============================================================================================================
54
55#include <QList>
56
57//=============================================================================================================
58// FORWARD DECLARATIONS
59//=============================================================================================================
60
61namespace FSLIB
62{
63class FsLabel;
64}
65
66//=============================================================================================================
67// DEFINE NAMESPACE MNELIB
68//=============================================================================================================
69
70namespace MNELIB
71{
72
73//=========================================================================================================
78{
79 Eigen::VectorXi roiIdx;
80 Eigen::MatrixXd ctrs;
81 Eigen::VectorXd sumd;
82 Eigen::MatrixXd D;
83 qint32 iLabelIdxOut;
84};
85
86//=========================================================================================================
91{
92 Eigen::MatrixXd matRoiMT;
93 Eigen::MatrixXd matRoiMTOrig;
94 qint32 nClusters;
95 Eigen::VectorXi idcs;
96 qint32 iLabelIdxIn;
97 QString sDistMeasure;
98
104 {
105 const QString distMeasure = sDistMeasure.isEmpty()
106 ? QStringLiteral("cityblock")
107 : sDistMeasure;
108
109 RegionMTOut out;
110 UTILSLIB::KMeans kMeans(distMeasure, QStringLiteral("sample"), 5);
112 out.roiIdx, out.ctrs, out.sumd, out.D);
114 return out;
115 }
116};
117
118//=============================================================================================================
130{
131public:
132 typedef QSharedPointer<MNEInverseOperator> SPtr;
133 typedef QSharedPointer<const MNEInverseOperator> ConstSPtr;
134
135 //=========================================================================================================
140
141 //=========================================================================================================
147 explicit MNEInverseOperator(QIODevice& p_IODevice);
148
149 //=========================================================================================================
162 const MNEForwardSolution& forward,
163 const FIFFLIB::FiffCov& noiseCov,
164 float loose = 0.2f,
165 float depth = 0.8f,
166 bool fixed = false,
167 bool limit_depth_chs = true);
168
169 //=========================================================================================================
176
177 //=========================================================================================================
189
190 //=========================================================================================================
195
196 //=========================================================================================================
213 bool assemble_kernel(const FSLIB::FsLabel& label,
214 const QString& method,
215 bool pick_normal,
216 Eigen::MatrixXd& K,
217 Eigen::SparseMatrix<double>& noise_norm,
218 QList<Eigen::VectorXi>& vertno);
219
220 //=========================================================================================================
228 bool check_ch_names(const FIFFLIB::FiffInfo& info) const;
229
230 //=========================================================================================================
244 Eigen::MatrixXd cluster_kernel(const FSLIB::FsAnnotationSet& annotationSet,
245 qint32 clusterSize,
246 Eigen::MatrixXd& D,
247 const QString& method = QStringLiteral("cityblock")) const;
248
249 //=========================================================================================================
254 inline Eigen::MatrixXd& getKernel();
255
256 //=========================================================================================================
261 inline Eigen::MatrixXd getKernel() const;
262
263 //=========================================================================================================
268 inline bool isFixedOrient() const;
269
270 //=========================================================================================================
288 MNEForwardSolution forward,
289 const FIFFLIB::FiffCov& noiseCov,
290 float loose = 0.2f,
291 float depth = 0.8f,
292 bool fixed = false,
293 bool limit_depth_chs = true);
294
295 //=========================================================================================================
311 float lambda2,
312 bool dSPM,
313 bool sLORETA = false) const;
314
315 //=========================================================================================================
324 static bool read_inverse_operator(QIODevice& p_IODevice, MNEInverseOperator& inv);
325
326 //=========================================================================================================
334 bool write(QIODevice& p_IODevice);
335
336 //=========================================================================================================
342 void writeToStream(FIFFLIB::FiffStream* p_pStream);
343
344 //=========================================================================================================
353 friend std::ostream& operator<<(std::ostream& out, const MNEInverseOperator& inv);
354
355public:
363 Eigen::MatrixXf source_nn;
364 Eigen::VectorXd sing;
376 QList<FIFFLIB::FiffProj> projs;
377 Eigen::MatrixXd proj;
378 Eigen::MatrixXd whitener;
379 Eigen::VectorXd reginv;
380 Eigen::SparseMatrix<double> noisenorm;
381
382private:
383 Eigen::MatrixXd m_K;
384};
385
386//=============================================================================================================
387// INLINE DEFINITIONS
388//=============================================================================================================
389
390inline Eigen::MatrixXd& MNEInverseOperator::getKernel()
391{
392 return m_K;
393}
394
395//=============================================================================================================
396
397inline Eigen::MatrixXd MNEInverseOperator::getKernel() const
398{
399 return m_K;
400}
401
402//=============================================================================================================
403
405{
406 return this->source_ori == FIFFV_MNE_FIXED_ORI;
407}
408
409//=============================================================================================================
410
411inline std::ostream& operator<<(std::ostream& out, const MNEInverseOperator& inv)
412{
413 out << "#### MNE Inverse Operator ####\n"
414 << " methods: " << inv.methods << '\n'
415 << " source_ori: " << inv.source_ori << '\n'
416 << " nsource: " << inv.nsource << '\n'
417 << " nchan: " << inv.nchan << '\n'
418 << " coord_frame: " << inv.coord_frame << '\n'
419 << " eigen_leads: " << *inv.eigen_leads << '\n'
420 << " eigen_fields:" << *inv.eigen_fields << '\n';
421 return out;
422}
423} // NAMESPACE
424
425#ifndef metatype_mneinverseoperatorsptr
426#define metatype_mneinverseoperatorsptr
427Q_DECLARE_METATYPE(QSharedPointer<MNELIB::MNEInverseOperator>);
428#endif
429
430#ifndef metatype_mneinverseoperators
431#define metatype_mneinverseoperators
433#endif
434
435#endif // MNE_INVERSE_OPERATOR_H
#define FIFFV_MNE_FIXED_ORI
Full FIFF measurement metadata: everything from FIFFB_MEAS / FIFFB_MEAS_INFO needed to interpret a re...
Matrix paired with row and column name lists, the on-disk form of FIFFB_PROJ_ITEM / FIFFB_MNE_NAMED_M...
SSP projection item: a named projection vector set with active/desired flags, parsed from FIFFB_PROJ_...
Noise / data covariance matrix as stored under FIFFB_MNE_COV, with channel names, kind,...
Primitive scalar typedefs and forward-compatible aliases backing the FIFF type system.
Q_DECLARE_METATYPE(QSharedPointer< MNELIB::MNEInverseOperator >)
MNELIB shared-library export/import macros and library build metadata.
#define MNESHARED_EXPORT
Definition mne_global.h:40
Forward solution (gain matrix mapping source dipoles to sensor measurements).
Container pairing the left and right cortical source spaces of a subject.
Core MNE data structures (source spaces, source estimates, hemispheres).
std::ostream & operator<<(std::ostream &out, const MNELIB::MNEForwardSolution &p_MNEForwardSolution)
FreeSurfer surface, annotation and parcellation I/O for mne-cpp.
qint32 fiff_int_t
Definition fiff_types.h:86
Labelled 4x4 FIFF affine: source frame, destination frame, rotation, translation and cached inverse.
FIFF noise / data covariance: matrix, channel names, kind, applied projectors, bads,...
Definition fiff_cov.h:82
QSharedDataPointer< FiffCov > SDPtr
Definition fiff_cov.h:88
Full FIFF measurement info: per-channel descriptors, sampling and filter setup, projectors,...
Definition fiff_info.h:90
Stripped FIFF measurement info: channel list, sampling rate, device→head transform and bad-channel li...
QSharedDataPointer< FiffNamedMatrix > SDPtr
FIFF tag-stream reader/writer: wraps a QIODevice and exposes typed read_* / write_* methods for every...
Container holding the lh and/or rh FsAnnotation for one parcellation atlas.
A FreeSurfer/MNE surface label: per-vertex indices, Tk-RAS positions and scalar values for one hemisp...
Definition fs_label.h:81
Lloyd-style K-means clustering with configurable metric, seeding and replicates.
Definition kmeans.h:112
bool calculate(const Eigen::MatrixXd &X, qint32 kClusters, Eigen::VectorXi &idx, Eigen::MatrixXd &C, Eigen::VectorXd &sumD, Eigen::MatrixXd &D)
In-memory representation of an -fwd.fif forward solution.
Output of a multi-threaded KMeans clustering step for a single cortical region.
Input parameters for multi-threaded KMeans clustering on a single cortical region.
Eigen::MatrixXd matRoiMTOrig
Eigen::MatrixXd matRoiMT
RegionMTOut cluster() const
Run KMeans clustering on this region.
MNE-style inverse operator.
MNEInverseOperator()
Constructs an empty inverse operator with invalid sentinel values.
FIFFLIB::FiffCov::SDPtr fmri_prior
QSharedPointer< const MNEInverseOperator > ConstSPtr
QSharedPointer< MNEInverseOperator > SPtr
Eigen::MatrixXd cluster_kernel(const FSLIB::FsAnnotationSet &annotationSet, qint32 clusterSize, Eigen::MatrixXd &D, const QString &method=QStringLiteral("cityblock")) const
Cluster the inverse kernel by cortical parcellation.
QList< FIFFLIB::FiffProj > projs
Eigen::SparseMatrix< double > noisenorm
FIFFLIB::FiffCov::SDPtr orient_prior
static MNEInverseOperator make_inverse_operator(const FIFFLIB::FiffInfo &info, MNEForwardSolution forward, const FIFFLIB::FiffCov &noiseCov, float loose=0.2f, float depth=0.8f, bool fixed=false, bool limit_depth_chs=true)
Assemble an inverse operator from a forward solution and noise covariance.
MNEInverseOperator & operator=(const MNEInverseOperator &other)=default
friend std::ostream & operator<<(std::ostream &out, const MNEInverseOperator &inv)
Stream-output operator for diagnostic printing.
FIFFLIB::FiffNamedMatrix::SDPtr eigen_leads
bool check_ch_names(const FIFFLIB::FiffInfo &info) const
Verify that inverse-operator channels are present in the measurement info.
FIFFLIB::FiffCoordTrans mri_head_t
MNEInverseOperator prepare_inverse_operator(qint32 nave, float lambda2, bool dSPM, bool sLORETA=false) const
Prepare the inverse operator for source estimation.
FIFFLIB::FiffCov::SDPtr depth_prior
Eigen::MatrixXd & getKernel()
Access the most recently assembled kernel (mutable).
bool assemble_kernel(const FSLIB::FsLabel &label, const QString &method, bool pick_normal, Eigen::MatrixXd &K, Eigen::SparseMatrix< double > &noise_norm, QList< Eigen::VectorXi > &vertno)
Assemble the inverse kernel matrix.
void writeToStream(FIFFLIB::FiffStream *p_pStream)
Write the inverse operator into an already-open FIFF stream.
~MNEInverseOperator()
Destructor.
FIFFLIB::FiffCov::SDPtr noise_cov
FIFFLIB::FiffCov::SDPtr source_cov
static bool read_inverse_operator(QIODevice &p_IODevice, MNEInverseOperator &inv)
Read an inverse operator from a FIFF file.
bool isFixedOrient() const
Check whether the inverse operator uses fixed source orientations.
bool write(QIODevice &p_IODevice)
Write the inverse operator to a FIFF file.
FIFFLIB::FiffNamedMatrix::SDPtr eigen_fields
List of MNESourceSpace objects forming a subject source space.