Skip to main content

A Python package for generating random variates from a truncated gamma distribution.

Project description

truncated-gamma-rvs

A Python package for generating random variates from a truncated gamma distribution.

Installation

pip install truncated-gamma-rvs

Quick Start

from truncated_gamma_rvs import truncgamma_rvs

# Generate 100,000 random variates from a gamma distribution truncated 
# to the interval [0, 1000], where the mean is 100 and the standard 
# deviation is 1/2 the value of the mean (e.g., the coefficient of variation).
x = truncgamma_rvs(
    mean_target = 100, 
    cv_target = 1/2, 
    A = 0, 
    B = 1000, 
    size = 100000, 
    random_state = 123)

What is a Truncated Gamma Distribution?

A truncated gamma distribution is a gamma distribution that has been "cut off" at specified lower (A) and upper (B) bounds. This is useful when you need gamma-distributed random variables that must fall within a specific range.

API Reference

truncgamma_rvs(mean_target, cv_target, A, B, size=1, random_state=None)

Generate random variates from a truncated gamma distribution.

Parameters:

  • mean_target (float): Target mean of the truncated distribution
  • cv_target (float): Target coefficient of variation
  • A (float): Lower bound (≥ 0)
  • B (float): Upper bound (> A)
  • size (int, optional): Number of samples to generate (default: 1)
  • random_state (int, optional): Random seed for reproducibility

Returns:

  • numpy.ndarray: Array of random samples

TruncatedGamma(alpha, theta, A, B)

Class for working with truncated gamma distributions.

Parameters:

  • alpha (float): Shape parameter (> 0)
  • theta (float): Scale parameter (> 0)
  • A (float): Lower bound (≥ 0)
  • B (float): Upper bound (> A)

Methods:

  • truncgamma_m1(): Calculate the first moment (mean)
  • truncgamma_m2(): Calculate the second moment
  • truncgamma_var(): Calculate the variance
  • truncgamma_cv(): Calculate the coefficient of variation

Requirements

  • Python ≥ 3.9
  • numpy
  • scipy

Development

git clone https://github.com/wkingc/truncated-gamma-rvs-py-package.git
cd truncated-gamma-rvs-py-package
pip install -e ".[dev]"
python -m pytest

License

MIT License. See LICENSE for details.

Documentation

For a complete usage guide, see https://www.kingcopeland.com/truncated-gamma-rvs-py/.

Citation

If you use this package in your research, please consider citing it:

@software{copeland2026tgammarvs,
    author = {Wade K. Copeland},
    title = {{truncated-gamma-rvs: A Python package for generating random variates from a truncated gamma distribution}},
    url = {https://pypi.org/project/truncated-gamma-rvs/},
    version = {0.1.5},
    year = {2026}
}

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

truncated_gamma_rvs-0.1.5.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

truncated_gamma_rvs-0.1.5-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file truncated_gamma_rvs-0.1.5.tar.gz.

File metadata

  • Download URL: truncated_gamma_rvs-0.1.5.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for truncated_gamma_rvs-0.1.5.tar.gz
Algorithm Hash digest
SHA256 907944bb0aadfa5499534a693aa0c9d0749d2fcc4efd22db02367c3112d7e156
MD5 eb4b8a77da2caf20342c862340c52ecd
BLAKE2b-256 5a78796bd1a8eb9c56234c0196e8ea28cd91fe2547a3fe5c63ea9c40085f11c4

See more details on using hashes here.

File details

Details for the file truncated_gamma_rvs-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for truncated_gamma_rvs-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f0eb9e3b4c4754d0842ec82dd01203db5b4fbad6f057d33cc9d8ed7f2e598414
MD5 d03f89d9395b3aa8a6043c834d1b4907
BLAKE2b-256 5cba46e7c5bd5a77b7fb039667f85371502e59a4cb31cee764934f4d45e12f9b

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