Repository navigation
Description
Question
On this sample, eegprep and EEGLAB return different dipole positions with standardBESA, while both report small residual variance (RV). Is this deviation acceptable for eegprep's standalone backend, or should the BESA autofit path implement the four-shell spherical forward model used by EEGLAB?
What was compared
- Data: EEGLAB
sample_data/eeglab_data_epochs_ica.set, components 1 through 3. - Settings:
pop_dipfit_settings(..., model='standardBESA'), followed bypop_multifit(..., threshold=100, dipplot='off'). - Same 30 selected electrodes, with EOG1 and EOG2 excluded; electrode radii 85 mm; empty coordinate transform on both sides.
- eegprep PR Show component properties and the remaining DIPFIT dialogs #591 verified at
7c5f0cf387bb57d91b36b8315df4cfa2ef530845; develop baselinec1e0942ee9af4791f7f308904a53a1fe183791b5. - EEGLAB
d0963be9d81acc5b66e84f8d3d7c89e3ce127cc4, FieldTrip pluginfieldtrip-20250523, MATLAB R2025b Update 7. - Official defaults were used for the fit grids: eegprep 11 x 11 x 6; EEGLAB 24 x 24 x 12. The prior isolation also compared identical grids and cross-fed starting positions; the forward-model difference remained.
Measured results
Coordinates and distances are in mm, in the spherical BESA frame used by the fitter. RV is a fraction. Distances are the full 3-D Euclidean separation between matched components, computed from full-precision official-multifit positions.
| Component | EEGLAB position (X, Y, Z) | eegprep position (X, Y, Z) | 3-D distance | EEGLAB RV | eegprep RV |
|---|---|---|---|---|---|
| 1 | 42.6358, -0.7557, -6.2491 | 22.7747, -0.2594, -13.4123 | 21.12 | 0.026193 | 0.020709 |
| 2 | -13.3446, -44.4421, 2.0858 | -5.2842, -22.3277, 1.1385 | 23.56 | 0.043325 | 0.043852 |
| 3 | 68.6342, 1.3846, -38.0883 | 28.6281, 0.6811, -23.9445 | 42.44 | 0.003737 | 0.003240 |
Overlay of both fits
Orange = EEGLAB; blue = eegprep. Each row is one component, with top, back, and side views from EEGLAB dipplot. Both fitted dipoles are drawn on the same MNI MRI, with the same camera and axes. dipplot maps spherical BESA coordinates into this MRI with the standard sph2spm transform. The distance labels are the 3-D separations in the original spherical frame.
Side-by-side dipplot views
Each figure shows one component with matching top, back, and side views. The upper row is EEGLAB dipplot of the EEGLAB fit. The lower row is the same dipplot view of the eegprep fit, so the MRI, camera, and axes match.
Why positions differ
A forward model predicts the electrode pattern produced by a dipole at a given position. Changing that prediction changes the position that best fits a component's scalp map.
- eegprep:
src/eegprep/plugins/dipfit/_fitting.py,_unit_moment_leadfield, uses(electrode - source) / distance^3followed by average referencing. The current fitter uses the outer head radius for electrode projection and the search boundary. The stored shell conductivities do not enter this leadfield. - EEGLAB:
plugins/dipfit/pop_multifit.manddipfit_nonlinear.mcall FieldTripft_dipolefitting. That path loadsplugins/dipfit/standard_BESA/standard_BESA.matand evaluates the four-shell conductor: radii[71, 72, 79, 85]mm, conductivities[0.33, 1, 0.0042, 0.33], origin[0, 0, 0].
These are different forward operators. Similar RV under each operator does not establish equivalent localization. The observed distance alone also does not establish which result is physiologically correct.
Relationship to #591
This behavior is pre-existing. The verification at 7c5f0cf3 found identical positions, moments and RV on develop c1e0942e. The earlier PR head 3f063136 also has multifit records identical to develop. #591's settings changes preserve fitted dipoles and remove a stale stored volume when the model file changes; the fitter is unchanged.
Options for a decision
- Accept and document the deviation. Describe the standalone forward model and the localization difference when users select
standardBESA. Add a regression test documenting the intended behavior, with any parity or tolerance policy approved by Suraj or Arno. - Implement four-shell spherical fitting. Load and validate the BESA shell geometry and conductivities, implement and validate the corresponding EEG leadfield, then compare leadfields and RV against FieldTrip. Review the reference, coordinate convention, interior-source constraints, actual multifit grid and optimization behavior, then add sample-data position regression coverage under an approved policy.
Which behavior should eegprep promise for standardBESA, and how should we assess whether this localization difference matters?




Activity
claude commentedon Nov 11, 2026
🤖 Plan:
plugins/dipfitResearch
The eegprep fitter uses the leadfield of a dipole in an infinite homogeneous medium,
delta / |delta|^3with average referencing. It ignores the sphere boundary as well as the shell conductivities.dipfit["vol"]is read only formax(r), which sets the electrode projection radius, the grid extent and the search bound. FieldTrip evaluates a four-shell concentric-sphere leadfield, so the two backends minimize different objectives. Similar RV under different operators is expected; it does not mean the localizations agree. The infinite-medium kernel also has no skull attenuation. That is consistent with eegprep pulling sources toward the center (all 3 eegprep fits sit 20 to 40 mm closer to the origin).Relevant code
_fitting.py#L369-L373: infinite-medium unit-moment leadfield_fitting.py#L419-L424: onlymax(vol.r)is used;vol.condis ignored_fitting.py#L343-L346: search bound is 0.995 × the outer radius, not the brain shell_fitting.py#L66-L68: default grid is 11×11×6; EEGLAB uses 24×24×12Proposed Fix (for human decision)
I recommend option 2, scoped narrowly. In my view, option 1 would document an incorrect model: the current kernel is not a spherical head model at all.
eeg_leadfield4port (FieldTripforward/private/eeg_leadfield4.m+eeg_leadfield4_prepare.m, the four-sphere series solution) toplugins/dipfit/private/. Makeleadfield_matrix/_unit_moment_leadfielduse it whenvolhas 4 radii and 4 conductivities. Keep the current kernel only for a single-spherevol, where it should also be replaced by the 1-shell analytic solution (eeg_leadfield1).ft_compute_leadfieldon the 30-electrode BESA montage at a few interior positions, using an@eeglab_test/MATLAB parity test. This is the cheapest test that pins the operator.pop_multifitcomparison. The expected residual differences come from the grid (11×11×6 vs 24×24×12) and from the optimizer (scipy vsfminsearch). Decide whether to match the EEGLAB grid default.Estimated size: about 150 to 250 lines plus a parity test. This is a core-function change, so it needs the MATLAB reference run and human approval.
Open questions
ft_inside_headmodeldoes for concentric spheres, or keep the outer radius? EEGLAB's component 3 lies at about 78 mm, so check what FieldTrip actually enforces before changing it.standardBEM/MNI models be scoped out explicitly, with a clear error until a BEM leadfield exists?arnodelorme commentedon Nov 11, 2026
Arno's reply to Suraj Ranganath about "eegprep questions: DIPFIT, electrode layouts and GUI defaults" is tracked in adelorme-assistant/tasks_arno#56 (https://github.com/adelorme-assistant/tasks_arno/issues/56).
— orchestrator
arnodelorme commentedon Nov 12, 2026
Mail update, November 12, 2026. Suraj Ranganath emailed five questions on November 11, 2026 ("eegprep questions: DIPFIT, electrode layouts and GUI defaults"), and Arno answered the same day at 12:37 from his UCSD address (his reply). His decisions:
The next steps are Suraj's; nothing waits on Arno here.
— orchestrator