rs_inventory_q / inventory_q: misleading 'Converged' print + snapshot off-by-one in Q-learning loop
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- python
- Lĩnh vực
- documentation
Hướng nghiên cứu
Bắt đầu với solve_rs_inventory_model và q_learning_rs_kernel trong lectures/rs_inventory_q.md, sau đó so sánh hàm solve tương ứng trong lectures/inventory_q.md và phần “Running Q-learning”. Kiểm tra thông báo kết thúc vòng lặp, thời điểm chụp snapshot và ngữ nghĩa gọi n so với n+1. Được coi là hoàn tất khi cả hai tệp bài giảng đều báo cáo chính xác việc không hội tụ, đồng thời phần văn bản, các chỉ mục snapshot và số bước đã thực thi khớp nhau.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
While reviewing lectures/rs_inventory_q.md as part of mirroring it into QuantEcon/lecture-dp, Copilot flagged three things — all real, none blocking, but worth a small follow-up here.
Issue 1 — `solve_rs_inventory_model` prints "Converged" unconditionally
`rs_inventory_q.md` (and the same pattern in `inventory_q.md` line 331):
def solve_rs_inventory_model(v_init, model, max_iter=10_000, tol=1e-6):
v = v_init.copy()
i, error = 0, tol + 1
while i < max_iter and error > tol:
new_v = T_rs(v, model)
error = np.max(np.abs(new_v - v))
i += 1
v = new_v
print(f"Converged in {i} iterations with error {error:.2e}")
...
If the loop exits because `i == max_iter` (before `error <= tol`), the print still claims convergence. With the default 10k cap that won't bite at the configured parameters, but it's misleading for anyone who tweaks settings.
Suggestion: only print "Converged" when `error <= tol`, otherwise warn (or raise). Same fix applies in `inventory_q.md`.
Issue 2 — snapshot recorded at the start of the loop iteration
`rs_inventory_q.md` (`q_learning_rs_kernel`):
for t in range(n_steps):
# Record policy snapshot if needed
if snap_idx < n_snaps and t == snapshot_steps[snap_idx]:
snapshots[snap_idx] = greedy_policy_from_q_rs(q, K)
snap_idx += 1
...
q[x, a] = (1 - α) * q[x, a] + α * target
...
The snapshot at index `t` captures `q` before the update for step `t`. So a "snapshot at step n" actually reflects `q` after `n` completed updates only if `t = n` is visited after the n-th update — which requires running `n + 1` iterations.
That's exactly what the caller does, but it's load-bearing for the narrative…
Issue 3 — narrative vs. code mismatch in "Running Q-learning"
`rs_inventory_q.md` line 658:
We run $n$ = 5 million steps and take policy snapshots at steps 10,000, 1,000,000, and $n$.
n = 5_000_000
snap_steps = np.array([10_000, 1_000_000, n], dtype=np.int64)
q_table, snapshots = q_learning_rs(model, n_steps=n+1, snapshot_steps=snap_steps)
`n_steps=n+1` is the workaround for Issue 2 — without it, the snapshot at step `n` would not capture the final update. Two ways to make the narrative consistent:
- Move the snapshot recording to after the Q update (or after the loop), then call with `n_steps=n`.
- Or keep the snapshot at the start of the iteration but adjust indices so the caller passes `n_steps=n` and `snapshot_steps=[..., n-1]` etc.
Option 1 is cleaner and would let the prose stay literal ("run `n` steps").
Happy to send a small PR if useful — none of these are blocking and `lecture-dp` is mirroring as-is so this stays a single-source fix.
🤖 Found via Copilot review on QuantEcon/lecture-dp#20
- Ngôn ngữ chính
- TeX
- Star
- 125
- Fork
- 57
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 18
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của QuantEcon/lecture-python.myst
-
Link Checker ReportĐang mởautomated issue linkchecker report
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
QuantEcon/lecture-python.myst#1062 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug content
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
QuantEcon/lecture-python.myst#1021 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[organization_capital] posterior-mean figure does not show the convergence the text describesĐang mởmedium-priority new-lecture
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
QuantEcon/lecture-python.myst#1015 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
QuantEcon/lecture-python.myst#990 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
QuantEcon/lecture-python.myst#986 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của QuantEcon/lecture-python.myst
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
btclib-org/portanode#699 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ObjectMapper
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
symfony/symfony-docs#23390 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Guidelines: redundant use cases, stale dev bundle after snapshot bumps, looking up snapshot APICó thể đã có người làm @totally-not-ai đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
vaadin/use-cases#441 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
sync-en
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
sync-en
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 3 ngày