2 ***********************************************************
3 $SNARK_Header: S N A R K 1 4 - A PICTURE RECONSTRUCTION PROGRAM $
4 $HeadURL: svn://dig.cs.gc.cuny.edu/snark/trunk/src/snark/signif1.c $
5 $LastChangedRevision: 90 $
6 $Date: 2014-07-02 17:31:12 -0400 (Wed, 02 Jul 2014) $
8 ***********************************************************
10 This function computes and stores the significance levels
13 iexp - experiment number.
14 nrun - number of runs in the current experiment.
15 tot_PAIRS - number of phantoms with PAIRed structures used for a given experiment.
16 compare - counter for the number of COMPAREs read in so far.
17 niters - number of iterations to be compared.
18 itr1 - array of length niters containing the iteration numbers for the first algorithm.
19 itr2 - array of length niters containing the iteration numbers for the second algorithm.
20 sigfl - file pointer to the file which stores the significance levels.
21 fom - character string denoting the figure of merit.
22 keywrd1 - string containing the keyword which defines the first algorithm.
23 keywrd2 - string containing the keyword which defines the second algorithm.
24 lowden - low clip value for pointwise accuracy calculation.
25 highden - high clip value for pointwise accuracy calculation.
32 #include "experimenter.h"
33 #include "read_fomfile.h"
36 void signif(int iexp, int nrun, int tot_PAIRS, int compare, int niters, int* itr1, int* itr2, FILE* sigfl, char* fom, char* keywrd1, char* keywrd2, float lowden, float highden)
39 double *fom1, *fom2, fom_diff, *sum_diff, *var, *sum_fom1, *sum_fom2;
41 // go here only if, for hit-ratio, there are no PAIRed structures
42 if (strstr(fom, "Hit-ratio") != NULL)
46 fprintf(sigfl, "\n \t \t FIGURE OF MERIT: %s\n", fom);
47 fprintf(sigfl, "%s \t %s \t Significance Level\n", keywrd1,
50 for (i = 0; i < niters; i++)
52 "%d \t %d \t No paired structures in this experiment\n",
58 // allocate memory for various arrays
60 // array to store figures of merit for algorithm 1
61 fom1 = (double *) malloc(niters * sizeof(double));
63 // array to store figures of merit for algorithm 2
64 fom2 = (double *) malloc(niters * sizeof(double));
66 // array to store sum of the differences between the foms for the two algorithms
67 sum_diff = (double *) malloc(niters * sizeof(double));
69 // array to store sum of the squares of this difference
70 var = (double *) malloc(niters * sizeof(double));
72 // array to store sum of foms for algorithm 1
73 sum_fom1 = (double *) malloc(niters * sizeof(double));
75 // array to store sum of foms for algorithm 2
76 sum_fom2 = (double *) malloc(niters * sizeof(double));
78 for (j = 0; j < niters; j++) // initialize arrays
86 for (i = 0; i < nrun; i++)
88 // read in foms and iteration numbers for both algorithms
89 read_fomfile(iexp, i + 1, compare, niters, fom, fom1, fom2);
90 for (j = 0; j < niters; j++)
93 a) compute difference between foms of the two algorithms
94 b) sum these differences
95 c) sum the squares of these differences
96 d) sum the foms for algorithms 1 and 2
99 fom_diff = fom1[j] - fom2[j];
100 sum_diff[j] = sum_diff[j] + fom_diff;
101 var[j] = var[j] + (fom_diff * fom_diff);
102 sum_fom1[j] = sum_fom1[j] + fom1[j];
103 sum_fom2[j] = sum_fom2[j] + fom2[j];
107 // For hit-ratio, number of phantoms = tot_PAIRS. While for other foms number of phantoms = nrun
109 if (strstr(fom, "Hit-ratio") != NULL)
114 for (j = 0; j < niters; j++)
116 // compute the average fom for algorithms 1 and 2
117 sum_fom1[j] = sum_fom1[j] / nrun;
118 sum_fom2[j] = sum_fom2[j] / nrun;
124 // calculate significance levels. Note that if var[j]=0.0, the significance level for than iteration is 0.5.
125 sum_diff[j] = sum_diff[j] / sqrt(var[j]);
126 sum_diff[j] = 0.5 * erf(sum_diff[j] / sqrt(2.0));
127 sum_diff[j] = 0.5 - dabs(sum_diff[j]);
131 // print results and free memory
132 if (strstr(fom, "Pointwise Accuracy") != NULL)
134 if (lowden == 0.0 && highden == 0.0) fprintf(sigfl, "\n \t FIGURE OF MERIT: %s. NO CLIPPING\n", fom);
135 else fprintf(sigfl, "\n \t FIGURE OF MERIT: %s. CLIP VALUES ARE %.3f AND %.3f\n", fom, lowden, highden);
137 else fprintf(sigfl, "\n \t \t FIGURE OF MERIT: %s\n", fom);
139 fprintf(sigfl, "%s \tmean\t\t\t%s\tmean\t\t\tsignificance level\n", keywrd1, keywrd2);
140 for (i = 0; i < niters; i++) fprintf(sigfl, "%d\t%.20f %d\t%.20f %.20f\n", itr1[i], sum_fom1[i], itr2[i], sum_fom2[i], sum_diff[i]);
150 // function to return the absolute value
151 double dabs(double x)
153 return x < 0 ? -x : x;