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/analyze2.c $
5 $LastChangedRevision: 137 $
6 $Date: 2014-07-15 16:38:33 -0400 (Tue, 15 Jul 2014) $
8 ***********************************************************
10 Previously part of SuperSNARK
17 #include "experimenter.h"
25 * This function reads the information in the file containing the comparisons
26 * to be made and coordinates the calculation and storage of the significance
30 * iexp - experiment number.
31 * nrun - number of runs in a given experiment.
32 * tot_PAIRS - number of phantoms with PAIRed structures used for a given
34 * anaflname - name of file containing comparisons to be made.
39 void analyze2(int iexp, int nrun, int tot_PAIRS, char* anaflname)
41 int *itr1, *itr2, niters, stru, poin, hitr, usr1, usr2, usr3, usr4, usr5, iroi, klds, wsqd, compare = 0, mode_flag = 0;
44 char string[MAXLINESIZE], key1[50], sigflname[MAXLINESIZE], key2[50],
45 keywrd1[50], keywrd2[50];
47 float lowden = 0.0, highden = 0.0;
51 if ((anafl = fopen(anaflname, "r")) == NULL)
53 errorc("in analyze2.c: error in opening file ", anaflname);
56 fgets(string, sizeof(string), anafl); // get name of file to store significance levels
57 while (isSkip(string)) //jump over comment lines and blank lines
59 fgets(string, sizeof(string), anafl);
62 for (i = strlen(string) - 1; i >= 0; i--)
64 if (iscntrl(string[i]) || string[i] == ' ')
67 if (strlen(string) == 0)
68 errorc("in analyze2.c: error in opening file ", sigflname);
70 strcpy(sigflname, string);
71 sprintf(sigflname, "%s.%d", sigflname, iexp);
73 if ((sigfl = fopen(sigflname, "w")) == NULL)
75 errorc("in analyze2.c: error in opening file ", sigflname);
78 fgets(string, sizeof(string), anafl); /* second line is either a MODE
79 * command or a COMPARE command */
80 while (isSkip(string)) //jump over comment lines and blank lines
82 fgets(string, sizeof(string), anafl);
85 if (strncasecmp(string, "mode", 4) == 0)
87 /* set mode_flag to 1 if second line is MODE and read in
90 sscanf(string, "%*s %f %f", &lowden, &highden);
94 { /* if second line is MODE */
95 fgets(string, sizeof(string), anafl); /* third line is COMPARE */
96 while (isSkip(string)) //jump over comment lines and blank lines
98 fgets(string, sizeof(string), anafl);
102 /* at this point string contains the COMPARE command */
104 while (strncasecmp(string, "end", 3) != 0)
106 /* beginning of while loop */
108 if (strncasecmp(string, "comp", 4) == 0)
110 /* If the string just read in has the COMPARE command:
111 * (1) increment compare counter and read in the two keywords.
112 * (2) get flags for the figures of merit (FOMs)
113 * (3) get the iteration numbers to be compared
114 * (4) compute significance for these iteration numbers.
115 * (5) free arrays for next set of iteration numbers. */
117 compare++; /* keeps count of number of COMPAREs read in */
118 sscanf(string, "%*s%s %s", key1, key2);
119 strncpy(keywrd1, key1, 4);
120 strncpy(keywrd2, key2, 4);
123 getfom(string, &stru, &poin, &hitr, &usr1, &usr2, &usr3, &usr4, &usr5, &iroi, &klds, &wsqd);
124 getiters(anafl, &itr1, &itr2, &niters, string);
125 computesig(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, keywrd1, keywrd2, stru, poin, hitr, iroi, klds, wsqd, usr1, usr2, usr3, usr4, usr5, lowden, highden);
130 if (strncasecmp(string, "mode", 4) == 0)
132 /* If string just read in has the MODE command then read in
133 * clip values and read the next string (which has the COMPARE
136 sscanf(string, "%*s %f %f", &lowden, &highden);
137 fgets(string, sizeof(string), anafl);
138 while (isSkip(string)) //jump over comment lines and blank lines
140 fgets(string, sizeof(string), anafl);
143 } /* end of while loop */
150 * This function coordinates the calculation and storage of the significance
153 * iexp - experiment number.
154 * nrun - number of runs for experiment iexp.
155 * tot_PAIRS - number of phantoms with PAIRed structures for experiment iexp.
156 * compare - number of COMPARE commands read in so far.
157 * niters - number of iterations to be compared.
158 * itr1 - array of length niters containing the iteration numbers to be
159 * compared for the first algorithm.
160 * itr2 - array of length niters containing the iteration numbers to be
161 * compared for the second algorithm.
162 * sigfl - file pointer to the file which stores the significance levels
163 * keywrd1 - keyword which defines the first algorithm.
164 * keywrd2 - keyword which defines the second algorithm.
165 * stru - equals 1 if structural accuracy is to be computed, else equals 0.
166 * poin - equals 1 if pointwise accuracy is to be computed, else equals 0.
167 * hitr - equals 1 if hit-ratio is to be computed, else equals 0.
168 * user - equals 1 if user-defined FOM is to be computed, else equals 0.
169 * lowden - lower clip value of MODE command.
170 * highden - higher clip value of MODE command.
173 void computesig(int iexp, int nrun, int tot_PAIRS, int compare, int niters, int* itr1, int* itr2, FILE* sigfl, char* keywrd1, char* keywrd2, int stru, int poin, int hitr, int iroi, int klds, int wsqd, int usr1, int usr2, int usr3, int usr4, int usr5, float lowden, float highden)
175 // Depending on the values of the FOM flags compute and print the corresponding significance levels
179 signif(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, "Structural Accuracy", keywrd1, keywrd2, lowden, highden);
184 signif(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, "Pointwise Accuracy", keywrd1, keywrd2, lowden, highden);
189 signif(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, "Hit-ratio", keywrd1, keywrd2, lowden, highden);
194 signif(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, "Imagewise-ROI", keywrd1, keywrd2, lowden, highden);
199 signif(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, "Kullback-Leibler distance", keywrd1, keywrd2, lowden, highden);
204 signif(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, "Weighted squared distance", keywrd1, keywrd2, lowden, highden);
209 signif(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, "User-defined-1", keywrd1, keywrd2, lowden, highden);
214 signif(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, "User-defined-2", keywrd1, keywrd2, lowden, highden);
219 signif(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, "User-defined-3", keywrd1, keywrd2, lowden, highden);
224 signif(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, "User-defined-4", keywrd1, keywrd2, lowden, highden);
229 signif(iexp, nrun, tot_PAIRS, compare, niters, itr1, itr2, sigfl, "User-defined-5", keywrd1, keywrd2, lowden, highden);