Skip to content

13.12 Probability problem set, part d: hypothesis tests, regression, queueing, balls into bins

There comes a point where a system starts making claims and serving load at the same time. Hypothesis tests: paired and two-sample permutation, McNemar, Holm turns “model B is better” into a p-value, and Logistic regression (IRLS), ROC-AUC, calibration (ECE) fits and scores the gateway’s policy classifier; both are short functions whose results are easy to misread. Later, the gateway routes requests across engine replicas and a load generator measures latency, and two pieces of probability decide whether those numbers make sense: Little’s law, which links throughput, latency, and concurrency, and the balls-into-bins arithmetic behind random and two-choice load balancing.

Concepts from other sections (11)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

This problem set works each idea once by hand, so the code and the dashboards that follow are transcriptions of things you have already computed. It is a pen-and-paper set with 19 answers (counting lettered parts) and one proof. A short review and three examples by hand come first; then the problems, each followed by a collapsed worked answer with the final result, the derivation, and the common wrong answers and why they are wrong. Try each problem before opening its answer. Read it alongside the hypothesis-tests and logistic-regression sections: Problems 1 to 4 are their tests by hand, Problems 5 to 9 the regression behind the policy head, and Problems 10 to 17 the queueing and load-balancing arithmetic that the load generator and the gateway’s router rely on.

The set builds on the sampling distributions of problem set C and on the hypothesis-testing and regression material in the chapter opening.

Learning objectives

  • Compute exact permutation, sign-flip, and McNemar p-values by enumeration, and apply Holm’s correction.
  • Fit a least-squares line by hand, interpret a logistic coefficient as a log odds ratio, and derive the logistic loss gradient.
  • Compute an AUC with ties and prove that the penalized logistic loss is convex.
  • Apply Little’s law and the M/M/1 formulas to relate arrival rate, utilization, concurrency, and latency.
  • Use linearity of expectation for empty bins and collisions, and state the power-of-two-choices bound.

The set uses these symbols.

SymbolMeaningType / shape
did_i, sis_ipaired differences and random signs ±1\pm 1reals
b01b_{01}, b10b_{10}discordant counts (only A right, only B right)integers
p(k)p_{(k)}, mm, α\alphasorted p-values, family size, levelreals, integer
β0\beta_0, β1\beta_1intercept and slope of a least-squares linereals
σ(z)\sigma(z)the sigmoid 1/(1+e−z)1/(1 + e^{-z})function
λ\lambda (lam), μ\mu (mu)arrival rate and service ratepositive reals
ρ=λ/μ\rho = \lambda/\muutilizationin [0,1)[0, 1)
LL, WWmean number in the system and mean time in the systemreals
nn, mmbins and ballspositive integers

A p-value is the probability under H0H_0 of a statistic at least as extreme as observed. Exact permutation p-values count the relabellings that H0H_0 makes equally likely: 2n2^n sign vectors for pairs, (Nna)\binom{N}{n_a} splits for two samples. McNemar uses only the discordant pairs, each a fair coin under H0H_0. Holm sorts the p-values and rejects the kk-th smallest while p(k)≤α/(m−k)p_{(k)} \le \alpha/(m - k) (with kk counted from 0).

Least squares minimizes ∑i(yi−β0−β1xi)2\sum_i (y_i - \beta_0 - \beta_1 x_i)^2; setting both partial derivatives to 0 gives β1=Sxy/Sxx\beta_1 = S_{xy}/S_{xx} with Sxy=∑(xi−xˉ)(yi−yˉ)S_{xy} = \sum (x_i - \bar x)(y_i - \bar y), Sxx=∑(xi−xˉ)2S_{xx} = \sum (x_i - \bar x)^2, and β0=yˉ−β1xˉ\beta_0 = \bar y - \beta_1 \bar x. In logistic regression the log-odds are linear, so a coefficient ww multiplies the odds by ewe^{w} per unit of its feature, and ddz[−ylog⁡σ(z)−(1−y)log⁡(1−σ(z))]=σ(z)−y\frac{d}{dz}[-y\log\sigma(z) - (1-y)\log(1-\sigma(z))] = \sigma(z) - y. The AUC is the fraction of (positive, negative) pairs ranked correctly, ties counting one half.

The second half of the set leaves statistics for systems. Little’s law says that in any system where items arrive at long-run rate λ\lambda and stay a mean time WW, the mean number inside is L=λWL = \lambda W, whatever the arrival or service distributions. The proof is an area argument: the area under “number inside over time” counts each item’s time inside once. In the M/M/1 queue (Poisson arrivals, exponential service, one server), the number in the system is geometric, P(N=k)=(1−ρ)ρkP(N = k) = (1 - \rho)\rho^k, so L=ρ/(1−ρ)L = \rho/(1 - \rho) and, by Little, W=L/λ=1/(μ−λ)W = L/\lambda = 1/(\mu - \lambda).

With mm balls thrown uniformly into nn bins, a given bin is missed by every ball with probability (1−1/n)m(1 - 1/n)^m, and linearity of expectation adds such indicators over bins or over pairs of balls with no independence needed. With m=nm = n, (1−1/n)n→e−1(1 - 1/n)^n \to e^{-1}. The most loaded bin holds about ln⁡n/ln⁡ln⁡n\ln n/\ln\ln n balls with one random choice; Azar, Broder, Karlin, and Upfal (1994) showed that sampling two bins and taking the emptier gives ln⁡ln⁡n/ln⁡2+O(1)\ln\ln n/\ln 2 + O(1), an exponential improvement.

These are siblings of Problems 2, 11, and 14, not problems of the set.

A two-sample p-value. Take a={4,6}a = \{4, 6\} and b={1,3}b = \{1, 3\}, so T=∣5−2∣=3T = |5 - 2| = 3. The six ways to pick group aa from {1,3,4,6}\{1, 3, 4, 6\} give ∣aˉ−bˉ∣|\bar a - \bar b| of {1,3}:3\{1,3\}: 3, {1,4}:2\{1,4\}: 2, {1,6}:0\{1,6\}: 0, {3,4}:0\{3,4\}: 0, {3,6}:2\{3,6\}: 2, {4,6}:3\{4,6\}: 3. Two of six reach 3: p=1/3p = 1/3.

An M/M/1 queue. With λ=3\lambda = 3 and μ=4\mu = 4 per second, ρ=3/4\rho = 3/4, L=(3/4)/(1/4)=3L = (3/4)/(1/4) = 3, and W=L/λ=1W = L/\lambda = 1 s, and indeed 1/(μ−λ)=11/(\mu - \lambda) = 1. The service time alone is 1/41/4 s; queueing quadrupled it.

Empty bins. Throw n=3n = 3 balls into 3 bins. A bin is empty with probability (2/3)3=8/27(2/3)^3 = 8/27, so the expected number of empty bins is 3⋅8/27=8/93 \cdot 8/27 = 8/9. Enumerating the 27 assignments agrees: 6 hit every bin (0 empty), 18 leave one empty, 3 leave two empty, and (18+6)/27=8/9(18 + 6)/27 = 8/9.

λ\lambda is written lam and μ\mu is mu in formulas; answers are exact (79/204879/2048, ee), not decimals. Lettered parts are answered separately, and the tag after each problem says what kind of answer is expected.

The first four problems compute each test of the hypothesis-tests section by exhaustive enumeration.

Problem 1. Model B minus model A on three prompts gives the paired differences d=(2,1,3)d = (2, 1, 3). Give the exact two-sided sign-flip p-value: the fraction of the 232^3 sign vectors ss with ∣∑isidi∣≥∣∑idi∣|\sum_i s_i d_i| \ge |\sum_i d_i|. [number, exact]

Answer

