Skip to content

fix(ceemdan): fix pure-IMF local mean, constant/zero-noise guards, and kwarg leakage - #195

Merged
laszukdawid merged 1 commit into
masterfrom
fix/ceemdan-critical-bugs
Nov 29, 2026
Merged

laszukdawid merged 1 commit into
masterfrom
fix/ceemdan-critical-bugs

Conversation

@laszukdawid

Copy link
Copy Markdown
Owner

Summary

Fixes four correctness bugs in PyEMD/CEEMDAN.py:

  1. Pure-IMF local mean bug: Previously, local_mean += imfs[-1] / self.trials assumed imfs[-1] was always the residue of self.emd(res, T, max_imf=1). When res is already a pure IMF (residue $\approx 0$), EMD.emd omits the zero residue from its return array, causing imfs[-1] to add the IMF itself instead of 0 (zeroing out the extracted cIMF). Now uses self.EMD.get_imfs_and_residue() (with imfs[-1] fallback for custom ext_EMD objects without it).
  2. Constant-signal NaN crash: Guard scale_s = np.std(S) when scale_s == 0, returning [S.copy()] with zero residue instead of dividing by zero.
  3. Zero-noise-scale / empty-noise-IMF crash: Guard _decompose_noise() and _trial_update() when a decomposed noise realization has 0 IMFs or zero standard deviation (noise_scale=0.0), preventing IndexError and ZeroDivisionError/NaN.
  4. Prevent CEEMDAN kwarg leakage to inner EMD: Pop CEEMDAN-only kwargs (range_thr, total_power_thr, noise_scale, beta_progress, seed, noise_kind, max_imf, processes) before instantiating EMD(**kwargs) so tuning CEEMDAN stopping thresholds does not unintentionally alter the inner EMD thresholds.

Tests

Added 4 regression tests in PyEMD/tests/test_ceemdan.py:

  • test_ceemdan_constant_signal_no_nan
  • test_ceemdan_zero_noise_scale_no_nan
  • test_ceemdan_kwargs_do_not_leak_thresholds_to_inner_emd
  • test_ceemdan_pure_imf_local_mean_is_zero

All 124 unit tests pass (python -m PyEMD.tests.test_all), and isort + black==25.11.0 pass.

Benchmark Comparison (vs master baseline)

Ran perf_test/perf_test_comprehensive.py --test ceemdan and --quick:

Test Params Baseline PR Change
CEEMDAN (--test ceemdan) trials=5, N=500 0.1783s 0.1484s -16.8% (within noise)
CEEMDAN (--test ceemdan) trials=10, N=500 0.2417s 0.2213s -8.4% (within noise)
CEEMDAN (--test ceemdan) trials=25, N=500 0.3670s 0.3334s -9.2% (within noise)
CEEMDAN (--quick) trials=3, N=500 0.1352s 0.1331s -1.6%
CEEMDAN (--quick) trials=5, N=500 0.1729s 0.1723s -0.3%

No performance regressions across CEEMDAN benchmarks.

@laszukdawid
laszukdawid merged commit 7e6cb42 into master Nov 29, 2026
5 checks passed
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