mixle.stats.combinator._base module¶
Shared bases for the single-child combinators (censoring/truncation/survival/tilt/…).
These combinators all wrap a single child distribution and are, mechanically, thin delegators: their accumulators forward sufficient-statistic bookkeeping to one child accumulator, and their data encoders forward to one child encoder plus a small per-row “mask”/statistic column. The two bases here factor out that boilerplate so each combinator only states what is genuinely its own.
SingleChildAccumulator(finding B7) owns the delegation trio (combine/value/from_value/scale) and thekey_merge/key_replacepooling for the common case wherevalue()is the bare child value. The child accumulator lives on the attribute named by_child_attr("base_accumulator"by default). Combinators that carry extra scalar sufficient statistics alongside the child value (hurdle, zero-inflated, tilt) override the statistic-bearing methods but still inherit the key-pooling delegation.MaskedBaseEncoder(finding B8) owns the identical__init__/__str__/__eq__of the per-combinator data encoders; each subclass overrides only_extra_columns(), the per-row extra column(s) appended to the base encoding.
- class SingleChildAccumulator[source]
Bases:
SequenceEncodableStatisticAccumulatorDelegate sufficient-statistic bookkeeping to a single child accumulator.
Subclasses set
_child_attr(the attribute name of the child accumulator) and implement the statistic-gathering methods (update/seq_update/initialize/seq_initialize/acc_to_encoder). The delegation trio and key-pooling below assumevalue()is the bare child value; combinators whosevalue()bundles extra scalars override the relevant methods.- combine(suff_stat)[source]
Merge serialized sufficient statistics into this accumulator.
- Parameters:
suff_stat (Any)
- Return type:
SingleChildAccumulator
- from_value(x)[source]
Restore this accumulator from serialized sufficient statistics.
- Parameters:
x (Any)
- Return type:
SingleChildAccumulator
- scale(c)[source]
Scale linear sufficient statistics in-place by
c.The structural default is correct for ordinary weighted sums, nested tuples/lists/dicts, and numeric arrays. Families whose
value()payload includes non-linear metadata such as support bounds must override this method and leave that metadata unscaled.- Parameters:
c (float)
- Return type:
SingleChildAccumulator
- key_merge(stats_dict)[source]
Pool this accumulator’s statistics into
stats_dictunder its merge key.The structural default implements the common single-key pattern: store the accumulator under
self.keysthe first time the key is seen, elsecombineinto the one already there. Accumulators with several named keys (e.g. an HMM’s init/trans/state keys) or a non-accumulator stats payload override this. AkeysofNone(the default) is a no-op.
- class MaskedBaseEncoder(base_encoder)[source]
Bases:
DataSequenceEncoderEncode observations via a child encoder plus per-row mask/statistic column(s).
Subclasses set the child encoder on
self.base_encoder(the default__init__accepts it directly) and override_extra_columns()to return the per-row extra column(s) appended to the base encoding.__str__/__eq__derive their label from the concrete class name.- Parameters:
base_encoder (DataSequenceEncoder)