Solve set: hypothesis tests, regression, queueing and Little's law, balls into bins
Overview
Section titled “Overview”| Module | S-M07d · solve · none · Pass 5 · 3 to 4 h |
| You build | answers in solve/S-M07d.toml (19 checked by SymPy) and 1 proof in solve/S-M07d/q9.md (self-graded against its rubric) |
| Contract | none: a pen and paper set |
| Tests | course/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 |
| Needs | S-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 by | no 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 |
| Milestone | MS-P5 (the Pass 5 gate runs ol check on every solve part of the pass) |
| Optional depth | 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) |
Key Takeaways
Section titled “Key Takeaways”- An exact permutation p-value is a count over a finite set of relabellings; with three pairs, even a unanimous win has (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 holds for any stable system; in M/M/1 the time in system explodes as utilization approaches 1 (q10 to q13).
- Throwing balls into bins leaves about of them empty, and asking two bins instead of one shrinks the fullest bin from to (q14 to q17).
How to work this chapter
Section titled “How to work this chapter”ol start S-M07d # writes solve/S-M07d.toml and the proof fileol 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 proof1. Why now
Section titled “1. Why now”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.
2. Principles
Section titled “2. Principles”| Symbol | Meaning | Type / shape |
|---|---|---|
| , | paired differences and random signs | reals |
| , | discordant counts (only A right, only B right) | integers |
| , , | sorted p-values, family size, level | reals, integer |
| , | intercept and slope of a least-squares line | reals |
| the sigmoid | function | |
(lam), (mu) | arrival rate and service rate | positive reals |
| utilization | in | |
| , | mean number in the system and mean time in the system | reals |
| , | bins and balls | positive integers |
2.1 Tests
Section titled “2.1 Tests”A p-value is the probability under of a statistic at least as extreme as observed. Exact permutation p-values count the relabellings that makes equally likely: sign vectors for pairs, splits for two samples. McNemar uses only the discordant pairs, a fair coin under . Holm sorts the p-values and rejects the -th smallest while .
2.2 Regression
Section titled “2.2 Regression”Least squares minimizes ; setting both partial derivatives to 0 gives with , , and . In logistic regression the log-odds are linear, so a coefficient multiplies the odds by per unit of its feature, and . The AUC is the fraction of (positive, negative) pairs ranked correctly, ties counting one half.
2.3 Queueing
Section titled “2.3 Queueing”Little’s law: in any system where items arrive at long-run rate and stay a mean time , the mean number inside is , 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: , so and, by Little, .
2.4 Balls into bins
Section titled “2.4 Balls into bins”With balls thrown uniformly into bins, a given bin is missed by every ball with probability , and linearity of expectation adds such indicators over bins or over pairs of balls with no independence needed. With , . The most loaded bin holds about balls with one random choice; Azar, Broder, Karlin, and Upfal (1994) showed that sampling two bins and taking the emptier gives , an exponential improvement.
3. Worked example by hand
Section titled “3. Worked example by hand”These are siblings of q2, q11, and q14, not graded problems.
A two-sample p-value. , : . The six ways to pick group from give of , , , , , . Two of six reach 3: . In solve/ this would be answer = "1/3".
An M/M/1 queue. , per second: , , s, and indeed . The service time alone is s; queueing quadrupled it.
Empty bins. balls into 3 bins: a bin is empty with probability , so the expected number of empty bins is . Enumerating the 27 assignments agrees: 6 hit every bin (0 empty), 18 leave one empty, 3 leave two empty, .
4. The problem set
Section titled “4. The problem set”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 as lam and as mu; exact fractions such as 79/2048 are welcome, is E or exp(1).
Hypothesis tests
Section titled “Hypothesis tests”q1. Model B minus model A on three prompts gives the paired differences . Give the exact two-sided sign-flip p-value: the fraction of the sign vectors with . [number, exact]
q2. Two unpaired samples, and , with statistic . Give the exact two-sided permutation p-value: the fraction of the ways to split the pooled values into two groups of two whose is at least the observed one. [number, exact]
q3. Two classifiers on the same eval set: A alone is right on examples, B alone on . Give the exact two-sided McNemar p-value , , . [number, exact]
q4. Five comparisons have p-values . Which hypotheses does Holm’s procedure reject at family-wise level ? Answer with the set of their indices. [set]
Regression
Section titled “Regression”q5. Fit the least-squares line to the points . (a) . [number, exact] (b) . [number, exact]
q6. A fitted logistic regression has log-odds . By what factor do the odds of multiply when increases by 2? [number, exact]
q7. For one example with , , and , the loss is . Give . [expr in w, x, y]
q8. A classifier scores three positives and three negatives . Give its ROC-AUC, counting a tied pair as one half. [number, exact]
q9. Prove that the penalized logistic loss , , , is convex, and say why that makes every stationary point a global minimum and Newton’s step well defined when . [proof]
Queueing and Little’s law
Section titled “Queueing and Little’s law”q10. A gateway receives requests per second and the mean time a request spends inside it is s. By Little’s law, how many requests are inside on average? [number, exact]
q11. A single-server queue with Poisson arrivals at per second and exponential service at rate per second (M/M/1). (a) The utilization . [number, exact] (b) The mean number in the system . [number, exact] (c) The mean time in the system , by Little’s law. [number, exact]
q12. Give the mean time in an M/M/1 system as a formula in the arrival rate and the service rate . [expr in lam, mu]
q13. Keep the service rate fixed. By what factor is the mean time in an M/M/1 system larger at utilization than at ? [number, exact]
Balls into bins
Section titled “Balls into bins”q14. Throw balls independently and uniformly into bins. Give the expected number of empty bins. [expr in n]
q15. As , what fraction of the bins in q14 is empty? [number, exact]
q16. Throw balls independently and uniformly into bins. Give the expected number of pairs of balls that land in the same bin. [expr in m, n]
q17. requests go to 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) with two choices, the same as with one.
(b) with two choices, against with one.
(c) with one choice, with two.
(d) a constant with two choices.
5. Pitfalls
Section titled “5. Pitfalls”| Pitfall | Symptom | Caught by |
|---|---|---|
| A one-sided count for a two-sided question | p halved | q1, q2, q3 (canaries) |
| The add-one Monte Carlo estimate where the exact p was asked | 1/3 instead of 1/4 | q1 (canary 1/3) |
| Bonferroni, no correction, or a Holm that does not stop | the wrong set of discoveries | q4 (canaries) |
| Regressing on , or a line through two points | a different slope | q5 (canaries) |
| The change in log-odds reported as the odds factor | 1 instead of | q6 (canary) |
| The likelihood’s gradient instead of the loss’s, or a missing chain-rule factor | Newton walks uphill, or a wrong scale | q7 (canaries) |
| Ties counted as wins or losses | 7/9 or 2/3 instead of 13/18 | q8 (canaries) |
| instead of ; the utilization reported as | 160 requests, or 4/5 | q10, q11 (canaries) |
| Service time or queue wait reported as the time in system | 1/10 or 2/5 s | q11 (canaries) |
| The limit given for the exact count | approximate where exact was asked | q14 (canary) |
| Ordered pairs or self-pairs counted | collisions | q16 (canary) |
| Believing two choices only shave a constant | answer (a) | q17 (canary) |
6. Where it’s used next
Section titled “6. Where it’s used next”| Direction | Module | How it uses this |
|---|---|---|
| Back | S-M07c | sampling distributions and intervals, read as tests here |
| Back | M07.5 | paired_permutation_test, permutation_test, mcnemar, holm are q1 to q4 in code (reading) |
| Back | M07.7 | IRLS, roc_auc, and the convexity of q9 (reading) |
| Forward | L6.7 | the zoo’s comparison table: q1 to q4 at scale |
| Forward | load.01 | the load generator reports concurrency, throughput, and latency, tied together by Little’s law |
| Forward | gw.05 | routing across replicas: random choice against least-loaded of two |