QuantEcon / QuantEcon/lecture-python.myst

[ge_arrow] Example 4 transition matrix row 2 sums to 1.8 (not a stochastic matrix)

Open
#1,030 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

  1. Correct row 2 (pending confirmation of intent) and refresh Example 4's discussion if any printed values are referenced in the text.
  2. 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 the NamedTuple) 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.