Skip to content

DIPFIT standardBESA: eegprep and EEGLAB dipole positions differ by 21 to 42 mm #600

Closed

Description

@suraj-ranganath

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 by pop_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 baseline c1e0942ee9af4791f7f308904a53a1fe183791b5.
  • EEGLAB d0963be9d81acc5b66e84f8d3d7c89e3ce127cc4, FieldTrip plugin fieldtrip-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

Matched dipoles in three orthogonal dipplot views

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.

Component 1: EEGLAB and eegprep

Component 2: EEGLAB and eegprep

Component 3: EEGLAB and eegprep

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^3 followed 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.m and dipfit_nonlinear.m call FieldTrip ft_dipolefitting. That path loads plugins/dipfit/standard_BESA/standard_BESA.mat and 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

  1. 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.
  2. 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

  1. claude commented on Nov 11, 2026

    @claude
    Contributor

    🤖 Plan:

    Research

    The eegprep fitter uses the leadfield of a dipole in an infinite homogeneous medium, delta / |delta|^3 with average referencing. It ignores the sphere boundary as well as the shell conductivities. dipfit["vol"] is read only for max(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

    Proposed 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.

    1. Add a private eeg_leadfield4 port (FieldTrip forward/private/eeg_leadfield4.m + eeg_leadfield4_prepare.m, the four-sphere series solution) to plugins/dipfit/private/. Make leadfield_matrix/_unit_moment_leadfield use it when vol has 4 radii and 4 conductivities. Keep the current kernel only for a single-sphere vol, where it should also be replaced by the 1-shell analytic solution (eeg_leadfield1).
    2. Validate each kernel in isolation before refitting. Compare leadfields against FieldTrip ft_compute_leadfield on 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.
    3. Then rerun the issue's 3-component pop_multifit comparison. The expected residual differences come from the grid (11×11×6 vs 24×24×12) and from the optimizer (scipy vs fminsearch). 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

    • Should the inside-head constraint use the brain shell (71 mm), as FieldTrip's ft_inside_headmodel does 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.
    • Should the default grid match EEGLAB (24×24×12), at roughly 20× the grid-search cost?
    • What position tolerance counts as parity after the kernel matches (for example, < 5 mm on these 3 components)? Suraj or Arno should set it.
    • Should standardBEM/MNI models be scoped out explicitly, with a clear error until a BEM leadfield exists?
  2. arnodelorme commented on Nov 11, 2026

    @arnodelorme
    Collaborator

    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

  3. arnodelorme commented on Nov 12, 2026

    @arnodelorme
    Collaborator

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions