Skip to content

Commit e27ddac

Browse files
jstacclaude
andcommitted
Use class-based NamedTuple for Model definition
Updated Model definition to use modern class-based NamedTuple syntax with type annotations instead of collections.namedtuple, matching the style used for ExtendedModel in the exercise solution. Before: Model = namedtuple('Model', ('β', 'γ', 'x_grid')) After: class Model(NamedTuple): β: float γ: float x_grid: np.ndarray This provides better type hints and is more consistent with modern Python typing conventions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e5c45f4 commit e27ddac

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lectures/cake_eating_numerical.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ We will use the following imports:
4949
import matplotlib.pyplot as plt
5050
import numpy as np
5151
from scipy.optimize import minimize_scalar, bisect
52-
from collections import namedtuple
5352
from typing import NamedTuple
5453
```
5554

@@ -180,7 +179,10 @@ We'll store the parameters $\beta$ and $\gamma$ and the grid in a
180179

181180
```{code-cell} python3
182181
# Create model data structure
183-
Model = namedtuple('Model', ('β', 'γ', 'x_grid'))
182+
class Model(NamedTuple):
183+
β: float
184+
γ: float
185+
x_grid: np.ndarray
184186
185187
def create_cake_eating_model(β=0.96, # discount factor
186188
γ=1.5, # degree of relative risk aversion
@@ -448,7 +450,7 @@ However, both changes will lead to a longer compute time.
448450
Another possibility is to use an alternative algorithm, which offers the
449451
possibility of faster compute time and, at the same time, more accuracy.
450452

451-
We explore this next.
453+
We explore this {doc}`soon <cake_eating_time_iter>`.
452454

453455

454456
## Exercises

0 commit comments

Comments
 (0)