Skip to content

Fix _segment normalization to match Koenig (SmoothLabels.m) reference#274

Open
Frederic-vW wants to merge 7 commits into
vferat:mainfrom
Frederic-vW:fix/koenig-normalization-segment
Open

Fix _segment normalization to match Koenig (SmoothLabels.m) reference#274
Frederic-vW wants to merge 7 commits into
vferat:mainfrom
Frederic-vW:fix/koenig-normalization-segment

Conversation

@Frederic-vW

Copy link
Copy Markdown
Contributor

Summary

  • Replace per-time-point data normalization and per-map std normalization in _segment with Koenig's row L2-norm (1/sqrt(Ne)) on maps only, matching NormDim(M,2)/sqrt(Ns) in the Matlab reference (SmoothLabels.m).
  • Fix a latent bug where in-place map normalization (states /= std) corrupted subsequent epoch predictions when _segment was called in a loop over epochs.
  • Verify that _smooth_segmentation is structurally equivalent to the Koenig reference once maps are correctly normalised.

Motivation

The previous std-normalization made lambda (the smoothing factor) incomparable to the original Pascual-Marqui/Koenig implementation. With row L2-norm normalization, lambda is directly transferable between implementations.

Test plan

  • Confirm existing tests pass
  • Verify smoothing output matches Koenig Matlab reference for same lambda value
  • Check multi-epoch prediction (the epochs-loop bug fix)

🤖 Generated with Claude Code

“Frederic-vW” and others added 2 commits June 18, 2026 20:50
Replace per-time-point data normalization and per-map std normalization
with Koenig's row L2-norm (1/sqrt(Ne)) on maps only. This makes lambda
directly comparable to the Matlab reference implementation and fixes a
latent bug where in-place map normalization corrupted subsequent epoch
predictions in a loop.

Also verified _smooth_segmentation is structurally equivalent to Koenig.

Modified by Frederic von Wegner with Claude assistance (claude-sonnet-4-6).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vferat

vferat commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Hello @Frederic-vW,

Thanks for spotting the issue and for the fix !

Do you know if the previous implementation give wrong microstate sequences ? Or the change is mainly to have similar lambda values across libraries ?

I had a quick look at the library and did not found any other implementation of functions using the std / Z score normalization, so we should be good to go with your current implementation

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.

2 participants