This repository has been archived by the owner on May 11, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
randomExcursionsVariant.c
67 lines (61 loc) · 2.65 KB
/
randomExcursionsVariant.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "../include/externs.h"
#include "../include/cephes.h"
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
R A N D O M E X C U R S I O N S V A R I A N T T E S T
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void
RandomExcursionsVariant(int n)
{
int i, p, J, x, constraint, count, *S_k;
int stateX[18] = { -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
double p_value;
if ( (S_k = (int *)calloc(n, sizeof(int))) == NULL ) {
fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\tRANDOM EXCURSIONS VARIANT: Insufficent memory allocated.\n");
return;
}
J = 0;
S_k[0] = 2*(int)epsilon[0] - 1;
for ( i=1; i<n; i ) {
S_k[i] = S_k[i-1] 2*epsilon[i] - 1;
if ( S_k[i] == 0 )
J ;
}
if ( S_k[n-1] != 0 )
J ;
fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t\tRANDOM EXCURSIONS VARIANT TEST\n");
fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t--------------------------------------------\n");
fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\tCOMPUTATIONAL INFORMATION:\n");
fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t--------------------------------------------\n");
fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t(a) Number Of Cycles (J) = %d\n", J);
fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t(b) Sequence Length (n) = %d\n", n);
fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t--------------------------------------------\n");
constraint = (int)MAX(0.005*pow(n, 0.5), 500);
if (J < constraint) {
fprintf(stats[TEST_RND_EXCURSION_VAR], "\n\t\tWARNING: TEST NOT APPLICABLE. THERE ARE AN\n");
fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t\t INSUFFICIENT NUMBER OF CYCLES.\n");
fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t---------------------------------------------\n");
for ( i=0; i<18; i )
fprintf(results[TEST_RND_EXCURSION_VAR], "%f\n", 0.0);
}
else {
for ( p=0; p<=17; p ) {
x = stateX[p];
count = 0;
for ( i=0; i<n; i )
if ( S_k[i] == x )
count ;
p_value = erfc(fabs(count-J)/(sqrt(2.0*J*(4.0*fabs(x)-2))));
if ( isNegative(p_value) || isGreaterThanOne(p_value) )
fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t(b) WARNING: P_VALUE IS OUT OF RANGE.\n");
fprintf(stats[TEST_RND_EXCURSION_VAR], "%s\t\t", p_value < ALPHA ? "FAILURE" : "SUCCESS");
fprintf(stats[TEST_RND_EXCURSION_VAR], "(x = -) Total visits = M; p-value = %f\n", x, count, p_value);
fprintf(results[TEST_RND_EXCURSION_VAR], "%f\n", p_value); fflush(results[TEST_RND_EXCURSION_VAR]);
}
}
fprintf(stats[TEST_RND_EXCURSION_VAR], "\n"); fflush(stats[TEST_RND_EXCURSION_VAR]);
free(S_k);
}