mixle.stats.combinator.schema module¶
Typed structured schema – named, type-validated fields over a CompositeDistribution.
mixle’s identity is composable models of heterogeneous data; CompositeDistribution already models a
product of differently-typed fields, but only positionally (a bare tuple, no names, no validation). A
Schema puts a typed record front-end on it: declare {name: (type, distribution)}, score/sample
with ordinary dicts, and have observations validated against their declared types before they reach the
model. The field types reuse the same friendly specs as SelectDistribution.by_type (‘str’, ‘int’,
‘float’, ‘number’, …), numpy-scalar aware.
- class Field(name, type_spec, dist)[source]
Bases:
objectOne schema field: a name, the type(s) its value must be, and the distribution that models it.
- name: str
- type_spec: Any
- dist: Any
- class Schema(fields)[source]
Bases:
objectAn ordered set of named, typed fields backed by a
CompositeDistribution.- Parameters:
fields (list[Field])
- classmethod from_fields(specs)[source]
Build from
[(name, type_spec, distribution), ...].
- validate(record)[source]
Raise if
recordis missing/has extra fields or a value’s type violates its declaration.
- to_tuple(record)[source]
Validate
recordand order its values into the composite’s positional tuple.
- log_density(record)[source]
Validated, named log-density: delegates to the backing composite after the type check.
- sample(seed=None, size=None)[source]
Draw record dict(s) from the model.
- marginal(names)[source]
The sub-schema over a subset of fields (a marginal of the joint, in the given order).