Algorithm Search⌘K

Algorithmadvanced

RankBoost

Also called Freund-Iyer-Schapire-Singer RankBoost.

Boosts weak rankers by reweighting the misordered document pairs at each round, minimizing an exponential pairwise loss.

Time
O(T (P + d N log N)) totalO(P + d N log N) per_round
Space
O(P + N) extra
Where
N = the number of documents; P = the number of crucial pairs; T = the number of rounds; d = the number of features
Properties
deterministicnot exactofflineiterative
Origin
Yoav Freund, Raj Iyer, Robert Schapire, Yoram Singer, 2003

RankBoost learns a ranking function H(x)=∑tαtht(x)H(x) = \sum_t \alpha_t h_t(x) for learning to rank by boosting on pairs. It keeps a distribution DD over the crucial pairs, the pairs (x0,x1)(x_0, x_1) where x1x_1 should rank above x0x_0. Each round picks a weak ranker hth_t that orders the heavy pairs well, gives it a weight αt\alpha_t, and multiplies the weight of each pair by eαt(ht(x0)−ht(x1))e^{\alpha_t (h_t(x_0) - h_t(x_1))}, so pairs that hth_t misorders get heavier. The AdaBoost page does this for labeled examples; here the examples are pairs and a weak ranker is any real function, so the analysis bounds the fraction of misordered pairs, not a classification error. The learning-to-rank page lists RankBoost among the pairwise methods; this page gives the algorithm, the bound rloss≤∏Zt\mathrm{rloss} \le \prod Z_t, the choice of α\alpha, the threshold weak learner, and a traced run.

In plain words

We have pairs of results where we know which one should come first. We build the scoring rule from many very simple rules, each looking at one feature and asking whether it is above a cut. Every pair has a weight, and at the start all weights are equal. In each round we choose the simple rule that gets the most weight of pairs right, and we decide how much to trust it. Then we make the pairs it got wrong heavier and the pairs it got right lighter, so the next rule focuses on the hard pairs. The final score adds the simple rules with their trust values.

The problem

The input is a set of queries with documents x∈Rdx \in \mathbb R^d and labels. The crucial pairs are the pairs (x0,x1)(x_0, x_1) of one query with label of x1x_1 greater than label of x0x_0; there are PP of them, with the initial distribution D1D_1 uniform. A weak ranker is a function h:Rd→[0,1]h : \mathbb R^d \to [0, 1]; the code uses the thresholds h(x)=[xf>θ]h(x) = [x_f > \theta]. The ranking loss of a scorer HH is the weighted fraction of crucial pairs that it does not order strictly right:

rloss(H)=∑(x0,x1)D1(x0,x1) [H(x0)≥H(x1)].\mathrm{rloss}(H) = \sum_{(x_0, x_1)} D_1(x_0, x_1)\, [H(x_0) \ge H(x_1)].

A tie counts as an error. RankBoost minimizes the exponential upper bound ∑D1eH(x0)−H(x1)\sum D_1 e^{H(x_0) - H(x_1)} of this loss greedily, one weak ranker at a time.

The algorithm

For a weak ranker hh under the distribution DD, let r=∑D(x0,x1)(h(x1)−h(x0))∈[−1,1]r = \sum D(x_0, x_1)(h(x_1) - h(x_0)) \in [-1, 1].

  1. RANKBOOST(pairs, T)
  2. 1D_1(p) ← 1 / P for each crucial pair p
  3. 2for t ← 1 to T:
  4. 3h_t ← the threshold ranker [x_f > θ] with the largest |r_t| under D_t
  5. 4α_t ← (1/2) ln((1 + r_t) / (1 - r_t))
  6. 5Z_t ← Σ_p D_t(p) e^{α_t (h_t(x_0) - h_t(x_1))}
  7. 6D_{t+1}(p) ← D_t(p) e^{α_t (h_t(x_0) - h_t(x_1))} / Z_t
  8. 7return H = Σ_t α_t h_t

Line L4 is method 3 of Freund et al. (2003), Section 3.2, which minimizes an upper bound on ZtZ_t and is the choice used in their experiments. Line L3 maximizes ∣r∣|r|, which minimizes that bound. A negative rtr_t gives a negative αt\alpha_t, which reverses the weak ranker.

Example

One query has four documents with features (0,1)(0, 1), (1,0)(1, 0), (2,2)(2, 2), (3,1)(3, 1) and labels 0, 1, 2, 1. The crucial pairs say that documents 1, 2 and 3 are above document 0, and document 2 is above documents 1 and 3: five pairs, each with weight 0.20.2 at the start.

round weak ranker rtr_t αt\alpha_t ZtZ_t 1−rt2\sqrt{1 - r_t^2} ∏Z\prod Z rloss after the round
1 [x0>0.5][x_0 > 0.5] 0.6 0.6931 0.7000 0.8000 0.7000 0.4
2 [x1>1.5][x_1 > 1.5] 0.7143 0.8959 0.5773 0.6999 0.4041 0.0
3 [x0>0.5][x_0 > 0.5] 0.5959 0.6868 0.7039 0.8030 0.2845 0.0

In round 1, three thresholds tie at r=0.6r = 0.6: [x0>0.5][x_0 > 0.5], [x0>1.5][x_0 > 1.5] and [x1>1.5][x_1 > 1.5]; the code takes the first in the order of feature and threshold. [x0>0.5][x_0 > 0.5] orders the three pairs above document 0 and ties on the two pairs above documents 1 and 3, so α1=12ln⁡4=ln⁡2\alpha_1 = \frac{1}{2}\ln 4 = \ln 2, and the two tied pairs are errors, rloss=0.4\mathrm{rloss} = 0.4. Their weights grow from 0.20.2 to 2/72/7, and the other three fall to 1/71/7. Round 2 picks [x1>1.5][x_1 > 1.5], which puts document 2 on top, with r=1/7+2/7+2/7=5/7r = 1/7 + 2/7 + 2/7 = 5/7. After it, every pair is ordered right. At each round, ZtZ_t is below 1−rt2\sqrt{1 - r_t^2} and the ranking loss is below ∏Z\prod Z, as the proof requires.

Correctness

The proof in proofs/correctness.md shows:

  • The bound. Unrolling line L6 gives DT+1=D1eH(x0)−H(x1)/∏tZtD_{T+1} = D_1 e^{H(x_0) - H(x_1)} / \prod_t Z_t. Since DT+1D_{T+1} sums to 1 and eu≥[u≥0]e^u \ge [u \ge 0], rloss(H)≤∏tZt\mathrm{rloss}(H) \le \prod_{t} Z_t. This is the theorem of Freund et al. (2003), Section 3, and it holds after every round, for any choice of αt\alpha_t.
  • The choice of α\alpha. For hh with values in [0,1][0, 1], convexity of eαue^{\alpha u} gives Z≤1−r2eα+1+r2e−αZ \le \frac{1 - r}{2} e^{\alpha} + \frac{1 + r}{2} e^{-\alpha}, minimized by the α\alpha of line L4 at the value 1−r2\sqrt{1 - r^2}. So rloss(H)≤exp⁡(−12∑trt2)\mathrm{rloss}(H) \le \exp(-\frac{1}{2} \sum_t r_t^2).
  • Exact minimum for 0-1 rankers. For h∈{0,1}h \in \{0, 1\}, Z(α)=W−1e−α+W0+W1eαZ(\alpha) = W_{-1} e^{-\alpha} + W_0 + W_1 e^{\alpha} is minimized at α=12ln⁡(W−1/W1)\alpha = \frac{1}{2}\ln(W_{-1}/W_1), method 2 of the paper. It can give a smaller ZZ than line L4.
  • The weak learner. Line L3 tries the midpoint between each two consecutive distinct values of each feature, which covers every distinct threshold ranker.

All of this is about the training pairs. How well HH orders the pairs of new queries is measured, not proved here.

Proof: The RankBoost ranking loss is at most the product of the normalizers, and each normalizer is at most the square root of 1 minus r squaredfull

The input is a list of NN crucial pairs (x0,x1)(x_0, x_1), each saying that x1x_1 must rank above x0x_0, and a distribution D1D_1 over them; the code uses the uniform D1D_1. Round tt picks a weak ranker ht:X→[0,1]h_t : X \to [0, 1] and a real αt\alpha_t, and sets

Dt+1(x0,x1)=Dt(x0,x1) eαt(ht(x0)−ht(x1))Zt,Zt=∑(x0,x1)Dt(x0,x1) eαt(ht(x0)−ht(x1)).D_{t+1}(x_0, x_1) = \frac{D_t(x_0, x_1)\, e^{\alpha_t (h_t(x_0) - h_t(x_1))}}{Z_t}, \qquad Z_t = \sum_{(x_0, x_1)} D_t(x_0, x_1)\, e^{\alpha_t (h_t(x_0) - h_t(x_1))}.

The final ranker is H=∑t≤TαthtH = \sum_{t \le T} \alpha_t h_t, and its ranking loss is rloss(H)=∑D1(x0,x1) [H(x0)≥H(x1)]\mathrm{rloss}(H) = \sum D_1(x_0, x_1)\, [H(x_0) \ge H(x_1)], so a tie counts as an error. This is the RankBoost of Freund et al. (2003), Figure 1.

Theorem 1 (the bound). rloss(H)≤∏t=1TZt\mathrm{rloss}(H) \le \prod_{t=1}^{T} Z_t.

Proof. Unroll the update. By induction on TT,

DT+1(x0,x1)=D1(x0,x1) eH(x0)−H(x1)∏t≤TZt.D_{T+1}(x_0, x_1) = \frac{D_1(x_0, x_1)\, e^{H(x_0) - H(x_1)}}{\prod_{t \le T} Z_t}.

DT+1D_{T+1} sums to 1, so ∏tZt=∑D1(x0,x1) eH(x0)−H(x1)\prod_t Z_t = \sum D_1(x_0, x_1)\, e^{H(x_0) - H(x_1)}. Each term is at least D1(x0,x1) [H(x0)≥H(x1)]D_1(x_0, x_1)\, [H(x_0) \ge H(x_1)], because eu≥1e^u \ge 1 for u≥0u \ge 0 and eu>0e^u > 0 always. □\square

The same argument holds for every prefix HT=∑t≤TαthtH_T = \sum_{t \le T} \alpha_t h_t, so the bound holds after each round. It is the theorem of Freund et al. (2003), Section 3.

Lemma 2 (method 3). Let hh take values in [0,1][0, 1] and let r=∑D(x0,x1)(h(x1)−h(x0))r = \sum D(x_0, x_1)(h(x_1) - h(x_0)), so ∣r∣≤1|r| \le 1. For every α\alpha,

Z(α)≤1−r2eα+1+r2e−α,Z(\alpha) \le \frac{1 - r}{2} e^{\alpha} + \frac{1 + r}{2} e^{-\alpha},

and for ∣r∣<1|r| < 1 the right side is smallest at α=12ln⁡1+r1−r\alpha = \frac{1}{2} \ln \frac{1 + r}{1 - r}, where it equals 1−r2\sqrt{1 - r^2}. So with this α\alpha, Z≤1−r2Z \le \sqrt{1 - r^2}.

Proof. Put u=h(x0)−h(x1)∈[−1,1]u = h(x_0) - h(x_1) \in [-1, 1]. By convexity of u↦eαuu \mapsto e^{\alpha u}, eαu≤1+u2eα+1−u2e−αe^{\alpha u} \le \frac{1 + u}{2} e^{\alpha} + \frac{1 - u}{2} e^{-\alpha}. Take the DD-weighted sum and use ∑Du=−r\sum D u = -r. The right side aeα+be−αa e^{\alpha} + b e^{-\alpha} with a=(1−r)/2a = (1 - r)/2 and b=(1+r)/2b = (1 + r)/2 is smallest at e2α=b/ae^{2\alpha} = b/a, with the value 2ab=1−r22\sqrt{ab} = \sqrt{1 - r^2}. □\square

Line L4 of the code uses this α\alpha, and line L5 computes ZZ exactly. Since 1−r2≤e−r2/2\sqrt{1 - r^2} \le e^{-r^2/2}, Theorem 1 gives rloss(H)≤exp⁡(−12∑trt2)\mathrm{rloss}(H) \le \exp(-\frac{1}{2} \sum_t r_t^2): if every round has ∣rt∣≥γ>0|r_t| \ge \gamma > 0, the ranking loss on the training pairs falls at least as fast as e−γ2T/2e^{-\gamma^2 T / 2}.

Lemma 3 (method 2 for {0,1}\{0, 1\} rankers). For hh with values in {0,1}\{0, 1\}, let Wb=∑D(x0,x1) [h(x0)−h(x1)=b]W_b = \sum D(x_0, x_1)\, [h(x_0) - h(x_1) = b] for b∈{−1,0,1}b \in \{-1, 0, 1\}. Then Z(α)=W−1e−α+W0+W1eαZ(\alpha) = W_{-1} e^{-\alpha} + W_0 + W_{1} e^{\alpha}, and when W−1,W1>0W_{-1}, W_1 > 0 its minimum is at α=12ln⁡(W−1/W1)\alpha = \frac{1}{2} \ln (W_{-1} / W_1), with the value W0+2W−1W1W_0 + 2\sqrt{W_{-1} W_1}. Also r=W−1−W1r = W_{-1} - W_1.

Proof. The value of eαue^{\alpha u} depends only on u∈{−1,0,1}u \in \{-1, 0, 1\}; group the pairs by uu. The minimum of ae−α+beαa e^{-\alpha} + b e^{\alpha} is 2ab2\sqrt{ab} at e2α=a/be^{2\alpha} = a/b. For rr, h(x1)−h(x0)=−uh(x_1) - h(x_0) = -u. □\square

Method 2 gives the exact minimum of ZZ for a {0,1}\{0, 1\} ranker, and method 3 a bound on it. The code uses method 3, with α\alpha from rr, as do the experiments of the paper. For the same ranker, method 2 can give a smaller ZZ than method 3, since W0+2W−1W1≤1−r2W_0 + 2\sqrt{W_{-1} W_1} \le \sqrt{1 - r^2} always.

Lemma 4 (the weak learner). Line L3 returns a threshold ranker h(x)=[xf>θ]h(x) = [x_f > \theta] with the largest ∣r∣|r| over all features ff and all real θ\theta.

Proof. For a fixed ff, hh depends on θ\theta only through the set of values of xfx_f above θ\theta. Below the smallest value or at or above the largest, hh is constant and r=0r = 0. Between two consecutive distinct values, every θ\theta gives the same hh, and the code tries the midpoint of each such interval. So it tries every distinct nonconstant threshold ranker, and keeps the one of largest ∣r∣|r|. □\square

Maximizing ∣r∣|r| minimizes the bound 1−r2\sqrt{1 - r^2} of Lemma 2, which is the choice of Freund et al. (2003), Section 4. A negative rr gives a negative α\alpha, which reverses the ranker.

Remark (clipping). If ∣r∣=1|r| = 1, the chosen ranker orders every pair of positive weight the right way (or every pair the wrong way), and α\alpha would be infinite. The code clips ∣r∣|r| to 1−10−101 - 10^{-10}, which gives α≈11.9\alpha \approx 11.9 and Z≤1−r2≈1.4⋅10−5Z \le \sqrt{1 - r^2} \approx 1.4 \cdot 10^{-5}. Theorem 1 does not depend on how α\alpha is chosen, so it still holds.

What is not proved. Theorem 1 bounds the loss on the training pairs. The paper also studies generalization under assumptions on how the data are drawn; that analysis is not used here, and the quality on new queries is a matter of measurement.

The tests in impl/python/test_rankboost.py check the choice of each weak ranker against a brute force over all features and all observed values, the formula for α\alpha, ZtZ_t against a direct sum and against 1−rt2\sqrt{1 - r_t^2}, r=W−1−W1r = W_{-1} - W_1, Theorem 1 after every round on random data, Lemma 3 by a grid search over α\alpha, the clipping, the rule that ties are errors, and the worked example of the page.

Complexity

Write π(x)=∑x0D(x0,x)−∑x1D(x,x1)\pi(x) = \sum_{x_0} D(x_0, x) - \sum_{x_1} D(x, x_1) for each document, the weight of pairs where xx should be above minus the weight where it should be below. Then r=∑xh(x) π(x)r = \sum_x h(x)\, \pi(x), so after computing π\pi in O(P)O(P), all thresholds of one feature are scored in one pass over the documents sorted by that feature. With the sorted orders kept from the start, a round costs O(P+dN)O(P + d N); sorting anew costs O(P+dNlog⁡N)O(P + d N \log N). Lines L5 and L6 cost O(P)O(P). The space is O(P+N)O(P + N). The code in this repository computes rr directly for each candidate, which is O(dNP)O(d N P) per round and is meant only as a reference. Predicting a document costs O(T)O(T).

