Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard hitlet entropy test from numerical errors #772

Merged
merged 4 commits into from Nov 14, 2023

Conversation

JelleAalbers
Copy link
Member

... by avoiding waveforms for which normalization is not reliable in float32.

What is the problem / what does the code in this PR do

While installing strax I got a failure in one of the hitlet tests that uses hypothesis to generate test data. This is the same test as in #539 / #544. The PR makes sure the test is skipped on data that is very susceptible to floating point errors. This avoids failures from slight implementation differences between the numba code and the numpy code we test against.

Can you briefly describe how it works?

The waveform that triggered the failure was something like [1, -1, 1e-5] (with a few extra zeros). Note the amplitude is much larger than its sum, causing numerical errors in float32 (e.g. the first step in the conditional entropy computation is to divide by the waveform sum), and about ~1% differences between the numpy and numba computation for waveforms like the above.

I arbitrarily put the threshold for skipping the test at sum < 1e-4 * min-to-max amplitude. Now I get no more failures from hypothesis even with a max_examples of several thousand.

Avoid waveforms for which normalization is not reliable in float32
WenzDaniel
WenzDaniel previously approved these changes Nov 8, 2023
Copy link
Collaborator

@WenzDaniel WenzDaniel left a comment

Choose a reason for hiding this comment

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

Thanks @JelleAalbers

@JelleAalbers
Copy link
Member Author

JelleAalbers commented Nov 8, 2023

Thanks Daniel! I just noticed I accidentally removed the final assert in the test for NaNs on zero waveforms.. let me put that back in.

Edit: Done. Apparently that auto-dismissed your review 🤔

@coveralls
Copy link

coveralls commented Nov 8, 2023

Coverage Status

coverage: 91.458%. remained the same
when pulling 7c8f48c on JelleAalbers:guard_entropy_test
into c88daf8 on AxFoundation:master.

Copy link
Collaborator

@dachengx dachengx left a comment

Choose a reason for hiding this comment

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

Thanks @JelleAalbers

@dachengx dachengx merged commit a9d4ebb into AxFoundation:master Nov 14, 2023
11 checks passed
@JelleAalbers JelleAalbers deleted the guard_entropy_test branch November 14, 2023 14:03
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.

None yet

4 participants