Home || Architecture || Video Search || Visual Search || Scripts || Applications || 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     AveragePrecision(Table::AnnotationTable* annotation) :
00021         Evaluation(annotation)
00022     {
00023     }
00024 
00025     virtual double Compute(Table::AnnotationTableBaseType* table)
00026     {
00027         ILOG_DEBUG("sorting table with size = " << table->Size());
00028         Sort(table, 2, false);
00029         ILOG_DEBUG("calling ComputeSub");
00030         return ComputeSub(table);
00031     }
00032 
00033     virtual double ComputeReversed(Table::AnnotationTableBaseType* table)
00034     {
00035         Sort(table, 2, false);
00036         Reverse(table);
00037         return ComputeSub(table);
00038     }
00039 
00040 private:
00041     double ComputeSub(Table::AnnotationTableBaseType* table)
00042     {
00043         double ap=0;
00044         int positiveCount=0;
00045         for(int i=0 ; i<table->Size() ; i++)
00046         {
00047             Quid q = table->Get1(i);
00048             if(mAnnotation->IsPositive(q))
00049             {
00050                 positiveCount++;
00051                 double precision = ((double)positiveCount)/((double)(i+1));
00052                 ap += precision;
00053             }
00054         }
00055         if(positiveCount > 0)
00056             ap /= (double)positiveCount;
00057         return ap;
00058     }
00059     ILOG_VAR_DECL;
00060 };
00061 
00062 ILOG_VAR_INIT(AveragePrecision, Impala.Core.Training);
00063 
00064 }//namespace Core
00065 }//namespace Training
00066 }//namespace Impala
00067 
00068 #endif

Generated on Fri Mar 19 09:31:19 2010 for ImpalaSrc by  doxygen 1.5.1