mixle.stats.compute.stacked module¶
Stacked mixture kernels built from distribution-owned backend math.
- class StackedComponentParams(component_type, strategy, params)[source]
Bases:
objectA generic route for homogeneous component scoring.
- strategy: str
- params: Any
- class StackedEstimatorView(estimators)[source]
Bases:
objectMinimal estimator view for component-stacked resident reductions.
- class StackedMixtureResidentStats(component_counts, component_stats, engine, component_type)[source]
Bases:
objectEngine-resident sufficient statistics for a homogeneous mixture.
- Parameters:
- component_counts: Any
- component_stats: Any
- engine: ComputeEngine
- value()[source]
Return sufficient statistics in the legacy
MixtureEstimatorformat.- Return type:
- local_value()[source]
Return this rank’s component-stat payload in the legacy local-slice format.
DTensor-backed model-parallel runs should run component M-steps on the local component shard and all-reduce only scalar mixture-weight totals. This method therefore prefers DTensor
to_local()chunks overfull_tensor()and returns(component_start, (counts, stats)). Non-sharded engines naturally return the full component range starting at zero.
- estimate(estimator)[source]
Estimate a distribution after converting to the legacy estimator protocol.
- Parameters:
estimator (ParameterEstimator)
- Return type:
- estimate_component_shard(estimator, total_count=None)[source]
Run the component-local part of a mixture M-step for this shard.
Component distributions are independent given posterior sufficient statistics. Mixture weights only need the scalar global total count (or fixed weights), so a model-parallel orchestrator can call this on each shard after an all-reduce of that scalar instead of gathering all component statistics to the driver.
- Parameters:
estimator (ParameterEstimator)
total_count (float | None)
- Return type:
StackedMixtureShardEstimate
- class StackedMixtureShardEstimate(component_start, component_stop, components, weights, total_count)[source]
Bases:
objectComponent-local M-step result for a homogeneous mixture shard.
- Parameters:
- component_start: int
- component_stop: int
- weights: ndarray
- total_count: float
- estimate_component_shard_value(estimator, component_start, value, total_count=None)[source]
Estimate the component-local part of a mixture M-step from an explicit shard value.
- tie_component_shard_values(estimator, shard_values)[source]
Apply mixle key tying to component-sharded mixture statistics.
MixtureAccumulator.key_merge/key_replaceassume a full component vector is materialized on one worker. Component-sharded model-parallel runs instead hold ranges[component_start, component_stop). This helper applies the same key protocol to those local ranges by materializing only the component accumulators owned by each shard.
- stacked_component_params(dists, engine)[source]
Return a generic stacked-scoring route for homogeneous components.
Generated declaration-backed routes are attempted first. Families with object lookups, table layouts, derived parameters, or wrapper structure can keep explicit
backend_stacked_*hooks and still compose through this single dispatcher.
- stacked_component_log_density(enc, route, engine)[source]
Evaluate a route returned by
stacked_component_params.
- stacked_component_sufficient_statistics(enc, weights, route, engine, estimator=None)[source]
Return component-stacked legacy sufficient statistics for a stacked route.
- unstack_component_stats(value, num_components)[source]
Return per-component legacy statistics from a component-stacked payload.
- class StackedMixtureKernel(dist, engine, estimator=None)[source]
Bases:
KernelHomogeneous mixture kernel with stacked component parameters.
The mixture mechanics live here: component matrix scoring, row-wise logsumexp, posterior weights, and legacy sufficient-stat dispatch. The leaf family still owns the actual component log-density math through
backend_stacked_paramsandbackend_stacked_log_density.- Parameters:
dist (Any)
engine (ComputeEngine)
estimator (ParameterEstimator | None)
- encode(data)[source]
Encode raw observations with the mixture’s ordinary encoder.
- component_scores(enc)[source]
Return unweighted component log densities with shape
(n, k).
- score(enc)[source]
Return row log densities after adding mixture log weights.
- posteriors(enc)[source]
Return posterior component weights for each encoded row.
- property has_resident_accumulate: bool
Return true when the leaf family can accumulate sufficient stats on the engine.
- resident_accumulate(enc, weights)[source]
Return engine-resident mixture sufficient statistics.
The mixture owns only the posterior mechanics. Leaf families own the sufficient-statistic algebra through
backend_stacked_sufficient_statistics.
- accumulate(enc, weights)[source]
Return mixture sufficient statistics in the legacy estimator format.
- refresh(dist)[source]
Refresh stacked parameters after an M-step without changing structure.
- Parameters:
dist (SequenceEncodableProbabilityDistribution)
- Return type:
None
- stacked_component_strategy(dist_type)[source]
Describe how homogeneous mixture component scoring will be dispatched.
- class StackedMixtureKernelFactory(fallback=None)[source]
Bases:
KernelFactoryFactory for homogeneous mixtures with distribution-owned stacked math.
- Parameters:
fallback (KernelFactory | None)
- build(dist, engine, estimator=None)[source]
Build a stacked mixture kernel when safe, otherwise use fallback.
- Parameters:
dist (SequenceEncodableProbabilityDistribution)
engine (ComputeEngine)
estimator (ParameterEstimator | None)
- Return type:
Kernel