fix: KS test
This commit is contained in:
parent
249a16536a
commit
bd56c1ec33
4 changed files with 95 additions and 161 deletions
15
readme.md
15
readme.md
|
|
@ -103,7 +103,7 @@ ChiBit | 0.9299 | 0.9299 | |
|
|||
ChiByte | 0.9819 | 0.9819 | |
|
||||
MeanByte | 0.7964 | 0.7964 | |
|
||||
Compression | N/A | 0.0146 | |
|
||||
KS | 0.5313 | 0.2476 | Mismatch |
|
||||
KS | 0.5313 | 0.9998 | Different method |
|
||||
Pi | 0.3784 | 0.3784 | |
|
||||
Shells | 0.7559 | 0.7559 | |
|
||||
Gaps | 0.0000 | 0.0000 | |
|
||||
|
|
@ -125,7 +125,7 @@ ChiBit | 0.5590 | 0.5590 | |
|
|||
ChiByte | 0.3748 | 0.3748 | |
|
||||
MeanByte | 0.0183 | 0.0183 | |
|
||||
Compression | N/A | 0.9308 | |
|
||||
KS | 0.2900 | 0.0178 | Mismatch |
|
||||
KS | 0.2900 | 0.1158 | Different method |
|
||||
Pi | 0.9765 | 0.9765 | |
|
||||
Shells | 0.7235 | 0.7235 | |
|
||||
Gaps | 0.6425 | 0.6425 | |
|
||||
|
|
@ -145,7 +145,7 @@ ChiBit | 0.8428 | 0.8428 | |
|
|||
ChiByte | 0.5785 | 0.5785 | |
|
||||
MeanByte | 0.9601 | 0.9601 | |
|
||||
Compression | N/A | 0.9308 | |
|
||||
KS | 0.7395 | 0.0441 | Mismatch |
|
||||
KS | 0.7395 | 0.7777 | Different method |
|
||||
Pi | 0.2806 | 0.2806 | |
|
||||
Shells | 0.7711 | 0.7711 | |
|
||||
Gaps | 0.1937 | 0.1937 | |
|
||||
|
|
@ -157,14 +157,9 @@ UnCorrelation | 0.4674 | 0.4674 | |
|
|||
|
||||
### Conclusions
|
||||
|
||||
Although the implementation of the randomness tests closely follows the original Java logic, differences in the results arise in the Kolmogorov-Smirnov test. The external libraries used for running the test probably differ in their implementation. Also the uniform distribution to test against is provided by the Apache Commons Math library. Since it would be way beyond the scope of this porting project to try to fully match the functionality of the dependencies used we just accept the minor difference. Another issue might be that Java emphasizes predictability and portability, enforcing strict IEEE 754 behavior across platforms. Rust on the other hand prioritizes performance and flexibility, allowing platform-specific optimizations that may deviate slightly from strict IEEE semantics.
|
||||
Although the implementation of the randomness tests closely follows the original Java logic, the Kolmogorov-Smirnov test deliberately differs. The Java version compares the data against a pseudo-random uniform sample, which makes the p-value change from run to run for the same input. This port instead runs a one-sample KS test of the byte values against the exact discrete uniform distribution over 0..255, with p-values from the asymptotic Kolmogorov distribution (Stephens' small-sample correction). The result is deterministic and calibrated: on `/dev/urandom` it fails about 1% of the time at alpha = 0.01, slightly less on small inputs because the discrete null makes the test a little conservative.
|
||||
|
||||
These differences are generally negligible for practical purposes and do not affect the overall functionality or
|
||||
statistical significance of the test.
|
||||
|
||||
### Bonus
|
||||
|
||||
We implemented a Well Equidistributed Long-period Linear pseudo-random number generator that is used with a random seed derived from an epoch timestamp that is being used as uniform distribution for the KS test.
|
||||
All other differences are generally negligible for practical purposes and do not affect the overall functionality or statistical significance of the tests.
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue