Skip to content

Preserve epochs when averaging permutation-entropy delays - #52

Merged
raphaelvallat merged 2 commits into
raphaelvallat:masterfrom
antonsoo:fix/permutation-entropy-delay-axis
Oct 17, 2026
Merged

raphaelvallat merged 2 commits into
raphaelvallat:masterfrom
antonsoo:fix/permutation-entropy-delay-axis

Conversation

@antonsoo

@antonsoo antonsoo commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

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.

@raphaelvallat raphaelvallat left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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

  1. Empty delay list still collapses to a scalar (inline). perm_entropy(x2d, delay=[]) returns a single nan with a "Mean of empty slice" warning instead of shape (n_epochs,). A ValueError would be clearer.
  2. The docstring doesn't describe the new behavior (entropy.py, delay parameter, 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().

Comment thread src/antropy/entropy.py Resolved
Comment thread src/antropy/entropy.py Resolved
Comment thread src/antropy/entropy.py Resolved
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (dfbe688) to head (e574842).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@raphaelvallat raphaelvallat left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Approved, thank you!

@raphaelvallat
raphaelvallat merged commit 7eb2776 into raphaelvallat:master Oct 17, 2026
15 of 17 checks passed
@raphaelvallat raphaelvallat mentioned this pull request Oct 17, 2026
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.

3 participants