Add Dice.from_dist to approximate distributions via quantile slicing - #14
Merged
Conversation
`Dice.from_dist(dist, n=6, quantiles=None)` builds a dice that approximates a continuous distribution by slicing equiprobable quantiles. It is duck-typed on the inverse-CDF: works with scipy frozen dists (.ppf) and the stdlib statistics.NormalDist (.inv_cdf), so no new dependency is added. Includes notebook demos (NormalDist plus a numpy exponential showing the duck-typing) and tests covering equiprobability, normal symmetry, custom quantiles, mean tracking, and the error cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
# Conflicts: # dicekit/__init__.py # nbs/__init__.py
Configure shared Conductor scripts for the uv + marimo workflow: - setup: uv sync - run: marimo edit on the nbs/ folder, bound to $CONDUCTOR_PORT, headless - archive: make clean - run_mode: concurrent (per-workspace port, no shared local state) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Adds
Dice.from_dist(dist, n=6, quantiles=None)— a classmethod that approximates a continuous distribution with aDiceby slicing equiprobable quantiles out of it.How
.ppf(scipy frozen distributions) or.inv_cdf(stdlibstatistics.NormalDist), raisingTypeErrorif neither is present. No new package dependency.n(default6): number of equiprobable faces, placed at the midpoint of each quantile bin —inv_cdf((i + 0.5) / n).quantiles: optional explicit sequence of probabilities in(0, 1)to slice at instead ofnmidpoints; faces stay equiprobable. Validated to be non-empty with everyqstrictly in(0, 1)(avoids±infon unbounded distributions), elseValueError.Notebook
Demo cells added in
nbs/__init__.py(source of truth): astatistics.NormalDistexample, the documented kwargs, and anumpyexponential example that doubles as a duck-typing showcase.dicekit/__init__.pyregenerated viamake build.Tests
8 new tests in
tests/test_basics.py: equiprobable faces, normal symmetry, monotonic midpoints, custom quantiles, duck-typed.ppfstub, mean tracking,TypeErroron bad object,ValueErroron bad quantiles.uv run pytest -q→ 34 passed.🤖 Generated with Claude Code