Algorithm Search⌘K

Definitioncore

Mean average precision

Also called MAP metric.

The mean over queries of average precision, the mean of the precision values at the ranks of the relevant documents.

Average precision (AP) scores one ranking for one query. It takes the precision at the rank of each relevant document, counts 0 for each relevant document that the ranking does not return, and divides the sum by the number of relevant documents. Mean average precision (MAP) is the arithmetic mean of AP over the queries of a test collection. AP is the area under the uninterpolated precision-recall curve, so one number rewards both early precision and high recall.

Definition

Input. A ranking d(1),…,d(n)d_{(1)}, \ldots, d_{(n)} of nn distinct document ids, with ranks starting at 1, and graded judgments g(d)∈{0,1,2,…}g(d) \in \{0, 1, 2, \ldots\}, where a document that is not judged has g(d)=0g(d) = 0. A document is relevant when g(d)≥1g(d) \ge 1. reli=1\mathrm{rel}_i = 1 when d(i)d_{(i)} is relevant, and P@i\mathrm{P@}i is the precision at rank ii. RR is the number of relevant documents in the judgments.

Value. When R≥1R \ge 1,

AP=1R∑i=1nreli P@i.\mathrm{AP} = \frac{1}{R} \sum_{i=1}^{n} \mathrm{rel}_i \, \mathrm{P@}i .
  • Gain: binary, with the threshold g≥1g \ge 1. A grade 2 document counts the same as a grade 1 document.
  • Discount: there is no fixed discount per rank. The relevant document at rank ii adds P@i/R\mathrm{P@}i / R, which is smaller when more nonrelevant documents come before it.
  • Normalization: division by RR, the number of relevant documents in the judgments. It is not the number of relevant documents retrieved. A relevant document that is not in the ranking adds 0 to the sum and still counts in RR.
  • Cutoff: none. The whole ranking counts. TREC runs return at most 1000 documents per topic, so the TREC value is in effect AP over the first 1000 ranks.
  • Ties: AP depends on the order of tied scores. This area orders by score descending, then by document id ascending. trec_eval orders tied documents by document number in reverse lexical order, and the toy example below shows that this changes AP from 0.8056 to 0.5889.
  • No relevant documents (R=0R = 0): undefined, because the sum is empty and the divisor is 0. Return None and leave the query out of the mean. trec_eval evaluates only the queries that are in its judgments file. For such a query with no relevant document it reports 0 and counts it in the mean.

MAP is the arithmetic mean of AP over the queries with R≥1R \ge 1. GMAP, the geometric mean, is exp⁡(1m∑qln⁡APq)\exp\big(\frac{1}{m}\sum_{q} \ln \mathrm{AP}_q\big) over the same mm queries. An AP of 0 makes the logarithm undefined, so implementations put a small floor under AP first; trec_eval takes the log of max⁡(AP,MIN_GEO_MEAN)\max(\mathrm{AP}, \mathrm{MIN\_GEO\_MEAN}) (file m_gm_map.c). GMAP gives more weight to the queries where a system does badly. The NIST appendix says that it came from the TREC 2004 robust track.

Claim 1 (area). For r∈(0,1]r \in (0, 1], let p(r)p(r) be the precision at the smallest rank whose recall is at least rr, and let p(r)=0p(r) = 0 if no rank of the ranking reaches recall rr. Then AP=∫01p(r) dr\mathrm{AP} = \int_0^1 p(r)\,dr.

Proof. Let i1<i2<⋯<imi_1 < i_2 < \cdots < i_m be the ranks of the relevant documents in the ranking, so m≤Rm \le R. Recall at rank kk is (number of relevant documents in the first kk ranks)/R/R. It changes only at the ranks iji_j, where it goes from (j−1)/R(j-1)/R to j/Rj/R. Take rr in the interval ((j−1)/R,j/R]((j-1)/R, j/R] with j≤mj \le m. The first rank with recall at least rr is the first rank with recall at least j/Rj/R, which is iji_j. So p(r)=P@ij=j/ijp(r) = \mathrm{P@}i_j = j/i_j on that interval. For j>mj > m, no rank reaches recall j/Rj/R, so p(r)=0p(r) = 0 on the interval. Each interval has length 1/R1/R, so

