Repository navigation
[likelihood_bayes.md] Update np.random → Generator API - #977
Conversation
📖 Netlify Preview Ready!Preview URL: https://pr-977--sunny-cactus-210e3e.netlify.app Commit: 📚 Changed LecturesBuild Info
|
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com>
Resolved the merge conflicts in this PR in commit |
|
Thanks @mmcky — sorry these were mine to answer and you got there first. Both replies are exactly what I would have said, so I have nothing to add; much appreciated, including the conflict resolution. I'll take it from here and check the rebuilt preview once the build finishes. |
Thanks so much @Chihiro2000GitHub. Appreciate the review. |
|
@mmcky -- I've now gone through the rebuilt preview myself and it looks good. The one visible difference from Everything else builds and reads exactly as it should, so no concerns at all from my side. |
|
thanks @Chihiro2000GitHub. @kp992 if you disagree -- feel free to open an issue. I'll merge this now. |
✅ Translation sync completed (zh-cn)Target repo: QuantEcon/lecture-python.zh-cn
|
|
Thanks @mmcky and @Chihiro2000GitHub. I am fine with the current PR as it is aligning with the style guide. |
…la.solve port (#301) * Advance four state files whose lectures already carry the source change career, jv and odu: QuantEcon/lecture-python.myst#760 changed only the H1 in each (Job Search renumbering), and #273 applied it here. The H1s on main already read VII, VIII and IX. likelihood_bayes: QuantEcon/lecture-python.myst#977 replaced the global np.random seed with default_rng; #248 delivered that change, and the file uses np.random.default_rng(142857) at the same two sites as the source, but the state kept the older sha. source-sha advanced to each file's last source commit and synced-at stamped; model, mode, section-count and tool-version are left as they were, since nothing was regenerated (the fa#160 convention). `translate status` at v0.29.6 now reports all four ALIGNED. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Advance mccall_q's state file too: its one outstanding change is applied The state sha is 46cf999 (QuantEcon/lecture-python.myst#624). The only later source change is QuantEcon/lecture-python.myst#760, which changed just the H1 (Job Search IX -> X); #273 applied it, and the H1 here reads 工作搜寻 X. The earlier default_rng change (QuantEcon/lecture-python.myst#959) and QuantEcon/lecture-python.myst#624's typo, legend and loop-guard edits are present. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * harrison_kreps: port the la.solve refactor by hand, and advance its state QuantEcon/lecture-python.myst#669 replaced the explicit inverse in price_single_beliefs with a linear solve. Its sync failed before it could file anything (a missing anthropic-api-key input on 2026-08-05), so the change never arrived. The source diff is seven lines of code in one cell, so it is ported by hand rather than regenerating a lecture the zh-cn editor has worked on: the code is the source's, and the three comments are translated as this edition translates code comments. The cell's code now matches the source (ASTs with string literals masked); the lecture executes with numerical output identical to the English. source-sha advanced and synced-at stamped; model, mode, section-count and tool-version unchanged, as nothing was regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Summary
This PR migrates legacy NumPy random API usage in
likelihood_bayes.mdas part of QuantEcon/meta#299.The lecture used the
@jit-basedset_seed()/np.random.seedidiom for reproducibility. It is replaced with an explicit seeded generatorrng = np.random.default_rng(142857)that is passed into the simulation functions.Details
@jit def set_seed(): np.random.seed(142857)mechanism withrng = np.random.default_rng(142857). The lecture reset the seed at two points (setup cell and before the mixture path), sorngis (re)created at both points to preserve that behaviour.np.random.beta→rng.betaandnp.random.rand()→rng.random(), and threadedrngas an explicit argument throughsimulate,simulate_mixture_path,martingale_simulate(and itsfraction_0_1/create_tablewrappers), andcompute_cond_var, updating the call sites.142857); the original lecture already seeded for reproducibility, so no new seed was introduced.Note for reviewers
compute_cond_var(theprangecase): the original used@jitwith aprangeloop containing the RNG draws, but there is noparallel=Trueanywhere in the file, so the loop already ran serially. Rather than lifting the draws out (which, since the loop's only content was the sampling, would dissolve the loop entirely and defeat the "pass a pre-drawn array into a jittedprangekernel" pattern), I changedprange→rangeso the function becomes an ordinary serial@jitfunction like the others, and passedrngin as an argument. This changes no runtime behaviour (it was already serial). If you intended this to be parallelized, the RNG should instead be drawn outside and passed in — happy to switch to that.prangeis now unused, so I also removed it from thefrom numba import ...line.simulate,simulate_mixture_path,martingale_simulate) have noparallel=True/prange, sorngis passed in explicitly (Case 2). Verified locally that passing aGeneratorinto these@jitfunctions and callingrng.beta/rng.randomcompiles and runs under Numba 0.62.1.142857is retained, so results remain reproducible.Hi @mmcky and @HumphreyYang, I'd be grateful if you could take a look when you have time.