Optimize Aiyagari model: Switch to VFI with JIT-compiled lax.while_loop #674
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.
Summary
This PR significantly improves the performance and code quality of the Aiyagari model lecture by switching from Howard Policy Iteration (HPI) to Value Function Iteration (VFI) as the primary solution method, with HPI moved to an advanced exercise.
Major Changes
Algorithm Changes
jax.lax.while_loopwith@jax.jitcompilation for optimal performanceParameter Optimization
Code Quality Improvements
@jax.jiton top-level functions (not helper functions)loop_stateinstead ofstateto avoid confusion with DP state variableslax.while_loopPerformance Improvements
JIT Compilation Analysis
We tested four different JIT compilation strategies for HPI:
Winner: Only JIT-compile the top-level function and let JAX optimize the entire call graph.
Educational Improvements
Testing
Files Changed
lectures/aiyagari.md: 216 insertions(+), 103 deletions(-)🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]