Skip to content

Solve set: hypothesis tests, regression, queueing and Little's law, balls into bins

ModuleS-M07d · solve · none · Pass 5 · 3 to 4 h
You buildanswers in solve/S-M07d.toml (19 checked by SymPy) and 1 proof in solve/S-M07d/q9.md (self-graded against its rubric)
Contractnone: a pen and paper set
Testscourse/solve/S-M07d/key.toml (hidden): typed answers plus reject canaries; the problems are in course/solve/S-M07d/problems.md and in section 4
NeedsS-M07c (sampling distributions). Reading: M07.5 hypothesis tests, M07.7 logistic regression, ROC-AUC, calibration, and the Probability and Statistics topic, hypothesis testing and regression sections
Used byno call site (a solve set). Do it alongside M07.5 and M07.7: q1 to q4 are their tests by hand, q5 to q9 the regression behind the policy head; q10 to q17 are the queueing and load-balancing arithmetic load.01 and the gateway’s router (gw.05) rely on
MilestoneMS-P5 (the Pass 5 gate runs ol check on every solve part of the pass)
Optional depthWasserman, 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)
  • 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 (q1, q2).
  • Holm stops at the first p-value above its bar and still rejects more than Bonferroni (q4).
  • A logistic coefficient is a log odds ratio, and the loss gradient is “prediction minus label, times the input” (q6, q7); that loss is convex, which is why IRLS converges (q9).
  • 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 (q10 to q13).
  • 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 (q14 to q17).
Terminal window
ol start S-M07d # writes solve/S-M07d.toml and the proof file
ol check S-M07d # SymPy checks the answers, then asks the proof rubric (y/n)
ol check S-M07d --regrade # ask the rubric again after you change the proof

Pass 5 is where your system starts making claims and serving load at the same time. M07.5 turns “model B is better” into a p-value and M07.7 fits and scores the gateway’s policy classifier; both are short functions whose results are easy to misread. In Pass 7 the gateway routes requests across engine replicas and the 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. This set works each idea once by hand, so the code and the dashboards that follow are transcriptions of things you have already computed.

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, 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).

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.

Little’s law: 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 q2, q11, and q14, not graded problems.

A two-sample p-value. a={4,6}a = \{4, 6\}, b={1,3}b = \{1, 3\}: 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. In solve/ this would be answer = "1/3".

An M/M/1 queue. λ=3\lambda = 3, μ=4\mu = 4 per second: ρ=3/4\rho = 3/4, L=(3/4)/(1/4)=3L = (3/4)/(1/4) = 3, 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. 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, (18+6)/27=8/9(18 + 6)/27 = 8/9.

Write each answer in solve/S-M07d.toml; lettered parts are their own tables:

[q1]
answer = "1/4"
[q4]
answer = "{1, 3}"
[q5.a]
answer = "2"
[q12]
answer = "1/(mu - lam)"
[q17]
answer = "a"
[q9]
proof = "S-M07d/q9.md"

Write λ\lambda as lam and μ\mu as mu; exact fractions such as 79/2048 are welcome, ee is E or exp(1).

q1. 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]

q2. 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]

q3. 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]

q4. 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]

q5. 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]

q6. 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]

q7. 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]

q8. 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]

q9. 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]

q10. 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]

q11. 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]

q12. 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]

q13. 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]

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

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

q16. 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]

q17. 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.

PitfallSymptomCaught by
A one-sided count for a two-sided questionp halvedq1, q2, q3 (canaries)
The add-one Monte Carlo estimate where the exact p was asked1/3 instead of 1/4q1 (canary 1/3)
Bonferroni, no correction, or a Holm that does not stopthe wrong set of discoveriesq4 (canaries)
Regressing xx on yy, or a line through two pointsa different slopeq5 (canaries)
The change in log-odds reported as the odds factor1 instead of eeq6 (canary)
The likelihood’s gradient instead of the loss’s, or a missing chain-rule factorNewton walks uphill, or a wrong scaleq7 (canaries)
Ties counted as wins or losses7/9 or 2/3 instead of 13/18q8 (canaries)
λ/W\lambda/W instead of λW\lambda W; the utilization reported as LL160 requests, or 4/5q10, q11 (canaries)
Service time or queue wait reported as the time in system1/10 or 2/5 sq11 (canaries)
The limit n/en/e given for the exact countapproximate where exact was askedq14 (canary)
Ordered pairs or self-pairs countedm2/nm^2/n collisionsq16 (canary)
Believing two choices only shave a constantanswer (a)q17 (canary)
DirectionModuleHow it uses this
BackS-M07csampling distributions and intervals, read as tests here
BackM07.5paired_permutation_test, permutation_test, mcnemar, holm are q1 to q4 in code (reading)
BackM07.7IRLS, roc_auc, and the convexity of q9 (reading)
ForwardL6.7the zoo’s comparison table: q1 to q4 at scale
Forwardload.01the load generator reports concurrency, throughput, and latency, tied together by Little’s law
Forwardgw.05routing across replicas: random choice against least-loaded of two