mixle.data.structure module¶
Sample structure – the exchangeability tag carried by every DataSource.
seq_encode(data, num_chunks=C) partitions a dataset by striding – chunk i is data[i::C] –
which silently reorders observations. That is correct only when the records are exchangeable. This module
makes the intended joint structure explicit so partitioning is justified rather than assumed, and so a
model can be checked against the data it is handed:
IID– independent & identically distributed records.EXCHANGEABLE– the joint law is permutation-invariant (de Finetti): order is irrelevantbut latent coupling is allowed (mixtures, Dirichlet-process models, …).
PARTIALLY_EXCHANGEABLE(by) – exchangeable within groups keyed byby(hierarchical /grouped / panel data): groups must stay intact on a partition.
SEQUENTIAL– each record is a whole ordered sequence (HMM / Markov / Hawkes / AR); therecords are mutually exchangeable, so they may be strided, but a record is never split internally (the encoder owns the within-record order).
The first three (and SEQUENTIAL, whose records are atomic) may stride records freely; only
PARTIALLY_EXCHANGEABLE constrains partitioning – groups are distributed whole. The default for an
un-annotated dataset is EXCHANGEABLE, which is exactly today’s striding behavior, so nothing changes
until a user opts in by tagging a source.
- class SampleStructure(kind, by=None)[source]
Bases:
objectThe joint structure of a dataset’s records (an exchangeability class).
- kind: str
- property strides_records: bool
True if records may be strided/shuffled across partitions (everything but grouped data).
- partially_exchangeable(by)[source]
Return a
PARTIALLY_EXCHANGEABLEstructure grouped by field name or key functionby.
- supported_structures(model)[source]
Return the
SampleStructurekinds a model/estimator can consume (by capability + name).
- check_model_structure(model, structure, *, strict=False)[source]
Warn (or, if
strict, raise) when a model cannot consume a source’s sample structure.Catches the silent footgun: a source tagged
SEQUENTIALhanded to an i.i.d. leaf (“did you mean an HMM?”), or grouped data handed to a model that ignores groups. A no-op when compatible.