Mercurial > hg > qm-dsp
diff hmm/hmm.c @ 48:03abd5957853
* Fix read from uninitialised memory in hmm code
author | cannam |
---|---|
date | Tue, 11 Nov 2008 12:51:24 +0000 |
parents | 00603b8a940f |
children | d72fcd34d9a7 |
line wrap: on
line diff
--- a/hmm/hmm.c Mon Nov 10 14:01:55 2008 +0000 +++ b/hmm/hmm.c Tue Nov 11 12:51:24 2008 +0000 @@ -577,6 +577,7 @@ { int i, j, t; double max; + int havemax; int N = model->N; int L = model->L; @@ -622,15 +623,18 @@ { for (j = 0; j < N; j++) { - max = -1000000; // TODO: what should this be?? = smallest possible sumlogprob + max = -1000000; + havemax = 0; + psi[t][j] = 0; for (i = 0; i < N; i++) { - if (phi[t-1][i] + log(a[i][j]) > max) + if (phi[t-1][i] + log(a[i][j]) > max || !havemax) { max = phi[t-1][i] + log(a[i][j]); phi[t][j] = max + logb[t][j]; psi[t][j] = i; + havemax = 1; } } }