4525a2be03092a60586be797bb58c43e53285793
[snark14.git] / src / snark / hit_ratio.c
1 /*
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/hit_ratio.c $
5  $LastChangedRevision: 80 $
6  $Date: 2014-07-01 21:01:54 -0400 (Tue, 01 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  Previously part of SuperSNARK
11  */
12
13 #include "malloc.h"
14 #include "experimenter.h"
15 #include "read_eval_phantom1.h"
16 #include "read_eval_recon1.h"
17 #include "hit_ratio.h"
18
19 /* ----------------------------- hit_ratio.c -------------------------------
20
21  This function computes the hit-ratio.
22
23  INPUTS:
24  itr1 - array of length niters containing the iteration numbers for the
25  first algorithm.
26  itr2 - array of length niters containing the iteration numbers for the
27  second algorithm.
28  niters - number of iterations to be compared.
29  pairs - array of length numpairs containing the indices of the structures
30  which are paired.
31  numpairs - number of pairs of structures.
32  keywrd1 - string containing the keyword which defines the first algorithm.
33  keywrd2 - string containing the keyword which defines the second algorithm.
34
35  OUTPUTS:
36  hit_ratio1 - array of length niters containing the hit ratio for
37  the first algorithm.
38  hit_ratio2 - array of length niters containing the hit ratio for
39  the second algorithm.
40
41  */
42
43 void hit_ratio(int* itr1, int* itr2, int niters, int* pairs, int numpairs,
44                 char* keywrd1, char* keywrd2, double* hit_ratio1, double* hit_ratio2)
45 {
46         double *phantom, *recon1, *recon2;
47         int *regions, numstr, i, j, hit1, hit2, *strarea;
48
49         /* read in abnormality index for phantom structures */
50
51         read_eval_phantom1(&regions, &numstr, &phantom, &strarea);
52
53         /* allocate memory to store abnormality indexes for
54          structures in the reconstructions*/
55
56         recon1 = (double *) malloc(numstr * sizeof(double));
57         recon2 = (double *) malloc(numstr * sizeof(double));
58
59         for (i = 0; i < niters; i++)
60         { /* read in abnormality indexes for structures in
61          the reconstructions. Initialize the arrays
62          which will store the structural accuracy */
63
64                 read_eval_recon1(&itr1[i], keywrd1, numstr, recon1);
65                 read_eval_recon1(&itr2[i], keywrd2, numstr, recon2);
66                 hit_ratio1[i] = 0.0;
67                 hit_ratio2[i] = 0.0;
68
69                 for (j = 0; j < numpairs * 2; j += 2)
70                 { /* compute hit-ratio for both algorithms */
71
72                         hit1 = (phantom[pairs[j] - 1] > phantom[pairs[j + 1] - 1])
73                                         == (recon1[pairs[j] - 1] > recon1[pairs[j + 1] - 1]);
74                         hit2 = (phantom[pairs[j] - 1] > phantom[pairs[j + 1] - 1])
75                                         == (recon2[pairs[j] - 1] > recon2[pairs[j + 1] - 1]);
76
77                         hit_ratio1[i] = hit_ratio1[i] + hit1;
78                         hit_ratio2[i] = hit_ratio2[i] + hit2;
79                 }
80                 hit_ratio1[i] = hit_ratio1[i] / numpairs; /* hit */
81                 hit_ratio2[i] = hit_ratio2[i] / numpairs; /* ratio */
82         }
83
84         free(phantom); /* free memory for next function call */
85         free(recon1);
86         free(recon2);
87         free(strarea);
88 }