Skip to content

Port the legacy GBM script and add its regression test - #13

Merged
rk-mlu merged 1 commit into
mainfrom
m1-port-gbm-script
Nov 4, 2026
Merged

rk-mlu merged 1 commit into
mainfrom
m1-port-gbm-script

Conversation

@rk-mlu

@rk-mlu rk-mlu commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

First legacy port of milestone M1, stacked on #12 (base m1-end-to-end-slice; GitHub retargets it to main once #12 is merged). It satisfies the milestone gate "at least one legacy script is ported onto the new features".

What is added

File Content
tests/regression/data/legacy_gbm_em_l2error.npz Errors of the unmodified legacy function num_exp_GBM.compute_L2_errors, Euler–Maruyama only, with seed, parameters, NumPy version and SHA-256 checksums of num_exp_GBM.py, StochODEs.py, SODESolvers.py
tests/regression/data/README.md Provenance and the code to regenerate the data
tests/regression/test_legacy_gbm.py Rebuilds the legacy Brownian paths, wraps them as BrownianPath, and requires the library to reproduce the legacy errors
examples/strong_error_gbm.py The experiment ported to the library API: errors, EOCs and 95 % confidence intervals; optional plot
tests/unit/test_examples.py Smoke test of the example with small parameters

Reference data

The legacy script draws all step sizes from one generator default_rng(20250718), increments of shape (n_paths, m, n). These are other random numbers than WienerProcess.sample_path draws for the same seed, so the test rebuilds the legacy paths (the convention is documented in the test module). The legacy L2_error() is exactly the library's default strong error, uniformly on the grid with p = 2.

To keep the test fast, the data use 2000 paths and N = 10·2^k for k = 0, …, 5 instead of 50 000 paths and k ≤ 7. On the generating machine the library reproduces all six errors bitwise; the test uses rtol = 1e-12 because exp may round differently on other platforms.

Example vs. legacy at full size (50 000 paths)

N legacy (new paths per N) example (one coarsened path) example 95 % CI
10 0.5646 0.5382 [0.4991, 0.5747]
20 0.4215 0.3966 [0.3814, 0.4112]
40 0.3069 0.3046 [0.2926, 0.3161]
80 0.2295 0.2219 [0.2161, 0.2276]
160 0.1658 0.1649 [0.1593, 0.1703]
320 0.1156 0.1164 [0.1135, 0.1193]
640 0.0847 0.0837 [0.0813, 0.0860]
1280 0.0592 0.0599 [0.0584, 0.0613]

Two independent Monte Carlo estimates; the differences are within their combined error (at N = 20 and 80 slightly outside the interval of the single estimate, as expected when comparing two estimates with heavy-tailed pathwise errors). The example needs about 3 GB with the book's parameters; --n-paths reduces that.

Not ported here

StrConvGBM.py (Python 2, unseeded) is superseded by num_exp_GBM.py. The Milstein part of num_exp_GBM.py and GBM_Milstein_L2error.py follow in M2; GBM_STM_* and GBM_BDF2_* with the implicit schemes in phase 2.

Checks

Fast suite 309 passed with PyTorch, 296 without; coverage 100 %; Ruff, mypy, codespell and Sphinx -W pass.


Generated by Claude Code

@rk-mlu
rk-mlu force-pushed the m1-port-gbm-script branch 2 times, most recently from 75150ee to 6a24501 Compare November 2, 2026 10:03
@rk-mlu
rk-mlu force-pushed the m1-port-gbm-script branch 4 times, most recently from af478cb to d3193b5 Compare November 3, 2026 17:41
- tests/regression/data/legacy_gbm_em_l2error.npz: errors of the unmodified
  legacy function num_exp_GBM.compute_L2_errors (Euler–Maruyama only, 2000
  paths, N = 10 * 2**k for k < 6, seed 20250718), with parameters and the
  SHA-256 checksums of the three script files.
- tests/regression/test_legacy_gbm.py rebuilds the legacy Brownian paths,
  wraps them as BrownianPath and reproduces the errors (bitwise on the
  generating machine, rtol 1e-12 in the test).
- examples/strong_error_gbm.py ports the experiment with the library's
  coupling (one finest path, coarsened) and prints errors, EOCs and 95 %
  confidence intervals; a smoke test runs it with small parameters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KaTyMUfivRVAGYQR6kGnp
@rk-mlu
rk-mlu changed the base branch from m1-end-to-end-slice to main November 4, 2026 10:03
@rk-mlu
rk-mlu force-pushed the m1-port-gbm-script branch from d3193b5 to f5d1154 Compare November 4, 2026 10:03
@rk-mlu
rk-mlu merged commit db7a1b6 into main Nov 4, 2026
13 of 24 checks passed
@rk-mlu
rk-mlu deleted the m1-port-gbm-script branch November 5, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants