Repository navigation
Problems: P5, the stationary distribution of a savings policy (#47) - #71
Merged
Merged
Conversation
Phase 2's first problem type, for #5, as designed in #47. The household and prices of lecture-jax's aiyagari_jax, with two sweeps: `dense`, the lecture's dense solve over every (assets, income) state, at 100 to 5,000 assets; and `sparse`, Young's lottery over an EGM policy, by power iteration, at 1,000 to 10,000,000 assets. Each cell's policy is computed by NumPy before the cell starts; the cell times building the transition, finding the distribution and summing out income. Power iteration stops at an L1 change of 1e-10 in float64 and 1e-6 in float32. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMZbJB4j8pmPEYyJ8SG
- NumPy's dense cells solve with scipy.linalg.solve: np.linalg.solve computes in float64 even for float32 arrays, so NumPy's float32 column was float64 arithmetic. M is built in place, as Numba's is, rather than through the lecture's four-dimensional construction. - NumPy's sparse cells import scipy.sparse in setup, not in the timed function, so their cold time no longer includes the import. - Answers are checked as the cumulative distribution of assets: the distribution is mostly zeros beside one atom at the borrowing constraint, so errors in its interior barely registered. - Numba's CSR indices are unsigned, which spares a negative-index check on every access, and the first loop of its build runs in parallel. - spec.py's sparse memory estimate covers NumPy in float32. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMZbJB4j8pmPEYyJ8SG
Contributor
Author
|
An independent review of
Two findings concern code already on |
This was referenced Nov 20, 2026
Closed
This was referenced Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2's first problem type, for #5: P5, the stationary distribution of a Markov chain, as designed in #47 (revised and approved on 2026-11-20).
What it adds
problems/stationary.py: the household and prices of lecture-jax'saiyagari_jax, in NumPy, Numba and JAX, with two sweeps.dense, the lecture's method: Howard policy iteration's index policy, the transition over every (assets, income) state built as a dense matrix, and the lecture's solve of (I − Pᵀ + 𝟏𝟏ᵀ) ψ = 𝟏. Assets 100 to 5,000.sparse, Young's lottery over an EGM policy: each state sends its mass to the grid points either side of its savings, and power iteration runs until the L1 change is below 1e-10 in float64 or 1e-6 in float32. Assets 1,000 to 10,000,000.problems/spec.py: P5's entry, between P4 and P7, with its sizes, memory estimate and the usual check against NumPy's float64, applied to the cumulative distribution of assets (stationary.sample).problems/README.md: P5's row in the problems table and a note on what it times. The note on P7's optional sweeps no longer says a default run is Phase 1's, since a default run now includes P5.Each cell's policy is computed by NumPy in float64 before the cell starts, so the cell times building the transition, finding the distribution and summing out income.
densesparsescipy.linalg.solve, sincenp.linalg.solvecomputes in float64 even for float32 arraysscipy.sparseCSR matrix of the transition's transposeprangeloop, thennp.linalg.solveprangeloop over its rows. The L1 change is summed in float64, since a float32 sum of millions of tiny terms stops changingcompute_asset_stationary, underjitjax.ops.segment_suminsidelax.while_loopAn independent review found five defects in the first commit, all fixed in
e59ded5; the comment below lists them.Checked on qe-mini1, CPU backends only
These were development runs, not measurements, so their rows aren't committed.
--quick: every cell ran onnumpy,numba,numba-parallelandjax-cpu, in both precisions, andsummarise.pyfound every answer within tolerance of NumPy's float64.numpyandjax-cpu: both ran well within the 900 s cell limit, and agreed.numpy,numbaandjax-cpu: every float64 answer was within 1e-12 of NumPy's, and every float32 answer within 2.4e-5 on the new check, against its tolerance of 1e-3.jax-gpuhasn't run, since qe-mini1 has no NVIDIA card. Its first run will be with Phase 2's measured runs, once P2, P6 and P8 are in, as planned.🤖 Generated with Claude Code
https://claude.ai/code/session_01WT8bMZbJB4j8pmPEYyJ8SG