1/41/4. ∑idi=6\sum_i d_i = 6. Of the 23=82^3 = 8 sign vectors, only (+,+,+)(+,+,+) and (−,−,−)(-,-,-) give ∣∑isidi∣=6|\sum_i s_i d_i| = 6; every other pattern flips at least one term and lands at 0, 2, or 4. So p=2/8=1/4p = 2/8 = 1/4: with three pairs, even a unanimous win cannot reach p<0.05p < 0.05. Common mistakes: 1/81/8, the one-sided count (only ++++++); 1/31/3, the add-one Monte Carlo estimate (c+1)/(R+1)(c + 1)/(R + 1), which the hypothesis-tests section uses when it samples, not the exact enumeration asked here.

Problem 2. Two unpaired samples, a={3,5}a = \{3, 5\} and b={1,2}b = \{1, 2\}, with statistic T=∣aˉ−bˉ∣T = |\bar a - \bar b|. Give the exact two-sided permutation p-value: the fraction of the ways to split the pooled values {1,2,3,5}\{1, 2, 3, 5\} into two groups of two whose TT is at least the observed one. [number, exact]

Answer

1/31/3. Observed T=∣4−1.5∣=2.5T = |4 - 1.5| = 2.5. The six ways to choose group aa from {1,2,3,5}\{1, 2, 3, 5\} give ∣aˉ−bˉ∣|\bar a - \bar b|: {1,2}:2.5\{1,2\}: 2.5, {1,3}:1.5\{1,3\}: 1.5, {1,5}:0.5\{1,5\}: 0.5, {2,3}:0.5\{2,3\}: 0.5, {2,5}:1.5\{2,5\}: 1.5, {3,5}:2.5\{3,5\}: 2.5. Two of six reach 2.5, so p=2/6=1/3p = 2/6 = 1/3. Common mistakes: 1/61/6, the one-sided count (aˉ−bˉ≥2.5\bar a - \bar b \ge 2.5 only); 1/41/4.

Problem 3. Two classifiers on the same eval set: A alone is right on b01=2b_{01} = 2 examples, B alone on b10=10b_{10} = 10. Give the exact two-sided McNemar p-value min⁡(1,2∑i=0k(ni)2−n)\min\bigl(1, 2\sum_{i=0}^{k}\binom{n}{i}2^{-n}\bigr), n=b01+b10n = b_{01} + b_{10}, k=min⁡(b01,b10)k = \min(b_{01}, b_{10}). [number, exact]

Answer

79/204879/2048 (≈0.0386\approx 0.0386). n=12n = 12, k=2k = 2. The tail is ∑i=02(12i)=1+12+66=79\sum_{i=0}^{2}\binom{12}{i} = 1 + 12 + 66 = 79 out of 212=40962^{12} = 4096, doubled for two sides: 2⋅79/4096=79/20482 \cdot 79/4096 = 79/2048. Under the null, each discordant example is a fair coin between A and B, which is why only the b01+b10b_{01} + b_{10} disagreements matter. Common mistakes: 79/409679/4096, the tail not doubled; 2(1+12)/40962(1 + 12)/4096, a tail that stops at k−1k - 1 and leaves out the observed count.

Problem 4. Five comparisons have p-values (p1,…,p5)=(0.03,0.002,0.04,0.012,0.3)(p_1, \dots, p_5) = (0.03, 0.002, 0.04, 0.012, 0.3). Which hypotheses does Holm’s procedure reject at family-wise level α=0.05\alpha = 0.05? Answer with the set of their indices. [set]

Answer

