Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

template<class T>
Real64* Impala::Core::Table::AveragePrecisionJudgedConfusion ( T *  rank,
AnnotationTable **  annotations,
int  tc,
int  nClasses,
int  topN = -1,
bool  apOfFoundOnly = false 
) [inline]

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

DOES NOT WORK!

Definition at line 113 of file AveragePrecisionConfusion.h.

References Impala::Core::Table::AnnotationTable::GetIndex(), Impala::Core::Table::AnnotationTable::GetNrPositive(), ILOG_VAR, and Impala::Application::DemoCamera2d::precision.

Referenced by Impala::Application::Util::DoAPConfusion().

00116 {
00117     ILOG_VAR(Impala.Core.Table.AveragePrecisionConfusion);
00118     int positiveCount = 0;
00119     Real64* conf;
00120     if (topN == -1)
00121     {
00122         topN = rank->Size();
00123         conf = new Real64[topN];
00124 
00125         for (int i=0 ; i < topN ; i++)
00126             conf[i] = 0;
00127     }
00128     
00129     // Get total positives
00130     int totPos = annotations[tc]->GetNrPositive();
00131 
00132     int i = 0;
00133     for (int t=0 ; t<topN ; t++)
00134     {
00135         if (positiveCount < totPos)
00136         {
00137             Quid q = rank->Get1(t);
00138             int qIndex = annotations[tc]->GetIndex(q);
00139             if (!(qIndex == annotations[tc]->Size())) // not annotated
00140             {
00141                 if (annotations[tc]->IsPositive(qIndex))
00142                 {
00143                     positiveCount++;
00144                     double precision = ((double)positiveCount)/((double)(i+1));
00145                     conf[tc] += precision;
00146                 }
00147                 else if (annotations[tc]->IsNegative(qIndex)) // Calculate AP loss (Best Case)
00148                 { 
00149                     // Direct Loss
00150                     Real64 directLoss = ((double) positiveCount + 1) / ((double)(i+1));
00151 
00152 
00153                     // Minimum Future Loss
00154                     // (Occurs when next all positive examples are encountered)
00155                     int posLeft = totPos - positiveCount - 1;
00156                     Real64 futureLoss = 0;
00157                     if (posLeft > 0)
00158                     {
00159                         for (int j=i+2; j<=i+1+posLeft ; j++)
00160                         {
00161                             futureLoss += 1.0 / (double) j;
00162                         }
00163                     }
00164 
00165                     // Maximum extra gain
00166                     // (Occurs when removed example is found directly after rest)
00167                     Real64 maxGain = totPos / ((double) i + (double) posLeft + 2.0);
00168 
00169                     // Total
00170                     Real64 totalLoss = directLoss + futureLoss - maxGain;
00171 
00172                     // Now determine where loss goes
00173                     Real64 totPosClasses = 0;
00174                     for (int j = 0; j < nClasses ; j++)
00175                     {
00176                         Quid q = rank->Get1(t);
00177                         int qInd = annotations[j]->GetIndex(q);
00178                         if (annotations[j]->IsPositive(qInd))
00179                             totPosClasses+= 1;
00180                     }
00181 
00182                     // Allocate loss
00183                     for (int j = 0; j < nClasses; j++)
00184                     {
00185                         Quid q = rank->Get1(t);
00186                         int qInd = annotations[j]->GetIndex(q);
00187                         if (annotations[j]->IsPositive(qInd))
00188                             conf[j] += totalLoss / totPosClasses;
00189                     }
00190                 }
00191                 if (annotations[tc]->IsPositive(qIndex) || annotations[tc]->IsNegative(qIndex))
00192                     i++;
00193             }
00194         }
00195     }
00196     int factor = (apOfFoundOnly) ? positiveCount : annotations[tc]->GetNrPositive();
00197     if (factor > 0)
00198         for(int i=0; i<topN; i++)
00199             conf[i] /= factor;
00200     return conf;
00201 }

Here is the call graph for this function:


Generated on Fri Mar 19 11:19:15 2010 for ImpalaSrc by  doxygen 1.5.1