Skip to content

Whole lectures: float64 sweeps over seeds for four float32 checks - #20

Merged
mmcky merged 1 commit into
mainfrom
float32-seed-sweeps
Nov 1, 2026
Merged

mmcky merged 1 commit into
mainfrom
float32-seed-sweeps

Conversation

@mmcky

@mmcky mmcky commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

A follow-up to #18, as evidence for four lecture-jax issues. #18 found that float32 changes hopenhayn, mle_jax and markov_asset_jax through the random sample jax.random draws, not through the arithmetic. This asks how much each answer moves with the sample in float64 alone, using the lectures' own cells at lecture-jax 4b939ec.

Lecture Sweep Result
hopenhayn p* over seeds 1234 to 1243, at 200 and 2,000 Monte Carlo draws At the lecture's 200 draws: 1.364 to 1.498, a standard deviation of 3.1%. The lecture's seed gives the lowest of the ten. At 2,000 draws: 1.442 to 1.492, 1.0%
mle_jax Newton–Raphson from the lecture's start, over seeds 0 to 19 Converges from all 20, so float32's failing sample (#18) was an unusual one
mle_jax log(jax_factorial(y)) against log(y!) 43.67 for every y above 20, because exp(lgamma(y + 1)).astype(int) overflows int64. The printed log-likelihoods are off; the estimates aren't, since the term doesn't depend on β
markov_asset_jax The power-iteration estimate over 20 start vectors, at 15, 100 and 1,000 steps 15 steps, as the lecture uses: 0.869 to 1.019, so the stability check fails from 5 of 20 start vectors. From 100 steps every start vector gives 0.9944, the exact radius

In this PR: lectures/whole/checks/seed_sweeps.py and its output, seeds.txt, with one sentence added to the README's float32 section. The runs were on an M1 Pro laptop's CPU, as diagnostic runs.

🤖 Generated with Claude Code

seed_sweeps.py runs hopenhayn, mle_jax and markov_asset_jax's own cells in
float64 over seeds, draw counts and iteration counts, with the output in
checks/seeds.txt:

- hopenhayn's p* has a standard deviation of 3.1% across ten seeds at the
  lecture's 200 draws, and 1.0% at 2,000; the lecture's seed gives the
  lowest of the ten.
- mle_jax's Newton-Raphson converges from all 20 seeds tried, but
  jax_factorial overflows past 20!, so log(y!) is 43.67 for every y > 20.
- markov_asset_jax's 15-step estimate fails the stability check from 5 of
  20 start vectors; from 100 steps every start vector gives the exact 0.9944.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The diagnostic script faithfully reuses the established sibling-check patterns with verified matching kwargs, unpacking, and loops, and its committed output aligns consistently with the README, leaving no outstanding issues.

No open issues 🎉

What changed in this PR

This PR adds a float64 diagnostic sweep as a follow-up to #18, providing evidence for four lecture-jax issues. Where #18 showed that float32 changes hopenhayn, mle_jax, and markov_asset_jax through the random sample (not the arithmetic), this PR quantifies how much each answer moves with the random seed, draw count, or step count within float64 alone. It fits into the lectures/whole/checks/ family of diagnostic scripts that reproduce lecture cells verbatim and vary a single ingredient.

Changes:

  • Adds seed_sweeps.py, which extracts and executes each lecture's own MyST code cells (via the same regex/exec pattern as the sibling checks) and sweeps seeds/draw counts/step counts for hopenhayn, mle_jax, markov_asset_jax, plus a jax_factorial overflow check.
  • Adds seeds.txt, the committed CPU output of that script (M1 Pro, diagnostic run).
  • Appends one sentence to the README's float32 section summarizing the float64 seed-sensitivity findings, linking to seeds.txt.
File Description
lectures/​whole/​checks/​seed_sweeps.py New diagnostic script sweeping seeds/draws/steps over four lecture checks, reusing the established cell-extraction pattern.
lectures/​whole/​checks/​seeds.txt Committed diagnostic output; numbers (3.1% sd, 5/20 start vectors, 20/20 mle converge) are consistent with the script and README.
lectures/​whole/​README.md Adds one sentence to the "random sample" bullet summarizing float64 across-seed variability, linking to checks/seeds.txt.

I verified the script against its sibling scripts and the PR data and found no substantive issues:

  • create_model(seed=, E_draw_size=, A_draw_size=) kwargs and compute_p_star(...)[0] unpacking match hopenhayn_check.py.
  • Reusing the same jax.random.key for the x and y draws in the mle block is faithful to the lecture (matches mle_check.py).
  • The markov estimate loop replicates markov_asset_check.py's 15-step power iteration exactly.
  • The README figures and the checks/seeds.txt relative link path are correct.

No code comments were warranted.

Review effort: Balanced

@mmcky
mmcky merged commit dc5439f into main Nov 1, 2026
1 check passed
@mmcky
mmcky deleted the float32-seed-sweeps branch November 1, 2026 09:51
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.

2 participants