template<class T>
AP on judged elements only, i.e. non-labeled quids are eliminated from the ranking. skipIsNegative indicates whether skips count as negative or are eliminated too. In case rank contains only a subset of relative to groundTruth, AP may be adjusted by setting apOfFoundOnly to true. Assumes that the first column of T contains Quids. Definition at line 124 of file AveragePrecisionSpeedup.h. References Impala::Core::Table::AnnotationTable::GetIndex(), Impala::Core::Table::AnnotationTable::GetNrPositive(), ILOG_VAR, Impala::Core::Table::AnnotationTable::IsNegative(), Impala::Core::Table::AnnotationTable::IsPositive(), Impala::Application::DemoCamera2d::precision, and Impala::Core::Table::Table::Size(). 00127 { 00128 ILOG_VAR(Impala.Core.Table.AveragePrecisionJudgedSpeedup); 00129 Real64 ap = 0; 00130 00131 Real64 pos99 = 0.999; // status = 3 00132 Real64 pos90 = 0.9; // status = 2 00133 Real64 pos10 = 0.1; // status = 1 00134 00135 Real64 curPos = 0; 00136 00137 // setting default status = 1 00138 int status = 1; 00139 Real64 curRef = pos10; 00140 00141 int totalPositive = groundTruth->GetNrPositive(); 00142 if ( 0 == totalPositive) 00143 return -1; 00144 00145 int positiveCount = 0; 00146 int curRank = 0; 00147 if (topN == -1) 00148 topN = rank->Size(); 00149 for (int i=0 ; i<topN ; i++) 00150 { 00151 Quid q = rank->Get1(i); 00152 int qIndex = groundTruth->GetIndex(q); 00153 if (qIndex == groundTruth->Size()) // not annotated 00154 continue; 00155 if (groundTruth->IsPositive(qIndex)) 00156 { 00157 positiveCount++; 00158 double precision = ((double)positiveCount)/((double)(curRank+1)); 00159 ap += precision; 00160 00161 // added by Jun Wu 00162 // compute the measure: recall 00163 curPos = positiveCount*1.0/totalPositive; 00164 00165 switch (status) { 00166 case 1: 00167 00168 if (curPos > curRef) 00169 { 00170 // reaching the point of 10% 00171 Real64 ratio = (positiveCount-1)*1.0/topN; 00172 fprintf(stdout," [1]recall=10.0%s %d / %d N= %d ratio= %f speedup= %.3f pos= %d\n", "%", positiveCount-1, totalPositive,topN, ratio, 0.1/ratio,i); 00173 status = 2; 00174 curRef = pos90; 00175 00176 } 00177 00178 break; 00179 00180 case 2: 00181 00182 if (curPos > curRef) 00183 { 00184 // reaching the point of 90% 00185 Real64 ratio = (positiveCount-1)*1.0/topN; 00186 fprintf(stdout," [2]recall=90.0%s %d / %d N= %d ratio= %f speedup= %.3f pos= %d\n", "%", positiveCount-1, totalPositive,topN, ratio, 0.9/ratio,i); 00187 status = 3; 00188 curRef = pos99; 00189 00190 } 00191 break; 00192 00193 case 3: 00194 00195 if (curPos > curRef) 00196 { 00197 // reaching the point of 99.9% 00198 Real64 ratio = (positiveCount-1)*1.0/topN; 00199 fprintf(stdout," [3]recall=99.9%s %d / %d N= %d ratio= %f speedup= %.3f pos= %d\n", "%", positiveCount, totalPositive,topN, ratio, 0.999/ratio,i+1); 00200 status = -1; 00201 curRef = 1e5; 00202 00203 } 00204 break; 00205 00206 default: 00207 00208 break; 00209 } 00210 // end of adding, by Jun Wu 00211 } 00212 if (groundTruth->IsPositive(qIndex) || skipIsNegative 00213 || groundTruth->IsNegative(qIndex)) 00214 { 00215 curRank++; 00216 } 00217 } 00218 int factor = (apOfFoundOnly) ? positiveCount : groundTruth->GetNrPositive(); 00219 if (factor > 0) 00220 ap /= factor; 00221 return ap; 00222 }
Here is the call graph for this function:
|