Skip to content

[heavy_tails.md] Update np.random → Generator API#747

Open
Chihiro2000GitHub wants to merge 1 commit into
mainfrom
update-rng-heavy-tails
Open

[heavy_tails.md] Update np.random → Generator API#747
Chihiro2000GitHub wants to merge 1 commit into
mainfrom
update-rng-heavy-tails

Conversation

@Chihiro2000GitHub
Copy link
Copy Markdown
Contributor

@Chihiro2000GitHub Chihiro2000GitHub commented May 22, 2026

Summary

This PR migrates legacy NumPy random API usage in heavy_tails.md as part of QuantEcon/meta#299.

Details

  • Replaced np.random.seed(...) with rng = np.random.default_rng(...) throughout the lecture.
  • Replaced np.random.randn, np.random.exponential, np.random.uniform, np.random.standard_t, and np.random.normal with the corresponding rng.* methods.
  • In the Q-Q plots cell, rng from the preceding empirical CCDF cell (seed 13) is reused directly — the Q-Q plots compare data_normal against data_exp, data_logn, and data_pareto, all of which were generated with rng = np.random.default_rng(13), so reusing the same rng for data_normal keeps the comparison consistent.
  • For scipy.stats calls (cauchy().rvs, pareto.rvs), random_state=rng is now passed explicitly, as confirmed in the scipy documentation.
  • In the exercise ht_ex5 solution, the function signatures of pareto_rvs and tax_rev were updated to accept rng as an explicit argument. This is flagged for your judgment as it changes the function signatures.
  • Exercise prose at ht_ex3 and ht_ex5 updated to reflect the new API.

Figures to review — please compare with the original rendered lecture:

  • Fig. 22.6 (draws from the Cauchy distribution): The prose describes "a few sudden large deviations from the mean", but after the API migration the new figure shows deviations of noticeably smaller magnitude than the original. It may be worth considering whether a prose update or a seed/parameter adjustment is needed. I have not made any changes here and leave this to your judgment.

  • Fig. 22.16 (Failure of the LLN): After the API migration, this figure could be interpreted as possibly converging if n were increased further, which may weaken the pedagogical point. It may be worth considering whether the seed or N should be adjusted. No changes made; leaving this to your judgment.

  • Exercise 22.4 violin plot: The y-axis scale changed from 1e6 to 1e7 after the migration (likely due to more extreme draws in the Pareto case), causing the plot to appear more compressed than before. The prose remains accurate, but the figure may be less readable. Leaving this to your judgment.

Something I noticed (not fixed in this PR)

While working on this file, I noticed some inconsistencies in the exercise numbering — just flagging them here in case they are useful. These were already present before this PR and are unrelated to the current changes. Exercise 22.1 does not exist on the rendered page (exercises start at 22.2). Exercise 22.3 (ht_ex3) says "Repeat exercise 1", but the exercise it refers to is rendered as Exercise 22.2, not 22.1. Additionally, the exercise rendered as 22.4 corresponds to the label ht_ex5 in the source, creating a mismatch between displayed numbers and internal labels. I have not made any changes here.

Hi @mmcky and @HumphreyYang, I'd be grateful if you could take a look when you have time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented May 22, 2026

Deploy Preview for taupe-gaufre-c4e660 ready!

Name Link
🔨 Latest commit d22033f
🔍 Latest deploy log https://app.netlify.com/projects/taupe-gaufre-c4e660/deploys/6a105da0e622510008ae1a2c
😎 Deploy Preview https://deploy-preview-747--taupe-gaufre-c4e660.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 22, 2026

@github-actions github-actions Bot temporarily deployed to pull request May 22, 2026 13:52 Inactive
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