Skip to content

Preserve integer derivative signs in Petrosian dimension - #56

Draft
antonsoo wants to merge 3 commits into
raphaelvallat:masterfrom
antonsoo:fix/petrosian-integer-differences
Draft

antonsoo wants to merge 3 commits into
raphaelvallat:masterfrom
antonsoo:fix/petrosian-integer-differences

Conversation

@antonsoo

@antonsoo antonsoo commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

petrosian_fd takes np.diff in the input dtype before counting changes in derivative sign. Unsigned inputs cannot represent falling differences, while narrow signed inputs can overflow. For example, np.array([10, 4, 9, 3, 8, 2, 7], dtype=np.uint8) gives 1 instead of approximately 1.1483.

For integer and boolean inputs, compare neighboring values directly and count changes between falling and non-falling steps. This also preserves full 64-bit integer comparisons. Keep the existing floating-point path.

Keep one uint8 regression for the integer path; the existing floating tests cover the other branch, and both new branch outcomes are covered. The larger dtype/layout matrix stays in the external recorded-data evidence. Full tests and Ruff pass. An independent Python-integer sign-change reference on recorded EEG and piano ADC traces checks 4,158 feature values across 42 dtype/layout calls: 1,188 wrong unsigned results become correct. All 1,188 floating-point feature controls are unchanged. This validates feature computation, without a clinical or classification-quality claim.

Impact: P2. Integer ADC input is legitimate and can give incorrect feature values; the floating path is unchanged. Original implementation and AI review: gpt-6.1-sol via Codex. This remains a draft pending the human contributor's opening summary.

@codecov-commenter

codecov-commenter commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6843920) to head (cecad1d).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #56   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          380       384    +4     
  Branches        65        66    +1     
=========================================
+ Hits           380       384    +4     

☔ 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

Copy link
Copy Markdown
Owner

Thank you for your contribution!

AntroPy now has guidelines for pull requests, including specific steps for AI-assisted PRs: #61

Before I review this PR, could you please go through those steps and update the PR accordingly? In particular: state the user-impact rating (P1-P3) with a short justification, start the description with a summary in your own words, report the exact AI model used (if any), and run an AI review and post a summary of it as a comment. Thanks!

@antonsoo
antonsoo marked this pull request as draft October 24, 2026 15:02
@antonsoo

Copy link
Copy Markdown
Contributor Author

Returned this to draft while applying the new guidelines. The original changes and this AI review used gpt-6.1-sol via Codex.

AI review: checked the final diff, the zero-crossing convention for zero derivatives, signed/unsigned 64-bit comparisons, booleans, axis handling, and the independent Python-integer reference. No new correctness issue was found. The floating path is unchanged. The recorded EEG/piano replay again checks 4,158 feature values with no mismatch, and every result matches the previous validated revision. The full suite and Ruff checks pass.

The simplification pass found no further change needed: direct comparisons avoid both subtraction overflow and loss of close 64-bit integers through a float cast. The single added regression covers those distinct dtype cases and both axes. No changelog change or extra tests were added.

Suggested impact: P2, since integer ADC input is legitimate and gives incorrect feature values, while floating inputs are unaffected. The opening summary still needs to be written by the human contributor before this is ready for review.

Comment thread tests/test_fractal.py
assert_allclose(aal(petrosian_fd, axis=1, arr=data), petrosian_fd(data))
assert_allclose(aal(petrosian_fd, axis=0, arr=data), petrosian_fd(data, axis=0))

def test_petrosian_integer_differences(self):

@raphaelvallat raphaelvallat Oct 31, 2026 •

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.

Please trim the tests as much as possible, while ensuring 100% coverage of the new if else. No need to test for all possible int dtypes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Trimmed to one uint8 case in b9019b0. It and the existing floating tests cover both outcomes of the new branch.

@antonsoo

Copy link
Copy Markdown
Contributor Author

Trimmed to one uint8 regression in b9019b0. The existing floating tests and this case cover both outcomes of the new branch. All 35 tests and Ruff pass; the runtime source and all 42 recorded EEG/audio reports are unchanged. This remains a draft pending the human-written opening summary.

@antonsoo

Copy link
Copy Markdown
Contributor Author

The current red coverage job failed in Codecov's report upload: Token required because branch is protected. The preceding pytest-and-coverage step passed, as did the OS/Python test matrix and Ruff. The requested smaller regression still covers both outcomes of the new branch. No source change is needed for that upload failure.

This branch has not been deployed

No deployments
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