simulate_hmm: Simulate Sequences of Hidden and Observed States from a...

Description Usage Arguments Examples

Description

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.

Usage

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)

Arguments

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

Examples

 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

greta-dev/greta.hmm documentation built on Oct. 5, 2019, 4:57 p.m.