Mercurial > forge
changeset 12493:32ce8fbfb857 octave-forge
Converted calculation in hmmviterbi to log space.
author | asnelt |
---|---|
date | Sat, 24 May 2014 23:09:12 +0000 |
parents | d7adff2641da |
children | e784cfb75305 |
files | main/statistics/NEWS main/statistics/inst/hmmviterbi.m |
diffstat | 2 files changed, 8 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/main/statistics/NEWS Sat May 24 19:47:26 2014 +0000 +++ b/main/statistics/NEWS Sat May 24 23:09:12 2014 +0000 @@ -1,7 +1,7 @@ Summary of important user-visible changes for statistics 1.2.4: ------------------------------------------------------------------- - ** Make princomp work with nargout < 2. + ** Made princomp work with nargout < 2. ** Renamed dendogram to dendrogram. @@ -9,6 +9,8 @@ ** Transposed output of hist3. + ** Converted calculation in hmmviterbi to log space. + ** The following functions are new: cdf signtest ttest ttest2 vartest vartest2 ztest qrandn dcov
--- a/main/statistics/inst/hmmviterbi.m Sat May 24 19:47:26 2014 +0000 +++ b/main/statistics/inst/hmmviterbi.m Sat May 24 23:09:12 2014 +0000 @@ -189,17 +189,16 @@ endif endif - # Each row in transprob and outprob should contain probabilities - # => scale so that the sum is 1 - # A zero row remains zero + # Each row in transprob and outprob should contain log probabilities + # => scale so that the sum is 1 and convert to log space # - for transprob s = sum (transprob, 2); s(s == 0) = 1; - transprob = transprob ./ (s * ones (1, columns (transprob))); + transprob = log (transprob ./ (s * ones (1, columns (transprob)))); # - for outprob s = sum (outprob, 2); s(s == 0) = 1; - outsprob = outprob ./ (s * ones (1, columns (outprob))); + outprob = log (outprob ./ (s * ones (1, columns (outprob)))); # Store the path starting from i in spath(i, :) spath = ones (nstate, len + 1); @@ -211,7 +210,7 @@ # Find the most likely paths for the given output sequence for i = 1:len # Calculate the new probabilities of the continuation with each state - nextpathprob = ((spathprob' .* outprob(:, sequence(i))) * ones (1, nstate)) .* transprob; + nextpathprob = ((spathprob' + outprob(:, sequence(i))) * ones (1, nstate)) + transprob; # Find the paths with the highest probabilities [spathprob, mindex] = max (nextpathprob); # Update spath and spathprob with the new paths