Description Usage Arguments Examples
Generate corresponding sequences of hidden and observed states from a Hidden Markov Model (HMM) with specified transition and emission matrices. The simulation is carried out directly in R and is provided only to generate datasets for demonstrating or testing HMMs.
1 2 3 4 5 | simulate_hmm(initial = random_simplex_matrix(1, 3),
transition = random_simplex_matrix(3, 3),
emission = random_simplex_matrix(3, 5), n_timesteps = 10)
random_simplex_matrix(nrow, ncol)
|
initial |
a length K row vector (ie. 1 x K matrix) of probabilities of initial hidden states |
transition |
a K x K matrix of transition probabilities between hidden states |
emission |
a K x N matrix of emission probabilities between hidden and observed states |
n_timesteps |
the number of timesteps (length of the observed state matrix) - must be a positive scalar integer |
nrow, ncol |
the number of rows and columns in the matrix |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # numbers of hidden and observable states
n_hidden <- 3
n_observable <- 5
# generate a square matrix of transition probabilities in the hidden states
transition <- simulate_simplex_matrix(n_hidden, n_hidden)
# and a rectangular matrix of probabilities of each observable state,
# given each hidden state
emission <- simulate_simplex_matrix(n_hidden, n_observable)
# simulate an HMM for 10 timesteps
hmm_data <- simulate_hmm(transition, emission, 10)
# pull out the observed states
hmm_data$observed
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.