HMM for prediction sequences of binary vectors having fixed length Please help me with a question.
I want to use the hidden Markov model (HMM) to predict sequences of binary vectors of fixed length.
For example, there are such observations:
01001
00101
10010
and so on.
I need to predict the next binary vector of this sequence.
How can I do it? What will be the model?
Thank you very much in advance!
 A: If you don't know the hidden states from which the sequences were generated, you'll need to build a basic HMM to start with and then train it using your observed data. You can do this using either the Baum Welch or Viterbi training algorithm. Here's an example of how you could do create and train a simple HMM with two hidden states "A" and "B" using the R package aphid.
install.packages("aphid")
library(aphid)
states <- c("Begin", "A", "B")
residues <- c("0", "1")

## build transition matrix for initial model
A <- matrix(c(0, 0, 0, 0.5, 0.8, 0.2, 0.5, 0.2, 0.8), nrow = 3)
dimnames(A) <- list(from = states, to = states)

## build emission matrix for initial model
E <- matrix(c(0.6, 0.4, 0.4, 0.6), nrow = 2)
dimnames(E) <- list(states = states[-1], residues = residues)

## create HMM object and plot
hmm_start <- structure(list(A = A, E = E), class = "HMM")
plot(hmm_start)


## read in observation data
observations <- strsplit(c("01001", "00101", "10010"), split = "")

## train model with observation data and plot new model
set.seed(999)
hmm_trained <- train(hmm_start, observations, method = "BaumWelch")
plot(hmm_trained)


## randomly simulate a sequence from the model
set.seed(999)
generate(hmm_trained, size = 5)

This returns a simulated sequence named with the hidden states 
 A   A   B   A   A 
"1" "1" "0" "0" "1" 

