🌐 [translation-sync] [mccall_q.md] Update np.random → Generator API - #229
🌐 [translation-sync] [mccall_q.md] Update np.random → Generator API#229mmcky wants to merge 2 commits into
Conversation
✅ Deploy Preview for astonishing-narwhal-a8fc64 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Translation Quality ReviewVerdict: PASS | Model: claude-sonnet-5 | Date: 2026-07-31 📝 Translation Quality
Summary: The translation of the Overview and Q-Learning sections is accurate, fluent, and largely faithful to the source, with correct handling of complex mathematical exposition and MyST formatting. Minor issues include a slight terminology conflation between 'gain parameter' and 'learning rate', a small restructuring in the Overview that adds minor interpretive phrasing not in the source, and a somewhat fragmented sentence describing the experimentation mechanism. None of these rise to the level of accuracy-threatening errors, and no syntax errors were found. Technical and mathematical content in the Overview and Q-Learning sections is accurately preserved, including all LaTeX equations and cross-references. Key terminology (Q-函数, Q-表, 时序差分学习, 时序差分误差, ε-贪婪算法) is applied consistently and matches standard usage in the field. Code comments were appropriately translated where relevant (e.g., progress print statements, docstrings) without altering code logic. Long, complex English sentences in the Q-Learning section are competently broken into readable Chinese sentences while preserving technical precision. Suggestions:
🔍 Diff Quality
Summary: The RNG refactor (np.random.seed -> np.random.default_rng passed explicitly) was correctly and completely mirrored in the Chinese translation at all matching locations, with structure and heading metadata unaffected. This review was generated automatically by action-translation review mode. |
There was a problem hiding this comment.
Pull request overview
This automated translation-sync PR updates the Chinese lecture mccall_q.md to match upstream changes that migrate legacy np.random.* usage toward the newer np.random.Generator API, and updates the translation sync state metadata accordingly.
Changes:
- Replaced global
np.random.seed(...)/np.random.random()usage with arng = np.random.default_rng(...)andrng.random()in the Q-learning section. - Threaded the
rngobject through Q-learning helper methods and the epoch runner. - Updated translation sync state (
source-sha,synced-at,mode,tool-version).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lectures/mccall_q.md | Migrates randomness in the Q-learning example toward the Generator API by introducing and passing an rng. |
| .translate/state/mccall_q.md.yml | Updates translation-sync bookkeeping metadata (source SHA/date/mode/tool version). |
Suppressed comments (4)
lectures/mccall_q.md:570
run_epochs被@jit编译后,目前把rng传入并调用qlmc.run_one_epoch(qtable, rng),这同样会将Generator传入jitclass方法。若按上面建议移除rng,这里也需要同步调整函数签名与调用。
def run_epochs(N, qlmc, qtable, rng):
lectures/mccall_q.md:673
- 上面若移除了
run_one_epoch(..., rng)的rng参数,这里也需要同步更新调用,否则会出现参数个数不匹配。
new_qtable = qlmc_new.run_one_epoch(qtable, rng)
lectures/mccall_q.md:596
- 上面若移除了
run_epochs(..., rng)的rng参数,这里的调用也需要相应更新,否则会出现参数个数不匹配。
qtable = run_epochs(20000, qlmc, qtable0, rng)
lectures/mccall_q.md:533
- 同上,
run_one_epoch作为jitclass方法目前依赖rng.random()并把rng传给temp_diff/draw_offer_index。这会把np.random.Generator引入 numba 编译域,通常会直接编译失败。建议移除rng参数,并在方法内改回np.random.random()。
def run_one_epoch(self, qtable, rng, max_times=20000):
"""
运行一个"轮次"。
"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| plt.rcParams['font.family'] = ['Source Han Serif SC'] | ||
|
|
||
| np.random.seed(123) | ||
| rng = np.random.default_rng(123) |
|
|
||
|
|
||
| def draw_offer_index(self): | ||
| def draw_offer_index(self, rng): |
Automated Translation Sync
This PR contains automated translations from QuantEcon/lecture-python.myst.
Source PR
#959 - [mccall_q.md] Update np.random → Generator API
Files Updated
lectures/mccall_q.md.translate/state/mccall_q.md.ymlDetails
This PR was created automatically by the translation action.