Mercurial > hg > qm-dsp
comparison hmm/hmm.c @ 30:a251fb0de594
* Make MFCC able to accept already-FFT'd input, and simplify API a bit
* Add log power value to MFCC, restore windowing, and avoid some heap allocs
* In HMM, bail out of iteration if loglik hits NaN
author | cannam |
---|---|
date | Fri, 18 Jan 2008 13:24:12 +0000 |
parents | d3a856b44c43 |
children | 00603b8a940f |
comparison
equal
deleted
inserted
replaced
29:1c9c4d2c0592 | 30:a251fb0de594 |
---|---|
157 | 157 |
158 double thresh = 0.0001; | 158 double thresh = 0.0001; |
159 int niter = 50; | 159 int niter = 50; |
160 int iter = 0; | 160 int iter = 0; |
161 double loglik1, loglik2; | 161 double loglik1, loglik2; |
162 while(iter < niter && !(iter > 1 && (loglik - loglik1) < thresh * (loglik1 - loglik2))) | 162 int foundnan = 0; |
163 | |
164 while (iter < niter && !foundnan && !(iter > 1 && (loglik - loglik1) < thresh * (loglik1 - loglik2))) | |
163 { | 165 { |
164 ++iter; | 166 ++iter; |
165 | 167 |
166 fprintf(stderr, "calculating obsprobs...\n"); | 168 fprintf(stderr, "calculating obsprobs...\n"); |
167 fflush(stderr); | 169 fflush(stderr); |
197 forward_backwards(xi, gamma, &loglik, &loglik1, &loglik2, iter, N, T, p0, a, b); | 199 forward_backwards(xi, gamma, &loglik, &loglik1, &loglik2, iter, N, T, p0, a, b); |
198 | 200 |
199 fprintf(stderr, "iteration %d: loglik = %f\n", iter, loglik); | 201 fprintf(stderr, "iteration %d: loglik = %f\n", iter, loglik); |
200 fprintf(stderr, "re-estimation...\n"); | 202 fprintf(stderr, "re-estimation...\n"); |
201 fflush(stderr); | 203 fflush(stderr); |
204 | |
205 if (isnan(loglik)) { | |
206 foundnan = 1; | |
207 continue; | |
208 } | |
202 | 209 |
203 baum_welch(p0, a, mu, cov, N, T, L, x, xi, gamma); | 210 baum_welch(p0, a, mu, cov, N, T, L, x, xi, gamma); |
204 | 211 |
205 /* | 212 /* |
206 printf("a:\n"); | 213 printf("a:\n"); |
276 } | 283 } |
277 //double s = 0; | 284 //double s = 0; |
278 for (j = 0; j < N; j++) | 285 for (j = 0; j < N; j++) |
279 { | 286 { |
280 a[i][j] = 0; | 287 a[i][j] = 0; |
288 if (sum_gamma[i] == 0.) continue; | |
281 for (t = 0; t < T-1; t++) | 289 for (t = 0; t < T-1; t++) |
282 a[i][j] += xi[t][i][j]; | 290 a[i][j] += xi[t][i][j]; |
283 //s += a[i][j]; | 291 //s += a[i][j]; |
284 a[i][j] /= sum_gamma[i]; | 292 a[i][j] /= sum_gamma[i]; |
285 } | 293 } |