Properties

  • The bound needs no assumption. rloss≤∏Zt\mathrm{rloss} \le \prod Z_t holds for any weak rankers and any αt\alpha_t.
  • Fast training loss decay. If every round has ∣rt∣≥γ|r_t| \ge \gamma, the training ranking loss is at most e−γ2T/2e^{-\gamma^2 T / 2}.
  • Scale free features. Threshold rankers depend only on the order of feature values, so monotone transforms of a feature change nothing.
  • Exponential weights. Pairs that stay misordered gain weight exponentially, so label noise can dominate later rounds, as in AdaBoost.
  • Equal weight per pair. The loss knows nothing about positions in the list, like the Ranking SVM and RankNet.

Variants and improvements

  • RankBoost.B. For bipartite feedback, relevant against irrelevant, Freund et al. (2003), Section 3.3, keep one weight per document instead of one per pair, which reduces the cost from O(P)O(P) to O(N)O(N) per round. The ranking loss is then the fraction of relevant-irrelevant pairs in the wrong order, which is one minus the area under the ROC curve when ties count as errors.
  • Missing features. The weak rankers of Freund et al. (2003), Section 4, give a default value qdefq_{\text{def}} to documents for which a feature is missing.
  • Method 2. For 0-1 rankers, choose α\alpha by the exact minimum of ZZ and the weak ranker by the smallest such ZZ.
  • Combining rankings. Each feature can be the score of another ranker, which makes RankBoost a learned form of rank aggregation, the setting the paper started from.
  • Boosted trees on pairwise losses. LambdaMART also boosts, with regression trees and a position-aware gradient in place of exponential weights.

When to use it

Use RankBoost when the features are scores or votes from several sources, the labels give preferences rather than grades, and a simple, interpretable additive model of thresholds is wanted. Its training bound is clean and needs no tuning of a step size. When the metric weights the top of the list or the data are large, LambdaMART is the usual choice today, which is a measured judgment.

Pitfalls

  • Ties are errors. The loss of line L7 counts H(x0)=H(x1)H(x_0) = H(x_1) as wrong. Counting ties as right, as some evaluations do, makes the bound look loose and hides weak rankers that do not separate pairs.
  • A perfect weak ranker. If ∣rt∣=1|r_t| = 1, line L4 divides by zero. Clip ∣r∣|r| slightly below 1; the code uses 1−10−101 - 10^{-10}, which gives α≈11.9\alpha \approx 11.9.
  • Pairs across queries. The crucial pairs of line L1 must come from one query, or the model learns to order queries.
  • Normalizing. Line L6 must divide by ZtZ_t. Without it, the weights shrink or grow exponentially and the rr of later rounds is not on the scale that line L4 assumes.
  • Overfitting with many rounds. The training loss can fall to 0 quickly, as in the example after two rounds. Choose TT by validation.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

rankboost.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/rankboost/. The authors are listed in prov/FQ86DQ.jsonl.

"""RankBoost with threshold weak rankers (Freund, Iyer, Schapire, Singer 2003).

A crucial pair (x0, x1) says that x1 must rank above x0. The distribution D
over the pairs starts uniform. In each round the weak ranker is
h(x) = 1 if x[f] > theta else 0, chosen to maximize |r| with

    r = sum over pairs of D(x0, x1) (h(x1) - h(x0)),

and its weight is alpha = (1/2) ln((1 + r) / (1 - r)). The update is

    D'(x0, x1) = D(x0, x1) exp(alpha (h(x0) - h(x1))) / Z.

The final ranker is H(x) = sum of alpha_t h_t(x). The ranking loss counts a
pair as an error if H(x0) >= H(x1), so ties are errors. Theorem 1 of the
paper gives rloss(H) <= prod Z_t. If |r| = 1 the weight would be infinite;
the code clips r to 1 - 1e-10 in absolute value.
"""

import math

CLIP = 1.0 - 1e-10


def crucial_pairs(queries):
    """(x0, x1) for every pair of one query with y(x1) > y(x0)."""
    out = []
    for xs, y in queries:
        for i in range(len(xs)):
            for j in range(len(xs)):
                if y[i] > y[j]:
                    out.append((xs[j], xs[i]))
    return out


def weak(f, theta):
    return lambda x: 1.0 if x[f] > theta else 0.0


