Skip to content

Preserve integer distances in sample and approximate entropy - #1138

Open
galafis wants to merge 1 commit into
blue-yonder:mainfrom
galafis:fix/integer-entropy-distances
Open

galafis wants to merge 1 commit into
blue-yonder:mainfrom
galafis:fix/integer-entropy-distances

Conversation

@galafis

@galafis galafis commented Oct 24, 2026

Copy link
Copy Markdown

Sample and approximate entropy subtract template vectors in the original input dtype. Unsigned subtraction wraps and signed subtraction/abs can overflow, so integer sensor signals produce different template-match counts and entropy from their mathematical values. Boolean signals raise on subtraction.

Promote integer inputs before computing template distances. Use float64 when all integer values are within +/-2**52, so their pairwise differences are exact and the normal fixed-width path stays fast. Use Python integer arithmetic outside that range to preserve exact signed differences at int64/uint64 limits; the floating-input path and the existing tolerance calculation are unchanged.

Eleven regression cases cover int8/uint8/int16/int64/uint64 arrays and Series plus booleans. A separate Python-loop oracle counts template matches using arbitrary-precision integer subtraction. All eleven fail before the fix. With the fix, the new tests and entire existing feature-calculation module pass: 96 passed, 3 skipped. Black 22.12.0, isort 5.12.0 (Black profile) and git diff --check pass.

The change is separate from pending PRs1133/1134: those cover energy and time-adjacent differences, whereas these estimators compare all embedded template pairs. No benchmark or performance claim is made. Only 64-bit values outside +/-2**52 take the object-integer path; it favors exact comparisons and may cost more than the fixed-width path.

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.

1 participant