I've read this article about Mean Average Precision (MAP).
Now, in my C++ code I have an std::vector<std::string> queries
, where queries[i]
is the identifier of the i-th
query.
In addition, I have a std::vector<std::vector<std::string> truePositives
where truePositives[i][z]
is the z
-th true positive correspondent to the i
-th query. Since the actual order in truePositives[i]
isn't important, I could have used std::vector<std::set<std::string>>
, but whatever...
Finally, I have a std::vector<std::string> topkTest
where topkTest[j]
is the j-th
element in the top-k
ranked list returned by the system for the given query, where k = min(data set size, 10k)
(following the suggestion in this question).
Here you can find my code to compute the MAP. I post it here because there is no actual way to say if the returned result (the map
value) is correct or not.
float map = 0;
for(size_t i=0; i<queries.size(); i++){
std::vector<std::string> topkTest;
//populate topkTest somehow using k
float correct = 0;
float ap = 0;
for(size_t j=0; j<topkTest.size(); j++){
//if topkTest[j] belongs to the true positives, increment the number of correct images
if(std::find(truePositives.begin(), truePositives.end(), topkTest[j]) != queries.end())
ap += ++correct / (j+1);
map += ap / topkTest.size();
}
map /= queries.size(),
What do you think about this?