Skip to content

[likelihood_ratio_process_2.md] Update np.random → Generator API#991

Open
Chihiro2000GitHub wants to merge 1 commit into
mainfrom
update-rng-likelihood-ratio-process-2
Open

[likelihood_ratio_process_2.md] Update np.random → Generator API#991
Chihiro2000GitHub wants to merge 1 commit into
mainfrom
update-rng-likelihood-ratio-process-2

Conversation

@Chihiro2000GitHub

@Chihiro2000GitHub Chihiro2000GitHub commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

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

All np.random.* draws are replaced with an explicit rng = np.random.default_rng().

Related PRs and issues

I checked for open PRs and issues related to this lecture. No open issue concerns it, and the only open PR that touches the file (#651, a likelihood_bayes style-guide PR) changes a single unrelated prose line — nothing overlaps with this migration.

Details

  • In the main text, rng is defined once in the imports cell and reused in the later main-text cells.
  • Each solution block (lr_ex4, lr_ex5, lr_ex6, lr_ex7) defines its own rng so the block stays self-contained.
  • Replacements: np.random.beta(...)rng.beta(...), and np.random.rand(N, T)rng.random((N, T)) (note the shape tuple).
  • No fixed seed is introduced, since the lecture did not seed before.

Numba notes. The two @jit(parallel=True) functions (compute_posterior_three_models, simulate_three_model_allocation) take pre-generated s_seq arrays as input and do not draw random numbers inside their prange loops, so no random draws occur inside the parallel loops.

The one jitted draw is in simulate (@jit), migrated by passing rng in as an explicit argument (w = rng.beta(a, b)). Note that simulate is not called anywhere in this lecture, so it is never compiled — the build therefore does not exercise that particular line. Flagging for reviewer judgment.

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

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rs2tDEcDXLnfMnM88v8e1D
@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

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

Commit: b5e5bd4

📚 Changed Lectures


Build Info

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