Metadata-Version: 2.4
Name: truncated-gamma-rvs
Version: 0.1.2
Summary: A Python package for generating random variates from a truncated gamma distribution.
Author-email: "Wade K. Copeland" <wade@kingcopeland.com>
License-Expression: MIT
Project-URL: Homepage, https://www.kingcopeland.com/truncated-gamma-rvs-py/
Project-URL: Repository, https://github.com/wkingc/truncated-gamma-rvs-py-package
Project-URL: Issues, https://github.com/wkingc/truncated-gamma-rvs-py-package/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: scipy
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: isort; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Dynamic: license-file

# truncated-gamma

[![](https://github.com/wkingc/truncated-gamma-rvs-py-package/actions/workflows/python-package.yml/badge.svg)](https://github.com/wkingc/truncated-gamma-rvs-py-package/actions/workflows/python-package.yml)

[![](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)

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

## Installation

```bash
pip install truncated-gamma-rvs
```

## Quick Start

```python
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

```bash
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](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:

```bibtex
@software{copeland2026tgammarvs,
  author = {Wade K. Copeland},
  title = {{truncated-gamma-rvs: A Python package for truncated gamma distributions}},
  url = {https://pypi.org/project/truncated-gamma-rvs/},
  version = {0.1.2},
  year = {2026}
}
```
