Skip to main content

Composable time-series missingness simulation for imputation benchmarking

Project description

TSGap

A Python library for simulating realistic missingness in time-series data for imputation benchmarking.

TSGap separates mechanisms (why data is missing: MCAR, MAR, MNAR) from patterns (how data is missing: pointwise, block, monotone, decay, markov). Any mechanism can be combined with any pattern, making it easy to create controlled missing-data scenarios for evaluating imputation methods.

Complete data (left) vs. five mechanism+pattern combinations at 20% missing rate.

Features

  • MCAR, MAR, and MNAR missingness mechanisms
  • Pointwise, block, monotone, temporal decay, and Markov-chain patterns
  • 2D (time, features) and 3D (samples, time, features) arrays
  • Exact or calibrated missing-rate control
  • Weighted multi-driver MAR
  • Reproducible masks with NumPy random seeds
  • Existing NaNs and target dimensions preserved across patterns

Installation

pip install tsgap

For development:

git clone https://github.com/feruzoripov/tsgap.git
cd tsgap
pip install -e ".[dev]"

Requires Python 3.9 or newer and NumPy 1.19 or newer.

Quick Start

import numpy as np
from tsgap import simulate_missingness

X = np.random.default_rng(42).standard_normal((1000, 6))

# MCAR: 15% scattered missing values
X_miss, mask = simulate_missingness(X, "mcar", 0.15, seed=42)

# MAR: missingness driven by dimension 0 and arranged in blocks
X_miss, mask = simulate_missingness(
    X, "mar", 0.25, seed=42,
    pattern="block", driver_dims=[0], block_len=10
)

# MNAR: extreme values missing with monotone dropout
X_miss, mask = simulate_missingness(
    X, "mnar", 0.20, seed=42,
    pattern="monotone", mnar_mode="extreme"
)

print(f"Actual missing rate: {(~mask).mean():.4f}")

The returned mask uses:

mask == True  -> observed
mask == False -> missing

Documentation

Example Use Cases

  • Random telemetry loss in sensor networks
  • Activity-dependent dropout in wearable devices
  • Participant dropout in longitudinal or clinical studies
  • Gradual signal loss from sensor degradation
  • Intermittent connectivity failures with bursty missingness

Evaluation Workflow

import numpy as np
from tsgap import simulate_missingness

X = np.random.default_rng(42).standard_normal((1000, 6))
X_miss, mask = simulate_missingness(X, "mar", 0.20, seed=42, driver_dims=[0])

X_imputed = your_imputation_method(X_miss)
missing_idx = ~mask

rmse = np.sqrt(np.mean((X[missing_idx] - X_imputed[missing_idx]) ** 2))
mae = np.mean(np.abs(X[missing_idx] - X_imputed[missing_idx]))

See docs/benchmarking.md for a complete baseline workflow.

The repository also includes a runnable benchmark example:

python examples/benchmark_imputation.py

Testing

pytest tsgap/tests/ -v

Citation

@software{tsgap,
  author = {Oripov, Feruz and Korchagina, Kseniia and Bonsu, Enock Adu and Bilgin, Ali and Aras, Shravan},
  title = {TSGap: A Python Library for Composable Time-Series Missingness Simulation},
  year = {2026},
  url = {https://github.com/feruzoripov/tsgap}
}

License

MIT

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

tsgap-0.4.0.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

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

tsgap-0.4.0-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file tsgap-0.4.0.tar.gz.

File metadata

  • Download URL: tsgap-0.4.0.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for tsgap-0.4.0.tar.gz
Algorithm Hash digest
SHA256 573ea765e47a1451984aad711c7eec9f1dcc4be7cc00124a4965c4d6bffac478
MD5 47ebe510aa413d42ef3a8297c92254a5
BLAKE2b-256 b6e26bc97505c7cde60d4e84b903f98c9e0bbb543fa2417e2218537634c6ce32

See more details on using hashes here.

File details

Details for the file tsgap-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: tsgap-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for tsgap-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b3632a0b74568d622560b636bb64210d05336be020b01e93e94c4c035e33d38
MD5 cec85b5ce02bd7da44197d918c988f19
BLAKE2b-256 6115d35eabb11bd076eec9043b15ae5213a9249b149205dad4fa093d60291c7a

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