HMM: Class constructor for Hidden Markov models

Description Usage Arguments Value See Also Examples

View source: R/HMM.R

Description

Creates a HMM object, as specified.

The HMM object contains five fields: states, transitions, constraints, emissions and parameters.

The field states contains a character vector with the names of the states. If the constructor is given a number S, it sets the names as follows: as.character(1:S). An additional field, called coordinates is provided too, were in the future the geolocation of the states will be specified. Note that state determines geolocation, but different states might share geolocation.

The field transitions contain a matrix which is a list of the transitions with non-zero probability. It is a two row integer matrix where each column represents the transition from first row state to second row state. The columns of the matrix are ordered by first row and then by second row. This order corresponds to a row major representation of the transition matrix. The states are referenced in the same order as they appear in field states. While (number of states)^2 transitions are possible, a much smaller number is expected. It defaults to still transitions for all states.

The field constraints is the augmented matrix of the system of linear equalities that the model must fulfill. The variables of the system correspond to the probabilities of transition, in the same order as in field transitions. It is a row major sparse matrix. The first rows should have equalities between pairs of transition probabilities, which are rows with just two non zero elements. Next, we have the sum up to one conditions, which are rows with constant term equal to one. Finally, the remaining constraints are expected to have constant term different from one (otherwise multiply the constraint by a constant). This structure, allows an efficient treatment of constraints that are equalities between pairs of transition probabilities.They are expected to be the most frequent constraints.

The field emissions consists in a matrix that contains the emission probabilities, where the number of rows is the number of states and each column correspond to a possible output. EM is a column major sparse matrix. Unlike usual, the emission probabilities are fixed, do not have parameters to estimate.

The field parameters contain additional information about the probabilities of transition and the initial state of the model. Also some auxiliary information to reduce the number of parameters of the model. See initparams, minparams and initsteady.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
HMM(...)

## S3 method for class 'integer'
HMM(S, TL, CT, EM = NULL, checks = TRUE)

## S3 method for class 'numeric'
HMM(S, ...)

## S3 method for class 'character'
HMM(S, ...)

Arguments

S

Number or names of states. It can be either a numeric or a character.

TL

Matrix of integers that lists non-zero transitions. The matrix corresponds to the field transitions of the object (see details).

CT

Matrix of constraints. It corresponds to the field constraints of the object (see details).

EM

Matrix of emissions. It corresponds to the field emissions of the object (see details).

Value

A HMM object.

See Also

initparams, minparams, initsteady

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
model1 <- HMM(5)
model2 <- HMM(c("a","b","c"),
            TL = matrix(c(1, 1,
                          1, 2,
                          2, 1,
                          2, 2,
                          2, 3,
                          3, 2,
                          3, 3), nrow = 2))
nstates(model1)
ntransitions(model1)
nstates(model2)
ntransitions(model2)

MobilePhoneESSnetBigData/destim documentation built on Dec. 7, 2020, 7:35 p.m.