rng/randomness_tests/binary_matrix.cpp

50 lines
1.4 KiB
C++

#include "./binary_matrix.h"
#include "./rngtest.h"
namespace splat {
binary_matrix_test::binary_matrix_test(std::vector<std::bitset<32>> &testData) : RNGTEST(testData){
testPValue = runTest(data);
testPassed = testPValue > 0.01;
}
std::string binary_matrix_test::getName() {
return "Binary Matrix Rank Test";
}
// We will use matrices of size 32x32 as recommended
double binary_matrix_test::runTest(std::vector<std::bitset<32>> &data) {
double num_matrices = (data.size()*32) / (32*32);
// [0] -> Full Rank
// [1] -> Full rank -1
// [2] -> < full rank -1
double counts[3] = {0,0,0};
for(int matrixIndex = 0; matrixIndex < num_matrices; matrixIndex++){
splat::matrix<32> matrix;
for(int i=0; i<32; i++){
matrix[i] = data[(matrixIndex*32) + i];
}
int rank = splat::getRank(matrix);
if(rank==32){
counts[0]++;
}else if(rank==31){
counts[1]++;
}else{
counts[2]++;
}
}
double x2obs = 0;
std::cout << "debug: "<< counts[0] << ","<<counts[1]<<","<<counts[2]<<"\n";
x2obs += std::pow((counts[0]-(0.2888*num_matrices)),2)/(0.2888*num_matrices);
x2obs += std::pow((counts[1]-(0.5776*num_matrices)),2)/(0.5776*num_matrices);
x2obs += std::pow((counts[2]-(0.1336*num_matrices)),2)/(0.1336*num_matrices);
std::cout << "debug: "<<x2obs << "\n";
return igam(1, x2obs/2);
}
}