mercredi 26 avril 2017

RDieHarder: calling 'dieharder' with 'file_input_raw' leads to 'Error. This cannot happen.'

I'am trying to test my RNG (written in VHDL, numbers stored in binary file) with the RDieHarder package. But when I call the dieharder() function twice (from R) this leads to

> dh <- dieharder(rng = 'file_input_raw', test = 'diehard_runs', inputfile = 'rand.bin')
# file_input_raw(): Error.  This cannot happen.
[user@host ~]$

and drops me to my shell.

Setup

Die Harder Version:

$ dieharder -h
#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
#=============================================================================#
...

R Version:

$ R --version
R version 3.3.3 (2017-03-06) -- "Another Canoe"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

RDieHarder Version:

> packageVersion('RDieHarder')
[1] ‘0.1.3’

MWE

To reproduce this, we first generate an appropriate binary file with dieharder and run the die hard tests on it.

$ dieharder -o -O0 -f rand.bin -t 5000000 && dieharder -g file_input_raw -d diehard_runs -f rand.bin
#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
#=============================================================================#
   rng_name    |           filename             |rands/second|
 file_input_raw|                        rand.bin|  4.49e+07  |
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
# The file file_input_raw was rewound 4 times
        diehard_runs|   0|    100000|     100|0.77169947|  PASSED  
        diehard_runs|   0|    100000|     100|0.68299332|  PASSED

All tests where passed, fine. So we switch to R and do the same thing again and asume we want some more tests, like the STS Runs test.

> library('RDieHarder')
> dh <- dieharder(rng = 'file_input_raw', test = 'diehard_runs', verbose = TRUE, inputfile = 'rand.bin')
Dieharder called with gen=201 test=15 seed=2852951401
# 10000000 rands were used in this test
# The file file_input_raw was rewound 2 times
#==================================================================
#                    Diehard Runs Test
#  This is the RUNS test.  It counts runs up, and runs down, 
# in a sequence of uniform [0,1) variables, obtained by float-  
# ing the 32-bit integers in the specified file. This example   
# shows how runs are counted:  .123,.357,.789,.425,.224,.416,.95
# contains an up-run of length 3, a down-run of length 2 and an 
# up-run of (at least) 2, depending on the next values.  The    
# covariance matrices for the runs-up and runs-down are well    
# known, leading to chisquare tests for quadratic forms in the  
# weak inverses of the covariance matrices.  Runs are counted   
# for sequences of length 10,000.  This is done ten times. Then 
# repeated.                                                     
#
# In Dieharder sequences of length tsamples = 100000 are used by
# default, and 100 p-values thus generated are used in a final
# KS test.
#==================================================================
#                        Run Details
# Random number generator tested: file_input_raw
# File rand.bin contains 5000000 rands of  type.
# Samples per test pvalue = 100000 (test default is 100000)
# P-values in final KS test = 100 (test default is 100)
#==================================================================
#                Histogram of p-values
##################################################################
# Counting histogram bins, binscale = 0.100000
#     20|    |    |    |    |    |    |    |    |    |    |
#       |    |    |    |    |    |    |    |    |    |    |
#     18|    |    |    |    |    |    |    |    |    |    |
#       |    |    |    |    |    |    |    |    |    |    |
#     16|    |    |    |    |    |    |    |    |    |    |
#       |    |    |    |    |    |    |    |    |    |    |
#     14|****|    |    |    |    |    |    |    |****|    |
#       |****|    |    |    |    |    |    |    |****|    |
#     12|****|    |****|    |****|    |****|    |****|    |
#       |****|    |****|    |****|    |****|    |****|    |
#     10|****|    |****|    |****|****|****|    |****|    |
#       |****|    |****|    |****|****|****|    |****|    |
#      8|****|    |****|****|****|****|****|****|****|    |
#       |****|    |****|****|****|****|****|****|****|    |
#      6|****|    |****|****|****|****|****|****|****|****|
#       |****|    |****|****|****|****|****|****|****|****|
#      4|****|****|****|****|****|****|****|****|****|****|
#       |****|****|****|****|****|****|****|****|****|****|
#      2|****|****|****|****|****|****|****|****|****|****|
#       |****|****|****|****|****|****|****|****|****|****|
#       |--------------------------------------------------
#       | 0.1| 0.2| 0.3| 0.4| 0.5| 0.6| 0.7| 0.8| 0.9| 1.0|
#==================================================================
# 10000000 rands were used in this test
# The file file_input_raw was rewound 2 times
#==================================================================
#                Histogram of p-values
##################################################################
# Counting histogram bins, binscale = 0.100000
#     20|    |    |    |    |    |    |    |    |    |    |
#       |    |    |    |    |    |    |    |    |    |    |
#     18|    |    |    |    |    |    |    |    |    |    |
#       |    |    |    |    |    |    |    |    |    |    |
#     16|    |    |    |    |    |****|    |    |****|    |
#       |    |    |    |    |    |****|    |    |****|    |
#     14|    |    |    |    |    |****|    |    |****|    |
#       |    |    |    |    |    |****|    |    |****|    |
#     12|    |****|    |    |    |****|    |    |****|    |
#       |    |****|    |    |    |****|    |    |****|    |
#     10|****|****|    |    |****|****|    |    |****|    |
#       |****|****|    |    |****|****|    |    |****|    |
#      8|****|****|****|    |****|****|****|    |****|****|
#       |****|****|****|    |****|****|****|    |****|****|
#      6|****|****|****|****|****|****|****|****|****|****|
#       |****|****|****|****|****|****|****|****|****|****|
#      4|****|****|****|****|****|****|****|****|****|****|
#       |****|****|****|****|****|****|****|****|****|****|
#      2|****|****|****|****|****|****|****|****|****|****|
#       |****|****|****|****|****|****|****|****|****|****|
#       |--------------------------------------------------
#       | 0.1| 0.2| 0.3| 0.4| 0.5| 0.6| 0.7| 0.8| 0.9| 1.0|
#==================================================================
# 10000000 rands were used in this test
# The file file_input_raw was rewound 2 times
> summary(dh)

    Diehard Runs Test

data:  Created by RNG `file_input_raw' with seed=0, sample of size 100
p-value = 0.7717


Summary for test data
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.03151 0.23500 0.49970 0.49850 0.75030 0.94720 


Stem and leaf plot for test data

  The decimal point is 1 digit(s) to the left of the |

  0 | 33667788889999
  1 | 3399
  2 | 0011333355
  3 | 0022222266
  4 | 222222446688
  5 | 229999
  6 | 0000224477778899
  7 | 225555
  8 | 0022446666888888
  9 | 003355

NULL

    One-sample Kolmogorov-Smirnov test

data:  object$data
D = 0.06947, p-value = 0.6936
alternative hypothesis: two-sided


    Wilcoxon signed rank test with continuity correction

data:  object$data
V = 2507, p-value = 0.952
alternative hypothesis: true location is not equal to 0.5

Warning:
In ks.test(object$data, "punif", 0, 1, exact = TRUE) :
  ties should not be present for the Kolmogorov-Smirnov test
> # calling dieharder() again yields an error
> dh <- dieharder(rng = 'file_input_raw', test = 'sts_runs', verbose = TRUE, inputfile = 'rand.bin')
Dieharder called with gen=201 test=101 seed=3570434269
# file_input_raw(): Error.  This cannot happen.
[user@host ~]$

So if This cannot happen why does it happen?

Thanks for your time and best regards,

Befedo




Aucun commentaire:

Enregistrer un commentaire