{2,4}\{2, 4\}. Sort: p2=0.002p_2 = 0.002, p4=0.012p_4 = 0.012, p1=0.03p_1 = 0.03, p3=0.04p_3 = 0.04, p5=0.3p_5 = 0.3. Holm compares the jj-th smallest with α/(m−j+1)\alpha/(m - j + 1): 0.002≤0.05/5=0.010.002 \le 0.05/5 = 0.01 (reject 2); 0.012≤0.05/4=0.01250.012 \le 0.05/4 = 0.0125 (reject 4); 0.03>0.05/3≈0.01670.03 > 0.05/3 \approx 0.0167: stop, and keep every remaining hypothesis, including p3p_3. Common mistakes: {2}\{2\}, Bonferroni (every p against 0.010.01), valid but weaker; {1,2,3,4}\{1, 2, 3, 4\}, no correction; {2,3,4}\{2, 3, 4\}, a step-down that does not stop at the first failure: once p1p_1 fails its bar, every larger p-value is kept.

The next five problems are the regression behind the policy head: a least-squares line, odds, the loss gradient, an AUC with a tie, and the convexity proof.

Problem 5. Fit the least-squares line y=β0+β1xy = \beta_0 + \beta_1 x to the points (0,1),(1,3),(2,4),(3,8)(0, 1), (1, 3), (2, 4), (3, 8). (a) β1\beta_1. [number, exact] (b) β0\beta_0. [number, exact]

Answer

(a) 11/511/5. (b) 7/107/10. xˉ=3/2\bar x = 3/2, yˉ=4\bar y = 4. With deviations x−xˉ=(−32,−12,12,32)x - \bar x = (-\frac32, -\frac12, \frac12, \frac32) and y−yˉ=(−3,−1,0,4)y - \bar y = (-3, -1, 0, 4): Sxy=92+12+0+6=11S_{xy} = \frac92 + \frac12 + 0 + 6 = 11 and Sxx=94+14+14+94=5S_{xx} = \frac94 + \frac14 + \frac14 + \frac94 = 5. (a) β1=Sxy/Sxx=11/5\beta_1 = S_{xy}/S_{xx} = 11/5. (b) The line passes through (xˉ,yˉ)(\bar x, \bar y): β0=4−115⋅32=710\beta_0 = 4 - \frac{11}5 \cdot \frac32 = \frac7{10}. Common mistakes: 26/11=Syy/Sxy26/11 = S_{yy}/S_{xy}, the reciprocal of the slope from regressing xx on yy; 7/37/3, the slope through the two end points; 11 for (b), the first yy; 44 for (b), yˉ\bar y.

Problem 6. A fitted logistic regression has log-odds log⁡p1−p=−2+0.5x\log\frac{p}{1-p} = -2 + 0.5x. By what factor do the odds of y=1y = 1 multiply when xx increases by 2? [number, exact]

Answer

ee. The log-odds grow by 0.5×2=10.5 \times 2 = 1, so the odds p/(1−p)=elog-oddsp/(1 - p) = e^{\text{log-odds}} multiply by e1≈2.718e^1 \approx 2.718. A logistic coefficient is a log odds ratio per unit of xx. Common mistakes: e1/2e^{1/2}, the factor for one unit; 11, the change in log-odds reported as if it were the odds factor.

Problem 7. For one example (x,y)(x, y) with x∈Rx \in \mathbb{R}, y∈{0,1}y \in \{0, 1\}, and p=σ(wx)=1/(1+e−wx)p = \sigma(wx) = 1/(1 + e^{-wx}), the loss is ℓ(w)=−[ylog⁡p+(1−y)log⁡(1−p)]\ell(w) = -[y\log p + (1 - y)\log(1 - p)]. Give dℓdw\frac{d\ell}{dw}. [expr in w, x, y]

Answer

dℓdw=(σ(wx)−y) x\frac{d\ell}{dw} = (\sigma(wx) - y)\,x ((1/(1 + exp(-w*x)) - y)*x). Let z=wxz = wx. Using ln⁡p=−ln⁡(1+e−z)\ln p = -\ln(1 + e^{-z}) and ln⁡(1−p)=−z−ln⁡(1+e−z)\ln(1 - p) = -z - \ln(1 + e^{-z}), ℓ=ln⁡(1+e−z)+(1−y)z\ell = \ln(1 + e^{-z}) + (1 - y)z, so dℓ/dz=−(1−p)+(1−y)=p−yd\ell/dz = -(1 - p) + (1 - y) = p - y. The chain rule multiplies by dz/dw=xdz/dw = x. Prediction minus label, times the input. Common mistakes: (y−σ(wx))x(y - \sigma(wx))x, the gradient of the log-likelihood rather than of the loss (a step along it walks uphill on the loss); σ(wx)−y\sigma(wx) - y, the chain-rule factor xx missing.

