Skip to content

simulate_mnhmm()

simulate_mnhmm() generates synthetic observed sequences and hidden-state paths from a Mixture Non-homogeneous Hidden Markov Model (MNHMM). You can simulate from supplied probability arrays, random parameters, or a fitted MNHMM object with fixed component probabilities.

Function Usage

python
simulate_mnhmm(
    n_sequences=None,
    n_clusters=None,
    n_states=None,
    initial_probs=None,
    transition_probs=None,
    emission_probs=None,
    cluster_probs=None,
    sequence_length=None,
    sequence_lengths=None,
    alphabet=None,
    n_symbols=None,
    state_names=None,
    cluster_names=None,
    coefs=None,
    model=None,
    random_state=None,
)

Entry Parameters

ParameterRequiredTypeDescription
n_sequencesConditionalint / NoneNumber of sequences to simulate when sequence_lengths is not supplied.
n_clustersConditionalint / NoneNumber of mixture clusters. Required unless simulating from model.
n_statesConditionalint / sequence of int / NoneHidden states per cluster. Required unless simulating from model.
initial_probsNosequence of arrays / NoneInitial-state probabilities per cluster. Randomly generated if omitted with other probability arrays.
transition_probsNosequence of arrays / NoneTransition matrices per cluster.
emission_probsNosequence of arrays / NoneEmission matrices per cluster.
cluster_probsNondarray / NoneMixture probabilities. Can be a vector or a sequence-specific matrix.
sequence_lengthConditionalint / NoneCommon sequence length when sequence_lengths is not supplied.
sequence_lengthsConditionalsequence of int / NoneSequence-specific lengths.
alphabetNosequence of str / NoneObserved-state labels.
n_symbolsNoint / NoneNumber of observed symbols when alphabet is omitted.
state_namesNosequence / NoneHidden-state labels.
cluster_namesNosequence of str / NoneCluster labels.
coefsNodict / NoneOptional dictionary containing probability arrays.
modelNoMNHMM / NoneFitted or constructed MNHMM with fixed component probabilities.
random_stateNoint / NoneSeed for reproducible simulation.

Example

python
from sequenzo import simulate_mnhmm

sim = simulate_mnhmm(
    n_sequences=200,
    n_clusters=3,
    n_states=[3, 4, 3],
    sequence_length=12,
    alphabet=["A", "B", "C"],
    random_state=42,
)

observations = sim["observations_df"]
hidden_states = sim["states_df"]

Simulating from a Model

If you already have an MNHMM object with fixed component probabilities, pass that object through model:

python
# Replace `mnhmm_model` with your fitted or constructed MNHMM object.
sim = simulate_mnhmm(model=mnhmm_model, random_state=42)

When model is supplied, the model must be an MNHMM instance with fixed component probabilities available. For multichannel models, simulate_mnhmm() returns one observed sequence column set per channel.

Returns

A dictionary containing simulated data and model metadata. The main entries are:

KeyAvailabilityDescription
observationsAll simulationsSimulated observed sequences.
statesAll simulationsSimulated hidden-state paths.
clustersAll simulationsSimulated mixture-cluster assignment for each sequence.
observations_dfAll simulationsSimulated observed sequences in tabular form. For multichannel simulations, this is a dictionary of channel-specific data frames.
states_dfAll simulationsSimulated hidden states and cluster assignments.
alphabetSingle-channel simulationsObserved-state alphabet.
alphabetsMultichannel simulationsObserved-state alphabet by channel.
channel_namesMultichannel simulationsChannel labels.
state_namesAll simulationsHidden-state labels by cluster.
cluster_namesAll simulationsMixture-cluster labels.
modelAll simulationsDictionary of the probability parameters used for simulation.

Notes

  • If probabilities are omitted, Sequenzo draws random categorical parameters.
  • Provide random_state when you need reproducible simulated datasets.
  • Use simulation to test analysis code, inspect whether parameters imply plausible trajectories, or build teaching examples.

See Also

Authors

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. https://doi.org/10.18637/jss.v088.i03

Sequenzo is released under the BSD-3-Clause License; this documentation site source is licensed under MIT.