|
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 U N S T E S T |
|
33 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
|
34 |
|
35 void |
|
36 Runs(int n) |
|
37 { |
|
38 int S, k; |
|
39 double pi, V, erfc_arg, p_value; |
|
40 |
|
41 S = 0; |
|
42 for ( k=0; k<n; k++ ) |
|
43 if ( epsilon[k] ) |
|
44 S++; |
|
45 pi = (double)S / (double)n; |
|
46 |
|
47 if ( fabs(pi - 0.5) > (2.0 / sqrt(n)) ) { |
|
48 fprintf(stats[TEST_RUNS], "\t\t\t\tRUNS TEST\n"); |
|
49 fprintf(stats[TEST_RUNS], "\t\t------------------------------------------\n"); |
|
50 fprintf(stats[TEST_RUNS], "\t\tPI ESTIMATOR CRITERIA NOT MET! PI = %f\n", pi); |
|
51 p_value = 0.0; |
|
52 } |
|
53 else { |
|
54 |
|
55 V = 1; |
|
56 for ( k=1; k<n; k++ ) |
|
57 if ( epsilon[k] != epsilon[k-1] ) |
|
58 V++; |
|
59 |
|
60 erfc_arg = fabs(V - 2.0 * n * pi * (1-pi)) / (2.0 * pi * (1-pi) * sqrt(2*n)); |
|
61 p_value = erfc(erfc_arg); |
|
62 |
|
63 fprintf(stats[TEST_RUNS], "\t\t\t\tRUNS TEST\n"); |
|
64 fprintf(stats[TEST_RUNS], "\t\t------------------------------------------\n"); |
|
65 fprintf(stats[TEST_RUNS], "\t\tCOMPUTATIONAL INFORMATION:\n"); |
|
66 fprintf(stats[TEST_RUNS], "\t\t------------------------------------------\n"); |
|
67 fprintf(stats[TEST_RUNS], "\t\t(a) Pi = %f\n", pi); |
|
68 fprintf(stats[TEST_RUNS], "\t\t(b) V_n_obs (Total # of runs) = %d\n", (int)V); |
|
69 fprintf(stats[TEST_RUNS], "\t\t(c) V_n_obs - 2 n pi (1-pi)\n"); |
|
70 fprintf(stats[TEST_RUNS], "\t\t ----------------------- = %f\n", erfc_arg); |
|
71 fprintf(stats[TEST_RUNS], "\t\t 2 sqrt(2n) pi (1-pi)\n"); |
|
72 fprintf(stats[TEST_RUNS], "\t\t------------------------------------------\n"); |
|
73 if ( isNegative(p_value) || isGreaterThanOne(p_value) ) |
|
74 fprintf(stats[TEST_RUNS], "WARNING: P_VALUE IS OUT OF RANGE.\n"); |
|
75 |
|
76 fprintf(stats[TEST_RUNS], "%s\t\tp_value = %f\n\n", p_value < ALPHA ? "FAILURE" : "SUCCESS", p_value); |
|
77 } |
|
78 |
|
79 fprintf(results[TEST_RUNS], "%f\n", p_value); |
|
80 } |