Repository navigation
doc(gh-2187): mathematical details for GaussianRandomWalk - #2266
Conversation
Add class, sample, log_prob, mean, and variance docstrings with mathematical derivations for the Gaussian random walk distribution, following the docstring style of the other pyro-pplgh-2187 doc PRs.
Benchmark reportthis PR + run time: 7 faster
- compile time: 1 slower, 0 fasterSignificant changes (8) ──────── run time ──────── ────── compile time ──────
benchmark baseline this PR Δ baseline this PR Δ
────────────────────────────────────────────────────────────────────────────────────────
- dirichlet_log_prob 637 µs 617 µs -3.2% 455.8 ms 574.3 ms +26.0%
+ normal_sample 24.7 ms 22.1 ms -10.7% 206.6 ms 204.0 ms -1.3%
+ hmc_logistic_regression 816.3 ms 775.4 ms -5.0% 3.54 s 3.38 s -4.8%
+ nuts_dense_mass_funnel 1.30 s 1.18 s -9.2% 2.84 s 2.71 s -4.5%
+ nuts_eight_schools 1.33 s 1.19 s -10.6% 2.95 s 2.65 s -10.1%
+ nuts_logistic_regression 1.21 s 1.13 s -6.4% 3.62 s 3.37 s -7.1%
+ nuts_vectorized_chains 2.84 s 2.66 s -6.3% 3.16 s 2.93 s -7.4%
+ svi_autodelta_map_logistic 340.2 ms 315.9 ms -7.1% 3.44 s 3.28 s -4.7%Red is slower, green is faster; a row is coloured by the worse of its two columns. A delta in parentheses cleared the threshold on a measurement below the resolution floor, so it is shown without being called a change. † marks a benchmark that could not be compared — see below. Full results
|
| baseline | this PR | |
|---|---|---|
| ref | master |
doc/gh-2187-gaussian-random-walk |
| commit | 93041d1e |
a1c8d453 |
| numpyro | 0.21.0 | 0.21.0 |
| jax | 0.11.1 | 0.11.1 |
| backend | cpu | cpu |
| python | 3.14.7 | 3.14.7 |
Runner: Linux-6.17.0-1022-azure-x86_64-with-glibc2.39, 4 CPUs.
Produced by this benchmark run.
|
Thanks for the PR! The math checks out against the implementation (I verified 1. Broken inline markup in the class docstring (line 1186) length :math:`n = ` :attr:`num_steps` starts at :math:`X_0` and evolvesRST requires the inline end-string to be immediately preceded by non-whitespace, so import docutils.core
text = r"length :math:`n = ` :attr:`num_steps` starts at :math:`X_0`"
print(docutils.core.publish_string(text, writer_name="pseudoxml").decode())Suggested fix: length :math:`n` (given by :attr:`num_steps`) starts at :math:`X_0` and evolves2. Every other method docstring in Optional nits
|
juanitorduz
left a comment
There was a problem hiding this comment.
Smal changes (see above)
|
Thanks @juanitorduz! I have addressed both requested changes (fixed the inline RST markup and updated the :rtype: annotations to jax.Array), along with the optional notation alignment to Normal. |
Summary
Adds mathematical explanations and implementation details for
GaussianRandomWalkto the class,sample,log_prob,mean, andvariancedocstrings, as tracked in gh-2187.R^n, defined via initial position and independent Normal increments.sample: cumulative sum of standard Normal draws.log_prob: sum of univariate Normal log densities over the initial position and increments.meanandvariance:E[X_t] = 0andVar(X_t) = (t+1) * scale^2, matching the implementation.Math details were checked numerically against the implementation (log_prob, mean, variance, batched scale shapes).
Testing
ruff checkandruff format --checkon the changed file: pass.ty checkandcodespell: pass.pytest test/test_distributions.py -k "random_walk or RandomWalk": 62 passed, 42 skipped (missing optional deps), 2 xfailed, on local CPU before opening the PR.