Skip to content

Fix assorted issues in prob_meaning lecture#878

Merged
jstac merged 11 commits into
mainfrom
prob_meaning_edits
May 29, 2026
Merged

Fix assorted issues in prob_meaning lecture#878
jstac merged 11 commits into
mainfrom
prob_meaning_edits

Conversation

@jstac
Copy link
Copy Markdown
Contributor

@jstac jstac commented May 26, 2026

Summary

Addresses #877 — a comprehensive revision of lectures/prob_meaning.md.

Mechanical fixes:

  • Typos (probabililty ×6, statististian, etc.), doubled words ("to to", "with with")
  • Wrong variance formula (extra factor of n), swapped upper/lower bounds
  • Notation: $P_{k,i}$$\rho_{k,i}$, subject-verb agreement, LaTeX *\cdot
  • compare() now includes $k=0$, log(I) range text matches code
  • Imprecise wording: $f_k^I$ approximates $\text{Prob}(X=k|\theta)$, not $\theta$
  • Use IID instead of i.i.d., **bold** instead of __bold__

Code quality:

  • PEP 8 naming (frequentistFrequentist, Bay_statbayes)
  • Clearer variable names (iipost/i, kkk, Khead_counts, etc.)
  • Replaced prettytable dependency with pandas DataFrame
  • Reproducible output via np.random.default_rng() seeds (modern NumPy API)
  • Standardized plotting to use ax. methods instead of plt.
  • Grid resolution bumped from 100 to 1000 points for smoother density plots
  • f-string formatting with comma separators for plot labels
  • Removed dead self.k assignment

Content restructuring:

  • Derived the $n$-step posterior $\text{Beta}(\alpha + k, \beta + n - k)$ before the exercise, replacing the duplicated derivation that appeared after
  • Added back-reference to prob_matrix lecture for Bayes' Law
  • Introduced $p(\theta)$ (lowercase) as density notation, noted it is a density
  • Broke up the crowded aligned equation in part (b) solution into three display equations with explanatory text
  • Removed repeated question text from solution headers (QuantEcon convention)
  • Renamed quantile variables $p_1, p_2$$q_1, q_2$ to avoid clash with density notation
  • Standardized $N$$n$ throughout
  • Cross-references now use actual lecture titles for better PDF rendering
  • Simplified plot legends and reduced clutter (removed n = 30, 70, 300, 500)

Test plan

  • Verify the lecture builds without errors
  • Check that all code cells execute correctly
  • Confirm plots render with improved grid resolution and reproducible seeds
  • Verify cross-references resolve correctly

🤖 Generated with Claude Code

jstac and others added 3 commits May 27, 2026 06:44
- Fix spelling: probabilties, probabililty (x6), statististian
- Fix doubled word: "to to help"
- Fix variance formula: remove erroneous factor of n (rho is Bernoulli, not binomial)
- Fix notation: P_{k,i} → rho_{k,i} to match definition
- Fix subject-verb agreement: "means converges" → "mean converges"
- Fix swapped upper/lower bounds in part (e) ppf calls
- Fix compare() to include k=0
- Fix LaTeX: replace * with \cdot for multiplication
- Fix log(I) range: text said 2 to 7, code has 2 to 6
- Fix imprecise wording: f_k^I approximates Prob(X=k|θ), not θ
- Clarify vague exercise pm_ex1 part 3

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Rename class frequentist → Frequentist (PEP 8)
- Rename Bay_stat → bayes (snake_case for instances)
- Rename ii → i/post, num → n_obs, num_list → n_obs_list,
  kk → k, K → head_counts, comp → table, step_num → n_obs,
  npt → n_thetas, nn → n_ns, nI → n_Is
- Replace (sample <= θ) * 1 with .astype(int) for consistency
- Shorten docstrings to fit within 80 characters
- Break long code lines (plot calls, list comprehensions, titles)
- Increase θ grid from 100 to 1000 points for smoother density plots
- Use f-strings with comma formatting for plot labels

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Add back-reference to prob_matrix lecture for Bayes' Law intro
- Derive the n-step posterior Beta(α+k, β+n-k) before the exercise,
  so the exercise solution code no longer precedes its own derivation
- Replace the duplicated derivation after the exercise with a concise
  summary referencing the formula above
- Remove duplicate "Now pretend..." sentence before part (c)
- Replace "this quantecon lecture" cross-references with actual titles
  for better PDF rendering

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jstac
Copy link
Copy Markdown
Contributor Author

jstac commented May 26, 2026

This PR addresses the issues catalogued in #877. The changes are split across three commits for easier review:

  1. Mechanical fixes — typos, spelling, the wrong variance formula, swapped bounds, notation inconsistencies, and other small corrections.
  2. Code quality — PEP 8 naming, clearer variable names, shorter docstrings, line length fixes, higher grid resolution for plots, and consistent use of .astype(int).
  3. Content restructuring — the key pedagogical change. The $n$-step posterior formula $\text{Beta}(\alpha + k, \beta + n - k)$ is now derived before the exercise, so the solution code no longer relies on a result that hasn't been shown yet. The duplicated derivation that appeared after the exercise is replaced with a concise summary. A back-reference to the prob_matrix lecture is added for readers who need a refresher on Bayes' Law, and cross-references now use actual lecture titles for better PDF rendering.

@jstac jstac mentioned this pull request May 26, 2026
21 tasks
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 26, 2026

📖 Netlify Preview Ready!

Preview URL: https://pr-878--sunny-cactus-210e3e.netlify.app

Commit: 400d8ab

📚 Changed Lectures


Build Info

jstac and others added 7 commits May 27, 2026 07:21
Drop the prettytable dependency — pandas is already imported and
renders nicely in Jupyter notebooks. The compare() method now returns
a DataFrame instead of printing a PrettyTable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The question asked for the likelihood of "a sample of length n from
a binomial" but the solution gave the single-flip Bernoulli case.
Reword both the questions and solution headers so parts (a) and (b)
are explicitly about a single coin flip. The general n-step case is
already derived in the lecture text before the exercise.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Both classes now accept an rng parameter and use rng.random()
instead of np.random.rand(). Each code cell passes a seeded
np.random.default_rng() for reproducible output across builds.

Also remove "typically" from the hump-shape sentence, since with
fixed seeds the behavior is deterministic.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Rename title from "P.D.F" to "PDF"
- Simplify legend labels: "n = 0 (prior)", "n = 1", etc.
- Remove n = 30, 70, 300, 500 from observation list to reduce
  clutter in the first PDF plot

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Solutions for parts (c)-(h) no longer duplicate the question text
as a header — they just use the part label. This follows the
QuantEcon convention.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Change P(θ) to p(θ) throughout and note it is a density
- Replace the single aligned equation block in the solution for
  part (b) with three separate display equations, each introduced
  by explanatory text (Bayes' Law, substitution, collecting powers)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Use **bold** instead of __bold__ for binomial distribution
- Use IID instead of i.i.d.
- Fix double "with" in exercise (c) wording
- Rename quantile variables from p_1/p_2 to q_1/q_2 to avoid
  clash with p(θ) density notation
- Fix "means and variances statistics" → "mean and standard deviation"
- Standardize N → n in post-exercise text to match pre-exercise
- Update "exceeds 500" → "exceeds 1000" to match revised n_obs_list
- Standardize frequentist plots to use ax. methods instead of plt.
- Remove dead self.k assignment in Frequentist.binomial()

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jstac jstac mentioned this pull request May 27, 2026
14 tasks
@jstac
Copy link
Copy Markdown
Contributor Author

jstac commented May 27, 2026

Note: If QuantEcon/QuantEcon.manual#84 is merged (which standardizes on \mathbb{P} for probability notation), this PR will need a follow-up commit to replace \textrm{Prob}(...) with \mathbb{P}\{...\} throughout.

Replace \textrm{Prob}(...) with \mathbb{P}{...} and E[...] with
\mathbb{E}[...] following QuantEcon.manual#84.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@jstac
Copy link
Copy Markdown
Contributor Author

jstac commented May 28, 2026

@thomassargent30

Please let me know if you would like any modifications to the PR. I'll aim to merge tomorrow but we can always walk things backwards.

I think these are all good changes.

@jstac jstac merged commit 30c5c43 into main May 29, 2026
1 check passed
@jstac jstac deleted the prob_meaning_edits branch May 29, 2026 04:26
thomassargent30 pushed a commit that referenced this pull request May 31, 2026
* Fix typos, spelling, notation errors, and swapped bounds in prob_meaning

- Fix spelling: probabilties, probabililty (x6), statististian
- Fix doubled word: "to to help"
- Fix variance formula: remove erroneous factor of n (rho is Bernoulli, not binomial)
- Fix notation: P_{k,i} → rho_{k,i} to match definition
- Fix subject-verb agreement: "means converges" → "mean converges"
- Fix swapped upper/lower bounds in part (e) ppf calls
- Fix compare() to include k=0
- Fix LaTeX: replace * with \cdot for multiplication
- Fix log(I) range: text said 2 to 7, code has 2 to 6
- Fix imprecise wording: f_k^I approximates Prob(X=k|θ), not θ
- Clarify vague exercise pm_ex1 part 3

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Improve code quality: naming, PEP 8, line length, grid resolution

- Rename class frequentist → Frequentist (PEP 8)
- Rename Bay_stat → bayes (snake_case for instances)
- Rename ii → i/post, num → n_obs, num_list → n_obs_list,
  kk → k, K → head_counts, comp → table, step_num → n_obs,
  npt → n_thetas, nn → n_ns, nI → n_Is
- Replace (sample <= θ) * 1 with .astype(int) for consistency
- Shorten docstrings to fit within 80 characters
- Break long code lines (plot calls, list comprehensions, titles)
- Increase θ grid from 100 to 1000 points for smoother density plots
- Use f-strings with comma formatting for plot labels

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Restructure Bayesian section: derive posterior before exercise

- Add back-reference to prob_matrix lecture for Bayes' Law intro
- Derive the n-step posterior Beta(α+k, β+n-k) before the exercise,
  so the exercise solution code no longer precedes its own derivation
- Replace the duplicated derivation after the exercise with a concise
  summary referencing the formula above
- Remove duplicate "Now pretend..." sentence before part (c)
- Replace "this quantecon lecture" cross-references with actual titles
  for better PDF rendering

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Replace prettytable with pandas DataFrame in compare()

Drop the prettytable dependency — pandas is already imported and
renders nicely in Jupyter notebooks. The compare() method now returns
a DataFrame instead of printing a PrettyTable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Fix exercise pm_ex2 parts (a) and (b) to match their solutions

The question asked for the likelihood of "a sample of length n from
a binomial" but the solution gave the single-flip Bernoulli case.
Reword both the questions and solution headers so parts (a) and (b)
are explicitly about a single coin flip. The general n-step case is
already derived in the lecture text before the exercise.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Add reproducible random seeds using modern NumPy API

Both classes now accept an rng parameter and use rng.random()
instead of np.random.rand(). Each code cell passes a seeded
np.random.default_rng() for reproducible output across builds.

Also remove "typically" from the hump-shape sentence, since with
fixed seeds the behavior is deterministic.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Clean up posterior PDF plots

- Rename title from "P.D.F" to "PDF"
- Simplify legend labels: "n = 0 (prior)", "n = 1", etc.
- Remove n = 30, 70, 300, 500 from observation list to reduce
  clutter in the first PDF plot

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Remove repeated question text from exercise solutions

Solutions for parts (c)-(h) no longer duplicate the question text
as a header — they just use the part label. This follows the
QuantEcon convention.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Use p(θ) for density notation and break up solution derivation

- Change P(θ) to p(θ) throughout and note it is a density
- Replace the single aligned equation block in the solution for
  part (b) with three separate display equations, each introduced
  by explanatory text (Bayes' Law, substitution, collecting powers)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Final review polish: notation, plotting style, consistency

- Use **bold** instead of __bold__ for binomial distribution
- Use IID instead of i.i.d.
- Fix double "with" in exercise (c) wording
- Rename quantile variables from p_1/p_2 to q_1/q_2 to avoid
  clash with p(θ) density notation
- Fix "means and variances statistics" → "mean and standard deviation"
- Standardize N → n in post-exercise text to match pre-exercise
- Update "exceeds 500" → "exceeds 1000" to match revised n_obs_list
- Standardize frequentist plots to use ax. methods instead of plt.
- Remove dead self.k assignment in Frequentist.binomial()

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Adopt new style guide notation conventions

Replace \textrm{Prob}(...) with \mathbb{P}{...} and E[...] with
\mathbb{E}[...] following QuantEcon.manual#84.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant