Skip to content

[likelihood_ratio_process.md] Update np.random → Generator API#976

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

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

Conversation

@Chihiro2000GitHub

Copy link
Copy Markdown
Contributor

Summary

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

A single generator rng = np.random.default_rng() is defined once in the setup cell and reused throughout, passed explicitly to the simulation functions.

Details

  • Defined one rng = np.random.default_rng() in the imports/setup cell and reused it across all main-text cells and simulation functions.
  • Migrated the legacy calls: np.random.betarng.beta, np.random.rand(N)rng.random(N), np.random.rand(N, T)rng.random((N, T)), and np.random.choice(...)rng.choice(...).
  • Threaded rng as an explicit argument through the simulation functions and their wrappers (simulate_likelihood_ratios, simulate_sequences, protocol_1/protocol_2 and their compute_*/analyze_* wrappers, simulate_markov_chain, analyze_markov_chains, compute_markov_selection_error) and updated the call sites.
  • No fixed seed was introduced; the original code did not seed, so simulation behaviour is unchanged.

Note for reviewers

  • simulate_likelihood_ratios is decorated with @jit but has no parallel=True/prange, so rng is passed in as an explicit argument (rng.beta) rather than lifting the draws into a precomputed array. Verified locally that this compiles and runs under Numba 0.62.1.
  • rng is defined once in the setup cell rather than at the first point of use, because it is shared across many far-apart sections; a single top-level generator seemed clearer and easier to locate than repeating default_rng() per block.
  • mc.simulate inside simulate_markov_chain uses QuantEcon's own internal RNG and is not an np.random.* call, so it is left unchanged (out of scope for this migration).

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

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

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

Commit: 8353cff

📚 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