Toolkit for modifying probabilities and shaping curves.
Project description
probkit
Toolkit for modifying probabilities and shaping curves.
Features
- Tunable sigmoid curves - Transform distributions with controllable steepness/flatness
- Probability modification - Scale probabilities using ratios with proper mathematical behavior
- Pure functional design - Deterministic functions for precise control
- Random sampling - Convenient random versions for generating samples from curves
- Zero dependencies - Only uses Python standard library
- Robust validation - Input validation and comprehensive error handling
- Well tested - Thoroughly unit tested with edge case coverage
Quick Start
Deterministic Functions
from probkit import ntsig, biased_curve, modified_probability
# Sigmoid-like curve through (0,0), (0.5,0.5), (1,1)
y = ntsig(k=0.5, x=0.3) # k controls steepness
# Custom curve between any two points
y = biased_curve(k=0.2, a=10, b=100, x=0.7) # From (0,10) to (1,100)
# Modify probability with a ratio
new_prob = modified_probability(0.3, 1.5) # Scale 30% by 1.5x
new_prob = modified_probability(0.3, 3, 2) # Scale 30% by ratio 3/2
Random Sampling
from probkit.sampling import rng
# Optionally set seed for reproducible results
rng.seed(42)
# Sample from curves with random x values
sample = rng.ntsig(k=0.5)
sample = rng.biased_curve(k=0.2, a=10, b=100)
# Generate multiple samples
samples = [rng.ntsig(0.3) for _ in range(1000)]
# Generate random values using the singleton RNG
random_val = rng.random() # Random float in [0,1)
choices = rng.choices(['a', 'b', 'c'], k=5) # All random.Random methods available
# Independent RNG instances for parallel work
fork1 = rng.fork() # Clone current state
spawn1 = rng.spawn(123) # Fresh RNG with seed 123
# Context managers that don't affect main RNG
with rng.forked() as r:
values = [r.ntsig(0.5) for _ in range(10)]
with rng.spawned(456) as r:
reproducible_values = [r.nthsig(0.3) for _ in range(10)]
API Reference
Curve Functions
ntsig(k, x)- Normalized tunable sigmoid. Negative k is flat (logit-like), positive k is steep (sigmoid-like)nthsig(k, x)- Normalized tunable half-sigmoid. Negative k is convex, positive k is concavebiased_curve(k, a, b, x)- Custom curve between points (0,a) and (1,b) with bias k
Probability Functions
modified_probability(k, a, b=None)- Scale probability by ratioa(ora/bif b provided) with proper saturation
Random Sampling
probkit.sampling.rng- Singleton RNG with allrandom.Randommethods plus probkit helpersrng.ntsig(k)- Sample from ntsig with random xrng.nthsig(k)- Sample from nthsig with random xrng.biased_curve(k, a, b)- Sample from biased_curve with random xrng.fork()- Clone current RNG state into independent instancerng.spawn(seed)- Create fresh RNG instance with specified seedrng.forked()- Context manager yielding forked RNG (doesn't affect main state)rng.spawned(seed)- Context manager yielding spawned RNG (doesn't affect main state)
Utilities
clamp(val, min_val, max_val)- Constrain value to rangetransform_range(x, old_range, new_range)- Linear transformation between rangeseffective_ratio(a, b)- Safe division with edge case handling
Use Cases
- Game development - Procedural generation, difficulty curves, loot tables
- Simulations - Monte Carlo methods, statistical modeling
- Data science - Distribution transformation, probability weighting
- Machine learning - Custom activation functions, data preprocessing
Install
Clone this repo or copy the probkit folder into your project. No external dependencies required.
# Example: install with pip from local folder
pip install .
Testing
Run all tests with:
python -m unittest discover tests -v
Deployment (notes for Taylor)
PyPI is set up to receive releases from the main branch or when tagged with v*. This is accomplished using PyPI OIDC and GitHub Actions.
Pushing to main will create a new dev release with automatic version bump.
Creating a v* tag will create a production release using that version number.
git tag v0.1.0 && git push --tags
Contributing
Pull requests and suggestions welcome! Open an issue or PR on GitHub.
License
MIT License. See LICENSE file for details.
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 Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file probkit-0.2.2.dev1.tar.gz.
File metadata
- Download URL: probkit-0.2.2.dev1.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ea552cf40551e4e69a76ead789b5f245fff1f15ee231c3e1b637a17172bb57f
|
|
| MD5 |
6e60603e5810857ed1ed17001795314a
|
|
| BLAKE2b-256 |
43efe633b36165aa3f8d66c642fb3cbcdbe3de0f500d88c1aa5715eb30c02c6b
|
Provenance
The following attestation bundles were made for probkit-0.2.2.dev1.tar.gz:
Publisher:
publish.yml on taylorvance/probkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
probkit-0.2.2.dev1.tar.gz -
Subject digest:
3ea552cf40551e4e69a76ead789b5f245fff1f15ee231c3e1b637a17172bb57f - Sigstore transparency entry: 427254616
- Sigstore integration time:
-
Permalink:
taylorvance/probkit@cac0307b91a324fc8012225ae99283359e986637 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/taylorvance
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cac0307b91a324fc8012225ae99283359e986637 -
Trigger Event:
push
-
Statement type:
File details
Details for the file probkit-0.2.2.dev1-py3-none-any.whl.
File metadata
- Download URL: probkit-0.2.2.dev1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f805e9d77bfd820777f8f74dbc4e8e84bdd33776ee6d94a96155727e5da5653
|
|
| MD5 |
e2d6d2e724eb4f38f1efbc56ec221887
|
|
| BLAKE2b-256 |
e5642279ef261cf2ce477dd7bf2ee144ba3c89698d355cbfad916557ed63748f
|
Provenance
The following attestation bundles were made for probkit-0.2.2.dev1-py3-none-any.whl:
Publisher:
publish.yml on taylorvance/probkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
probkit-0.2.2.dev1-py3-none-any.whl -
Subject digest:
1f805e9d77bfd820777f8f74dbc4e8e84bdd33776ee6d94a96155727e5da5653 - Sigstore transparency entry: 427254620
- Sigstore integration time:
-
Permalink:
taylorvance/probkit@cac0307b91a324fc8012225ae99283359e986637 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/taylorvance
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cac0307b91a324fc8012225ae99283359e986637 -
Trigger Event:
push
-
Statement type: