Description Usage Arguments Details Value References See Also Examples
This function computes the log-likelihood of an observed sequence being generated by a hidden Markov model with fixed parameters.
1 | evaluation(hmm , sequence , method = "f" )
|
hmm |
a list with the necessary variables to define a hidden Markov model. |
sequence |
sequence of observations to be evaluated. HMM and PHMM use a vector. GHMM uses a matrix. |
method |
method specified to perform the evaluation |
The methods to be selected can be "f" for the forward algorithm or "b" for the backward algorithm. GHMM uses a matrix with the variables as rows and consecutive observations in the columns.
A value that represents the log-likelihood of the sequence given the hiddden Markov model.
Cited references are listed on the RcppHMM manual page.
generateObservations
, verifyModel
, loglikelihood
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | ## Values for a hidden Markov model with categorical observations
# Set the model parameters
n <- c("First","Second")
m <- c("A","T","C","G")
A <- matrix(c(0.8,0.2,
0.1,0.9),
nrow = 2,
byrow = TRUE)
B <- matrix(c(0.2, 0.2, 0.3, 0.3,
0.4, 0.4, 0.1, 0.1),
nrow = 2,
byrow = TRUE)
Pi <- c(0.5, 0.5)
params <- list( "Model" = "HMM",
"StateNames" = n,
"ObservationNames" = m,
"A" = A,
"B" = B,
"Pi" = Pi)
HMM <- verifyModel(params)
# Data simulation
set.seed(100)
length <- 100
observationSequence <- generateObservations(HMM, length)
#Sequence evaluation
# It assumes that it will be evaluated using the forward algorithm
evaluation(HMM, observationSequence$Y)
# The user sets the backward algorithm to evaluate the algorithm
evaluation(HMM, observationSequence$Y, "b")
## Values for a hidden Markov model with discrete observations
n <- c("Low","Normal","High")
A <- matrix(c(0.5, 0.3,0.2,
0.2, 0.6, 0.2,
0.1, 0.3, 0.6),
ncol=length(n), byrow=TRUE)
B <- c(2600, # First distribution with mean 2600
2700, # Second distribution with mean 2700
2800) # Third distribution with mean 2800
Pi <- rep(1/length(n), length(n))
HMM.discrete <- verifyModel(list("Model"="PHMM", "StateNames" = n, "A" = A, "B" = B, "Pi" = Pi))
# Data simulation
set.seed(100)
length <- 100
observationSequence <- generateObservations(HMM.discrete, length)
#Sequence evaluation
# It assumes that it will be evaluated using the forward algorithm
evaluation(HMM.discrete, observationSequence$Y)
# The user sets the backward algorithm to evaluate the algorithm
evaluation(HMM.discrete, observationSequence$Y, "b")
## Values for a hidden Markov model with continuous observations
# Number of hidden states = 3
# Univariate gaussian mixture model
N = c("Low","Normal", "High")
A <- matrix(c(0.5, 0.3,0.2,
0.2, 0.6, 0.2,
0.1, 0.3, 0.6),
ncol= length(N), byrow = TRUE)
Mu <- matrix(c(0, 50, 100), ncol = length(N))
Sigma <- array(c(144, 400, 100), dim = c(1,1,length(N)))
Pi <- rep(1/length(N), length(N))
HMM.cont.univariate <- verifyModel(list( "Model"="GHMM",
"StateNames" = N,
"A" = A,
"Mu" = Mu,
"Sigma" = Sigma,
"Pi" = Pi))
# Data simulation
set.seed(100)
length <- 100
observationSequence <- generateObservations(HMM.cont.univariate, length)
#Sequence evaluation
# It assumes that it will be evaluated using the forward algorithm
evaluation(HMM.cont.univariate, observationSequence$Y)
# The user sets the backward algorithm to evaluate the algorithm
evaluation(HMM.cont.univariate, observationSequence$Y, "b")
## Values for a hidden Markov model with continuous observations
# Number of hidden states = 2
# Multivariate gaussian mixture model
# Observed vector with dimensionality of 3
N = c("X1","X2")
M <- 3
# Same number of dimensions
Sigma <- array(0, dim =c(M,M,length(N)))
Sigma[,,1] <- matrix(c(1.0,0.8,0.8,
0.8,1.0,0.8,
0.8,0.8,1.0), ncol = M,
byrow = TRUE)
Sigma[,,2] <- matrix(c(1.0,0.4,0.6,
0.4,1.0,0.8,
0.6,0.8,1.0), ncol = M,
byrow = TRUE)
Mu <- matrix(c(0, 5,
10, 0,
5, 10),
nrow = M,
byrow = TRUE)
A <- matrix(c(0.6, 0.4,
0.3, 0.7),
ncol = length(N),
byrow = TRUE)
Pi <- c(0.5, 0.5)
HMM.cont.multi <- verifyModel(list( "Model" = "GHMM",
"StateNames" = N,
"A" = A,
"Mu" = Mu,
"Sigma" = Sigma,
"Pi" = Pi))
# Data simulation
set.seed(100)
length <- 100
observationSequence <- generateObservations(HMM.cont.multi, length)
#Sequence evaluation
# It assumes that it will be evaluated using the forward algorithm
evaluation(HMM.cont.multi, observationSequence$Y)
# The user sets the backward algorithm to evaluate the algorithm
evaluation(HMM.cont.multi, observationSequence$Y, "b")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.