Skip to content

fit_mhmm()

fit_mhmm() estimates Mixture HMM parameters with EM. The E-step computes posterior cluster responsibilities; the M-step updates mixture weights and each cluster's HMM parameters.

Function Usage

python
fit_mhmm(
    model,
    n_iter=100,
    tol=1e-2,
    verbose=False
)

seqHMM Parameter Mapping

SequenzoseqHMM
modelmhmm object
n_iter, tol, verbosefit_model.mhmm EM controls

Entry Parameters

ParameterRequiredTypeDescription
modelMHMMModel from build_mhmm().
n_iterintMaximum EM iterations. Default 100.
tolfloatLog-likelihood convergence tolerance. Default 1e-2.
verboseboolPrint progress. Default False.

What It Returns

The same MHMM object, modified in place:

AttributeMeaning
log_likelihoodFitted mixture log-likelihood
cluster_probsEstimated mixture weights
clusters[k].*Fitted parameters for cluster k
n_iter, convergedOptimization diagnostics

Example

python
from sequenzo.seqhmm import build_mhmm, fit_mhmm, predict_mhmm

mhmm = build_mhmm(seq, n_clusters=3, n_states=4, random_state=42)
mhmm = fit_mhmm(mhmm, n_iter=100, tol=1e-2, verbose=True)

print(mhmm.log_likelihood, mhmm.cluster_probs)
clusters = predict_mhmm(mhmm)

R Counterpart

  • Closest R function: seqHMM fit_model() for mhmm objects
  • Mapping note: Same EM structure; R may combine with global/local refinement via fit_model_advanced() in Sequenzo.

Notes

  • Cluster labels from EM can be label-switching sensitive across runs; compare solutions with BIC and interpret cluster-specific parameters, not just index order.
  • Use compare_models() to choose n_clusters and n_states.

Authors

Code: Yuqi Liang

Documentation: Yuqi Liang

References

Helske, S., & Helske, J. (2019). Mixture hidden Markov models for sequence data: The seqHMM package in R. Journal of Statistical Software, 88(3), 1–32.