Skip to content

pop_preclust: Match the preclustering dialog and dipole normalization - #1031

Open
arnodelorme wants to merge 134 commits into
agent/issue-967-clustfrom
agent/issue-971-preclust
Open

arnodelorme wants to merge 134 commits into
agent/issue-967-clustfrom
agent/issue-971-preclust

Conversation

@arnodelorme

@arnodelorme arnodelorme commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 Part of #971 and #875. Match the preclustering dialog and dipole normalization. Stacked on #982.

Live MATLAB, EEGPrep before and after

Function output distances

Vertical control offsets

Native measurements and validation

The largest vertical offset is 0.647 px. On the N400 study (10 recorded datasets, 77 components), the two true dialog submissions at dipole weights 1 and 2 give a worst full-matrix relative error of 1.71e-16. Both had returned 0.5013 relative error. The dipole coordinates now use the sample standard deviation of their radii once, as in EEGLAB. Nineteen clustering tests passed. Jamming source 30d7ec8 and EEGLAB 5e0be870.

Full inventory report for the project team. pop_preclust (p. 51). PDF · Editable Word.

arnodelorme and others added 25 commits November 29, 2026 14:56
Use the supergui layout, EEGLAB's blank geometry row, the full slope and
R-square labels, and blank checkbox strings from pop_rejtrend.m.

Fixes #910

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the fixed window sizes and margins with the supergui layout so the
continuous and epoched windows take their height from EEGLAB's geometry and
geomvert, and bold the first row as pop_interp.m does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Use EEGLAB's geometry {1 [2 0.7] [2 0.7]} and the supergui layout, so the
Remove components dialog is 171 px high on Linux, as in EEGLAB.

Fixes #936

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@claude

claude Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @arnodelorme's task in 1m 3s —— View job


Code review

  • Overall assessment: Looks good. I compared the dipole normalization in std_preclust.py with EEGLAB functions/studyfunc/std_preclust.m (develop). It matches: dipoles are divided by the sample standard deviation of their radii (std(sqrt(x.^2+y.^2+z.^2))), and EEGLAB then sets norm = 0, so the first-PC normalization is skipped. The two dialog strings also match pop_preclust.m L165 and L186: 'Build pre-clustering matrix for STUDY set: ' and '3 25'. Removing the local double_dip_help stylesheet is safe because qt.py (L995) already styles that button globally.
  • Highest-risk area: the numerics in std_preclust._reduce_measure and _normalize_first_pc.
  • Merge recommendation: Safe to merge once the AGENTS.md core-function MATLAB reference evidence is in place. The PR body reports N400 full-matrix parity at 1.71e-16, and Arno Delorme still has to approve the numerical change.

Blocking

None.

Important

None.

Nits

None.

Test gaps

None. test_preclustering_dipoles_scale_by_sample_radius_deviation_once uses hand-picked positions with weight=2, norm=1. That catches both bugs fixed here: the population standard deviation and the second first-PC normalization.

EEGLAB parity notes

  • A related problem outside this diff (it predates this PR): _normalize_first_pc (std_preclust.py L309-L313) still uses np.std(data[:, 0]), which is the population standard deviation (ddof=0). EEGLAB divides by std(clustdatatmp(:,1)), which is the sample standard deviation (ddof=1).
    • Effect: spec, erp, scalp, ersp and itc columns with norm=1 end up scaled by sqrt((n-1)/n) relative to EEGLAB. When those measures are mixed with dipoles, the relative weight between measures changes too.
    • Why the PR's check misses it: the N400 validation in the PR body only covers dipole-weight submissions.
    • Suggested follow-up: switch to np.std(data[:, 0], ddof=1), guarded for a single row, and add a mixed spec + dipoles parity check.
  • With a single component, or with identical radii, EEGLAB divides by 0 and gets Inf/NaN. EEGPrep falls back to a scale of 1. This also predates this PR, so I'm noting it here rather than flagging it.

I checked for correctness bugs, EEGLAB parity, data structure compatibility, tests for the changed behavior, and CLAUDE.md/AGENTS.md compliance. I did not run the tests: pytest was not allowed in this CI sandbox.

