Skip to main content

InvDipoleFit

Namespace: INVLIB  ·  Library: Inverse Library

Python equivalent

mne.fit_dipole in MNE-Python.

#include <inv/inv_dipole_fit.h>

class INVLIB::InvDipoleFit

High-level driver for sequential dipole fitting.

InvDipoleFit orchestrates the complete dipole-fit pipeline: it sets up the forward model via InvDipoleFitData, computes initial guess grids via InvGuessData, reads averaged or raw data, and fits an equivalent current dipole (ECD) at each requested time point.

Refactored from fit_dipoles.c / dipole_fit_setup.c (MNE-C).

src/examples/ex_inv_dipole_fit/main.cpp
InvDipoleFitSettings settings; // the options of the MNE-C mne_dipole_fit tool
settings.measname = tmp.filePath("synthetic-ave.fif");
settings.include_meg = true;
settings.include_eeg = false;
settings.guess_mindist = 0.0f;
settings.tmin = 0.0f;
settings.dipname = tmp.filePath("fit.dat"); // MNE-C .dat dipole file
settings.checkIntegrity();
InvDipoleFit fit(&settings);
InvEcdSet dipoles = fit.calculateFit();
const bool saved = dipoles.save_dipoles_dip(tmp.filePath("fit.dip")); // readable by mne.read_dipole
const InvEcdSet reread = InvEcdSet::read_dipoles_dip(tmp.filePath("fit.dip"));

Public Methods​

InvDipoleFit(p_settings)​

Constructs Dipole Fit algorithm.

Parameters:


~InvDipoleFit()​

Destructs the Dipole Fit.


calculateFit()​

Execute the dipole fit using the stored settings.

Returns:


Static Methods​

fit_dipoles(dataname, data, fit, guess, tmin, tmax, tstep, integ, verbose, p_set)​

Fit a single dipole to each time point of averaged data.

Refactored: fit_dipoles (fit_dipoles.c)

Parameters:

  • dataname : const QString & Data file name.

  • data : *MNEMeasData ** The measured data.

  • fit : *InvDipoleFitData ** Precomputed fitting data.

  • guess : *InvGuessData ** The initial guesses.

  • tmin : float Fit start time (s).

  • tmax : float Fit end time (s).

  • tstep : float Time step to use (s).

  • integ : float Integration time (s).

  • verbose : int Verbose output.

  • p_set : InvEcdSet & The fitted dipole set.

Returns:

  • bool — true when successful.

fit_dipoles_raw(dataname, raw, sel, fit, guess, tmin, tmax, tstep, integ, verbose, p_set)​

Fit a single dipole to each time point of raw data.

Reads data in overlapping segments of SEG_LEN seconds and extracts values at each requested time point.

Refactored: fit_dipoles_raw (fit_dipoles.c)

Parameters:

  • dataname : const QString & Data file name.

  • raw : *MNERawData ** The raw data description.

  • sel : MNELIB::mneChSelection Channel selection to use.

  • fit : *InvDipoleFitData ** Precomputed fitting data.

  • guess : *InvGuessData ** The initial guesses.

  • tmin : float Fit start time (s).

  • tmax : float Fit end time (s).

  • tstep : float Time step to use (s).

  • integ : float Integration time (s).

  • verbose : int Verbose output.

  • p_set : InvEcdSet & The fitted dipole set.

Returns:

  • bool — true when successful.

fit_dipoles_raw(dataname, raw, sel, fit, guess, tmin, tmax, tstep, integ, verbose)​

Fit dipoles to raw data (convenience overload without output set).

Refactored: fit_dipoles_raw (fit_dipoles.c)

Parameters:

  • dataname : const QString & Data file name.

  • raw : *MNERawData ** The raw data description.

  • sel : MNELIB::mneChSelection Channel selection to use.

  • fit : *InvDipoleFitData ** Precomputed fitting data.

  • guess : *InvGuessData ** The initial guesses.

  • tmin : float Fit start time (s).

  • tmax : float Fit end time (s).

  • tstep : float Time step to use (s).

  • integ : float Integration time (s).

  • verbose : int Verbose output.

Returns:

  • bool — true when successful.

Example​

Used in examples​

ex_inv_dipole_fit​

Inverse library: equivalent current dipole fitting in a sphere model.

src/examples/ex_inv_dipole_fit/main.cpp, line 136
settings.tmin = 0.0f;
settings.dipname = tmp.filePath("fit.dat"); // MNE-C .dat dipole file
settings.checkIntegrity();
InvDipoleFit fit(&settings);
InvEcdSet dipoles = fit.calculateFit();
const bool saved = dipoles.save_dipoles_dip(tmp.filePath("fit.dip")); // readable by mne.read_dipole
const InvEcdSet reread = InvEcdSet::read_dipoles_dip(tmp.filePath("fit.dip"));
const Vector3d posMm = dipoles.size() > 0 ? Vector3d(1e3 * dipoles[0].rd.cast<double>()) : Vector3d::Zero();
ok &= expect(saved && dipoles.size() == 1 && dipoles[0].valid && (posMm - mnePosMm).norm() < 1.0 && std::abs(100.0 * dipoles[0].good - 99.99996959113513) < 0.01 && dipoles[0].nfree == 297 && reread.size() == 1 && (reread[0].rd - dipoles[0].rd).norm() < 1e-4f,
"InvDipoleFitSettings/InvDipoleFit/InvEcdSet: the pipeline fit matches mne.fit_dipole and round-trips through .dip");

Authors of this file​