77 lines
1.8 KiB
C
77 lines
1.8 KiB
C
#include <stdio.h>
|
|
#include <math.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include "include/externs.h"
|
|
#include "include/cephes.h"
|
|
#include "include/matrix.h"
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
R A N K T E S T
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
int
|
|
Rank(int n, BitSequence *epsilon)
|
|
{
|
|
int ret = 0;
|
|
int N, i, k, r;
|
|
double p_value, product, chi_squared, arg1, p_32, p_31, p_30, R, F_32, F_31, F_30;
|
|
BitSequence **matrix = create_matrix(32, 32);
|
|
|
|
N = n/(32*32);
|
|
if ( isZero(N) ) {
|
|
p_value = 0.00;
|
|
}
|
|
else {
|
|
r = 32; /* COMPUTE PROBABILITIES */
|
|
product = 1;
|
|
for ( i=0; i<=r-1; i++ )
|
|
product *= ((1.e0-pow(2, i-32))*(1.e0-pow(2, i-32)))/(1.e0-pow(2, i-r));
|
|
p_32 = pow(2, r*(32+32-r)-32*32) * product;
|
|
|
|
r = 31;
|
|
product = 1;
|
|
for ( i=0; i<=r-1; i++ )
|
|
product *= ((1.e0-pow(2, i-32))*(1.e0-pow(2, i-32)))/(1.e0-pow(2, i-r));
|
|
p_31 = pow(2, r*(32+32-r)-32*32) * product;
|
|
|
|
p_30 = 1 - (p_32+p_31);
|
|
|
|
F_32 = 0;
|
|
F_31 = 0;
|
|
for ( k=0; k<N; k++ ) { /* FOR EACH 32x32 MATRIX */
|
|
def_matrix(32, 32, matrix, k, epsilon);
|
|
#if (DISPLAY_MATRICES == 1)
|
|
display_matrix(32, 32, matrix);
|
|
#endif
|
|
R = computeRank(32, 32, matrix);
|
|
if ( R == 32 )
|
|
F_32++; /* DETERMINE FREQUENCIES */
|
|
if ( R == 31 )
|
|
F_31++;
|
|
}
|
|
F_30 = (double)N - (F_32+F_31);
|
|
|
|
chi_squared =(pow(F_32 - N*p_32, 2)/(double)(N*p_32) +
|
|
pow(F_31 - N*p_31, 2)/(double)(N*p_31) +
|
|
pow(F_30 - N*p_30, 2)/(double)(N*p_30));
|
|
|
|
arg1 = -chi_squared/2.e0;
|
|
|
|
p_value = exp(arg1);
|
|
if ( isNegative(p_value) || isGreaterThanOne(p_value) ) {
|
|
goto end;
|
|
}
|
|
}
|
|
|
|
if (p_value < ALPHA) {
|
|
goto end;
|
|
}
|
|
|
|
ret = 1;
|
|
|
|
end:
|
|
delete_matrix(32, matrix);
|
|
return ret;
|
|
}
|