merging_of_opinions#
Series: lecture-python.myst
File:
lectures/merging_of_opinions.mdAudit date: 2026-08-26
Corpus snapshot:
e25fdf2345Categories audited: writing, math, code, figures, references, links, admonitions (JAX out of scope)
Overall score: 8.1 / 10
Priority: LOW
Score breakdown#
Category |
Score |
One-line note |
|---|---|---|
Writing |
4.5/10 |
|
Math |
7/10 |
|
Code |
8.5/10 |
|
JAX |
out of scope |
JAX rules target |
Figures |
7.5/10 |
|
References |
9/10 |
|
Links |
10/10 |
no mechanical violations detected. |
Admonitions |
10/10 |
no mechanical violations detected. |
Issues#
Critical#
None found.
High severity#
[qe-fig-001] — Do not set figure size unless necessary. Count: 8. Lines: 578, 675, 742, 828, 985, 1012, 1041, 1239. Example: figsize=.
[qe-writing-006] — Capitalize lecture titles properly. Count: 1. Lines: 353. Example: H2 Title Case: ‘The Beta–Bernoulli model’ (Beta).
Medium severity#
[qe-code-001] (reviewer) — Follow PEP8 unless closer to mathematical notation. Count: 3. Lines: 626, 481, 1240. Example: 626 puts
from matplotlib.lines import Line2Din the middle of a plotting cell, 560 lines after the import cell at 57-62 (flake8 E402), where the lecture’s other four imports are collected at the top as the series convention asks. Twenty-two assignments are padded with extra spaces to align their=signs - 481, 497, 524, 530, 531, 677, 680, 682, 686, 740, 956, 957, 958, 960, 1225, 1226, 1230, 1231, 1232, 1233, 1236 (E221) - which PEP8 lists under extraneous whitespace, and unlike a matrix literal there is nothing mathematical being aligned: they are scalars and array allocations (ns = np.arange(1, N_max + 1),tv_all = np.empty(...)). 1240 adds a double space inside a call argument list,ax.loglog(ns_rate, mean_tv, color='steelblue', ...)(E241). Nothing else: no long lines, no operator-spacing problems, and the Unicode Greek convention is followed (μ_seqat 980, 1007, 1036).[qe-fig-003] — No matplotlib embedded titles. Count: 4. Lines: 588, 599, 607, 624. Example: .set_title.
[qe-math-009] (reviewer) — Choose simplicity in mathematical notation. Count: 4. Lines: 93, 388, 397, 439. Example: the subscript on \(P\) carries four different kinds of index and the reader has to infer which from context every time: a horizon, \(P_n = P|_{\mathscr{F}_n}\) (93); a parameter value, \(P_p\) for the IID Bernoulli\((p)\) law (388); an agent, \(P_i\) for agent \(i\)’s mixture (394); and both at once, \(P_{1,n}\) (439). By 901 a fifth reading is in play, \(P_n\) as the \(n\)-th marginal factor. The argument of \(P\) is overloaded too: \(P_i(A)\) at 397 is a measure applied to an event, and \(P_i(x^n)\) at 405, 422 and 439 is applied to a single history - the lecture needs a whole sentence (404-406) to say which is meant, which is itself the evidence that the notation is doing too much. Distinct letters would cost nothing: \(P^{(n)}\) or \(P|_n\) for restrictions, \(\mathrm{Ber}_p\) for the parameterised law, \(m_i(x^n)\) for the marginal likelihood. Separately 884 and 947 decorate the normal law as \(\mathcal{N}\) where the lecture already writes \(\mathrm{Beta}\) and \(\mathrm{Bernoulli}\) upright (366, 373, 890, 1149) - qe-math-011 (proposed) counts those four and the fix is to match the convention the same file already uses.
[qe-math-011 (proposed)] — Distribution names in plain letters, not \mathcal / \mathbb. Count: 4. Lines: 884, 947. Example: decorated distribution
\mathcal{N}.[qe-math-015 (proposed)] (reviewer) — Lowercase for densities/PMFs, uppercase for CDFs. Count: 3. Lines: 405, 422, 439. Example: the lecture is careful about case everywhere else - the prior density is lower-case \(\pi_i\) (393, 411), the generic Radon-Nikodym density is lower-case \(f = d\mu/d\nu\) (136), the Beta density is \(\pi_i(p)\) (411) - and then writes the probability mass function of a history with a capital: \(P_i(x^n)\) at 405, 422 and 439, where 434 confirms it is a mass function (“It depends on the data only through the count \(k\), so histories with the same number of successes receive the same probability”). Under the rule this should be \(p_i(x^n)\), or \(m_i(x^n)\) for a marginal likelihood, which is the name 386 gives it. The counter-reading is that \(P_i(x^n)\) abbreviates the measure of the cylinder set \(\{X_1 = x_1, \ldots, X_n = x_n\}\), in which case a capital is right - but that reading is exactly why 404-406 has to explain the notation, and the same symbol is applied to a genuine event two lines earlier at 397, so the two uses are not distinguishable by shape.
[qe-writing-001] — Use one sentence per paragraph. Count: 2. Lines: 290, 312. Example: 2 sentences in one paragraph.
[qe-writing-002] (reviewer) — Keep writing clear, concise, and valuable. Count: 3. Lines: 1149, 457, 1289. Example: 1147-1149 is where the lecture’s most delicate point lives and it is delivered in two sentences of 38 and 49 words, the second carrying a parenthetical, an inline set-builder and a parenthetical gloss at the end - “yet \(Q^* \not\ll P\) globally because the set \(\{\lim k_n/n = p^*\}\) has \(Q^*\)-measure one but \(P\)-measure zero (different Bernoulli product measures are mutually singular)”. 457-460 is 40 words with a parenthetical in the middle of the premise. And “Applications in economics” (1287-1303) is thirteen bullets of one-line paraphrase with no synthesis and no ordering principle - a bibliography set as prose, where two or three sentences saying what the literature collectively established would carry more per word. Against that, the rest of the file is a model of one-sentence-per-paragraph and qe-writing-001 measures only 2.
[qe-writing-003] (reviewer) — Maintain logical flow. Count: 4. Lines: 85, 871, 1307, 331. Example: (1) 85 defines “the tail \(\sigma\)-algebra \(\mathscr{F}_\infty = \sigma(\bigcup_{n \geq 1}\mathscr{F}_n)\)”, and that is not the tail \(\sigma\)-algebra - the tail is \(\bigcap_n \sigma(x_n, x_{n+1},\ldots)\), whereas \(\sigma(\bigcup_n \mathscr{F}_n)\) is the \(\sigma\)-algebra generated by the filtration, which for \(\Omega = S^{\mathbb{N}}\) with the product \(\sigma\)-algebra is all of \(\mathscr{F}\) (73-75). The mislabel is load-bearing: 210-214 puts \(Z = dQ/dP\) on \((\Omega, \mathscr{F})\) and 226 sets \(Z_\infty = \mathbb{E}_P[Z \mid \mathscr{F}_\infty]\), so on the lecture’s own definitions \(Z_\infty = Z\) and the distinction it maintains between them for the next thousand lines is empty; and 1086-1099 turns on whether local absolute continuity extends to \(\mathscr{F}_\infty\), which is a different question if \(\mathscr{F}_\infty = \mathscr{F}\). (2) \(P_n\) is defined twice with incompatible meanings: 93-94 sets \(P_n = P|_{\mathscr{F}_n}\), the joint law of the first \(n\) observations, and 871, 884, 890 and 901-902 use \(P_n\) for the \(n\)-th marginal factor on \((S, \mathscr{S})\) - so
Let $P = \bigotimes_{n=1}^\infty P_n$at 901 reads, under the earlier definition, as a product of restrictions of \(P\) with itself. (3) 1307 repeats 1153 almost word for word - both begin “DiaconisFreedman1986 study the consistency of Bayes estimates” - and cites the same paper two different ways,{cite:t}at 1153 and{cite}at 1307, which is the qe-ref-001 hit. (4) 331-333 gives the wrong reason for a right conclusion: “One-sided absolute continuity \(Q \ll P\) gives merging \(Q\)-almost surely. Since \(Q \ll P\) means every \(P\)-null set is also \(Q\)-null, \(Q\)-a.s. convergence does not automatically imply \(P\)-a.s. convergence.” The stated fact is what makes a \(P\)-a.s. statement imply a \(Q\)-a.s. one; it is not a reason for the non-implication in the other direction.[qe-writing-004] — Avoid unnecessary capitalization in narrative text. Count: 1. Lines: 314. Example: mid-sentence ‘Step’.
[qe-writing-007] (reviewer) — Use visual elements to enhance understanding. Count: 3. Lines: 971, 609, 933. Example: the Kakutani section ends in three consecutive code cells (971-994, 998-1021, 1027-1050) that are identical apart from
cases[0]/cases[1]/cases[2], a colour and a caption, each drawing one line of \(\log Z_N\) on its own axes. The section’s whole point is the dichotomy - constant and \(c/\sqrt n\) drift give \(P \perp Q\), \(c/n\) gives \(P \sim Q\) - and that comparison is destroyed by putting the three on three separate axes with three separate y-scales. Worse, each cell draws its ownx = rng.standard_normal(N_plot)from the same generator (981, 1008, 1037), so the three panels use three different shock paths and the visible differences conflate the drift regime with the sampling noise; one figure, one \(x\), three lines on shared axes would make the dichotomy immediate and is strictly less code. Second, panel (d) of{numref}`fig-merging-of-opinions-beta-bernoulli`(609-637) already plots the two posterior densities at four horizons, and \(d_n\) - the quantity panel (b) plots on a log scale, and the object{prf:ref}`total_variation_distance`defines as \(\tfrac12\int|d\mu/d\lambda - d\nu/d\lambda|d\lambda\) - is literally half the area between those two curves; shading it would tie the definition at 120-134, the code at 501, and panels (b) and (d) together in one stroke. Third, the dichotomy table at 933-937 tabulates three scenarios by whether \(\sum_n(1-\rho_n)\) converges, and \(1-\rho_n\) for the three Gaussian cases is a two-line plot the lecture never draws.[qe-writing-008] — Remove excessive whitespace between words. Count: 2. Lines: 229, 1277. Example: 2 spaces.
Low severity#
[qe-ref-001] — Use correct citation style. Count: 1. Lines: 1307. Example:
{cite}in author position: ‘{cite}`DiaconisFreedman1986`study’.
Strengths#
The theorem is set up before it is stated and every ingredient it needs is defined first: the standard Borel assumption with the reason it is needed (69-71, ‘guarantees the existence of regular conditional distributions, which the theorem requires’), absolute continuity in its three flavours as a
{prf:definition}(98-109), total variation with the equivalent sup and integral forms (120-134), and only then the merging question at 185-192.The proof of
{prf:ref}`blackwell_dubins`is given in three numbered steps (288-324) and each step names the tool it uses - the representation of \(d_n\) via \(Z_\infty/Z_n\), convexity of total variation for the supermartingale property, \(L^1(P)\) convergence of the martingale for the limit - and 296-298 states the economic content of the supermartingale step in one sentence: ‘Conditioning on more information reduces distinguishability on average’.The identity the whole proof rests on is set as an exercise with a hint and a five-line worked solution (142-166) rather than asserted: 139 states \(\|\mu-\nu\|_{TV} = \mathbb{E}_\nu[(f-1)^+]\) and the solution derives it from \(\mathbb{E}_\nu[f]=1\) and \(|f-1| = (f-1)^+ + (1-f)^+\).
The Beta-Bernoulli example is carried all the way from the marginal likelihood in closed form (420-430, with the beta-function identity written out) to the exact TV formula (464-468, justified by de Finetti and the mutual singularity of Bernoulli product measures at 453-460) to code that computes it (474-544), so the simulated \(d_n\) is the theorem’s \(d_n\) and not a proxy.
The negative result is done properly: the point-mass example (781-855) gives \(d_n = 1\) for every \(n\), and 802-804 heads off the obvious objection by computing the one-step predictive gap, \(|p_P - p_Q| = 0.45\), and saying explicitly that it ‘is not the quantity that appears in Blackwell-Dubins’.
The lecture is candid where the simulation falls short of the theorem: 718-720 says the distances at \(n = 500\) ‘are not yet close to zero’ and that this is still consistent with an asymptotic statement, and 770-772 says the supermartingale figure ‘is only an illustration, not a proof, because it uses unconditional averages rather than the full conditional expectation’.
Bold is reserved for definitions on first use without exception - all nine spans (85, 87, 101, 104 twice, 107, 131, 872, 1104) define a term - and italic carries every emphasis (possible 114, not 333, both 335, future/past 174) and the run-in labels (Hint: 147, Proof sketch. 229, Proof idea. 919), so qe-writing-005 has nothing to report.
All six figures carry
mystnbcaption and name metadata with multi-line captions that say what each panel shows (562-568, 664-670, 730-736, 807-815, 972-978, 1209-1215), and the four-panel figure’s panels are then walked through one by one at 643-654.
Recommended actions#
Rename \(\mathscr{F}_\infty\) at 85: it is the \(\sigma\)-algebra generated by the filtration, not the tail \(\sigma\)-algebra, and on the lecture’s own construction (73-75) it equals \(\mathscr{F}\) - which also makes \(Z_\infty = \mathbb{E}_P[Z \mid \mathscr{F}_\infty]\) at 226 equal to \(Z\). Either say so, or state the weaker \(\mathscr{F}_\infty \subseteq \mathscr{F}\) the rest of the lecture (1086-1099) actually needs.
Give the two meanings of \(P_n\) different symbols: it is the restriction \(P|_{\mathscr{F}_n}\) at 93 and the \(n\)-th marginal factor at 871, 884, 890 and 901, and both readings are live in the Kakutani section. While there, unify the other three subscripts on \(P\) (\(P_p\) 388, \(P_i\) 394, \(P_{1,n}\) 439) and write the history mass function in lower case, \(p_i(x^n)\) or \(m_i(x^n)\), per qe-math-015 (proposed).
Merge the three Kakutani cells (971-1050) into one figure with three lines on shared axes, drawing a single
x = rng.standard_normal(N_plot)once and reusing it - as written each panel uses a different shock path, so the comparison the section exists to make is confounded.Delete or rewrite 1307: it repeats 1153 nearly verbatim about the same paper, and it is the file’s one qe-ref-001 hit - 1153 already gets it right with
{cite:t}DiaconisFreedman1986study ..., so the fix is to make 1307 match or to drop the duplicate paragraph. Do NOT change the thirteen bullet citations at 1291-1303 on the strength of that hit (see scanner_doubts).Fix the reasoning at 331-333: the stated fact (\(Q \ll P\) means every \(P\)-null set is \(Q\)-null) is why \(P\)-a.s. implies \(Q\)-a.s., not why \(Q\)-a.s. fails to imply \(P\)-a.s.
Shade the total-variation area in panel (d) of the four-panel figure (609-637): it is half the area between the two posterior densities already drawn there and it is the quantity panel (b) plots, so one
fill_betweenconnects the definition at 120-134 to both panels.Split the two sentences at 1147-1149 and the one at 457-460, and replace the thirteen-bullet list at 1291-1303 with two or three sentences plus the citations.
Do NOT lower-case ‘Step’ at 314: it refers to the labelled ‘Step 1’ at 290, which is the already-known qe-writing-004 false-positive shape. The other three writing hits are genuine - the Title-Case H2 at 353 (‘The Beta-Bernoulli model’ is flagged on ‘Beta’, a proper noun, so check before editing: the heading is in fact correct sentence case and needs no change), the two two-sentence paragraphs at 290 and 312, and the double spaces at 229 and 1277.
Sweep the mechanical items: the eight
figsizeoverrides (578, 675, 742, 828, 985, 1012, 1041, 1239), the four panelset_titlecalls (588, 599, 607, 624) which duplicate what the caption at 565-567 already lists, the two\mathcal{N}sites (884, 947), thefrom matplotlib.lines import Line2Dat 626, the twenty-two E221 alignment paddings, theBlackwell--Dubinsat 1299 which uses a LaTeX double hyphen where the rest of the file uses the Unicode en dash, and the eightfontsize=8overrides.