mixle.stats.compute.torch_mixture module¶
Compatibility wrapper for Torch-backed local model evaluation.
Historically this module contained one Torch implementation class per
distribution family. That made Torch support an omni-file and duplicated the
math already owned by the distributions. The remaining TorchMixture class
is a small adapter over the modular compute-engine stack:
data are encoded with the model’s normal
dist_to_encoderprotocol;scoring and accumulation dispatch through
dist.kernel(engine=...)when a Torch kernel is available;unsupported object-valued models fall back to the legacy
seq_*protocol as fixed, CPU-scored compatibility paths;gradient fitting delegates to the declaration/objective-based generic optimizers in
mixle.inference.estimation.
- class TorchMixture(model, device='cpu', dtype=None)[source]
Bases:
objectThin compatibility adapter over
ComputeEnginekernels.New code should prefer
dist.kernel(engine=TorchEngine(...)),optimize(..., engine=...),fit_mle/fit_map, ormixle.inference.objectivesdirectly. This class exists so older code and compatibility tests importingmixle.stats.compute.torch_mixture.TorchMixturekeep working while distribution math remains distribution-owned.- Parameters:
model (SequenceEncodableProbabilityDistribution)
device (str)
dtype (Any)
- encode(data)[source]
Encode observations using the model’s canonical sequence encoder.
- seq_component_log_density(enc, model=None)[source]
Return component log-density matrix as a NumPy array.
- seq_log_density(enc, model=None)[source]
Return per-row model log densities as a NumPy array.
- posteriors(enc, model=None)[source]
Return posterior component weights as a Torch tensor.
- weighted_suff_stats(enc, gamma, model=None)[source]
Return legacy-format sufficient statistics for posterior weights.
- em_step(enc, estimator, model=None, weights=None)[source]
Run one EM M-step using modular kernels when possible.
- initialize(enc, estimator, rng, p=0.1)[source]
Initialize through the standard sequence-initialization protocol.
- fit(enc, estimator, max_its=100, delta=1.0e-8, rng=None, init_p=0.1, model=None, out=None)[source]
Run local EM to convergence and return
(model, log_likelihood).
- fit_mle(enc, model=None, max_its=500, lr=0.05, optimizer='adam', tol=1.0e-7, out=None, print_iter=100, return_result=False)[source]
Delegate gradient MLE to the generic declaration-backed fitter.
- fit_map(enc, model=None, priors=None, prior_strength=1.0, w_alpha=None, max_its=500, lr=0.05, optimizer='adam', tol=1.0e-7, out=None, print_iter=100, return_result=False)[source]
Delegate MAP fitting to the generic objective/declaration path.
priorsandw_alphaare accepted for source compatibility; rich conjugate priors now belong in distribution/objective declarations rather than this compatibility shim.