Skip to content

Commit 4eac159

Browse files
jstacclaude
andcommitted
Refactor f and f_prime to use explicit alpha parameter
Changed from closure-based approach to explicit parameter passing: - f = lambda k, α: k**α (instead of f = lambda k: k**α with global α) - f_prime = lambda k, α: α * k**(α - 1) - Updated K operator to call f(s, α) and f_prime(s, α) This makes the NumPy version consistent with the JAX implementation and ensures the α stored in the Model is actually used in the K operator (previously it was unpacked but unused). Benefits: - Consistency between NumPy and JAX versions - Clearer function dependencies (α is an explicit parameter) - Actually uses model.α instead of relying on closure Tested successfully with same convergence behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1ca20dd commit 4eac159

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lectures/cake_eating_egm.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def K(
243243
244244
# Solve for updated consumption value
245245
for i, s in enumerate(s_grid):
246-
vals = u_prime(σ(f(s) * shocks)) * f_prime(s) * shocks
246+
vals = u_prime(σ(f(s, α) * shocks)) * f_prime(s, α) * shocks
247247
c_out[i] = u_prime_inv(β * np.mean(vals))
248248
249249
# Determine corresponding endogenous grid
@@ -266,12 +266,11 @@ First we create an instance.
266266

267267
```{code-cell} python3
268268
# Define utility and production functions with derivatives
269-
α = 0.4
270269
u = lambda c: np.log(c)
271270
u_prime = lambda c: 1 / c
272271
u_prime_inv = lambda x: 1 / x
273-
f = lambda k: k**α
274-
f_prime = lambda k: α * k**(α - 1)
272+
f = lambda k, α: k**α
273+
f_prime = lambda k, α: α * k**(α - 1)
275274
276275
model = create_model(u=u, f=f, u_prime=u_prime,
277276
f_prime=f_prime, u_prime_inv=u_prime_inv)

0 commit comments

Comments
 (0)