Problem 8. A classifier scores three positives 0.8,0.5,0.350.8, 0.5, 0.35 and three negatives 0.6,0.35,0.10.6, 0.35, 0.1. Give its ROC-AUC, counting a tied pair as one half. [number, exact]

Answer

13/1813/18. There are 3×3=93 \times 3 = 9 positive-negative pairs. 0.80.8 beats all three negatives (3); 0.50.5 beats 0.350.35 and 0.10.1 (2); 0.350.35 beats 0.10.1 and ties 0.350.35 (1.5). AUC =6.5/9=13/18= 6.5/9 = 13/18. Common mistakes: 2/32/3, the tie counted as a loss; 7/97/9, the tie counted as a win.

Problem 9. Prove that the penalized logistic loss L(w)=−∑i[yilog⁡pi+(1−yi)log⁡(1−pi)]+λ2∥w∥2L(w) = -\sum_i [y_i\log p_i + (1 - y_i)\log(1 - p_i)] + \frac{\lambda}{2}\lVert w\rVert^2, pi=σ(xi⋅w)p_i = \sigma(x_i \cdot w), λ≥0\lambda \ge 0, is convex, and say why that makes every stationary point a global minimum and Newton’s step well defined when λ>0\lambda > 0. [proof]

Answer

Setup. Examples (xi,yi)(x_i, y_i), i=1,…,ni = 1, \dots, n, with xi∈Rdx_i \in \mathbb R^d, yi∈{0,1}y_i \in \{0, 1\}; XX is the n×dn \times d matrix with rows xix_i; σ(z)=1/(1+e−z)\sigma(z) = 1/(1 + e^{-z}), pi=σ(xi⋅w)p_i = \sigma(x_i \cdot w), pp the vector of the pip_i; λ≥0\lambda \ge 0.

Gradient and Hessian. With zi=xi⋅wz_i = x_i \cdot w, each term is ℓi=ln⁡(1+e−zi)+(1−yi)zi\ell_i = \ln(1 + e^{-z_i}) + (1 - y_i)z_i, so dℓi/dzi=pi−yid\ell_i/dz_i = p_i - y_i (Problem 7) and, since σ′=σ(1−σ)\sigma' = \sigma(1 - \sigma), d2ℓi/dzi2=pi(1−pi)d^2\ell_i/dz_i^2 = p_i(1 - p_i). By the chain rule, ∇L(w)=X⊤(p−y)+λw,H(w)=X⊤SX+λI,S=diag⁡(pi(1−pi)).\nabla L(w) = X^\top(p - y) + \lambda w, \qquad H(w) = X^\top S X + \lambda I, \quad S = \operatorname{diag}(p_i(1 - p_i)).

Positive semidefinite. For every v∈Rdv \in \mathbb R^d, v⊤Hv=∑ipi(1−pi)(xi⋅v)2+λ∥v∥2≥0,v^\top H v = \sum_i p_i(1 - p_i)(x_i \cdot v)^2 + \lambda\lVert v\rVert^2 \ge 0, since 0<pi<10 < p_i < 1 makes every weight positive. When λ>0\lambda > 0 and v≠0v \ne 0 the last term is strictly positive, so HH is positive definite.

Conclusion. A twice-differentiable function with a positive semidefinite Hessian everywhere is convex, so LL is convex (strictly when λ>0\lambda > 0). For convex differentiable LL, L(u)≥L(w)+∇L(w)⋅(u−w)L(u) \ge L(w) + \nabla L(w) \cdot (u - w) for all uu, so a point with ∇L(w)=0\nabla L(w) = 0 has L(u)≥L(w)L(u) \ge L(w) for every uu: a global minimum, unique when λ>0\lambda > 0. Newton’s step solves HΔ=−∇LH\Delta = -\nabla L; with λ>0\lambda > 0, HH is positive definite, hence invertible, so the system has exactly one solution. This is why the IRLS fitter of Logistic regression (IRLS), ROC-AUC, calibration (ECE) converges.

A complete proof derives the gradient and Hessian, shows v⊤Hv≥0v^\top H v \ge 0 from 0<pi<10 < p_i < 1, draws both conclusions, and defines every symbol. The model proof is also in course/solutions/solve/S-M07d/q9.md.

The next four problems move from statistics to systems: concurrency from throughput and latency, and how latency grows as a server fills.

Problem 10. A gateway receives λ=40\lambda = 40 requests per second and the mean time a request spends inside it is W=0.25W = 0.25 s. By Little’s law, how many requests are inside on average? [number, exact]

Answer

1010. L=λW=40×0.25=10L = \lambda W = 40 \times 0.25 = 10 requests in flight on average. Little’s law needs only a stable system, no distributional assumption. Common mistakes: 160=λ/W160 = \lambda/W; 1/1601/160.

Problem 11. A single-server queue with Poisson arrivals at λ=8\lambda = 8 per second and exponential service at rate μ=10\mu = 10 per second (M/M/1). (a) The utilization ρ=λ/μ\rho = \lambda/\mu. [number, exact] (b) The mean number in the system L=ρ/(1−ρ)L = \rho/(1 - \rho). [number, exact] (c) The mean time in the system WW, by Little’s law. [number, exact]

Answer

(a) 4/54/5. (b) 44. (c) 1/21/2 s. (a) ρ=8/10\rho = 8/10. (b) L=4/51/5=4L = \frac{4/5}{1/5} = 4. (c) W=L/λ=4/8=1/2W = L/\lambda = 4/8 = 1/2 s, which agrees with 1/(μ−λ)=1/21/(\mu - \lambda) = 1/2. Common mistakes: 5/4=μ/λ5/4 = \mu/\lambda for (a); 4/54/5 for (b), the utilization reported as the number in system; 16/5=ρ2/(1−ρ)16/5 = \rho^2/(1 - \rho) for (b), the number waiting in queue without the one in service; 1/101/10 for (c), the service time alone; 2/52/5 for (c), the queue wait W−1/μW - 1/\mu without the service.

Problem 12. Give the mean time in an M/M/1 system as a formula in the arrival rate λ\lambda and the service rate μ>λ\mu > \lambda. [expr in lam, mu]

Answer

W=1μ−λW = \dfrac{1}{\mu - \lambda} (1/(mu - lam)). L=ρ/(1−ρ)=λ/(μ−λ)L = \rho/(1 - \rho) = \lambda/(\mu - \lambda), and Little’s law gives W=L/λ=1/(μ−λ)W = L/\lambda = 1/(\mu - \lambda). Common mistakes: 1/μ1/\mu, the service time with no queueing; λ/(μ−λ)\lambda/(\mu - \lambda), which is LL, not WW.

Problem 13. Keep the service rate μ\mu fixed. By what factor is the mean time in an M/M/1 system larger at utilization ρ=0.9\rho = 0.9 than at ρ=0.5\rho = 0.5? [number, exact]

Answer

55. W=1μ−λ=1μ(1−ρ)W = \frac{1}{\mu - \lambda} = \frac{1}{\mu(1 - \rho)}, so with μ\mu fixed the ratio is 1−0.51−0.9=5\frac{1 - 0.5}{1 - 0.9} = 5. Going from half to 90% busy multiplies latency by five; this is the curve behind keeping a server below saturation. Common mistakes: 9/59/5, the ratio of the utilizations; 99, the ratio of L=ρ/(1−ρ)L = \rho/(1 - \rho) values (99 against 11), which compares counts, not times (the arrival rates differ).

The last four problems are the load-balancing arithmetic: empty bins, collisions, and the power of two choices.

Problem 14. Throw nn balls independently and uniformly into nn bins. Give the expected number of empty bins. [expr in n]

Answer

n(1−1/n)nn(1 - 1/n)^n. A given bin is missed by one ball with probability 1−1/n1 - 1/n and by all nn independent balls with probability (1−1/n)n(1 - 1/n)^n. Linearity of expectation adds this indicator over the nn bins, with no independence between bins needed. Common mistakes: (1−1/n)n(1 - 1/n)^n, the probability for one bin, not the expected count; n/en/e, the large-nn limit, not the exact value.

Problem 15. As n→∞n \to \infty, what fraction of the bins in Problem 14 is empty? [number, exact]

Answer

1/e1/e (≈0.368\approx 0.368). The fraction is (1−1/n)n→e−1(1 - 1/n)^n \to e^{-1}. Common mistakes: 0; 1−1/e1 - 1/e, the occupied fraction.

Problem 16. Throw mm balls independently and uniformly into nn bins. Give the expected number of pairs of balls that land in the same bin. [expr in m, n]

Answer

m(m−1)2n\dfrac{m(m - 1)}{2n} =(m2)/n= \binom m2/n. Each of the (m2)\binom m2 unordered pairs of distinct balls lands in the same bin with probability 1/n1/n (the second ball matches the first’s bin); linearity adds them. This is the birthday problem: collisions appear once m≈2nm \approx \sqrt{2n}. Common mistakes: m2/nm^2/n, counting ordered pairs and self-pairs; m/nm/n, the mean load, not the collisions.

Problem 17. nn requests go to nn servers. Each request either picks one server uniformly at random, or samples two servers and joins the less loaded one (the power of two choices). With high probability the maximum load grows like: [choice] (a) ln⁡n/ln⁡ln⁡n\ln n/\ln\ln n with two choices, the same as with one. (b) ln⁡ln⁡n/ln⁡2\ln\ln n/\ln 2 with two choices, against ln⁡n/ln⁡ln⁡n\ln n/\ln\ln n with one. (c) n\sqrt{n} with one choice, ln⁡n\ln n with two. (d) a constant with two choices.

Answer

(b). With one uniform choice the fullest bin holds about ln⁡n/ln⁡ln⁡n\ln n/\ln\ln n; with the less loaded of two random choices it holds ln⁡ln⁡n/ln⁡2+O(1)\ln\ln n/\ln 2 + O(1) (Azar, Broder, Karlin, and Upfal), an exponential improvement. Common mistakes: (a), believing the second choice only shaves a constant; (d), a constant: the bound still grows, just very slowly; (c) has the wrong rates for both.

In the tests, the commonest slip is a one-sided count for a two-sided question, which halves pp; count both tails, or double the binomial tail (Problems 1, 2, and 3). Quoting the add-one Monte Carlo estimate where the exact pp was asked gives 1/3 instead of 1/4; enumerate all 232^3 sign vectors (Problem 1). Using Bonferroni, no correction, or a Holm that does not stop gives the wrong set of discoveries; sort, compare with α/(m−j+1)\alpha/(m - j + 1), and stop at the first failure (Problem 4).

The regression slips change the answer’s scale or sign. Regressing xx on yy, or drawing a line through two points, gives a different slope; use Sxy/SxxS_{xy}/S_{xx} over all four points (Problem 5). Reporting the change in log-odds as the odds factor gives 1 instead of ee; exponentiate the change (Problem 6). Counting ties as wins or losses gives 7/9 or 2/3 instead of 13/18; a tie counts one half (Problem 8).

Warning: Taking the likelihood’s gradient instead of the loss’s makes Newton walk uphill, and dropping the chain-rule factor gives the wrong scale. Differentiate the loss: (p−y)x(p - y)x (Problem 7).

The queueing slips mix up the three quantities of Little’s law. Computing λ/W\lambda/W instead of λW\lambda W gives 160 requests, and reporting the utilization as LL gives 4/5; use L=λWL = \lambda W and L=ρ/(1−ρ)L = \rho/(1 - \rho) (Problems 10 and 11). Reporting the service time or the queue wait as the time in system gives 1/10 or 2/5 s; W=L/λW = L/\lambda is wait plus service (Problem 11c).

In balls into bins, giving the limit n/en/e where the exact count was asked is approximate where exact was wanted; keep n(1−1/n)nn(1 - 1/n)^n (Problem 14). Counting ordered pairs or self-pairs gives m2/nm^2/n collisions; count (m2)\binom m2 unordered pairs (Problem 16). And believing two choices only shave a constant leads to answer (a); the bound drops from ln⁡n/ln⁡ln⁡n\ln n/\ln\ln n to ln⁡ln⁡n/ln⁡2\ln\ln n/\ln 2 (Problem 17).

This set reads the sampling distributions and intervals of problem set C as tests. Hypothesis tests: paired and two-sample permutation, McNemar, Holm implements paired_permutation_test, permutation_test, mcnemar, and holm, which are Problems 1 to 4 in code, and Logistic regression (IRLS), ROC-AUC, calibration (ECE) implements IRLS and roc_auc and relies on the convexity of Problem 9. In AI Engineering, the comparison table of The evaluation harness and the model zoo runs Problems 1 to 4 at scale, and the open-loop load generator reports concurrency, throughput, and latency, tied together by Little’s law. In AI Engineering, Routing, cascades, and failover routes across replicas with random choice against least-loaded of two.

  • Wasserman, All of Statistics, ch. 10 and 13.
  • Harchol-Balter, Performance Modeling and Design of Computer Systems, ch. 6 (Little’s law) and 14 (M/M/1).
  • Mitzenmacher and Upfal, Probability and Computing, ch. 5 (balls and bins) and 17 (the power of two choices).
  • Exact permutation p-value: the fraction of equally likely relabellings under H0H_0 whose statistic is at least as extreme as observed.
  • McNemar test: an exact binomial test on the discordant pairs of two classifiers evaluated on the same examples.
  • Holm’s procedure: a step-down correction that compares the sorted p-values with α/m,α/(m−1),…\alpha/m, \alpha/(m-1), \dots and stops at the first failure.
  • Log odds ratio: a logistic coefficient; increasing its feature by one multiplies the odds by ewe^{w}.
  • Little’s law: L=λWL = \lambda W for any stable system.
  • Utilization: ρ=λ/μ\rho = \lambda/\mu, the fraction of time a server is busy.
  • Power of two choices: sampling two bins and joining the emptier, which cuts the maximum load from ln⁡n/ln⁡ln⁡n\ln n/\ln\ln n to ln⁡ln⁡n/ln⁡2+O(1)\ln\ln n/\ln 2 + O(1).
  • An exact permutation p-value is a count over a finite set of relabellings; with three pairs, even a unanimous win has p=1/4p = 1/4 (Problems 1 and 2).
  • Holm stops at the first p-value above its bar and still rejects more than Bonferroni (Problem 4).
  • A logistic coefficient is a log odds ratio, and the loss gradient is “prediction minus label, times the input” (Problems 6 and 7); that loss is convex, which is why IRLS converges (Problem 9).
  • Little’s law L=λWL = \lambda W holds for any stable system; in M/M/1 the time in system 1/(μ−λ)1/(\mu - \lambda) explodes as utilization approaches 1 (Problems 10 to 13).
  • Throwing nn balls into nn bins leaves about 1/e1/e of them empty, and asking two bins instead of one shrinks the fullest bin from ln⁡n/ln⁡ln⁡n\ln n/\ln\ln n to ln⁡ln⁡n/ln⁡2\ln\ln n/\ln 2 (Problems 14 to 17).