template<class T>
Calculates a confusion matrix based on the AP. This calculates how much AP is lost to non-target classes. annotations: Arrray of pointers to AnnotationTable. Size = nClasses tc: target class nClasses: total number of classes Definition at line 23 of file AveragePrecisionConfusion.h. References Impala::Core::Table::AnnotationTable::GetNrPositive(), ILOG_VAR, and Impala::Application::DemoCamera2d::precision. Referenced by Impala::Application::Util::DoAPConfusion(). 00024 { 00025 ILOG_VAR(Impala.Core.Table.AveragePrecisionConfusion); 00026 int positiveCount = 0; 00027 Real64* conf; 00028 if (topN == -1) 00029 { 00030 topN = rank->Size(); 00031 conf = new Real64[topN]; 00032 00033 for (int i=0 ; i < topN ; i++) 00034 conf[i] = 0; 00035 } 00036 00037 // Get total positives 00038 int totPos = annotations[tc]->GetNrPositive(); 00039 00040 for (int i=0 ; i<topN ; i++) 00041 { 00042 if (positiveCount < totPos) 00043 { 00044 Quid q = rank->Get1(i); 00045 if (annotations[tc]->IsPositive(q)) 00046 { 00047 positiveCount++; 00048 double precision = ((double)positiveCount)/((double)(i+1)); 00049 conf[tc] += precision; 00050 } 00051 else // Calculate AP loss (Best Case) 00052 { 00053 // Direct Loss 00054 Real64 directLoss = ((double) positiveCount + 1) / ((double)(i+1)); 00055 00056 00057 // Minimum Future Loss 00058 // (Occurs when next all positive examples are encountered) 00059 int posLeft = totPos - positiveCount - 1; 00060 Real64 futureLoss = 0; 00061 if (posLeft > 0) 00062 { 00063 for (int j=i+2; j<=i+1+posLeft ; j++) 00064 { 00065 futureLoss += 1.0 / (double) j; 00066 } 00067 } 00068 00069 // Maximum extra gain 00070 // (Occurs when removed example is found directly after rest) 00071 Real64 maxGain = totPos / ((double) i + (double) posLeft + 2.0); 00072 00073 // Total 00074 Real64 totalLoss = directLoss + futureLoss - maxGain; 00075 00076 // Now determine where loss goes 00077 Real64 totPosClasses = 0; 00078 for (int j = 0; j < nClasses ; j++) 00079 { 00080 Quid q = rank->Get1(i); 00081 if (annotations[j]->IsPositive(q)) 00082 totPosClasses+= 1; 00083 } 00084 00085 // Allocate loss 00086 for (int j = 0; j < nClasses; j++) 00087 { 00088 Quid q = rank->Get1(i); 00089 if (annotations[j]->IsPositive(q)) 00090 conf[j] += totalLoss / totPosClasses; 00091 } 00092 } 00093 } 00094 } 00095 if (annotations[tc]->GetNrPositive() > 0) 00096 for(int i=0; i<topN; i++) 00097 conf[i] /= annotations[tc]->GetNrPositive(); 00098 return conf; 00099 }
Here is the call graph for this function:
|