QuantEcon / QuantEcon/lecture-python.myst
[ge_arrow] Example 4 transition matrix row 2 sums to 1.8 (not a stochastic matrix)
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 123
- Forks
- 57
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 11
Description
Problem
Example 4 of lectures/ge_arrow.md defines a 3-state transition matrix whose second row does not sum to 1, so it is not a valid stochastic matrix (ge_arrow.md#L1270 on main):
λ = .9
μ = .9
δ = .05
# prosperous, moderate, and recession states
P = np.array([[1-λ, λ, 0], [μ/2, μ, μ/2], [(1-δ)/2, (1-δ)/2, δ]])
Row sums: row 1 = 0.1 + 0.9 + 0 = 1 ✅, row 2 = 0.45 + 0.9 + 0.45 = 1.8 ❌, row 3 = 0.475 + 0.475 + 0.05 = 1 ✅.
All of Example 4's published output (Q, R, A, α, ψ, J) is computed from this matrix, so the numbers shown on the live lecture page for that example don't correspond to a well-defined Markov economy.
Likely intended matrix
The natural reading, given row 3's pattern of splitting the off-diagonal mass, is that row 2 was meant to be [(1-μ)/2, μ, (1-μ)/2] = [0.05, 0.9, 0.05] — a sticky "moderate" state — which sums to 1. Someone closer to the original intent (perhaps Tom) should confirm before we change the published numbers.
Suggested fix
- Correct row 2 (pending confirmation of intent) and refresh Example 4's discussion if any printed values are referenced in the text.
- Add a cheap validation when the model is constructed, e.g.
assert np.allclose(P.sum(axis=1), 1), so an invalid transition matrix fails loudly instead of silently producing plausible-looking output. The NumPy restructure discussed in #717 (a validating factory alongside theNamedTuple) is a natural home for this.
Context
Found during the style-guide review that wrapped up #717. The bug pre-dates that PR — it is present on main and was carried over unchanged by the JAX rewrite.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lectures/ge_arrow.md around line 1270 and compare Example 4 with the discussion of #717. Confirm the intended second row with a maintainer before changing it, then check the published Q, R, A, α, ψ, and J output. Add the proposed transition-matrix validation in the model-construction path and verify the lecture output is consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- documentation, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100