feat: Monte Carlo uncertainty propagation (gpu_stack.uncertainty)#8
Merged
Conversation
…tainty) Adds `gpu_stack/uncertainty.py` with UncertainAssignment, three distribution types (uniform, normal, lognormal), and `propagate_uncertainty` that resolves targets over n_samples draws. Uses SymPy lambdify fast-path for vectorised evaluation (200 samples in <1 ms vs ~14 s per-sample) with fallback to per-sample resolver. Returns structured TargetUncertaintyStats with mean, sample std, p5/p50/p95, failure count, and echoed input specs. 35 tests cover determinism, quantile ordering, analytic correctness, failure counting, and all three distribution types. https://claude.ai/code/session_01Eu2JVnPFgMQftwYTP3cGQZ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
$(cat <<'EOF'
Summary
gpu_stack/uncertainty.pywith a public API for Monte Carlo uncertainty propagation over the existing symbolic resolveruniform(low, high),normal(mean, std),lognormal(mu, sigma)with sign-assumption validation against SymPy variable assumptionsUncertainAssignment(name, distribution)pairs a registered variable name with a distribution; validated at constructionpropagate_uncertainty(preset_or_assignments, targets, uncertain, n_samples, seed)collects per-target samples through the existing publicresolve()pathUncertaintyResult/TargetUncertaintyStatsresult artifacts withto_dict()and echoed input specstests/test_uncertainty.pycovering: distribution validation, sign-assumption rejection, determinism by seed, quantile ordering, analytic correctness on a hand-checkable linear case, failure-count behavior, all three distribution types, multi-target runs, and performance sanityTest plan
python -m pytest tests/test_uncertainty.py -q-- 35 passedpython -m pytest -q-- 705 passed (670 baseline + 35 new)python -m gpu_stack.cli audit --fail-on-issues-- PASS_is_finite_floathelper, fixed deadif not _has_numpy: passbranch and redundant import, fixed population vs sample std (now Bessel-corrected), added duplicate variable name validation, corrected return type annotation on_try_lambdify_pathhttps://claude.ai/code/session_01Eu2JVnPFgMQftwYTP3cGQZ
EOF
)
Generated by Claude Code