Skip to content

[T-023] Samplers: uniform/prior (inverse-CDF), Latin hypercube, scrambled Sobol, grid #36

Closed

Description

@CodewithJha

Task T-023 · Milestone M2 — Scenario + kinematic2d · Size S · Priority P0 · Epic #2

Implements FR-SEL-001

Branch feat/t-023-samplers-uniform-prior-inverse-cdf — one task = one branch = one PR (doc 32 §6)

Summary

Implement the Sampler protocol and UniformSampler, PriorSampler, LatinHypercubeSampler, SobolSampler, GridSampler in scenario/samplers.py (doc 05 §3, doc 07 §3).

Context / motivation

Baselines (S-RANDOM/LHS/SOBOL/GRID), S-PROBE warm-up and the risk-volume QMC all reuse these samplers; getting their statistics right is essential for a fair comparison.

Scope

In scope

  • sample(n, rng) -> (n,d) in the unit cube; prior inverse-CDF mapping (loguniform for P3 → uniform in unit space because the scale is log — document the interaction of prior and scale carefully).
  • LHS: scipy.stats.qmc.LatinHypercube(d, optimization='random-cd', seed=…).
  • Sobol: qmc.Sobol(d, scramble=True, seed=…), block draws of 2^m, power-of-two warning suppressed.
  • Grid: levels per dimension at {0, 1/(k−1), …, 1}.
  • Seeds derived from the injected Generator (no global RNG).

Implementation guidance

  • SciPy seed= accepts a Generator; pass rng to keep determinism. Sobol state needs to be resumable for strategies → expose skip(n)/fast_forward.
  • Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff PLR2004); public APIs typed (mypy strict) and documented.

Acceptance criteria

  • Distribution tests: KS test vs uniform for each marginal (p > 0.01 over fixed seeds).
  • LHS: exactly one sample per stratum per dimension.
  • Sobol prefix of 2^m has balance property; deterministic with seed.
  • Grid size k^d and ordering documented.
  • Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
  • Docs, config reference and CHANGELOG Unreleased updated where behaviour, keys or interfaces changed.
  • Definition of Done (doc 32 §3) satisfied.

Tests required

  • tests/unit/scenario/test_samplers.py.

Dependencies

Blocked by: #34 (T-021)

Blocks: #84 (T-050a), #105 (T-100b), #136 (T-077)

Parallelization notes

Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:

  • backend/src/roboprobe/scenario/samplers.py
  • backend/tests/unit/scenario/test_samplers.py

Owns samplers.py.

Definition of Done

Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-023 (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.

References

Design docs: doc 05 §3 · doc 07 §3 · doc 09 §5.4

Requirements: FR-SEL-001 (traceability: doc 28)

External:

Activity

  1. added
    area:scenarioScenario space, sampling, scenario files
    priority:P0Critical path / blocks others
    milestone:M2M2 — Scenario + kinematic2d
    taskChild task of a milestone epic
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:scenarioScenario space, sampling, scenario filesmilestone:M2M2 — Scenario + kinematic2dpriority:P0Critical path / blocks otherssize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions