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_encoder protocol;

  • 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: object

Thin compatibility adapter over ComputeEngine kernels.

New code should prefer dist.kernel(engine=TorchEngine(...)), optimize(..., engine=...), fit_mle / fit_map, or mixle.inference.objectives directly. This class exists so older code and compatibility tests importing mixle.stats.compute.torch_mixture.TorchMixture keep 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.

Parameters:

data (Any)

Return type:

tuple[int, Any]

seq_component_log_density(enc, model=None)[source]

Return component log-density matrix as a NumPy array.

Parameters:
Return type:

ndarray

seq_log_density(enc, model=None)[source]

Return per-row model log densities as a NumPy array.

Parameters:
Return type:

ndarray

posteriors(enc, model=None)[source]

Return posterior component weights as a Torch tensor.

Parameters:
Return type:

Any

weighted_suff_stats(enc, gamma, model=None)[source]

Return legacy-format sufficient statistics for posterior weights.

Parameters:
Return type:

Any

em_step(enc, estimator, model=None, weights=None)[source]

Run one EM M-step using modular kernels when possible.

Parameters:
  • enc (tuple[int, Any])

  • estimator (ParameterEstimator)

  • model (Any | None)

  • weights (Any | None)

Return type:

Any

initialize(enc, estimator, rng, p=0.1)[source]

Initialize through the standard sequence-initialization protocol.

Parameters:
Return type:

Any

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

Parameters:
Return type:

tuple[Any, float]

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.

Parameters:
Return type:

Any

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.

priors and w_alpha are accepted for source compatibility; rich conjugate priors now belong in distribution/objective declarations rather than this compatibility shim.

Parameters:
Return type:

Any