Skip to content

Comments

Fix computational issues across analyses, stats, prep and utils#252

Open
deep-introspection wants to merge 2 commits intomasterfrom
cleaning
Open

Fix computational issues across analyses, stats, prep and utils#252
deep-introspection wants to merge 2 commits intomasterfrom
cleaning

Conversation

@deep-introspection
Copy link
Contributor

Summary

Systematic audit and correction of computational issues across the codebase.

WTC mode in xwt() (analyses.py)

  • Wavelet coherence was computed without smoothing, making pointwise |W1×W2*|/(|W1|×|W2|) trivially 1.0
  • A min-max normalization was rescaling numerical noise to [0,1]
  • Now uses proper Gaussian time-smoothing (Grinsted et al., 2004): WTC = |S(W1×W2*)|² / (S(|W1|²) × S(|W2|²))

n:m PLV in compute_nmPLV() (analyses.py)

  • Phase adjustment used scalar multiplication (k * exp(iφ)) which changes magnitude, not phase
  • Now uses exponentiation (exp(iφ)^n = exp(inφ)) for correct n:m phase coupling
  • Also removed **filter_options passed to compute_single_freq() which doesn't accept them

Cluster statistics (stats.py)

  • statscluster: threshold was set to alpha (e.g. 0.05), a p-value, but MNE expects a test statistic (e.g. t≈2.02). This made nearly all values form one cluster.
  • statscluster: argsarg typo caused NameError on f multipleway path
  • statscluster: hardcoded pvalue=0.05 → uses alpha parameter
  • statscondCluster: F-threshold used alpha/2 (too conservative for one-tailed F-test) → uses alpha
  • statsCond: replaced fragile float equality on p-values with boolean mask from fdr_correction

Other fixes

  • compute_conn_mvar (analyses.py): counter += countercounter += 1 (was always 0, making retry logic dead code)
  • AR_local (prep.py): clean_epochs_subj[subject_id].infoclean_epochs_subj.info (was indexing into epochs, not subjects)
  • generate_virtual_epoch (utils.py): n_chan/2n_chan//2 (float division caused TypeError)

Impact on existing pipelines

  • No impact (5 fixes): dead code paths, already-crashing functions, or identical behavior
  • More sensitive thresholds (2 fixes): statscondCluster and statscluster were overly conservative or broken; may detect previously missed effects
  • Different results (1 fix): compute_nmPLV output changes fundamentally — previous results were not measuring n:m phase coupling

Test plan

  • All 160 existing tests pass
  • Each issue verified with standalone script before fixing
  • Each fix tested with standalone script after implementation
  • WTC mode validated with synthetic 10 Hz coherent signal (coherence 0.997 at 10 Hz vs 0.59 at 20 Hz)

analyses.py:
- compute_conn_mvar: counter += counter -> counter += 1 (was always 0)
- compute_nmPLV: use phase exponentiation for n:m PLV instead of
  scalar multiplication which doesn't change phase angles
- compute_nmPLV: remove **filter_options passed to compute_single_freq
  which doesn't accept them

stats.py:
- statscluster: fix undefined variable 'args' -> 'arg' in f_mway_rm call
- statscluster: compute proper t/F critical values as cluster thresholds
  instead of using alpha (a p-value) as a test statistic threshold
- statscluster: use alpha parameter instead of hardcoded 0.05 in
  f_threshold_mway_rm
- statscondCluster: use alpha instead of alpha/2 for F-test threshold
- statsCond: use boolean mask from fdr_correction instead of fragile
  float equality comparison on p-values

prep.py:
- AR_local: fix clean_epochs_subj[subject_id].info to
  clean_epochs_subj.info (was indexing epoch not subject)

utils.py:
- generate_virtual_epoch: use n_chan//2 instead of n_chan/2 to avoid
  TypeError from float index
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