A statistical computing library implemented in JAX.
Project description
Statax
Statax is a JAX-based library for statistical computations, providing efficient and GPU-accelerated implementations of common statistical methods. The library leverages JAX's automatic differentiation, vectorization, and just-in-time compilation capabilities to deliver high-performance statistical functions.
Features
Currently, Statax focuses on bootstrap methods for confidence interval estimation:
- Multiple Bootstrap Methods:
- Basic Bootstrap
- Percentile Bootstrap
- Bias-Corrected (BC) Bootstrap
- Bias-Corrected and Accelerated (BCa) Bootstrap
- T Bootstrap
- Standard Bootstrap
[!TIP] For a detailed breakdown of the mathematics and assumptions behind these methods check out this article.
- JAX Integration:
- Fully compatible with JAX arrays and transformations
- Leverages JAX's JIT compilation for performance
- Supports GPU acceleration
Although, there is certainly scope for this project to expand in the future.
Installation
Development
This project uses uv for package management.
git clone https://github.com/jack-norrie/statax.git
cd statax
uv sync
Requirements
- Python 3.11+
- JAX (with optional CUDA support)
Quick Start
Basic Bootstrap Example
import jax
import jax.numpy as jnp
from jax import random
from statax.bootstrap import PercentileBootstrapper
# Generate some data
key = random.key(42)
data = random.normal(key, shape=(100,))
# Define a statistic function
def mean_statistic(x):
return jnp.mean(x)
# Create a bootstrapper
bootstrapper = PercentileBootstrapper(mean_statistic)
# Generate bootstrap replicates
bootstrapper.resample(data=data, n_resamples=2000, key=random.key(0))
# Calculate confidence interval
ci_low, ci_high = bootstrapper.ci(confidence_level=0.95)
print(f"95% CI: ({ci_low:.4f}, {ci_high:.4f})")
Comparing Different Bootstrap Methods
import jax
import jax.numpy as jnp
from jax import random
import matplotlib.pyplot as plt
from statax.bootstrap import (
BasicBootstrapper,
PercentileBootstrapper,
BCBootstrapper,
BCaBootstrapper,
TBootstrapper,
StandardBootstrapper,
)
# Generate skewed data
key = random.key(42)
data = jnp.exp(random.normal(key, shape=(100,)))
# Define statistic
def median_statistic(x):
return jnp.median(x)
# Compare different bootstrap methods
bootstrappers = {
"Basic": BasicBootstrapper(median_statistic),
"Percentile": PercentileBootstrapper(median_statistic),
"BC": BCBootstrapper(median_statistic),
"BCa": BCaBootstrapper(median_statistic),
"T": TBootstrapper(median_statistic),
"Standard": StandardBootstrapper(median_statistic),
}
results = {}
for name, bootstrapper in bootstrappers.items():
bootstrapper.resample(data=data, n_resamples=2000, key=random.key(0))
ci_low, ci_high = bootstrapper.ci(confidence_level=0.95)
results[name] = (ci_low, ci_high)
print(f"{name} Bootstrap 95% CI: ({ci_low:.4f}, {ci_high:.4f})")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the terms of the MIT license.
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 statax-0.3.0.tar.gz.
File metadata
- Download URL: statax-0.3.0.tar.gz
- Upload date:
- Size: 58.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a23f8ed72e218f4b1b936361b25d2975bd89e0bc413b17b023288befb6c3012
|
|
| MD5 |
e5857667f5e2c7c61f5e6cf3e11daaac
|
|
| BLAKE2b-256 |
d40a9ebe5252410469cdbbc2901ec80b26a488e60b47c3620dcbdc65c508ac07
|
File details
Details for the file statax-0.3.0-py3-none-any.whl.
File metadata
- Download URL: statax-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
427d36ec467978228b1a4ceda5ef82df773452e3e0dad6438385260d61452577
|
|
| MD5 |
43cc4e3dda53dad5b9d3eed9e21082d8
|
|
| BLAKE2b-256 |
66e0d33401b2ed4d0aeb79b797ce62c72806d62ecd31f468e72c1e3970921919
|