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
import probkit.sampling
# Optionally set seed for reproducible results
sampling.seed(42)
# Sample from curves with random x values
sample = sampling.sample_ntsig(k=0.5)
sample = sampling.sample_biased_curve(k=0.2, a=10, b=100)
# Generate multiple samples
samples = [sampling.sample_ntsig(0.3) for _ in range(1000)]
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.seed(value)- Set seed for reproducible random samplingprobkit.sampling.sample_ntsig(k)- Sample from ntsig with random xprobkit.sampling.sample_nthsig(k)- Sample from nthsig with random xprobkit.sampling.sample_biased_curve(k, a, b)- Sample from biased_curve with random x
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
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.1.3.dev1.tar.gz.
File metadata
- Download URL: probkit-0.1.3.dev1.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a14b138ad5860fc66968212093fe09aed0026085315ff72c599827c4feb5704
|
|
| MD5 |
f1755d73f727f5d6d56db457ca70373f
|
|
| BLAKE2b-256 |
a11300a0e843c418f6f745fde9e1e47b326af2ba84b5b2beae88890e85b2971e
|
Provenance
The following attestation bundles were made for probkit-0.1.3.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.1.3.dev1.tar.gz -
Subject digest:
6a14b138ad5860fc66968212093fe09aed0026085315ff72c599827c4feb5704 - Sigstore transparency entry: 396523656
- Sigstore integration time:
-
Permalink:
taylorvance/probkit@e87eb34bd8bd67bb74e463aa06c910bbbf573406 -
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@e87eb34bd8bd67bb74e463aa06c910bbbf573406 -
Trigger Event:
push
-
Statement type:
File details
Details for the file probkit-0.1.3.dev1-py3-none-any.whl.
File metadata
- Download URL: probkit-0.1.3.dev1-py3-none-any.whl
- Upload date:
- Size: 7.0 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 |
30260e95b57c75cd0a653f5b1749694304d73999c5f16bcd8c59429e1c888b80
|
|
| MD5 |
fa0b798f1f552ae8fef12791caf30d14
|
|
| BLAKE2b-256 |
c9e69f4d11df3c1d2ad870265406dcc42d97a7f111a1ee0045cbb06f5dbab551
|
Provenance
The following attestation bundles were made for probkit-0.1.3.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.1.3.dev1-py3-none-any.whl -
Subject digest:
30260e95b57c75cd0a653f5b1749694304d73999c5f16bcd8c59429e1c888b80 - Sigstore transparency entry: 396523675
- Sigstore integration time:
-
Permalink:
taylorvance/probkit@e87eb34bd8bd67bb74e463aa06c910bbbf573406 -
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@e87eb34bd8bd67bb74e463aa06c910bbbf573406 -
Trigger Event:
push
-
Statement type: