[heavy_tails.md] Update np.random → Generator API#747
Open
Chihiro2000GitHub wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
✅ Deploy Preview for taupe-gaufre-c4e660 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
40 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR migrates legacy NumPy random API usage in
heavy_tails.mdas part of QuantEcon/meta#299.Details
np.random.seed(...)withrng = np.random.default_rng(...)throughout the lecture.np.random.randn,np.random.exponential,np.random.uniform,np.random.standard_t, andnp.random.normalwith the correspondingrng.*methods.rngfrom the preceding empirical CCDF cell (seed 13) is reused directly — the Q-Q plots comparedata_normalagainstdata_exp,data_logn, anddata_pareto, all of which were generated withrng = np.random.default_rng(13), so reusing the samerngfordata_normalkeeps the comparison consistent.scipy.statscalls (cauchy().rvs,pareto.rvs),random_state=rngis now passed explicitly, as confirmed in the scipy documentation.pareto_rvsandtax_revwere updated to acceptrngas an explicit argument. This is flagged for your judgment as it changes the function signatures.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
nwere increased further, which may weaken the pedagogical point. It may be worth considering whether the seed orNshould 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 labelht_ex5in 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.