Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

addlog.c

Go to the documentation of this file.
00001 
00017 /*
00018  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00019  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00020  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology, Nagoya Institute of Technology
00021  * All rights reserved
00022  */
00023 
00024 #include <sent/stddefs.h>
00025 #include <sent/hmm.h>
00026 
00027 #define TBLSIZE 500000          
00028 #define VRANGE 15               
00029 #define TMAG 33333.3333         
00030 
00031 static LOGPROB tbl[TBLSIZE];    
00032 
00039 void
00040 make_log_tbl()
00041 {
00042   LOGPROB f;
00043   int i;
00044 
00045   j_printerr("Generating addlog table...");
00046   for (i=0;i<TBLSIZE;i++){
00047     f = - ((float)VRANGE * (float)i / (float)TBLSIZE);
00048     tbl[i] = log(1 + exp(f));
00049     /*if (i < 10 || i > TBLSIZE - 10) j_printf("%f: %d(%f)\n", f, i, tbl[i]);*/
00050   }
00051   j_printerr("%d kb...done\n",(TBLSIZE * sizeof(LOGPROB)) / 1024);
00052 }
00053 
00065 LOGPROB
00066 addlog(LOGPROB x, LOGPROB y)
00067 {
00068   /* return(log(exp(x)+exp(y))) */
00069   LOGPROB tmp;
00070   unsigned int idx;
00071   
00072   if (x < y) {
00073     if ((tmp = x - y) < LOG_ADDMIN) return y;
00074     else {
00075       idx = (unsigned int)((- tmp) * TMAG + 0.5);
00076       /* j_printf("%f == %f\n",tbl[idx],log(1 + exp(tmp))); */
00077       return (y + tbl[idx]);
00078     }
00079   } else {
00080     if ((tmp = y - x) < LOG_ADDMIN) return x;
00081     else {
00082       idx =(unsigned int)((- tmp) * TMAG + 0.5);
00083       /* j_printf("%f == %f\n",tbl[idx],log(1 + exp(tmp))); */
00084       return (x + tbl[idx]);
00085     }
00086   }
00087 }
00088 
00097 LOGPROB
00098 addlog_array(LOGPROB *a, int n)
00099 {
00100   LOGPROB tmp;
00101   LOGPROB x,y;
00102   unsigned int idx;
00103 
00104   y = LOG_ZERO;
00105   for(n--; n >= 0; n--) {
00106     x = a[n];
00107     if (x > y) {
00108       tmp = x; x = y; y = tmp;
00109     }
00110     /* always y >= x */
00111     if ((tmp = x - y) < LOG_ADDMIN) continue;
00112     else {
00113       idx = (unsigned int)((- tmp) * TMAG + 0.5);
00114       y += tbl[idx];
00115     }
00116   }
00117   return(y);
00118 }

Generated on Tue Mar 28 16:01:39 2006 for Julius by  doxygen 1.4.2