Skip to content

[likelihood_var.md] Update np.random → Generator API#995

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

[likelihood_var.md] Update np.random → Generator API#995
Chihiro2000GitHub wants to merge 1 commit into
mainfrom
update-rng-likelihood-var

Conversation

@Chihiro2000GitHub

Copy link
Copy Markdown
Contributor

Summary

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

The single np.random.randn(...) draw is replaced with an explicit rng = np.random.default_rng(), threaded through the simulation functions.

Related PRs and issues

I checked for open PRs and issues related to this lecture. No open PR touches it and no open issue concerns it — nothing overlaps with this migration.

Details

  • rng = np.random.default_rng() is defined once in the imports cell (main text).
  • np.random.randn(m)rng.standard_normal(m).
  • rng is passed explicitly as an argument through simulate_var and simulate_samuelson, and all call sites are updated. The lecture has no @jit/prange code, so rng can be threaded as an ordinary argument.
  • No fixed seed is introduced, since the lecture did not seed before.

mvn.rvs (scipy). simulate_var also draws the initial state via scipy.stats.multivariate_normal.rvs, which otherwise uses NumPy's global random state. To keep the whole function on the single explicit generator, I pass random_state=rng — supported per the scipy manual, whose random_state/seed accepts a numpy.random.Generator. This is slightly beyond the pure np.random scope; if you'd prefer to leave mvn.rvs untouched, just say so and I'll revert that one line.

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-995--sunny-cactus-210e3e.netlify.app

Commit: f3c42f9

📚 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