Skip to content

update sp800_22_non_overlapping_template_matching_test.py#24

Open
goonstream wants to merge 2 commits intodj-on-github:masterfrom
goonstream:master
Open

update sp800_22_non_overlapping_template_matching_test.py#24
goonstream wants to merge 2 commits intodj-on-github:masterfrom
goonstream:master

Conversation

@goonstream
Copy link

When using the sp800_22_non_overlapping_template_matching_test.py, I observed that the calculated p-value occasionally exceeded 1. After investigation, this anomaly was traced to an implementation error in the chi-square statistic calculation within the code

@goonstream goonstream closed this Mar 30, 2025
@goonstream goonstream reopened this Mar 30, 2025

mu = float(M-m+1)/float(2**m) # Compute mu and sigma
sigma = M * ((1.0/float(2**m))-(float((2*m)-1)/float(2**(2*m))))
variance = M * ((1.0/float(2**m))-(float((2*m)-1)/float(2**(2*m))))
Copy link
Author

Choose a reason for hiding this comment

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

According to the documentation, the original sigma was actually variance

chisq += ((W[j] - mu)**2)/(variance)

p = gammaincc((N-1)/2.0, chisq/2.0) # Compute P value
p = gammaincc(N/2.0, chisq/2.0) # Compute P value
Copy link
Author

Choose a reason for hiding this comment

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

There is no need to change here, the original author code is inherently correct

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