def candidates(pts):
    """All (f, theta) with theta a midpoint of two consecutive distinct values of x[f]."""
    out = []
    for f in range(len(pts[0][0])):
        vals = sorted(set(x[f] for p in pts for x in p))
        out += [(f, (a + b) / 2.0) for a, b in zip(vals, vals[1:])]
    return out


def r_value(h, pts, dist):
    return sum(d * (h(x1) - h(x0)) for d, (x0, x1) in zip(dist, pts))


def best_weak_ranker(pts, dist):
    """The (f, theta, r) with the largest |r|; ties keep the first candidate."""
    best = None
    for f, theta in candidates(pts):
        r = r_value(weak(f, theta), pts, dist)
        if best is None or abs(r) > abs(best[2]) + 1e-15:
            best = (f, theta, r)
    return best


def alpha_of(r):
    r = max(-CLIP, min(CLIP, r))
    return 0.5 * math.log((1.0 + r) / (1.0 - r))


def fit(queries, rounds):
    """Returns the list of (alpha, f, theta) and the list of Z_t."""
    pts = crucial_pairs(queries)
    dist = [1.0 / len(pts)] * len(pts)                                 # @line L1
    model, zs = [], []
    for _ in range(rounds):                                            # @line L2
        f, theta, r = best_weak_ranker(pts, dist)                      # @line L3
        a = alpha_of(r)                                                # @line L4
        h = weak(f, theta)
        new = [d * math.exp(a * (h(x0) - h(x1))) for d, (x0, x1) in zip(dist, pts)]
        z = sum(new)                                                   # @line L5
        dist = [v / z for v in new]                                    # @line L6
        model.append((a, f, theta))
        zs.append(z)
    return model, zs                                                   # @line L7


def score(model, x):
    return sum(a * weak(f, theta)(x) for a, f, theta in model)


def ranking_loss(model, pts, dist=None):
    """sum of D(x0, x1) over the pairs with H(x0) >= H(x1); D is uniform by default."""
    dist = [1.0 / len(pts)] * len(pts) if dist is None else dist
    return sum(d for d, (x0, x1) in zip(dist, pts) if score(model, x0) >= score(model, x1))


def w_values(h, pts, dist):
    """W_b = sum of D over the pairs with h(x0) - h(x1) = b, for b = -1, 0, +1."""
    w = {-1: 0.0, 0: 0.0, 1: 0.0}
    for d, (x0, x1) in zip(dist, pts):
        w[int(h(x0) - h(x1))] += d
    return w


def method2_alpha(w):
    """The alpha that minimizes Z = W_-1 e^-alpha + W_0 + W_+1 e^alpha (Section 3.2)."""
    return 0.5 * math.log(w[-1] / w[1])


def method2_z(w):
    return w[0] + 2.0 * math.sqrt(w[-1] * w[1])
test_rankboost.py 127 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/rankboost/. The authors are listed in prov/FQ86DQ.jsonl.

import math
import random

from rankboost import (
    alpha_of,
    best_weak_ranker,
    crucial_pairs,
    fit,
    method2_alpha,
    method2_z,
    r_value,
    ranking_loss,
    w_values,
    weak,
)

EXAMPLE = [([[0.0, 1.0], [1.0, 0.0], [2.0, 2.0], [3.0, 1.0]], [0, 1, 2, 1])]


def random_queries(seed, n_queries=4, n_docs=6, d=3):
    rng = random.Random(seed)
    queries = []
    for _ in range(n_queries):
        xs = [[rng.randint(0, 9) / 9.0 for _ in range(d)] for _ in range(n_docs)]
        y = [rng.randint(0, 2) for _ in range(n_docs)]
        queries.append((xs, y))
    return queries


def replay(queries, model):
    """The distributions D_1, ..., D_T recomputed from the fitted model."""
    pts = crucial_pairs(queries)
    dist = [1.0 / len(pts)] * len(pts)
    out = []
    for a, f, theta in model:
        out.append(dist)
        h = weak(f, theta)
        new = [d * math.exp(a * (h(x0) - h(x1))) for d, (x0, x1) in zip(dist, pts)]
        z = sum(new)
        dist = [v / z for v in new]
    return pts, out


