nodehmm
Implementation of Forward, Backward, Viterbi, and Baum-Welch(Forward-Backward) algorithms.
You can use an open source train corpus for Chinese in: https://github.com/liwenzhu/corpusZh
Test
To run the unittest:
$ npm test
Benchmark
To get the benchmarks:
$ node benchmarks/index.js
Forward
Forward algorithm is to compute the probability of a sequence of given observation :
var HEALTHY = 0 FEVER = 1 NORMAL = 0 COLD = 1 DIZZY = 2; var hmm = model = ; var states = 'Healthy' 'Fever'; model; // ('Healthy': 0.6, 'Fever': 0.4)model; // matrix Amodel; // matrix Bmodel; var alpha = ; for var i = 0; i < stateslength; i++ alphai = ; var result = hmm;console // -4.698248486593353
Backward
this is the same as forward algorithm:
var HEALTHY = 0 FEVER = 1 NORMAL = 0 COLD = 1 DIZZY = 2; var hmm = model = ; var states = 'Healthy' 'Fever'; model; // ('Healthy': 0.6, 'Fever': 0.4)model; // matrix Amodel; // matrix Bmodel;var beta = ; for var i = 0; i < stateslength; i++ betai = ; exports { var result = hmm; test; test;};
Viterbi
Get the most possible hidden sequence of the given observation:
var HEALTHY = 0 FEVER = 1 NORMAL = 0 COLD = 1 DIZZY = 2; var hmm = model = ; var states = 'Healthy' 'Fever'; model; // ('Healthy': 0.6, 'Fever': 0.4)model; // matrix Amodel; // matrix Bmodel; var result = hmm;console; // [0,0,1]result = result;console; // ['Healthy','Healthy','Fever']