diff 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
line wrap: on
line diff
--- a/hmm/hmm.c	Wed Jan 16 18:02:31 2008 +0000
+++ b/hmm/hmm.c	Fri Jan 18 13:24:12 2008 +0000
@@ -159,7 +159,9 @@
 	int niter = 50;	
 	int iter = 0;
 	double loglik1, loglik2;
-	while(iter < niter && !(iter > 1 && (loglik - loglik1) < thresh * (loglik1 - loglik2)))	
+	int foundnan = 0;
+
+	while (iter < niter && !foundnan && !(iter > 1 && (loglik - loglik1) < thresh * (loglik1 - loglik2)))	
 	{
 		++iter;
 		
@@ -199,6 +201,11 @@
 		fprintf(stderr, "iteration %d: loglik = %f\n", iter, loglik);		
 		fprintf(stderr, "re-estimation...\n");
 		fflush(stderr);
+
+		if (isnan(loglik)) {
+		    foundnan = 1;
+		    continue;
+		}
 		
 		baum_welch(p0, a, mu, cov, N, T, L, x, xi, gamma);
 			
@@ -278,6 +285,7 @@
 		for (j = 0; j < N; j++)
 		{
 			a[i][j] = 0;
+			if (sum_gamma[i] == 0.) continue;
 			for (t = 0; t < T-1; t++)
 				a[i][j] += xi[t][i][j];
 			//s += a[i][j];