Hidden Markov Model

420 views Asked by At

I am a home user of Matlab so I don't have access to all the MatLab toolboxes but I'm not against buying one once in awhile. I'm currently using another piece of free software (VarScreen) to generate Hidden Markov Models. That tool takes a number of vectors as input data, along with the number of states I think might exist in the state HMM. In this case I gave it 5 input vectors, a target vector and told it to create a model 3 states using 2 vectors. It picked what it considered the best 2 vectors, generated a model and returned the following:

Specifications of the best HMM model correlating with RETURN_1D...

Means (top number) and standard deviations (bottom number)

State         CCMA_13           CCMA_89

   1        -11.96117          -7.22653
             21.46392          23.05265

   2         18.24447           7.26517
             18.36591          21.69893

   3          2.75350          12.63285
             20.37755          17.43237

Transition probabilities...

         1        2        3
  1   0.9913   0.0087   0.0000
  2   0.0073   0.9843   0.0084
  3   0.0015   0.0032   0.9952

Further properties of each state...
  Percent of cases state is highest (tied cases are ignored)
  Correlation of state probability with target
  Mean of target when in this state (tied cases are ignored)
  Standard deviation of target when in this state (tied cases are ignored)

State     Percent    Correlation   Target mean   Target StdDev

  1         26.92      -0.08378      -0.18628        2.27240
  2         26.11       0.06865       0.24341        1.53242
  3         46.98       0.01524       0.09744        1.52846

As I understand the free tool the HMM is generated using only the vectors. The correlations are generated looking at how the states matched the target vector. These results are at least a potentially reasonable view of the financial data I provided (27% bearish, 26% bullish, 47% flat) but I haven't actually tried to use the model anywhere to see if it really provides any value.

Anyway, the question for here is how I would do something similar with MatLab itself or the Statistics & Machine Learning Toolbox? (Or any other toolbox) I could do the choice of 2 out of 5 vectors in a loop but reading the online help files for things like hmmgenerate/hmmtrain/etc. hasn't yet clicked for me about how the model gets generated.

Thanks!

1

There are 1 answers

0
Eskapp On

This answer might come a bit late but could be useful for other people looking at this thread.

Matlab itself does not currently have any built-in proficient toolbox for HMMs. It only includes some basic functions such as hmmtrain, hmmestimate, or hmmviterbi. However, as soon as you want to tune a bit your model, these functions are not enough.

That being said, there is an excellent Matlab toolbox that has been developed by Prof. Kevin Murphy that you can find in its earlier version here: http://www.cs.ubc.ca/~murphyk/Software/HMM/hmm.html, which includes a "How to use" that is pretty well done. This toolbox has been improved later on and all the files can be found at : https://github.com/probml/pmtk3

The first link I gave you also includes some useful readings if you are willing to go deeper into the theory.

Hope this helps!