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//=============================================================================================================
132{
133public:
134 typedef QSharedPointer<MNEInverseOperator> SPtr;
135 typedef QSharedPointer<const MNEInverseOperator> ConstSPtr;
136
137 //=========================================================================================================
142
143 //=========================================================================================================
149 explicit MNEInverseOperator(QIODevice& p_IODevice);
150
151 //=========================================================================================================
164 const MNEForwardSolution& forward,
165 const FIFFLIB::FiffCov& noiseCov,
166 float loose = 0.2f,
167 float depth = 0.8f,
168 bool fixed = false,
169 bool limit_depth_chs = true);
170
171 //=========================================================================================================
178
179 //=========================================================================================================
191
192 //=========================================================================================================
197
198 //=========================================================================================================
215 bool assemble_kernel(const FSLIB::FsLabel& label,
216 const QString& method,
217 bool pick_normal,
218 Eigen::MatrixXd& K,
219 Eigen::SparseMatrix<double>& noise_norm,
220 QList<Eigen::VectorXi>& vertno);
221
222 //=========================================================================================================
230 bool check_ch_names(const FIFFLIB::FiffInfo& info) const;
231
232 //=========================================================================================================
246 Eigen::MatrixXd cluster_kernel(const FSLIB::FsAnnotationSet& annotationSet,
247 qint32 clusterSize,
248 Eigen::MatrixXd& D,
249 const QString& method = QStringLiteral("cityblock")) const;
250
251 //=========================================================================================================
256 inline Eigen::MatrixXd& getKernel();
257
258 //=========================================================================================================
263 inline Eigen::MatrixXd getKernel() const;
264
265 //=========================================================================================================
270 inline bool isFixedOrient() const;
271
272 //=========================================================================================================
290 MNEForwardSolution forward,
291 const FIFFLIB::FiffCov& noiseCov,
292 float loose = 0.2f,
293 float depth = 0.8f,
294 bool fixed = false,
295 bool limit_depth_chs = true);
296
297 //=========================================================================================================
313 float lambda2,
314 bool dSPM,
315 bool sLORETA = false) const;
316
317 //=========================================================================================================
326 static bool read_inverse_operator(QIODevice& p_IODevice, MNEInverseOperator& inv);
327
328 //=========================================================================================================
336 bool write(QIODevice& p_IODevice);
337
338 //=========================================================================================================
344 void writeToStream(FIFFLIB::FiffStream* p_pStream);
345
346 //=========================================================================================================
355 friend std::ostream& operator<<(std::ostream& out, const MNEInverseOperator& inv);
356
357public:
365 Eigen::MatrixXf source_nn;
366 Eigen::VectorXd sing;
378 QList<FIFFLIB::FiffProj> projs;
379 Eigen::MatrixXd proj;
380 Eigen::MatrixXd whitener;
381 Eigen::VectorXd reginv;
382 Eigen::SparseMatrix<double> noisenorm;
383
384private:
385 Eigen::MatrixXd m_K;
386};
387
388//=============================================================================================================
389// INLINE DEFINITIONS
390//=============================================================================================================
391
392inline Eigen::MatrixXd& MNEInverseOperator::getKernel()
393{
394 return m_K;
395}
396
397//=============================================================================================================
398
399inline Eigen::MatrixXd MNEInverseOperator::getKernel() const
400{
401 return m_K;
402}
403
404//=============================================================================================================
405
407{
408 return this->source_ori == FIFFV_MNE_FIXED_ORI;
409}
410
411//=============================================================================================================
412
413inline std::ostream& operator<<(std::ostream& out, const MNEInverseOperator& inv)
414{
415 out << "#### MNE Inverse Operator ####\n"
416 << " methods: " << inv.methods << '\n'
417 << " source_ori: " << inv.source_ori << '\n'
418 << " nsource: " << inv.nsource << '\n'
419 << " nchan: " << inv.nchan << '\n'
420 << " coord_frame: " << inv.coord_frame << '\n'
421 << " eigen_leads: " << *inv.eigen_leads << '\n'
422 << " eigen_fields:" << *inv.eigen_fields << '\n';
423 return out;
424}
425} // NAMESPACE
426
427#ifndef metatype_mneinverseoperatorsptr
428#define metatype_mneinverseoperatorsptr
429Q_DECLARE_METATYPE(QSharedPointer<MNELIB::MNEInverseOperator>);
430#endif
431
432#ifndef metatype_mneinverseoperators
433#define metatype_mneinverseoperators
435#endif
436
437#endif // MNE_INVERSE_OPERATOR_H
constexpr auto 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.