∫01p(r) dr=∑j=1m1R P@ij+∑j=m+1R1R⋅0=AP.□\int_0^1 p(r)\,dr = \sum_{j=1}^{m} \frac{1}{R}\,\mathrm{P@}i_j + \sum_{j=m+1}^{R} \frac{1}{R}\cdot 0 = \mathrm{AP}. \quad \square

Manning, Raghavan and Schuetze (Section 8.4) state this as an approximation to the area under the uninterpolated curve. With pp defined as above, a step function, the equality is exact.

Claim 2 (range). 0≤AP≤10 \le \mathrm{AP} \le 1, and AP=1\mathrm{AP} = 1 exactly when the first RR ranks hold all the relevant documents.

Proof. With the notation of Claim 1, the jj-th relevant document is at rank ij≥ji_j \ge j, so P@ij=j/ij≤1\mathrm{P@}i_j = j/i_j \le 1. The sum has m≤Rm \le R terms, each at most 1, so AP≤m/R≤1\mathrm{AP} \le m/R \le 1. Equality needs m=Rm = R and ij=ji_j = j for every jj, that is, the relevant documents fill ranks 1 to RR. Conversely, such a ranking has every term equal to 1. □\square

Claim 3. If R=1R = 1, AP equals the reciprocal rank of the one relevant document, or 0 if it is not retrieved.

Proof. The sum has at most one term, P@i1=1/i1\mathrm{P@}i_1 = 1/i_1, and R=1R = 1. □\square

So mean reciprocal rank and MAP agree on a query set where every query has exactly one relevant document.

Examples and non-examples

The fixed run on the toy collection

Query q1 "sorted array search" has the relevant documents d1 (grade 2), d2 and d8 (grade 1), so R=3R = 3. The fixed run ranks 1, 6, 8, 2, 4 with the tie rule of this area. The relevant documents are at ranks 1, 3 and 4.

Rank of relevant document 1 3 4
Relevant so far 1 2 3
Precision at that rank 1 2/3 3/4
AP=13(1+23+34)=13⋅2912=2936≈0.8056.\mathrm{AP} = \frac{1}{3}\left(1 + \frac{2}{3} + \frac{3}{4}\right) = \frac{1}{3}\cdot\frac{29}{12} = \frac{29}{36} \approx 0.8056.

By Claim 1, the same number is the area under the step function that is 1 for recall in (0,1/3](0, 1/3], 2/32/3 on (1/3,2/3](1/3, 2/3] and 3/43/4 on (2/3,1](2/3, 1]: (1+2/3+3/4)/3=29/36(1 + 2/3 + 3/4)/3 = 29/36.

Ties change AP

The scores tie d1 with d6 at 2.0 and d2 with d4 at 1.0. There are four orders of the tied documents.

Order Relevant at ranks AP
1, 6, 8, 2, 4 (this area) 1, 3, 4 29/36 = 0.8056
1, 6, 8, 4, 2 1, 3, 5 34/45 = 0.7556
6, 1, 8, 2, 4 2, 3, 4 23/36 = 0.6389
6, 1, 8, 4, 2 (trec_eval) 2, 3, 5 53/90 = 0.5889

For the trec_eval order, AP=(1/2+2/3+3/5)/3=(53/30)/3=53/90\mathrm{AP} = (1/2 + 2/3 + 3/5)/3 = (53/30)/3 = 53/90. One run file thus gives 0.8056 or 0.5889, depending only on the tie rule. The tie-aware AP of McSherry and Najork (2008) is the mean over the four orders: (290+272+230+212)/(4⋅360)=1004/1440=251/360≈0.6972(290 + 272 + 230 + 212)/(4 \cdot 360) = 1004/1440 = 251/360 \approx 0.6972. Their paper shows how to get this mean without listing the orders, which matters when a tie group is large.

MAP over several queries

Query RR Ranking Relevant at ranks AP
q1 3 1, 6, 8, 2, 4 1, 3, 4 29/36
q2 "posting list merge" 3 8, 5, 1, 4, 2 2, 4 (d3 missing) 1/3
q3 "rank documents" 1 2, 6, 7, 1, 5 3 1/3
q4 "quantum circuit" 0 1, 2, 3, 4, 5 none None

