Repository navigation
Preserve epochs when averaging permutation-entropy delays - #52
raphaelvallat merged 2 commits into
Conversation
There was a problem hiding this comment.
Hi @antonsoo! Thank you so much for your contribution. See Opus 5.5 review below:
The fix looks right: averaging along axis=0 gives one value per epoch for 2D input and still a scalar for 1D input. A few things to consider:
Worth fixing in this PR
- Empty delay list still collapses to a scalar (inline).
perm_entropy(x2d, delay=[])returns a singlenanwith a "Mean of empty slice" warning instead of shape(n_epochs,). AValueErrorwould be clearer. - The docstring doesn't describe the new behavior (
entropy.py,delayparameter, around line 154). It only says results are averaged "across all these delays". Worth saying the average is taken per epoch for 2D input, and adding a 2D multi-delay doctest.
Existing issues on the edited line (here or in a follow-up)
3. Tuples aren't accepted (inline). delay=(1, 2, 3) falls through to the scalar path and raises TypeError at delay < 1.
4. Odd array shapes break (inline). np.array(2) passes the ndarray check and then fails on iteration. np.array([[1, 2]]) fails inside the recursive call.
Performance (minor)
5. Repeated work per delay (inline). Each delay re-runs np.asarray(x), the input checks, and the full-array abs().max().
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #52 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 370 376 +6
Branches 62 64 +2
=========================================
+ Hits 370 376 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Averaging permutation entropy over several delays currently reduces both the delay and epoch axes for 2D input, giving one scalar for the entire batch. Average along the delay axis to keep one value per epoch.
The review follow-up also rejects empty or multidimensional delay sequences, accepts tuples and scalar NumPy arrays, and documents a 2D multi-delay example. Convert input lists to an array once before dispatching delays; single-delay checks still validate each lag separately.
All 32 project tests and repository Ruff checks pass, and the affected doctest passes. A recorded ECG/audio workload preserves the independently checked 1,024 epoch features and every original result record after the follow-up. Both fixes also compose locally with the ordinal-comparison PR #53.