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

BalancedAveragePrecision.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Training_BalancedAveragePrecision_h
00002 #define Impala_Core_Training_BalancedAveragePrecision_h
00003 
00004 #include "Core/Training/Evaluation.h"
00005 #include "Core/Table/Sort.h"
00006 //#include "Core/Table/Reverse.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Training
00013 {
00014 
00015 
00016 /*
00017  * a Balance version of AP (BAP)
00018  * see Van Gemert, Veenman, Geusebroek, "Episode-Constrained Cross-Validation in
00019  * Video Concept Retrieval", Transactions of Mulimedia (submitted :) )
00020  * It deals with the inbalance of positive shots between cross-validation folds
00021  * as will happen with episode constrained x-val since it is splitting videos
00022  * not shots.
00023  * theoretically more balanced than AP, and optimising BAP optimes AP.
00024  * however... practical... it is the same as AP when
00025  * dealing with large numbers of negative samples.
00026  */
00027 class BalancedAveragePrecision : public Evaluation
00028 {
00029 public:
00030 
00031     BalancedAveragePrecision(Table::AnnotationTable* annotation) :
00032         Evaluation(annotation)
00033     {
00034     }
00035 
00036     virtual double
00037     Compute(Table::ScoreTable* table)
00038     {
00039         Sort(table, 2, false);
00040         return ComputeSub(table);
00041 
00042     }
00043 
00044     virtual double
00045     ComputeReversed(Table::ScoreTable* table)
00046     {
00047         Sort(table, 2, false);
00048         Reverse(table);
00049         return ComputeSub(table);
00050 
00051     }
00052 
00053 private:
00054 
00055     double
00056     ComputeSub(Table::ScoreTable* table)
00057     {
00058         // first compute AP
00059         double ap = 0;
00060         int positiveCount = 0;
00061         for (int i=0 ; i<table->Size() ; i++)
00062         {
00063             Quid q = table->Get1(i);
00064             if (mAnnotation->IsPositive(q))
00065             {
00066                 positiveCount++;
00067                 double precision = ((double)positiveCount)/((double)(i+1));
00068                 ap += precision;
00069             }
00070         }
00071         if (positiveCount > 0)
00072             ap /= (double)positiveCount;
00073 
00074         // then compute WAP (worst case AP, ie: assume all perfectly-wrong)
00075         double wap = 0;
00076         double WminusR = table->Size() - positiveCount;
00077         for (int i=1 ; i<=positiveCount ; i++)
00078         {
00079             wap = wap + ((double)i)/(WminusR + (double)i);
00080         }
00081         wap /= (double)positiveCount;
00082 
00083         // finally, compute BAP
00084         double bap = 1.0;
00085         if (wap!=1.0)
00086             bap = (ap - wap)/(1-wap);
00087 
00088         return bap;    
00089     }
00090 };
00091 
00092 }//namespace Core
00093 }//namespace Training
00094 }//namespace Impala
00095 
00096 #endif

Generated on Thu Jan 13 09:04:41 2011 for ImpalaSrc by  doxygen 1.5.1