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 the key_merge/key_replace pooling for the common case where value() 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: SequenceEncodableStatisticAccumulator

Delegate 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 assume value() is the bare child value; combinators whose value() 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

value()[source]

Return this accumulator’s serialized sufficient statistics.

Return type:

Any

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_dict under its merge key.

The structural default implements the common single-key pattern: store the accumulator under self.keys the first time the key is seen, else combine into 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. A keys of None (the default) is a no-op.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

key_replace(stats_dict)[source]

Replace this accumulator’s statistics from the pooled stats_dict entry (see key_merge).

Parameters:

stats_dict (dict[str, Any])

Return type:

None

class MaskedBaseEncoder(base_encoder)[source]

Bases: DataSequenceEncoder

Encode 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)

seq_encode(x)[source]

Encode the iid observation sequence x for vectorized evaluation.

Parameters:

x (Sequence[Any])

Return type:

tuple[Any, …]