API Reference
Installation | Core concepts | Mechanisms | Patterns | Mathematical details | Benchmarking workflow | API reference
simulate_missingness
simulate_missingness(
X,
mechanism,
missing_rate,
seed=None,
pattern="pointwise",
**kwargs,
)
Simulate missingness in a 2D (time, features) or 3D
(samples, time, features) NumPy array.
Returns:
X_missing, mask
where X_missing is a copy of X with NaNs inserted and mask is a boolean
array with True for observed values and False for missing values.
Core parameters:
Parameter |
Type |
Description |
|---|---|---|
|
|
Input data, shape |
|
|
|
|
|
Target fraction missing, clipped to |
|
|
Random seed |
|
|
Missingness pattern |
Mechanism parameters:
Parameter |
Mechanisms |
Default |
Description |
|---|---|---|---|
|
all |
|
Dimensions to mask |
|
MAR |
|
Driver dimensions |
|
MAR |
|
Per-driver weights |
|
MAR, MNAR |
|
Dependency strength |
|
MAR |
|
Minimum probability floor |
|
MAR |
|
Driver direction |
|
MNAR |
|
MNAR scoring mode |
Pattern parameters:
Parameter |
Patterns |
Default |
Description |
|---|---|---|---|
|
block |
|
Block length in timesteps |
|
block |
|
Relative block length as a fraction of the time axis, or |
|
block |
|
Fraction of missingness in blocks. Set below |
|
decay |
|
Decay ramp steepness |
|
decay |
|
Normalized ramp center |
|
markov, gilbert_elliott |
|
Missing/bad-state persistence. For |
|
gilbert_elliott |
|
Loss probability in the bad state. MCAR only. |
|
gilbert_elliott |
|
Loss probability in the good state. MCAR only. For partial rates, |
gilbert_elliott supports only mechanism="mcar". missing_rate=0 adds no
artificial missingness and missing_rate=1 masks all eligible entries. Partial
rates outside the feasible range defined by good_loss and bad_loss raise
ValueError.
simulate_many_rates
from tsgap import simulate_many_rates
rates = [0.05, 0.15, 0.25]
results = simulate_many_rates(X, "mcar", rates, seed=42)
Returns a dictionary mapping each rate to (X_missing, mask). When a seed is
provided, each rate gets a deterministic offset from the base seed.
MissingnessSimulator
from tsgap import MissingnessSimulator
sim = MissingnessSimulator(
"mar", missing_rate=0.25, seed=42,
driver_dims=[0], pattern="block", block_len=10
)
X_missing, mask = sim.generate(X)
This object-oriented wrapper is useful when the same missingness configuration is applied to multiple arrays.
Registries
from tsgap import MECHANISMS, PATTERNS
print(MECHANISMS.keys())
print(PATTERNS.keys())
The registries expose the currently available mechanism and pattern names, including aliases.