For q2, AP=(1/2+2/4+0)/3=1/3\mathrm{AP} = (1/2 + 2/4 + 0)/3 = 1/3; the 0 is for d3, which the run does not return. For q3 the only relevant document is at rank 3, so AP=1/3\mathrm{AP} = 1/3 (Claim 3). q4 is left out.

  • MAP =(29/36+1/3+1/3)/3=(53/36)/3=53/108≈0.4907= (29/36 + 1/3 + 1/3)/3 = (53/36)/3 = 53/108 \approx 0.4907.
  • If q4 is wrongly kept with the value 0, the mean becomes 53/144≈0.368153/144 \approx 0.3681. The same run file gives two different MAP values, so a report must say how it handles queries with R=0R = 0.
  • GMAP =(29/36⋅1/3⋅1/3)1/3≈0.4473= (29/36 \cdot 1/3 \cdot 1/3)^{1/3} \approx 0.4473, lower than MAP because two of the three values are low.

Non-examples

  • Dividing by the number of relevant documents retrieved. For q2 that gives (1/2+2/4)/2=1/2(1/2 + 2/4)/2 = 1/2 instead of 1/31/3, so a run that stops early is not punished for the relevant document it never found.
  • Detection mean average precision in object detection. It matches predicted boxes to ground-truth boxes by overlap, computes an interpolated precision-recall area per class, and averages over classes. It shares the name but not the input or the formula.
  • The 11-point average of the interpolated precision-recall curve. For the fixed run on q1 it is 37/44≈0.840937/44 \approx 0.8409, not 29/3629/36, because interpolation takes the maximum precision over later ranks.
  • Normalized discounted cumulative gain, which uses the grades. AP gives d1 (grade 2) and d8 (grade 1) the same weight.
  • R-precision and AP are both normalized by RR and both reach 1 only on a ranking with all relevant documents first.
  • Mean reciprocal rank uses only the first relevant document, and equals MAP when R=1R = 1 on every query.
  • Bpref and inferred average precision are built for judgments that are far from complete. AP counts every unjudged document as nonrelevant.
  • AP and MAP are standard targets in learning to rank.

What is proved here: Claims 1 to 3, which hold for every ranking. What is only measured: how stable MAP is as a way to order systems, and how it behaves with incomplete judgments. Buckley and Voorhees (2004) report that MAP, P(10) and R-precision become unreliable when the judgments are made much less complete, while bpref stays closer to the ranking of systems under full judgments. A claim that one system has a higher MAP than another needs a paired test over the queries, such as the sign test, the Wilcoxon signed-rank test, a permutation test or a bootstrap interval, with the number of queries and the p-value.

References

  1. Christopher D. Manning, Prabhakar Raghavan and Hinrich Schuetze, Introduction to Information Retrieval, Cambridge University Press, 2008, Chapter 8, Section 8.4 (mean average precision, and the remark that it approximates the area under the uninterpolated precision-recall curve)
  2. Common Evaluation Measures, appendix to the TREC 2006 proceedings, NIST, sections on average precision (worked example with relevant documents at ranks 1, 2, 4 and 7) and on geometric MAP
  3. trec_eval, the TREC evaluation program by Chris Buckley, maintained by NIST, file m_map.c (sum of precision at each relevant retrieved document, divided by num_rel), file m_gm_map.c (log of MAX(AP, MIN_GEO_MEAN)), file form_res_rels.c (order of tied scores)
  4. Frank McSherry and Marc Najork, Computing information retrieval performance measures efficiently in the presence of tied scores, ECIR 2008, LNCS 4956, pp. 414-421, tie-aware average precision, equal to the mean over all orders of the tied documents
  5. Chris Buckley and Ellen M. Voorhees, Retrieval evaluation with incomplete information, SIGIR 2004, pp. 25-32, Sections 3 and 4 (MAP is not robust when the judgments become much less complete)
  6. Ellen M. Voorhees and Donna K. Harman (editors), TREC, Experiment and Evaluation in Information Retrieval, MIT Press, 2005, Chapter 3, Chris Buckley and Ellen M. Voorhees, Retrieval system evaluation, pp. 53-75

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/WP8DJA/text.yaml