HMMs can also be encoded as a textual file. Its syntax is quite straightforward, so it will be explained by means of an example.
Hmm v1.0 NbStates 5 State Pi 0.1 A 0.1 0.2 0.3 0.4 0.0 IntegerOPDF [0.4 0.6 ] State Pi 0.3 A 0.2 0.2 0.2 0.2 0.2 IntegerOPDF [0.5 0.5 ] State Pi 0.2 A 0.2 0.2 0.2 0.2 0.2 IntegerOPDF [0.5 0.5 ] State Pi 0.2 A 0.2 0.2 0.2 0.2 0.2 IntegerOPDF [0.5 0.5 ] State Pi 0.2 A 0.2 0.2 0.2 0.2 0.2 IntegerOPDF [0.5 0.5 ]
All the white space characters (tab, space, new line,...) are treated the same, and several white spaces are equivalent to a signle one. So, for example, the whole file could be encoded as a single line.
The first line just gives the file syntax's version number. The NbStates
keyword of course gives the number of states of the HMM described.
After that comes a list of n
state descriptions, where n
is the HMM's number of states. This list is ordered, so the i-th element of the list matches the i-th state. Each such description is composed of:
The State
keyword.
The probability that this state is an initial state. This probability is preceded bye the Pi
keyword.
The state-to-state transition probabilities. Those probabilities are written as the A
keyword followed by n
an ordered list of probabilities. If the state currently described is state number i, then the j probability of the list is that of going from state i to state j.
A description of the observation distribution function.. The exact syntax depends on the type of distribution; it can be found in the javadoc of the relevant class (for example, jahmm.io.OpdfGaussianReader for gaussian distributions).
The example given above describes integer distributions. It begins with the IntegerOPDF
keyword followed by an ordered list of probabilities between brackets. The first probability is related to the integer '0', the second to '1', etc... In the example above, the probability that the first state emits '1' is equal to 0.6.