Skip to content

doc(gh-2187): explain GaussianStateSpace joint distribution - #2323

Merged
juanitorduz merged 1 commit into
pyro-ppl:masterfrom
jabrailkhalil:doc/gaussian-state-space-math
Oct 4, 2026
Merged

juanitorduz merged 1 commit into
pyro-ppl:masterfrom
jabrailkhalil:doc/gaussian-state-space-math

Conversation

@jabrailkhalil

Copy link
Copy Markdown
Contributor

Part of #2187, following my GaussianRandomWalk documentation in #2266.

I expanded the GaussianStateSpace docstring to explain the joint density, the innovation transform and its unit Jacobian, and the marginal mean/covariance recurrence. I also clarified that samples start after the deterministic initial state, that the transition matrix is shared across the batch, and that the covariance-related attributes describe innovation noise.

The executable position/velocity example shows two initial states, their mean trajectories, and the sample and log-probability shapes. This change only updates the class docstring; it adds no dependencies or runtime behavior.

Validation on Windows CPU with Python 3.12.10 and JAX/jaxlib 0.11.2:

  • pytest -q test/test_distributions.py -k 'GaussianStateSpace or gaussian_random_walk_state_space_equivalence': 147 passed, 110 skipped, 5 xfailed, in each of the default and JAX_ENABLE_X64=1 runs.
  • Full Sphinx HTML build with warnings treated as errors: passed. The focused Sphinx doctest build passed all 9 example statements; I also executed those statements in both precision modes.
  • Ruff check/format, license-header check, and ty check: passed.
  • Independent NumPy/SciPy checks matched the documented means, marginal variances, and full joint Gaussian density for all three noise parameterizations, with default, explicit, and batched initial states. Eager and JIT log densities agreed in both precision modes.

@github-actions github-actions Bot added the awaiting review Awaiting review from maintainers label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

Benchmark report

this PR doc/gaussian-state-space-math at c2f05c61 vs baseline master at 5a3e636c

+ run time:     1 faster
  compile time: unchanged across 32 benchmarks

Significant changes (1)

                          ─────── run time ───────     ────── compile time ─────
  benchmark               baseline  this PR      Δ     baseline   this PR      Δ
────────────────────────────────────────────────────────────────────────────────
+ biject_to_constraints     2.2 ms   2.1 ms  -5.7%     184.2 ms  199.9 ms  +8.5%

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

distributions

                                 ──────── run time ────────     ────── compile time ─────
  benchmark                      baseline  this PR        Δ     baseline   this PR      Δ
─────────────────────────────────────────────────────────────────────────────────────────
+ biject_to_constraints            2.2 ms   2.1 ms    -5.7%     184.2 ms  199.9 ms  +8.5%
  categorical_log_prob             1.2 ms   1.2 ms    -1.5%      52.5 ms   52.2 ms  -0.4%
  dirichlet_log_prob               410 µs   386 µs  (-5.7%)     324.5 ms  335.9 ms  +3.5%
  dirichlet_sample                42.0 ms  41.8 ms    -0.4%     546.5 ms  539.2 ms  -1.3%
  gamma_log_prob                   1.3 ms   1.4 ms    +3.6%       1.94 s    1.93 s  -0.2%
  gamma_sample                    19.3 ms  19.6 ms    +1.2%     512.1 ms  512.7 ms  +0.1%
  lkj_cholesky_sample              4.2 ms   4.3 ms    +1.2%     802.0 ms  809.6 ms  +0.9%
  mixture_same_family_log_prob     565 µs   574 µs    +1.6%      62.0 ms   57.3 ms  -7.6%
  multivariate_normal_log_prob     430 µs   446 µs    +3.8%     453.3 ms  413.0 ms  -8.9%
  normal_log_prob                  435 µs   421 µs    -3.2%      47.1 ms   46.8 ms  -0.7%
  normal_sample                   19.5 ms  19.2 ms    -1.7%     154.3 ms  146.4 ms  -5.1%
  stick_breaking_transform         3.6 ms   3.6 ms    +0.9%     160.7 ms  153.4 ms  -4.5%
  student_t_log_prob               2.4 ms   2.4 ms    -0.6%      65.1 ms   66.1 ms  +1.6%
  truncated_normal_log_prob        470 µs   463 µs    -1.7%      42.8 ms   40.4 ms  -5.5%

