You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor lake_model.md: Improve model structure and notation
Major improvements:
- Added create_lake_model() function to generate model instances with precomputed matrices A, R, and g
- Replaced A_hat notation with R throughout (code and LaTeX) for cleaner notation
- Updated LakeModel NamedTuple to store computed matrices A and R
- Modified all functions to unpack model using tuple unpacking for efficiency
- Added type hints to stock_update(), rate_update(), and create_lake_model()
- Simplified generate_path() function by removing unused time parameter
- Updated rate_steady_state() to use Perron-Frobenius theorem (argmax instead of searching for eigenvalue near 1)
- Converted all LakeModel() instantiations to use create_lake_model()
- Updated markov simulation to use dedicated simulate_markov() function
Benefits:
- Matrices computed once at model creation instead of repeatedly
- Cleaner mathematical notation using R instead of \hat{A}
- More efficient code with direct tuple unpacking
- Better type safety with added annotations
- More mathematically rigorous using Perron-Frobenius theorem
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
"""Computes steady-state unemployment for a given λ"""
423
-
model = LakeModel(λ=λ_val)
456
+
model = create_lake_model(λ=λ_val)
424
457
steady_state = rate_steady_state(model)
425
458
return steady_state[0]
426
459
@@ -517,7 +550,7 @@ $$
517
550
518
551
with probability one.
519
552
520
-
Inspection tells us that $P$ is exactly the transpose of $\hat A$ under the assumption $b=d=0$.
553
+
Inspection tells us that $P$ is exactly the transpose of $R$ under the assumption $b=d=0$.
521
554
522
555
Thus, the percentages of time that an infinitely lived worker spends employed and unemployed equal the fractions of workers employed and unemployed in the steady state distribution.
523
556
@@ -530,17 +563,17 @@ We can investigate this by simulating the Markov chain.
530
563
Let's plot the path of the sample averages over 5,000 periods
531
564
532
565
```{code-cell} ipython3
533
-
def markov_update(state, t, P, keys):
566
+
def markov_update(state, P, key):
534
567
"""
535
568
Sample next state from transition probabilities.
536
569
"""
537
570
probs = P[state]
538
-
state_new = jax.random.choice(keys[t],
571
+
state_new = jax.random.choice(key,
539
572
a=jnp.arange(len(probs)),
540
573
p=probs)
541
574
return state_new
542
575
543
-
model_markov = LakeModel(d=0, b=0)
576
+
model_markov = create_lake_model(d=0, b=0)
544
577
T = 5000 # Simulation length
545
578
546
579
α, λ = model_markov.α, model_markov.λ
@@ -550,10 +583,21 @@ P = jnp.array([[1 - λ, λ],
550
583
551
584
xbar = rate_steady_state(model_markov)
552
585
553
-
# Simulate the Markov chain
586
+
# Simulate the Markov chain - we need a different approach for random updates
0 commit comments