arnodelorme and others added 29 commits November 30, 2026 23:24
[GUI] Initialize the ERP and scalp-map plot dialog from the dataset
[GUI] Match the dataset ERP comparison and plot options
[GUI] Match the spline and 3-D head plot controls
# Conflicts:
#	tests/test_gui_geometry.py
pop_newset: Show the correct storage options for saved and modified datasets
pop_studydesign: Open legacy designs and place their independent variables in the reference panel
pop_chanplot: Match channel rows and measure selection to the study
[GUI] Match the pop_dipfit_headmodel dialog on configured MRI data
[GUI] Match the pop_leadfield dialog on configured MRI data
[GUI] Match the pop_dipfit_settings dialog on configured MRI data
[GUI] Match the pop_dipfit_nonlinear dialog on configured MRI data
Keep develop's PUBLIC_CALLS table and add the two pop_runica cases,
keep both documentation paragraphs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
[GUI] Run the ERP image MATLAB pixel gap check on Linux only
pop_precomp: Restore separate channel and component precomputation dialogs
pop_clustedit: Restore cluster editing actions and content-sized rows
Keep the reviewed one-pixel tolerance and develop's pop_runica test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l-edits

[GUI] Let edit boxes half a pixel apart in MATLAB land on neighbouring pixels
[GUI] Match ten dialog functions against recorded EEGLAB calls
@arnodelorme

arnodelorme commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

🤖 EEGLAB reference run and dipole comparison, as Arno asked on December 1, 2026 before any merge. Not merged.

State of the branch. Develop is merged in (ccc6a38f7, one conflict in tests/test_study_clustering.py, both tests kept). The base is still agent/issue-967-clust, which is already in develop, so the base must be changed to develop before a merge.

1. Direct comparison of the dipole normalization with EEGLAB (jamming, MATLAB R2025b, EEGLAB 3dd650cc7, study n400clustedit.study of eeglab_tests fec88f9, 10 datasets, 77 components, std_preclust(STUDY, ALLEEG, 1, {'dipoles' 'norm' 1 'weight' w}) on both sides, the whole 77 x 3 matrix compared).

Dipole weight This branch (ccc6a38f7), relative error Develop (068ad1743), relative error
1 1.6e-16 0.501
2 1.6e-16 0.501
10 1.9e-16 0.501

On develop the matrix is about half the size of EEGLAB's (ratio of norms 0.4987). With this branch it is equal to rounding. This repeats the measurement of the description at the final commit and with the current EEGLAB.

Why. std_preclust.m lines 390 to 394 divide the three coordinates by std of the radii (MATLAB's std, so N minus 1) and then set norm = 0, so dipoles skip the second normalization that the other measures get. Develop used the N version of the standard deviation and normalized twice. The two changed lines of std_preclust.py do exactly what the MATLAB lines do.

2. EEGLAB reference suite on this branch, run 46818277933 (gh workflow run eeglab-reference.yml --ref agent/issue-971-preclust), real MATLAB backend, EEGLAB d0963be9 and eeglab_tests fec88f9f (the pinned commits), 55 minutes with the queue.

Shard Passed Failed Skipped
heavy (includes test_reference_std_preclust, dipoles at weight 10) 3 0 0
study 341 0 27
core 3528 2 17
misc 688 0 8
stats 257 0 0
hybrid 143 0 4
parity 10 0 2

Total 4970 passed, 2 failed, 58 skipped. The 2 failures are not from this branch: both are tests/test_stream11_datasets.py::test_f42_merge_opens_newset_and_cancel_preserves_datasets ([False] and [True]), the merge menu test that fails on develop on every platform and in the two earlier reference runs (46603716218 and 46605236026). Its repair is #1062. The skipped tests are the same as in the earlier runs (the study shard gave 341 passed and 27 skipped there too). Most are tests the suite marks as heavy and skips unless --run-heavy-reference is given. The others need an AMICA binary, Windows paths or several gigabytes of memory.

Conclusion. The numbers support the change: it removes a factor of two error in the dipole part of the preclustering matrix. It is a numerical change of a processing function, so the merge stays Arno's decision.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant