Worked examples — Federated learning
This page is a workout. The parent note built the machinery — the loss , the FedAvg averaging rule, non-IID data, and differential privacy. Here we run that machinery through every case it can face and check each answer by hand.
Before anything, let us make sure two words never sneak up on you:
The scenario matrix
Federated learning problems fall into a handful of case classes. Every worked example below is tagged with the cell it lands in, and together they cover the whole grid.
| Cell | Case class | The twist it tests |
|---|---|---|
| A | Balanced clients | Equal — does weighted = plain average? |
| B | Unbalanced clients | Very different — who pulls the model? |
| C | Degenerate input | A client with (dropout / empty device) |
| D | Multi-epoch drift | local epochs — the gap vs pure gradient descent |
| E | Communication cost | Bytes on the wire, federated vs centralized |
| F | Non-IID conflict | Clients whose optima point opposite ways |
| G | Privacy noise | Adding DP noise, and what it costs in accuracy |
| H | Exam twist | A "spot the trap" question combining B + C |
Case A — Balanced clients
- Write the totals. . Why this step? The FedAvg rule needs the denominator first — it is the shared "size of the pie."
- Compute each weight fraction. for all three. Why this step? When counts are equal, every fraction collapses to — the weighted average becomes the plain average. This is the sanity anchor for all later cases.
- Average. . Why this step? Blending the models is literally a coordinate-wise weighted mean.
Verify: The plain mean of is . Weighted and plain agree exactly — as they must when are equal. ✓ (Units: weights are unitless model parameters.)
Case B — Unbalanced clients
- Totals. .
- Fractions. , . Why this step? This vs split is the whole point of the [!mistake] in the parent note — data size is voting power.
- Weighted average. .
- Naive average (the trap). .

Look at the figure: the black tick (weighted ) sits close to the big client A, while the grey tick (plain ) drifts toward the tiny, noisy client B.
Verify: Sanity check the extremes: if B had we'd expect . Our formula gives as . The weighted answer sits between, closer to A — correct. ✓
Case C — Degenerate input (empty client)
- Totals over the sampled set. . Why this step? FedAvg's denominator is — the total of this round's clients, not all clients.
- Fractions. . Why this step? The empty client gets weight exactly zero — the maths deletes it automatically. This is the degenerate case working by design.
- Average. .
Verify: Drop the empty client entirely and re-run: . Identical — proving the term is genuinely inert. ✓
Case D — Multi-epoch drift ()
- One true GD step. . Why this step? The parent note proved: with , FedAvg one global gradient step. This is our baseline.
- Local epoch 1. .
- Local epoch 2. Re-evaluate the gradient at the new point: . Why this step? Multi-epoch training keeps stepping on the client's own loss, not the global one — this recomputation is exactly where drift is born.
- Local epoch 3. . Why this step? Notice the pattern . Three epochs travelled to , well past the single-step .

The orange curve races down faster with : fewer communication rounds, but on a many-client problem each client races toward its own minimum — that is the drift term. See Optimization Theory for the convergence machinery.
Verify: Closed form . Matches step 4 exactly. ✓ For a single client (no heterogeneity, ) more epochs is pure speedup — drift only bites across differing clients.
Case E — Communication cost
- Bytes per model transfer. . Why this step? We ship weights, not data — the model size is fixed regardless of dataset size.
- Per round, both directions, all clients. .
- All rounds. .
- Centralized upload. . Why this step? Centralized cost scales with data volume; federated with model size × rounds. That difference is the whole economic argument, tied to Edge Computing.
- Ratio. cheaper here.
Verify: Units line up: ; ; . ✓
Case F — Non-IID conflict
- Model the global loss. With equal weight and quadratic local losses centred at each optimum, . Why this step? A quadratic bowl per client is the standard local model near an optimum; averaging bowls gives the global bowl.
- Minimise. . Why this step? With equal weights the global optimum is the midpoint of the two client optima — the compromise no client is happy with.
- Divergences. , . Why this step? Large, symmetric is the signature of harmful non-IID data — both clients get dragged units from where they wanted to be. This is the case Multi-Task Learning and personalisation aim to soften.
Verify: Midpoint of and is . ✓ And confirms it's a minimum, not a maximum. ✓
Case G — Privacy noise
- Per-client noise std. . Why this step? Clipping to first bounds sensitivity — without it we'd need infinite noise (parent note's Gboard example). See Differential Privacy.
- Variance adds when averaging independent noises. Averaging independent draws each of variance gives variance . Why this step? Independent randomness cancels — this is why federating over many clients helps privacy-vs-accuracy: noise averages out but the signal doesn't.
- Aggregated std. .
- Accuracy impact. The reported weight is — a perturbation. Tolerable.
Verify: ; ; . ✓ Trade-off holds: raise to and the perturbation jumps to — stronger privacy, weaker accuracy, exactly as in Privacy-Preserving ML.
Case H — Exam twist (combines B + C + a robustness trap)
- Naive plain average (trap 1). — dominated by both the empty client's junk and the attacker. Rejected.
- Standard FedAvg with reported sizes. . Fractions . Weighted: . Why this step? Weighting did kill the empty client (Case C) — but the attacker declared the largest , so weighting amplifies it. FedAvg alone is not robust.
- The lesson. Size-weighting defends against noise-from-small-clients but not against a lying large client. You need a robust aggregator (coordinate median / trimmed mean) — see Byzantine Robust Learning.
- Trimmed-mean sketch. Drop the top and bottom value, average the middle: honest weights near – survive, the outlier and the junk are discarded, giving .
Verify: Naive: . ✓ FedAvg: . ✓ Both "correct by formula" yet both wrong for safety — that is the exam trap: the arithmetic is fine, the threat model is not.
Recall Quick self-test
Equal makes weighted average equal to ::: the plain average. A client with receives FedAvg weight ::: exactly zero (it drops out). After local epochs on with , one weight becomes ::: . The global optimum of two equal, opposing clients sits at ::: the midpoint of their optima. Averaging independent DP noise draws shrinks the noise std by a factor of ::: . Size-weighting protects against small noisy clients but NOT against ::: a Byzantine client lying about a huge .