Commit b27f1eb
Reorganize and rename optimal savings lectures (#735)
* Reorganize and rename optimal savings lectures
This commit restructures the cake eating lecture series into a more coherent "Introduction to Optimal Savings" section with clearer naming and terminology.
Changes:
- Created new "Introduction to Optimal Savings" section in table of contents
- Renamed all 6 lectures with "os" prefix for consistency:
* cake_eating.md → os.md (Optimal Savings I: Cake Eating)
* cake_eating_numerical.md → os_numerical.md (Optimal Savings II: Numerical Cake Eating)
* cake_eating_stochastic.md → os_stochastic.md (Optimal Savings III: Stochastic Returns)
* cake_eating_time_iter.md → os_time_iter.md (Optimal Savings IV: Time Iteration)
* cake_eating_egm.md → os_egm.md (Optimal Savings V: The Endogenous Grid Method)
* cake_eating_egm_jax.md → os_egm_jax.md (Optimal Savings VI: EGM with JAX)
- Updated all lecture titles to use "Optimal Savings I-VI" naming convention
- Replaced "cake eating" terminology with "optimal savings" throughout all lectures
- Updated terminology in os_stochastic.md: "cake" → "wealth/harvest" to better reflect stochastic growth
- Updated all cross-references across the codebase to use new filenames
- Made cross-references robust to future title changes by using {doc}`filename` format
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Add IFP I lecture and restructure IFP series
- Add new ifp_discrete.md as "IFP I: Discretization and VFI"
- Implements income fluctuation problem using discretization and value function iteration
- Uses Model NamedTuple for clean parameter management
- Includes both Python loop and jax.lax.while_loop implementations for comparison
- Demonstrates proper JAX benchmarking with block_until_ready()
- Shows 3-4x speedup from using jax.lax.while_loop over plain Python
- Converts vmap implementation section to exercise format
- Rename ifp.md to ifp_egm.md as "IFP II: The Endogenous Grid Method"
- Updated title and cross-references
- Maintains continuity with new IFP I lecture
- Update _toc.yml to reflect new lecture order
- Update cross-references in ifp_advanced.md
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix build errors in ifp_discrete.md
- Add URL for Epstein-Zin preferences link
- Remove reference to non-existent opt_savings_2 lecture
- Fix exercise syntax: use {exercise} with {solution-start}/{solution-end}
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix exercise syntax in ifp_egm.md
- Change {exercise-start}/{exercise-end} to {exercise}
- Keep {solution-start}/{solution-end} syntax for solutions
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Add IFP II lecture on Optimistic Policy Iteration
- New ifp_opi.md lecture implementing OPI for income fluctuation problem
- Uses Model NamedTuple structure consistent with ifp_discrete.md
- Implements policy operator T_σ and iterate_policy_operator
- Provides comprehensive timing comparisons between VFI and OPI
- Shows 2-2.5x speedup from OPI over VFI
- Includes exercise exploring parameter sensitivity
- Update _toc.yml to include ifp_opi between ifp_discrete and ifp_egm
- Update ifp_egm.md title from "IFP II" to "IFP III"
- Reflects new lecture ordering with OPI as second lecture
Technical highlights:
- Uses @jax.jit decorators and jax.lax.while_loop for performance
- Properly handles JAX traced values with jnp.where instead of Python if
- Tests multiple values of m (policy iteration steps) to find optimal
- Visualization comparing OPI performance across different m values
Tested: Converts to Python and runs successfully with realistic speedups
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix exercise labels in ifp_egm.md
- Change ifp_ex1, ifp_ex2, ifp_ex3 to ifp_egm_ex1, ifp_egm_ex2, ifp_egm_ex3
- Prevents label conflicts with ifp_opi.md exercises
- Fix exercise-start/exercise-end syntax for ifp_ex3 to use {exercise}
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Add @jax.jit decorators to VFI and OPI functions
- Improves performance by JIT compiling the main iteration routines
- Speedup now consistently 2.5-2.6x (vs 2.4-2.5x before)
- Absolute times also improved (OPI: ~0.3-0.4s vs ~0.4-0.5s)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Extend m_vals range in OPI performance testing
- Add m=1, 200, 400 to test range
- Now tests m_vals = [1, 5, 10, 25, 50, 100, 200, 400]
- Shows performance across wider range of policy iteration steps
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Add explanation of OPI performance across different m values
- Explains why m=1 is slower than VFI (implementation overhead)
- Notes optimal performance at m=25-50 (3x speedup)
- Explains degradation for large m (200, 400)
- Emphasizes the 'sweet spot' concept for choosing m
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix build errors in ifp_egm.md
- Change equation label from 'eqvfs' to 'eqvfs_egm' to avoid duplicate with ifp_discrete.md
- Add missing closing backticks after solution-end directives
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: nested note admonition in exercise
* fix: exercise gates
* fix: link to earlier exercise
* Minor edits to code and markdown
* fix: JAX compatibility and code improvements in IFP and OS lectures
Fixed JAX implementation issues and improved code quality across multiple lectures:
## ifp_egm.md
- Fixed compute_asset_stationary() argument order (c_vals, ae_vals, ifp)
- Fixed jax.vmap() to use in_axes parameter instead of axes
- Fixed fori_loop update function signature (t, state) instead of (state, t)
- Fixed jax.random.fold_in argument order
- Added int32 type casting for JAX compatibility
- Improved code comments and documentation
- Reorganized simulation section before exercises
## os_numerical.md
- Simplified maximize() function by removing unused args parameter
- Renamed state_action_value() to B() for clarity
- Improved function documentation and code organization
- Fixed code examples to use simplified function signatures
## Minor edits to ifp_advanced.md and os.md
All lectures now convert to Python via jupytext and run without errors.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: improve parameter naming and function signatures in ifp_egm
- Simplify K_numpy parameter names from c_vals_init/ae_vals_init to c_vals/ae_vals
- Update solve_model and solve_model_numpy signatures to accept both initial conditions
- Fix argument order in compute_asset_stationary calls
- Add clear comments for initial conditions setup
- Standardize parameter ordering across NumPy and JAX implementations
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: resolve build errors in ifp_egm and os_numerical
ifp_egm.md fixes:
- Add missing initialization in solve_model_numpy (c_vals, ae_vals = c_vals_init, ae_vals_init)
- Fix update function parameter order in simulate_household (t, state instead of state, t)
- Fix jax.random.fold_in argument order (key, t instead of t, key)
- Add .astype(jnp.int32) to z_next_idx to fix dtype mismatch
- Update jax.vmap to use in_axes instead of axes
- Add missing arguments to sim_all_households call
- Fix compute_asset_stationary argument order in all calls
os_numerical.md fixes:
- Simplify maximize function signature from (g, upper_bound, args) to (g, upper_bound)
- Remove unused args parameter and tuple unpacking
All changes tested by converting to Python with jupytext and running successfully.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Matt McKay <mmcky@users.noreply.github.com>
Co-authored-by: mmcky <mamckay@gmail.com>1 parent 96662c4 commit b27f1eb
File tree
13 files changed
+1283
-294
lines changed- lectures
13 files changed
+1283
-294
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
75 | 84 | | |
76 | 85 | | |
77 | 86 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
85 | 90 | | |
86 | 91 | | |
87 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
164 | | - | |
| 163 | + | |
165 | 164 | | |
166 | 165 | | |
167 | 166 | | |
| |||
182 | 181 | | |
183 | 182 | | |
184 | 183 | | |
185 | | - | |
186 | | - | |
| 184 | + | |
187 | 185 | | |
188 | 186 | | |
189 | 187 | | |
| |||
197 | 195 | | |
198 | 196 | | |
199 | 197 | | |
200 | | - | |
201 | | - | |
| 198 | + | |
202 | 199 | | |
203 | 200 | | |
204 | 201 | | |
| |||
251 | 248 | | |
252 | 249 | | |
253 | 250 | | |
254 | | - | |
| 251 | + | |
255 | 252 | | |
256 | 253 | | |
257 | 254 | | |
| |||
578 | 575 | | |
579 | 576 | | |
580 | 577 | | |
581 | | - | |
| 578 | + | |
582 | 579 | | |
583 | 580 | | |
584 | 581 | | |
| |||
911 | 908 | | |
912 | 909 | | |
913 | 910 | | |
914 | | - | |
| 911 | + | |
915 | 912 | | |
916 | 913 | | |
917 | 914 | | |
| |||
0 commit comments