|
1 /* |
|
2 * Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * The original NIST Statistical Test Suite code is placed in public domain. |
|
16 * (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) |
|
17 * |
|
18 * This software was developed at the National Institute of Standards and Technology by |
|
19 * employees of the Federal Government in the course of their official duties. Pursuant |
|
20 * to title 17 Section 105 of the United States Code this software is not subject to |
|
21 * copyright protection and is in the public domain. The NIST Statistical Test Suite is |
|
22 * an experimental system. NIST assumes no responsibility whatsoever for its use by other |
|
23 * parties, and makes no guarantees, expressed or implied, about its quality, reliability, |
|
24 * or any other characteristic. We would appreciate acknowledgment if the software is used. |
|
25 */ |
|
26 |
|
27 #include "openc.h" |
|
28 #include "../include/externs.h" |
|
29 #include "../include/cephes.h" |
|
30 |
|
31 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
32 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 |
|
33 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
|
34 |
|
35 void |
|
36 RandomExcursionsVariant(int n) |
|
37 { |
|
38 int i, p, J, x, constraint, count, *S_k; |
|
39 int stateX[18] = { -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; |
|
40 double p_value; |
|
41 |
|
42 if ( (S_k = (int *)calloc(n, sizeof(int))) == NULL ) { |
|
43 fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\tRANDOM EXCURSIONS VARIANT: Insufficent memory allocated.\n"); |
|
44 return; |
|
45 } |
|
46 J = 0; |
|
47 S_k[0] = 2*(int)epsilon[0] - 1; |
|
48 for ( i=1; i<n; i++ ) { |
|
49 S_k[i] = S_k[i-1] + 2*epsilon[i] - 1; |
|
50 if ( S_k[i] == 0 ) |
|
51 J++; |
|
52 } |
|
53 if ( S_k[n-1] != 0 ) |
|
54 J++; |
|
55 |
|
56 fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t\tRANDOM EXCURSIONS VARIANT TEST\n"); |
|
57 fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t--------------------------------------------\n"); |
|
58 fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\tCOMPUTATIONAL INFORMATION:\n"); |
|
59 fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t--------------------------------------------\n"); |
|
60 fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t(a) Number Of Cycles (J) = %d\n", J); |
|
61 fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t(b) Sequence Length (n) = %d\n", n); |
|
62 fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t--------------------------------------------\n"); |
|
63 |
|
64 constraint = (int)MAX(0.005*pow(n, 0.5), 500); |
|
65 if (J < constraint) { |
|
66 fprintf(stats[TEST_RND_EXCURSION_VAR], "\n\t\tWARNING: TEST NOT APPLICABLE. THERE ARE AN\n"); |
|
67 fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t\t INSUFFICIENT NUMBER OF CYCLES.\n"); |
|
68 fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t---------------------------------------------\n"); |
|
69 for ( i=0; i<18; i++ ) |
|
70 fprintf(results[TEST_RND_EXCURSION_VAR], "%f\n", 0.0); |
|
71 } |
|
72 else { |
|
73 for ( p=0; p<=17; p++ ) { |
|
74 x = stateX[p]; |
|
75 count = 0; |
|
76 for ( i=0; i<n; i++ ) |
|
77 if ( S_k[i] == x ) |
|
78 count++; |
|
79 p_value = erfc(fabs(count-J)/(sqrt(2.0*J*(4.0*fabs(x)-2)))); |
|
80 |
|
81 if ( isNegative(p_value) || isGreaterThanOne(p_value) ) |
|
82 fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\t(b) WARNING: P_VALUE IS OUT OF RANGE.\n"); |
|
83 fprintf(stats[TEST_RND_EXCURSION_VAR], "%s\t\t", p_value < ALPHA ? "FAILURE" : "SUCCESS"); |
|
84 fprintf(stats[TEST_RND_EXCURSION_VAR], "(x = %2d) Total visits = %4d; p-value = %f\n", x, count, p_value); |
|
85 fprintf(results[TEST_RND_EXCURSION_VAR], "%f\n", p_value); |
|
86 } |
|
87 } |
|
88 fprintf(stats[TEST_RND_EXCURSION_VAR], "\n"); |
|
89 free(S_k); |
|
90 } |