mixle.stats.sequences._keyed_accumulator module

Shared key-merge plumbing for the (init, trans) two-key Markov-transform accumulators.

Both MarkovTransformAccumulator (dense, 3-set) and SparseMarkovAssociationAccumulator (sparse, 2-set) hold two independently keyed sufficient statistics – an init_count vector and a trans_count (sparse) matrix – plus a delegated size/length accumulator. The single-key default on StatisticAccumulator (keyed on self.keys) does not fit this two-key shape, so the pooling logic below is shared here rather than re-implemented in each module.

The E-step itself (responsibility scatter, _track_ll log-density byproduct) is not shared: the dense and sparse paths differ in row-weight construction (outer product vs broadcast), init-term smoothing, normalization denominator, sparse-matrix type, and scatter mechanism, and the sparse model carries an extra low-memory bincount encoding with no dense analogue. Only the genuinely identical key plumbing is collapsed.

class InitTransKeyedAccumulator[source]

Bases: object

Mixin providing key_merge/key_replace for an (init_key, trans_key) accumulator.

Expects the host accumulator to define init_key, trans_key, init_count, trans_count, and size_accumulator. size_accumulator may be None (the dense model) or a real accumulator/NullAccumulator (the sparse model); the is not None guard handles both, since NullAccumulator.key_merge/key_replace are no-ops.

key_merge(stats_dict)[source]

Merge the keyed init_count and trans_count into stats_dict, then the size acc.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

key_replace(stats_dict)[source]

Replace init_count and trans_count from stats_dict, then the size acc.

Parameters:

stats_dict (dict[str, Any])

Return type:

None