No project description provided
Project description
discrete dists
Simple utilities for defining complex distributions over discrete elements. Backed by a fast sum-tree implementation written in Rust.
Getting Started
pip install discrete-dists
API
Uniform Distribution
A very simple wrapper over np.random.default_rng().integers
, conforming to the Distribution
API defined in this library.
This wrapper additionally introduces importance sampling ratio calculations, sampling without replacement, and stratified sampling.
import numpy as np
from discrete_dists.uniform import Uniform
rng = np.random.default_rng(0)
u = Uniform(100)
# sampling
print(u.sample(rng, 10))
print(u.stratified_sample(rng, 10))
print(u.sample_without_replacement(rng, 10))
# importance sampling ratio
other = Uniform(10)
items = [0, 3, 8]
isrs = u.isr(other, items)
# updating the support
u.update_single(150)
Proportional Distribution
Sample proportional to a list of values.
from discrete_dists.proportional import Proportional
p = Proportional(5)
# set the values to sample proportional to
p.update(idxs=[0, 2], values=[1, 2])
# approximately 33% of values are 0, and 66% are 2
print(p.sample(rng, 10000))
p.update(idxs=[1], values=[2])
# approximately 20% are 0, 40% are 1, and 40% are 2
print(p.sample(rng, 10000))
Mixture Distribution
Mix together arbitrary distributions with arbitrary supports.
from discrete_dists.proportional import Proportional
from discrete_dists.uniform import Uniform
from discrete_dists.mixture import MixtureDistribution, SubDistribution
prop = Proportional(100)
m = MixtureDistribution([
SubDistribution(d=prop, p=0.2),
SubDistribution(d=Uniform(10), p=0.8),
])
prop.update(idxs=np.arange(100), values=100-np.arange(100))
print(m.sample(rng, 10000))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file discrete_dists-1.1.2.tar.gz
.
File metadata
- Download URL: discrete_dists-1.1.2.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26d4a01d61a377a5a95f509b3644e337ad3cb6abdcc151faebf6bf09730e2b2a |
|
MD5 | 2b0b73bfa9b9adb7b955f2cca249ce2f |
|
BLAKE2b-256 | 9d12428ff73c5c4c7622492469a3c96c2a06e6df1d054dee978e552831f97880 |
File details
Details for the file discrete_dists-1.1.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 314.9 kB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82e3d9d3054f11c140f0d0539eb550feb1f3dc1daf49e51b6ebdf2796a548bee |
|
MD5 | 747f12780f7ce2f48c39b0b350b3ddda |
|
BLAKE2b-256 | c1aab4b05f487f4a01f63e141ea687a037e27c01b92911191edf2eb67ac01155 |
File details
Details for the file discrete_dists-1.1.2-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 348.1 kB
- Tags: PyPy, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecbeeaa8b39484f9d56ab77172a2ac02a3c0f5ae4eb2280383aba665f0630f3a |
|
MD5 | ca1795420a3988c7ab04fed1fb0506ed |
|
BLAKE2b-256 | 0e28b521a40c587d6dc3b8f3c429e0992528eca8abca42c63bc64d2666e34279 |
File details
Details for the file discrete_dists-1.1.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 315.0 kB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a11e3686d5aee77b82fa7873c36308b3634c89e5a67b9d31e90c407ea762d390 |
|
MD5 | c139afdc42027c29d6b43f032cd1275d |
|
BLAKE2b-256 | ee9bd168713c80748e2bb00226e8520178db225042083cb3c1529e4d35fb850c |
File details
Details for the file discrete_dists-1.1.2-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 348.2 kB
- Tags: PyPy, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c810f936b6afa8815ad0d4628826ea4869df3c7d2adee9798175ac49eda07ba0 |
|
MD5 | 33cbc41c25dc2610a219a3e02d9a37d2 |
|
BLAKE2b-256 | f6bd4b112e4efca8b6d8e3a8460bbde74c0fa07f7a1d0560f366462911a3d474 |
File details
Details for the file discrete_dists-1.1.2-cp313-cp313-win_amd64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 170.3 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e60beb6f7abd21c2f1e484946d654ee786d65d3b56bba3e74f2a5cef3029b5f2 |
|
MD5 | ebfd7d6a65fedf4bcf53b4a06f68454e |
|
BLAKE2b-256 | afd9af931c76083b3a8b3e6ecf0164f31b8974a30ab55f1b2e5af87dc429549b |
File details
Details for the file discrete_dists-1.1.2-cp313-cp313-win32.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp313-cp313-win32.whl
- Upload date:
- Size: 174.7 kB
- Tags: CPython 3.13, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d9dde27dbc48adffa72528b7a7a8e9a26ec2ad16676494d1cdeb4c557a8e4ef |
|
MD5 | 2f3ddf6e86e951b99f75552c2d547a51 |
|
BLAKE2b-256 | 6706aef3a3fd2884d13da4883e7abc8f4bf2208957ff879762d7fd41fda13fef |
File details
Details for the file discrete_dists-1.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 314.2 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7043c12a9c6f5fd52073efe1c89bd4410b735f6badaa8d37f4e093cb8feb65c0 |
|
MD5 | 051eeca6fd2c852421089d947a9f11b8 |
|
BLAKE2b-256 | 1a66ea9cb00023b5fef1635f177da3c7e0659dfee07f7bafd321bf3cf85a9ec7 |
File details
Details for the file discrete_dists-1.1.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 348.5 kB
- Tags: CPython 3.13, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8eb0a80366de1250cc21a7cb24ec049f0973a6f2f8786568592746297ed68ed3 |
|
MD5 | e01881668a8390e674f776192a04d9b3 |
|
BLAKE2b-256 | 62b2251cdcf79a3b8ffceedbc094d6fcde0d19a6af180af48521b2d82d456696 |
File details
Details for the file discrete_dists-1.1.2-cp313-cp313-macosx_11_0_arm64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 275.6 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2759ede26a68c1c416438e5fcdbc7ff4819b02084e8f78a692d11e03619d7ce0 |
|
MD5 | f50364b48be4e2fb34298996d238c8be |
|
BLAKE2b-256 | b100f697b33ab47a4d93b580d6866afd8eaef4f2f32acd57b3ce3d8721f96859 |
File details
Details for the file discrete_dists-1.1.2-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 170.4 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 436a2395cc8a0a5e3cb239014b212f44df2da4aaebdd8865e2ecbd5ddab3dfec |
|
MD5 | 7546a077854aaf3131187aabed88c15e |
|
BLAKE2b-256 | 39063ec25c49fc6e6f0ff0447cd564683a48e7021497734b1b88d4a2f3b40013 |
File details
Details for the file discrete_dists-1.1.2-cp312-cp312-win32.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp312-cp312-win32.whl
- Upload date:
- Size: 174.7 kB
- Tags: CPython 3.12, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40c4c7d714a7bf2707af906f03c12737db1c5db1120d08b2bbc879e42ca1778d |
|
MD5 | 3c85a5e63f1ef4852bc77de5101dfe78 |
|
BLAKE2b-256 | 7f5a7c9f338f458a031a9548e248dac44795ce0c61e4d9fb054fb7ec1740a3b5 |
File details
Details for the file discrete_dists-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 314.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88920fac9920dfde23c3a14e7e9eaeebaebb2dcab165cdff778eb432ba78dfaf |
|
MD5 | 8a674c3c939e5dfbb13c05344800af9c |
|
BLAKE2b-256 | 93b08b460689fe242401d124dbd78a04e9ecf79afb2d05449677ab54b6b04175 |
File details
Details for the file discrete_dists-1.1.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 348.9 kB
- Tags: CPython 3.12, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd1588e650db785d10cc0bcd60ef7a672d14ad50275c551135f2cb0ed8558445 |
|
MD5 | 163cb8259cdf38a076db97981ae2d488 |
|
BLAKE2b-256 | a9d1405d05dd9703ff7431427565723bdb6b6497a24557acf662f2e4ae0ae8c6 |
File details
Details for the file discrete_dists-1.1.2-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 275.6 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e29206fad6024e6d55cfb0884478dc62d800ed658565da39e75b87855653ce55 |
|
MD5 | 9efc33340737654c6bb38a291621224c |
|
BLAKE2b-256 | e635aaf2f6ca98f9bbee79401fa8d33220808580fb9cddfdf80b8a21092f8154 |
File details
Details for the file discrete_dists-1.1.2-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 169.9 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93308c9734c6ab061110c0b24265ae3b4e96c68ef6cf86df02db889339fd1dd1 |
|
MD5 | ca17c68475326cec1f483b6c423c9a17 |
|
BLAKE2b-256 | a8ddd06ccabf1389b0904314bc5480f555e98ad8df7f89923022499a91ca495e |
File details
Details for the file discrete_dists-1.1.2-cp311-cp311-win32.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp311-cp311-win32.whl
- Upload date:
- Size: 174.7 kB
- Tags: CPython 3.11, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6abf87ef83c2d1bb451f30600dbc2dea8cd7e664de0e2241df355e1d3faa1c40 |
|
MD5 | 4826db66d7abdf54d289910afd60c382 |
|
BLAKE2b-256 | 34315bb4a3e61dce6515412ea898b1818f96a4bab734819f04aaa0527d1c2e1c |
File details
Details for the file discrete_dists-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 315.0 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ce7cc946d07a9a25167ca3abb7a871e08b7e3ca71ccd0f9b00c8a0b3aa5ee43 |
|
MD5 | 72ec571bbf3fcef0622ae2b1ba928d57 |
|
BLAKE2b-256 | f58cce4da96a9c28ea89fa4bc1cbd5deda949f2ce7544f26f026574c035bccce |
File details
Details for the file discrete_dists-1.1.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 348.4 kB
- Tags: CPython 3.11, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01de1f9353dfe91e7412b65fd6affa369d7904b10580ac1bb6f4738689040071 |
|
MD5 | 4119c0e3dc2597febc5a03c28ac9def6 |
|
BLAKE2b-256 | 9c69c471191a696ccfc2d0f27c5408d2e8216431d8e4d547f4b5a8e9a39d4c29 |
File details
Details for the file discrete_dists-1.1.2-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 279.4 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32571f381f35040ab05f7b85839f770452407b6f1a7e5ada071d8b8899953db5 |
|
MD5 | 9ed3eeb9977fa0f7c3692571372bcbb5 |
|
BLAKE2b-256 | fd8a2d6e70b5630837682483bf34617813836f6e0bb9dec191506130349c00a9 |
File details
Details for the file discrete_dists-1.1.2-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 170.0 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25636337c92b103bbf7fdcd7a6bcdb46adeeb950a3485299d4793d259b33185f |
|
MD5 | f3dd5249e5cc01c0e88f51dd0d0ce703 |
|
BLAKE2b-256 | 73ebf3b0c0bc209ce95e74863a80ffe0c8c93df695ddeed0befd2395d6b084d6 |
File details
Details for the file discrete_dists-1.1.2-cp310-cp310-win32.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp310-cp310-win32.whl
- Upload date:
- Size: 174.8 kB
- Tags: CPython 3.10, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb1fe55c118ad22cc0107919bd5bc47b76bf72fed20cefd96f3de9ee7c958e19 |
|
MD5 | 287ca3dfc46e1c141d68e88a31b3a2c9 |
|
BLAKE2b-256 | 47065eacd1e319590214f0540744a4875de39ad9c2f66a26ce90d57962ce48ef |
File details
Details for the file discrete_dists-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 315.3 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b62f7299c9321d9c9ed1fd98d314cfe6f00f26e375dff48652cf8e94e8a362dc |
|
MD5 | 1609e60ec6b08be41d95f90e6b95b1e0 |
|
BLAKE2b-256 | 4d2ff334fa3a8ef71c77ff9604bcbb8d7af494f46a6ed902643abcae6e36ccaf |
File details
Details for the file discrete_dists-1.1.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl
.
File metadata
- Download URL: discrete_dists-1.1.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 348.4 kB
- Tags: CPython 3.10, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7c764617d0d8fa25bb2161ff1df1638e16822f034e0bcbcc166324da915b341 |
|
MD5 | ae872ecf46e70aadec53e923623b0ff5 |
|
BLAKE2b-256 | e78d3a68cd00c100580f17aa72df038df2aee7f5fbf9c4e620399951698d6bd5 |