[Subject Prev][Subject Next][Thread Prev][Thread Next][Date Index][Thread Index]

[hts-users:02311] Numerical issue while estimating adaptation transforms


Hi,

I faced a numerical issue while estimating adaptation transforms. I made a simple modification to fix this problem; use double precision instead of single one to accumulate statistics. It works and it fixes my problem. I attached patch codes to show my modifications.

Best regards,

Heiga ZEN (Byung Ha CHUN)

--
--------------------------
Heiga ZEN (Byung Ha CHUN)
Speech Technology Group
Cambridge Research Lab
Toshiba Research Europe
phone: +44 1223 436975



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email ______________________________________________________________________
--- HAdapt.h	2008-08-07 13:36:18.952464000 +0000
+++ HAdapt.h	2009-12-13 21:20:22.064496000 +0000
@@ -92,7 +92,7 @@
 typedef struct _AccCache{
    int     baseclass;
    DVector bVector;
-   TriMat *bTriMat;
+   DTriMat *bTriMat;
    struct _AccCache *next;
 } AccCache;  
 
--- HAdapt.c	2008-08-07 13:36:18.948477000 +0000
+++ HAdapt.c	2009-12-13 21:40:59.204122000 +0000
@@ -140,8 +140,8 @@
    double  occ;
    DVector spSum;
    DVector spSumSq;
-   TriMat *bTriMat;
-   TriMat *bDiagMat;
+   DTriMat *bTriMat;
+   DTriMat *bDiagMat;
    DVector bVector;
 } RegAcc;
 
@@ -1392,47 +1391,47 @@
 
 /* --------------- handling the RegAcc structure ------------------ */
 
-static TriMat *CreateBlockTriMat(MemHeap *x, IntVec blockSize)
+static DTriMat *CreateBlockTriMat(MemHeap *x, IntVec blockSize)
 {
-  TriMat *tm;
+   DTriMat *tm;
   int nblock, bsize, b, *i;
   
   nblock = IntVecSize(blockSize);
-  tm = (TriMat *)New(x,sizeof(TriMat)*(nblock+1));  
+   tm = (DTriMat *)New(x,sizeof(DTriMat)*(nblock+1));  
   i = (int *)tm; *i = nblock;
   for (b=1;b<=nblock;b++) {
     bsize = blockSize[b];
-    tm[b] = CreateTriMat(x, bsize); 
-    ZeroTriMat(tm[b]);
+      tm[b] = CreateDTriMat(x, bsize); 
+      ZeroDTriMat(tm[b]);
   }
   return(tm);
 }
 
-static void ZeroBlockTriMat(TriMat *bTriMat)
+static void ZeroBlockTriMat(DTriMat *bTriMat)
 {
   int *nblock,b;
 
   nblock = (int *)bTriMat;
   for (b=1; b<=*nblock; b++)
-      ZeroTriMat(bTriMat[b]);  
+     ZeroDTriMat(bTriMat[b]);
 }
 
-static void ZeroBaseTriMat(TriMat *bTriMat)
+static void ZeroBaseTriMat(DTriMat *bTriMat)
 {
   int i;
   int *vsize;
-  TriMat tm;
+   DTriMat tm;
  
   vsize = (int *)bTriMat;
   for (i=1;i<=*vsize;i++) {
     tm = bTriMat[i];
-    ZeroTriMat(tm);
+      ZeroDTriMat(tm);
   }  
 }
 
 static void CreateBaseTriMat(XFInfo *xfinfo, MemHeap *x, MixPDF *mp, int class)
 {
-  TriMat *tm;
+   DTriMat *tm;
   int vsize = VectorSize(mp->mean);
    IntVec blockSize = GetBlockSize(xfinfo,class);
   RegAcc *regAcc, *ra;
@@ -1449,13 +1448,13 @@
     ZeroDVector(regAcc->bVector);
     regAcc->bDiagMat = CreateBlockTriMat(x,blockSize); 
     ZeroBlockTriMat(regAcc->bDiagMat);
-    tm = (TriMat *)New(x,sizeof(TriMat)*(vsize+1));
+      tm = (DTriMat *)New(x,sizeof(DTriMat)*(vsize+1));
     vsp = (int *)tm; *vsp = vsize;
     for (b=1,cntj=1;b<=IntVecSize(blockSize);b++) {
       bsize = blockSize[b];
       for (j=1;j<=bsize;j++,cntj++) {
-	tm[cntj] =  CreateTriMat(x, bsize);  
-	ZeroTriMat(tm[cntj]);
+            tm[cntj] =  CreateDTriMat(x, bsize);  
+            ZeroDTriMat(tm[cntj]);
       }
     }
     regAcc->bTriMat = tm;    
@@ -1483,7 +1482,7 @@
 void UpdateAccCache(double Lr, Vector svec, MixPDF *mp)
 {
    AccCache *paac;
-   TriMat m;
+   DTriMat m;
    int vsize = VectorSize(mp->mean);
    Vector covar;
    int i, j, bstart, bsize;
@@ -1495,7 +1494,7 @@
          nblock = (long)(paac->bTriMat[0]);
 	for (bl=1,bstart=0;bl<=nblock;bl++) {
 	  m = paac->bTriMat[bl];
-	  bsize = TriMatSize(m);
+            bsize = DTriMatSize(m);
 	  for (i=1;i<=bsize;i++) { /* Fill the accumulate stores */
 	    for (j=1; j<=i; j++)
 		m[i][j] = svec[i+bstart] * svec[j+bstart];
@@ -1518,7 +1517,7 @@
    int i,j,k,b,bsize;
    long nblock, bl;
    int cnt, cnti, cntj;
-   TriMat tm, m;
+   DTriMat tm, m;
    RegAcc *ra;
    DVector acc;
    BaseClass *bclass;
@@ -1537,7 +1536,7 @@
             nblock = (long)(ra->bDiagMat[0]);
 	 for (bl=1,cnti=1;bl<=nblock;bl++) {
 	   m = ra->bDiagMat[bl];
-	   bsize = TriMatSize(m);
+               bsize = DTriMatSize(m);
 	   for (i=1;i<=bsize;i++,cnti++) { /* Fill the accumulate stores */
 	     tm = ra->bTriMat[cnti];
 	     for (j=1; j<=bsize; j++)
@@ -1554,7 +1553,7 @@
    if ((regAcc->bTriMat!=NULL) && (regAcc->bVector[1]==0.0) && (svec!=NULL)) {
       nblock = (long)(regAcc->bDiagMat[0]);
       for (bl=1,cnt=1; bl<=nblock; bl++) {
-         bsize = TriMatSize(regAcc->bDiagMat[bl]);
+         bsize = DTriMatSize(regAcc->bDiagMat[bl]);
          m = regAcc->bDiagMat[bl];
          for (i=1,cnti=cnt; i<=bsize; i++,cnti++) {
             for (j=1,cntj=cnt; j<=i; j++,cntj++)
@@ -1570,7 +1569,7 @@
    int i,j,k,b,bsize;
    long nblock, bl;
    int cnti;
-   TriMat tm, m;
+   DTriMat tm, m;
    RegAcc *ra;
    DVector acc;
    BaseClass *bclass;
@@ -1591,7 +1590,7 @@
                nblock = (long)(ra->bDiagMat[0]);
             for (bl=1,cnti=1;bl<=nblock;bl++) {
               m = paac->bTriMat[bl];
-              bsize = TriMatSize(m);
+                  bsize = DTriMatSize(m);
               for (i=1;i<=bsize;i++,cnti++) { /* Fill the accumulate stores */
                 tm = ra->bTriMat[cnti];
                 for (j=1; j<=bsize; j++)
@@ -2223,7 +2222,7 @@
   RegAcc *ra;
   int i,j,k;
   int cnti,b,bsize;
-  TriMat tm;
+   DTriMat tm;
  
   ra = GetRegAcc(mp);
 
@@ -3357,23 +3355,23 @@
     for (j=1;j<=bsize;j++)
       tvec[i] += cofact[j]*invgmat[i][j];
   /* Now set up the quadratic equation */
-  a=0;b=0;c=-occ;
+   a=0.0;b=0.0;c=-occ;
   for (i=1;i<=bsize;i++) {
     a += tvec[i]*cofact[i];
     b += tvec[i] * kmat[i];
   }
   if(bsize != dim)  b += tvec[dim] * kmat[dim];
   /* Must by definition be real */
-  tmp = (b*b-4*a*c);
-  if (tmp<0) {
+   tmp = (b*b-4.0*a*c);
+   if (tmp<0.0) {
     HError(-1,"WARNING: accumulates incorrect (%f < 0) - resetting",tmp);
-    tmp=0;
+      tmp=0.0;
   }
   
   tmp = sqrt(tmp);
   /* Now get the possible values of alpha */
-  alpha1 = (-b+tmp)/(2*a);
-  alpha2 = (-b-tmp)/(2*a);
+   alpha1 = (-b+tmp)/(2.0*a);
+   alpha2 = (-b-tmp)/(2.0*a);
   like1 = GetAlphaLike(a,b,c,alpha1);
   like2 = GetAlphaLike(a,b,c,alpha2);