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

AveragePrecision.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Training_AveragePrecision_h
00002 #define Impala_Core_Training_AveragePrecision_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 
00017 class AveragePrecision : public Evaluation
00018 {
00019 public:
00020 
00021     AveragePrecision(Table::AnnotationTable* annotation) :
00022         Evaluation(annotation)
00023     {
00024     }
00025 
00026     virtual double
00027     Compute(Table::ScoreTable* table)
00028     {
00029         Sort(table, 2, false);
00030         return ComputeSub(table);
00031     }
00032 
00033     virtual double
00034     ComputeReversed(Table::ScoreTable* table)
00035     {
00036         Sort(table, 2, false);
00037         Reverse(table);
00038         return ComputeSub(table);
00039     }
00040 
00041 private:
00042 
00043     double
00044     ComputeSub(Table::ScoreTable* table)
00045     {
00046         double ap = 0;
00047         int positiveCount = 0;
00048         for (int i=0 ; i<table->Size() ; i++)
00049         {
00050             Quid q = table->Get1(i);
00051             if (mAnnotation->IsPositive(q))
00052             {
00053                 positiveCount++;
00054                 double precision = ((double)positiveCount)/((double)(i+1));
00055                 ap += precision;
00056             }
00057         }
00058         if (positiveCount > 0)
00059             ap /= (double)positiveCount;
00060         return ap;
00061     }
00062 
00063     ILOG_VAR_DECL;
00064 
00065 };
00066 
00067 ILOG_VAR_INIT(AveragePrecision, Impala.Core.Training);
00068 
00069 }//namespace Core
00070 }//namespace Training
00071 }//namespace Impala
00072 
00073 #endif

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