def test_page_example():
    pts = crucial_pairs(EXAMPLE)
    assert len(pts) == 5
    model, zs = fit(EXAMPLE, 2)
    a1, f1, t1 = model[0]
    assert (f1, t1) == (0, 0.5)
    assert abs(a1 - math.log(2)) < 1e-12
    assert abs(zs[0] - 0.7) < 1e-12
    assert (model[1][1], model[1][2]) == (1, 1.5)
    assert abs(ranking_loss(model[:1], pts) - 0.4) < 1e-12
    assert ranking_loss(model, pts) == 0.0


def test_weak_ranker_is_brute_force_best():
    for seed in range(5):
        queries = random_queries(seed)
        model, _ = fit(queries, 4)
        pts, dists = replay(queries, model)
        for (a, f, theta), dist in zip(model, dists):
            r = r_value(weak(f, theta), pts, dist)
            values = sorted(set(v for p in pts for x in p for v in x))
            for ff in range(3):
                for tt in values:
                    assert abs(r_value(weak(ff, tt), pts, dist)) <= abs(r) + 1e-12
            assert abs(a - 0.5 * math.log((1 + r) / (1 - r))) < 1e-12


def test_z_matches_formula_and_square_root_bound():
    for seed in range(5):
        queries = random_queries(seed + 10)
        model, zs = fit(queries, 5)
        pts, dists = replay(queries, model)
        for (a, f, theta), dist, z in zip(model, dists, zs):
            h = weak(f, theta)
            direct = sum(d * math.exp(a * (h(x0) - h(x1))) for d, (x0, x1) in zip(dist, pts))
            assert abs(direct - z) < 1e-12
            r = r_value(h, pts, dist)
            assert z <= math.sqrt(1 - r * r) + 1e-12
            w = w_values(h, pts, dist)
            assert abs(r - (w[-1] - w[1])) < 1e-12


def test_ranking_loss_bounded_by_product_of_z():
    for seed in range(5):
        queries = random_queries(seed + 20)
        pts = crucial_pairs(queries)
        model, zs = fit(queries, 8)
        prod = 1.0
        for t in range(1, len(model) + 1):
            prod *= zs[t - 1]
            assert ranking_loss(model[:t], pts) <= prod + 1e-12


def test_method2_alpha_minimizes_z():
    queries = random_queries(30)
    pts = crucial_pairs(queries)
    dist = [1.0 / len(pts)] * len(pts)
    f, theta, _ = best_weak_ranker(pts, dist)
    h = weak(f, theta)
    w = w_values(h, pts, dist)
    a = method2_alpha(w)

    def z(alpha):
        return w[-1] * math.exp(-alpha) + w[0] + w[1] * math.exp(alpha)

    assert abs(z(a) - method2_z(w)) < 1e-12
    grid = [i / 1000.0 for i in range(-3000, 3001)]
    assert all(z(a) <= z(b) + 1e-12 for b in grid)


def test_clipping_of_perfect_weak_ranker():
    # One weak ranker orders every pair, so r = 1 and alpha is clipped.
    queries = [([[0.0], [1.0]], [0, 1])]
    model, zs = fit(queries, 1)
    assert math.isfinite(model[0][0]) and model[0][0] > 10
    assert alpha_of(1.0) == alpha_of(2.0)


def test_ties_count_as_errors():
    pts = crucial_pairs([([[0.0], [0.0]], [0, 1])])
    assert ranking_loss([], pts) == 1.0

History

Freund, Iyer, Schapire and Singer presented RankBoost at ICML in 1998, in the setting of combining the preferences of several experts, such as several search engines, and published the full version in JMLR in 2003. It carried the AdaBoost analysis to pairs: the bound on the training ranking loss, the choices of α\alpha, an efficient bipartite version, and threshold weak rankers. It was one of the first learning-to-rank methods and is a standard baseline beside the Ranking SVM and RankNet.

References

  1. Yoav Freund, Raj Iyer, Robert E. Schapire and Yoram Singer, An efficient boosting algorithm for combining preferences, Journal of Machine Learning Research 4, 2003, pp. 933-969; Figure 1 (the algorithm), Section 3 and Theorem 1 (the ranking loss is at most the product of the Z_t), Section 3.2 (the choices of alpha), Section 3.3 and Figure 2 (RankBoost.B for bipartite feedback), Section 4 (threshold weak rankers)

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 proofH1 sketch
  • a full proof of time.per_round
  • a full proof of time.total
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • at least three sources
  • a scene preset for the example