mixle.stats.combinator.record module¶
Named-record distributions for dict/DataFrame observations.
RecordDistribution is a product distribution like CompositeDistribution,
but its children are addressed by field name instead of tuple position. It is
small on purpose: named observations reuse the same distribution, estimator,
accumulator, encoder, kernel, and engine protocols as the rest of
mixle.stats.
- DictRecordAccumulator
alias of
RecordAccumulator
- DictRecordAccumulatorFactory
alias of
RecordAccumulatorFactory
- DictRecordDataEncoder
alias of
RecordDataEncoder
- DictRecordDistribution
alias of
RecordDistribution
- DictRecordEstimator
alias of
RecordEstimator
- DictRecordSampler
alias of
RecordSampler
- class RecordAccumulator(fields, accumulators)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate field-wise sufficient statistics for record data.
- Parameters:
fields (Sequence[Any])
accumulators (Sequence[SequenceEncodableStatisticAccumulator])
- update(x, weight, estimate)[source]
Accumulate one weighted mapping record.
- initialize(x, weight, rng)[source]
Randomly initialize child accumulators from one mapping record.
- Parameters:
weight (float)
rng (RandomState)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Accumulate encoded records with per-row weights.
- seq_initialize(x, weights, rng)[source]
Randomly initialize child accumulators from encoded records.
- Parameters:
weights (ndarray)
rng (RandomState)
- Return type:
None
- get_seq_lambda()[source]
Return child sequence update callables for legacy orchestration.
- combine(suff_stat)[source]
Merge field-wise sufficient statistics into this accumulator.
- value()[source]
Return field-wise sufficient-statistic payloads in estimator order.
- from_value(x)[source]
Restore child accumulators from a field-wise payload.
- scale(c)[source]
Scale each field accumulator using its family-specific protocol.
- Parameters:
c (float)
- Return type:
RecordAccumulator
- key_merge(stats_dict)[source]
Merge keyed child statistics into the shared stats dictionary.
- key_replace(stats_dict)[source]
Replace keyed child statistics from the shared stats dictionary.
- acc_to_encoder()[source]
Return a record encoder composed from child accumulator encoders.
- Return type:
RecordDataEncoder
- class RecordAccumulatorFactory(fields, factories)[source]
Bases:
StatisticAccumulatorFactoryFactory that creates record accumulators with matching child factories.
- Parameters:
fields (Sequence[Any])
factories (Sequence[StatisticAccumulatorFactory])
- make()[source]
Create a fresh record accumulator.
- Return type:
RecordAccumulator
- class RecordDataEncoder(fields, encoders)[source]
Bases:
DataSequenceEncoderEncode a sequence of mapping records field-by-field.
- Parameters:
fields (Sequence[Any])
encoders (Sequence[DataSequenceEncoder])
- class RecordDistribution(fields, dists=None)[source]
Bases:
SequenceEncodableProbabilityDistributionProduct distribution over mapping records with a fixed field set.
- Parameters:
fields (Any)
dists (Sequence[SequenceEncodableProbabilityDistribution] | None)
- compute_capabilities()[source]
Return engine support inherited from all child distributions.
- compute_declaration()[source]
Return a child-role declaration for generated metadata consumers.
- density(x)[source]
Return probability density/mass for one mapping record.
- log_density(x)[source]
Return summed child log densities for one mapping record.
- seq_log_density(x)[source]
Return per-row log densities for encoded record fields.
- backend_seq_log_density(x, engine)[source]
Return per-row log densities using backend-aware child scorers.
- classmethod backend_stacked_params(dists, engine)[source]
Return stacked child parameters for homogeneous named-record mixtures.
- classmethod backend_stacked_log_density(x, params, engine)[source]
Return an
(n, k)matrix of record log densities.
- classmethod backend_stacked_sufficient_statistics_with_estimator(x, weights, params, engine, estimator)[source]
Return per-component legacy named-record sufficient statistics.
- gradient_fit_state(engine, torch, leaves, recurse, tensor_param)[source]
Return distribution-owned state for autograd fitting.
- seq_ld_lambda()[source]
Return legacy sequence log-density callables for this distribution.
- support_size()[source]
Product of field support sizes (
Noneif any field is infinite).- Return type:
int | None
- sampler(seed=None)[source]
Return a sampler that draws mapping records field-by-field.
- Parameters:
seed (int | None)
- Return type:
RecordSampler
- estimator(pseudo_count=None)[source]
Return a record estimator with child estimators from each field.
- Parameters:
pseudo_count (float | None)
- Return type:
RecordEstimator
- decomposition()[source]
Record fields are independent: split along the field (factor) axis, sufficient stats SUM-reduce.
- dist_to_encoder()[source]
Return a data encoder for this record field/source layout.
- Return type:
RecordDataEncoder
- enumerator()[source]
Creates RecordEnumerator iterating mapping records in descending joint probability order.
- Return type:
RecordEnumerator
- conditional_enumerator(given)[source]
Enumerate complete records consistent with the fixed fields in
given.givenis a mapping{source: value}pinning a subset of fields (the canonical most-probable-completion / imputation query: complete missing fields, best first). Because the fields are independent,P(record | given)is proportional to the jointP(record), so descending order over the free fields is also descending conditional order. Each yielded value is a complete record with the fixed fields merged back in, and itslog_probis the full jointlog_density(the enumerator contract:lp == dist.log_density(value)) – the fixed fields enter as a constant offset, which only shifts every score by the same amount.Raises ValueError if
givennames a field this record does not have.
- structural_fine_bucket(value, quantizer)[source]
Sum of child structural buckets – mirrors the count index’s child convolution.
Like
CompositeDistribution.structural_fine_bucket(), but fields are addressed by source name rather than tuple position.- Return type:
- quantized_count_index(quantizer, max_fine_bucket)[source]
Structural count index: the additive law – the carrier’s n-ary product over fields.
Identical reduction to
CompositeDistribution.quantized_count_index()(the joint histogram is the convolution of the per-field histograms in the witness-retaining count semiring); the only difference is that the unranked structural tuple is relabelled into a mapping record keyed by source, so witnesses match what the model actually scores.- Parameters:
max_fine_bucket (int)
- class RecordEstimator(fields, estimators=None)[source]
Bases:
ParameterEstimatorEstimator for independent named fields.
- Parameters:
fields (Any)
estimators (Sequence[ParameterEstimator] | None)
- accumulator_factory()[source]
Return a factory for record sufficient-statistic accumulators.
- Return type:
RecordAccumulatorFactory
- class RecordSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw mapping records from a
RecordDistribution.- Parameters:
dist (RecordDistribution)
seed (int | None)
- field(name, source=None)[source]
Declare a named model field and the input key/column it reads.
field('x')reads input key'x'and names the model field'x'.field('x_copy', source='x')names a second model variable that reads the same input key, useful for dependence features and repeated views.
- record(fields)[source]
Create a
RecordDistributionfrom a field-to-distribution mapping.