I'm trying to compute the Average Precision (and Mean Average Precision) on the Oxford Building image dataset.
Below there is the code that they provide for computing Average Precision. Notice that pos_set
is the union of the "optimal" and "good" images from the ground trouth set, while junk_set
is a set of not-relevant images.
void OxfordTest::computeAp(std::vector<std::string> &ranked_list){
float old_recall = 0.0;
float old_precision = 1.0;
float ap = 0.0;
size_t intersect_size = 0;
size_t i = 0;
size_t j = 0;
for ( ; i<ranked_list.size(); ++i) {
if(!pos_set.count(ranked_list[i]))
std::cin.get();
}
if (junk_set.count(ranked_list[i])) continue;
if (pos_set.count(ranked_list[i])) intersect_size++;
float recall = intersect_size / (float)pos_set.size();
float precision = intersect_size / (j + 1.0);
ap += (recall - old_recall)*((old_precision + precision)/2.0);
old_recall = recall;
old_precision = precision;
j++;
}
}
Which is something totally different from the notion given on the linked Wikipedia page. What is the correlation between these notions?
I'm more than sure that Wikipedia's notion is correct, since it corresponds with the one given in this answer and this article.
I don't understand why in the code above it is reported:
- The recall, while the Wikipedia's notion include only precision in the last formula.
- Even considering the formula with the delta recall, nobody talks about `(old_precision + precision) /2