handlers

                                  ───────── run time ─────────     ────── compile time ──────
  benchmark                       baseline   this PR         Δ     baseline   this PR       Δ
─────────────────────────────────────────────────────────────────────────────────────────────
  initialize_model_hierarchical    30.2 ms   29.4 ms     -2.6%       2.85 s    2.77 s   -2.7%
  log_density_hierarchical          2.5 ms    2.4 ms     -2.7%       1.02 s  983.7 ms   -4.0%
  nested_handler_stack              984 µs    981 µs     -0.3%       646 µs    567 µs  -12.3%
  potential_energy_and_grad          21 µs     17 µs  (-21.0%)      82.1 ms   78.1 ms   -4.9%
  predictive_forward_sampling     478.3 ms  468.6 ms     -2.0%     125.5 ms  152.1 ms  +21.2%
  trace_seeded_model                616 µs    568 µs   (-7.9%)     415.2 ms  413.6 ms   -0.4%

mcmc

                             ──────── run time ───────     ───── compile time ─────
  benchmark                  baseline   this PR      Δ     baseline  this PR      Δ
───────────────────────────────────────────────────────────────────────────────────
  hmc_logistic_regression    526.8 ms  517.1 ms  -1.8%       2.43 s   2.38 s  -1.9%
  nuts_dense_mass_funnel     836.2 ms  847.9 ms  +1.4%       1.93 s   1.84 s  -4.6%
  nuts_eight_schools         822.6 ms  827.3 ms  +0.6%       1.89 s   1.86 s  -1.6%
  nuts_hierarchical_glm        2.21 s    2.25 s  +1.4%       3.66 s   3.48 s  -5.1%
  nuts_logistic_regression   786.9 ms  775.4 ms  -1.5%       2.41 s   2.34 s  -3.1%
  nuts_vectorized_chains       1.78 s    1.78 s  -0.2%       2.01 s   2.00 s  -0.5%

svi

                                             ──────── run time ───────     ───── compile time ─────
  benchmark                                  baseline   this PR      Δ     baseline  this PR      Δ
───────────────────────────────────────────────────────────────────────────────────────────────────
  svi_autodelta_map_logistic                 221.2 ms  223.4 ms  +1.0%       2.31 s   2.39 s  +3.3%
  svi_autodiagonalnormal_hierarchical        751.7 ms  742.7 ms  -1.2%       3.68 s   3.66 s  -0.6%
  svi_automultivariatenormal_eight_schools   534.0 ms  532.0 ms  -0.4%       3.35 s   3.21 s  -4.3%
  svi_autonormal_logistic                    531.6 ms  523.1 ms  -1.6%       2.61 s   2.53 s  -3.0%
  svi_multi_particle_elbo                      1.03 s    1.02 s  -0.9%       2.65 s   2.54 s  -4.1%
  svi_trace_mean_field_elbo                  858.4 ms  861.9 ms  +0.4%       3.96 s   3.85 s  -2.7%
Methodology and environment

Each benchmark is set up untimed, then called once with the JAX caches cleared and several more times warm. Run is the fastest warm call; compile is the first call minus that, i.e. the tracing, lowering and XLA compilation the warm calls did not have to pay for.

Both refs were measured on the same runner over 2 interleaved round(s), taking the best observation per benchmark. A result is called neutral when it moves less than ±5% (run) or ±25% (compile), or when the measurement itself is under 1 ms (run) / 50 ms (compile) — a shared CI runner cannot resolve changes below that. Compile time gets the looser band because it is measured once per round rather than best-of-N, and swings by roughly 20% even between two runs of identical code. A delta shown in parentheses did clear its threshold, but on a measurement below the resolution floor, so it is reported without being called a change.

baseline this PR
ref master doc/gaussian-state-space-math
commit 5a3e636c c2f05c61
numpyro 0.22.0 0.22.0
jax 0.11.2 0.11.2
backend cpu cpu
python 3.14.8 3.14.8

Runner: Linux-6.17.0-1022-azure-x86_64-with-glibc2.39, 4 CPUs.

Produced by this benchmark run.

@juanitorduz
juanitorduz merged commit 8c9ee7d into pyro-ppl:master Oct 4, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review Awaiting review from maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants