🌐 [translation-sync] [likelihood_bayes.md] Update np.random → Generator API - #248
🌐 [translation-sync] [likelihood_bayes.md] Update np.random → Generator API#248mmcky 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. |
|
| Criterion | Score |
|---|---|
| Accuracy | 7/10 |
| Fluency | 8/10 |
| Terminology | 7/10 |
| Formatting | 6/10 |
| Overall | 7.1/10 |
Summary: The translation of the changed sections is generally accurate and fluent, correctly conveying the Bayesian learning and likelihood ratio process content. However, there are several formatting deviations from the source: added font-loading code not in the original, dropped mystnb figure caption/name metadata (replaced with ad hoc title text), a notation inconsistency (l_t vs ℓ) in two equations, a hardcoded equation reference instead of a proper cross-reference, and a mistranslated docstring (Jensen-Shannon vs KL divergence). These issues should be fixed to restore fidelity to the source and preserve cross-referencing functionality, but they do not undermine the overall clarity of the translated exposition. Overall mathematical notation and LaTeX equations are preserved accurately across the changed sections The recursive Bayes' law derivation and martingale convergence argument are translated clearly and are faithful to the source's logical structure Technical vocabulary (先验, 后验, 似然比过程, 鞅收敛定理, etc.) is used consistently and matches the glossary conventions
Suggestions:
- [major · formatting] lectures/likelihood_bayes.md — ## Overview / loading Python modules code cell: The translation's code cell in the Overview section inserts extra font-loading code (FONTPATH, mpl.font_manager, etc.) that does not exist in the English source. This is a code block, and adding untranslated/unrelated code changes the technical content of the document beyond translation scope. → Remove the added font-loading lines and keep the code cell identical to the English source's import block, unless this is a standard, approved addition applied consistently across all translated lectures (in which case it should be verified against project convention).
- [major · accuracy] lectures/likelihood_bayes.md — ### Some simulations, code cell with mystnb figure captions: Several code cells in the English source under 'Another timing protocol' and figures (e.g., fig-posterior-lratio-f, fig-posterior-lratio-g) include a ```{code-cell} ipython3
mystnb:
figure:
caption: ...
name: ...
---``` block for figure captioning and cross-referencing. The Chinese translation drops these mystnb figure metadata blocks entirely (e.g., for the π_seq_f and π_seq_g plot… → Preserve the mystnb figure directive blocks with caption/name exactly as in English, translating only the caption text if needed, and do not add sup-plots titles not present in the source unless doing so is a documented project-wide convention.
- [minor · terminology] lectures/likelihood_bayes.md — eq_recur1 code block variable naming: The English source uses ℓ(w_{t+1}) (lowercase ell) consistently in equation eq_recur1 and eq:like44, but the Chinese translation renders it as 'l_t(w_{t+1})' in the math (e.g., \pi_{t+1}=\frac{\pi_{t} l_t(w_{t+1})}{...}), inconsistent with the English source's ℓ notation and with earlier occurrences in the same translated document that correctly use ℓ. This is an inconsistency introduced by the t… → Use \ell(w_{t+1}) consistently to match the English source, e.g., \pi_{t+1}=\frac{\pi_{t} \ell(w_{t+1})}{\pi_{t} \ell(w_{t+1})+1-\pi_{t}}.
-
[minor · accuracy] lectures/likelihood_bayes.md — ## Initial prior is verified by paths drawn from subjective conditional densities, near 'Combining this equation with equation': The translation replaces the cross-reference to equation {eq}
eq:expect_pi_inftywith the literal text '方程(20)', which is a fragile, non-portable reference (hardcoded numbering) not present in the English source's MyST cross-reference syntax. This could break or become incorrect if equation numbering changes and does not match the source's use of the equation label. → Use the MyST equation cross-reference as in the source: '将此方程与方程 {eq}eq:expect_pi_infty结合,我们推断出...' -
[minor · terminology] lectures/likelihood_bayes.md — ### 在错误模型下
$\pi_t$ 的行为 / compute_div_m docstring: In the compute_div_m function's docstring, the Chinese translation says '计算Jensen-Shannon散度' (Compute Jensen-Shannon divergence), but the English source docstring says 'Compute KL(m, f) and KL(m, g)'. This mistranslates the function's actual purpose/documentation, introducing an inaccurate technical claim (the function computes two KL divergences, not a Jensen-Shannon divergence, even though the … → Translate literally: '计算 KL(m, f) 和 KL(m, g)'
🔍 Diff Quality
| Check | Status |
|---|---|
| Scope Correct | ✅ |
| Position Correct | ✅ |
| Structure Preserved | ✅ |
| Heading-map Correct | ✅ |
| Overall | 10/10 |
Summary: The translation sync correctly mirrors the RNG refactor changes (prange/set_seed removal, rng parameter threading, docstring/comment case fixes) in the same relative positions without altering document structure or scope.
This review was generated automatically by action-translation review mode.
There was a problem hiding this comment.
Pull request overview
This PR syncs the zh-cn likelihood_bayes lecture with upstream changes that migrate examples away from the legacy np.random.* global RNG APIs toward the NumPy Generator API, and updates translation-sync metadata accordingly.
Changes:
- Replace
np.random.seed/np.random.*usage withnp.random.default_rng(...)andrng.*calls in the lecture’s code cells. - Update the lecture’s translation frontmatter (headings) and the document label to match the upstream source.
- Update
.translate/state/likelihood_bayes.md.ymlto the new source SHA, sync date, mode, and tool version.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lectures/likelihood_bayes.md | Updates RNG usage to Generator, adjusts headings/label, and tweaks some plotting code. |
| .translate/state/likelihood_bayes.md.yml | Records updated translation sync state (source SHA/date/mode/tool version). |
Suppressed comments (4)
lectures/likelihood_bayes.md:456
simulate_mixture_pathis still decorated with@jitbut now callsrng.random()/rng.beta(). This prevents Numba from compiling in nopython mode, so the loop will run in object mode and negate the intended speedup. Consider removing@jitand vectorizing the draws with boolean masking.
@jit
def simulate_mixture_path(x_true, T, rng):
"""
模拟混合时序协议下的 T 个观测值。
"""
w = np.empty(T)
for t in range(T):
if rng.random() < x_true:
w[t] = rng.beta(F_a, F_b)
lectures/likelihood_bayes.md:750
martingale_simulateremains@jit-decorated but now depends on a NumPyGenerator(rng). This will push Numba into object mode, which is likely to be significantly slower for the (N×T) simulation loops used later (e.g. 10,000×200). To keep performance while using the Generator API, consider pre-drawing all required random numbers outside the jitted function (uniforms + beta draws for F/G) usingrng, and pass those arrays into a nopython-jittable function; alternatively, remove@jitif performance is acceptable without it.
@jit
def martingale_simulate(π0, rng, N=5000, T=200):
π_path = np.empty((N,T+1))
w_path = np.empty((N,T))
π_path[:,0] = π0
for n in range(N):
π = π0
for t in range(T):
# draw w
if rng.random() <= π:
w = rng.beta(F_a, F_b)
else:
w = rng.beta(G_a, G_b)
π = π*f(w)/g(w)/(π*f(w)/g(w) + 1 - π)
lectures/likelihood_bayes.md:914
compute_cond_varnow uses a pure-Pythonforloop overmc_size(default 1e6) while still being@jit-decorated and callingrng.*. Becauserngprevents nopython compilation, this will run in object mode and is likely to be prohibitively slow. You can remove@jitand sample the mixture in a fully vectorized way withrng(no Python loop).
@jit
def compute_cond_var(π, rng, mc_size=int(1e6)):
# Create Monte Carlo draws
mc_draws = np.zeros(mc_size)
for i in range(mc_size):
if rng.random() <= π:
mc_draws[i] = rng.beta(F_a, F_b)
else:
mc_draws[i] = rng.beta(G_a, G_b)
lectures/likelihood_bayes.md:863
- This figure uses
ax.set_xlabel('time'), while the rest of the lecture consistently labels time as "t". For consistency with other figures and the code variable, consider using't'here too.
ax.legend(loc='upper right')
ax.set_xlabel('time')
ax.set_ylabel(r'$\pi_t$')
ax2 = ax.twinx()
ax2.set_ylabel(r"$w_t$")
plt.show()
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @jit | ||
| def simulate(a, b, T=50, N=500): | ||
| def simulate(a, b, rng, T=50, N=500): | ||
| ''' | ||
| 生成N组T个似然比观测值, | ||
| 以N x T矩阵形式返回。 |
| ax.plot(range(T+1), π_path[i, :], lw=2) | ||
|
|
||
| ax.set_xlabel('$t$') | ||
| ax.set_xlabel('time') |
| ax.hist(π_path3[:,t], bins=20, alpha=0.4, label=f'T={t}') | ||
|
|
||
| ax.set_ylabel('计数') | ||
| ax.set_ylabel('count') |
Automated Translation Sync
This PR contains automated translations from QuantEcon/lecture-python.myst.
Source PR
#977 - [likelihood_bayes.md] Update np.random → Generator API
Files Updated
lectures/likelihood_bayes.md.translate/state/likelihood_bayes.md.ymlDetails
This PR was created automatically by the translation action.