Skip to main content

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

Package

This package is hosted on PyPI and as such can be installed with most popular package managers. For example, to install this package using pip simply use the command:

pip install statax

Development

This project uses uv for package management. Therefore, if you would like to contribute to this project please use uv to track any changes to the project's dependencies.

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


Download files

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

Source Distribution

statax-0.3.2.tar.gz (58.7 kB view details)

Uploaded Source

Built Distribution

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

statax-0.3.2-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file statax-0.3.2.tar.gz.

File metadata

  • Download URL: statax-0.3.2.tar.gz
  • Upload date:
  • Size: 58.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.14

File hashes

Hashes for statax-0.3.2.tar.gz
Algorithm Hash digest
SHA256 8b6bf2992dfb8b437ee02829ccc66f56ef79e651ab297ac1bf95ec151907df91
MD5 1241f205615eae909dea8e0c10786a06
BLAKE2b-256 528f29f3acf6c372b2bd54fee72a736e4f34f4cd5af96d7ceadf2ece6dd2fbd6

See more details on using hashes here.

File details

Details for the file statax-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: statax-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.14

File hashes

Hashes for statax-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1a9ca394395f990a835517994e890c2bb1646b259ac9c71ec2cf39fb02cb42f4
MD5 5127d30afa9a83a1f4a9ae06d198b990
BLAKE2b-256 0a07236ce724402f00bc1aa913988f3f4cf87d645843f774e125089272d228ff

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