Skip to main content

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 concave
  • biased_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 ratio a (or a/b if b provided) with proper saturation

Random Sampling

  • probkit.sampling.seed(value) - Set seed for reproducible random sampling
  • probkit.sampling.sample_ntsig(k) - Sample from ntsig with random x
  • probkit.sampling.sample_nthsig(k) - Sample from nthsig with random x
  • probkit.sampling.sample_biased_curve(k, a, b) - Sample from biased_curve with random x

Utilities

  • clamp(val, min_val, max_val) - Constrain value to range
  • transform_range(x, old_range, new_range) - Linear transformation between ranges
  • effective_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

probkit-0.1.dev5.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

probkit-0.1.dev5-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file probkit-0.1.dev5.tar.gz.

File metadata

  • Download URL: probkit-0.1.dev5.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for probkit-0.1.dev5.tar.gz
Algorithm Hash digest
SHA256 4b91b0d0f7878d502d3b2aed9a4508f8996cdf08b91ca3c6db2b2a54fde46bfc
MD5 853f866f95b1c60613327b7ed43807bf
BLAKE2b-256 e06baccd87fd5b2c2df8142da65e2b3cf2eb475fe91096515977eb9f57684421

See more details on using hashes here.

File details

Details for the file probkit-0.1.dev5-py3-none-any.whl.

File metadata

  • Download URL: probkit-0.1.dev5-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for probkit-0.1.dev5-py3-none-any.whl
Algorithm Hash digest
SHA256 092bfd1d39c06cdcb31187411b3cd443128c307184e4b2024f78f4393b74ee40
MD5 e7d94bc158332fff0f88eb4910c34dcc
BLAKE2b-256 e0edff954812b34a30872b3389e7eef9cc540d14becf7e999fcb0bea95c73d1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page