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 |
|---|---|---|
|
|
Real numeric data, shape |
|
|
|
|
|
Target fraction missing, clipped to |
|
|
Random seed |
|
|
Missingness pattern |
Unknown mechanism- or pattern-specific keyword arguments raise TypeError, so
misspelled configuration names cannot be silently ignored. Numerical
configuration values must be finite, and infinite input values are rejected.
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 |
|
MAR |
|
Allow target/driver overlap for explicit hybrid behavior |
|
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. See the feasibility constraint below. |
gilbert_elliott supports only mechanism="mcar". missing_rate=0 adds no
artificial missingness and missing_rate=1 masks all eligible entries. Partial
rates must satisfy good_loss <= missing_rate <= good_loss + (bad_loss - good_loss) / (2 - persist). Rates outside this persistence-aware feasible
range raise ValueError.
For the Markov pattern, partial missing rates must satisfy
missing_rate <= 1 / (2 - persist). Infeasible combinations raise
ValueError; missing_rate=1.0 remains an explicit all-missing special case.
For pointwise, MAR and MNAR dependencies apply to the final individual masked
positions. For temporal patterns such as block, decay, markov, and
monotone, MAR/MNAR generate a mechanism-informed missingness budget that is
then reshaped in time by the selected pattern.
The monotone pattern applies its allocated budget to the final eligible timestamps in each series. Pre-existing NaNs remain missing but do not consume the artificial missingness budget or define the artificial dropout point.
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.