00001 #ifndef Impala_Core_Training_RecallAtN_h 00002 #define Impala_Core_Training_RecallAtN_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 00021 class RecallAtN : public Evaluation 00022 { 00023 public: 00024 00025 RecallAtN(Table::AnnotationTable* annotation, int n, int totalRelevance) : 00026 Evaluation(annotation) 00027 { 00028 mN = n; 00029 mTotalRelevance = totalRelevance; 00030 } 00031 00032 virtual double 00033 Compute(Table::ScoreTable* table) 00034 { 00035 Sort(table, 2, false); 00036 00037 int positiveCount = 0; 00038 for (int i=0 ; i<table->Size() && i<mN ; i++) 00039 { 00040 Quid q = table->Get1(i); 00041 if (mAnnotation->IsPositive(q)) 00042 positiveCount++; 00043 } 00044 double recall = ((double)positiveCount)/((double)mTotalRelevance); 00045 return recall; 00046 } 00047 00048 private: 00049 00050 int mN; // N is the number at which we compute the precision. 00051 int mTotalRelevance; 00052 00053 }; 00054 00055 }//namespace Core 00056 }//namespace Training 00057 }//namespace Impala 00058 00059 #endif