libsent/src/phmm/gprune_common.c

説明を見る。
00001 
00024 /*
00025  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00026  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00027  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00028  * All rights reserved
00029  */
00030 
00031 #include <sent/stddefs.h>
00032 #include <sent/htk_hmm.h>
00033 #include <sent/htk_param.h>
00034 #include <sent/hmm.h>
00035 #include <sent/gprune.h>
00036 #include "globalvars.h"
00037 
00047 static int
00048 find_insert_point(LOGPROB score, int len)
00049 {
00050   /* binary search on score */
00051   int left = 0;
00052   int right = len - 1;
00053   int mid;
00054 
00055   while (left < right) {
00056     mid = (left + right) / 2;
00057     if (OP_calced_score[mid] > score) {
00058       left = mid + 1;
00059     } else {
00060       right = mid;
00061     }
00062   }
00063   return(left);
00064 }
00065 
00086 int
00087 cache_push(int id, LOGPROB score, int len)
00088 {
00089   int insertp;
00090 
00091   if (len == 0) {               /* first one */
00092     OP_calced_score[0] = score;
00093     OP_calced_id[0] = id;
00094     return(1);
00095   }
00096   if (OP_calced_score[len-1] >= score) { /* bottom */
00097     if (len < OP_gprune_num) {          /* append to bottom */
00098       OP_calced_score[len] = score;
00099       OP_calced_id[len] = id;
00100       len++;
00101     }
00102     return len;
00103   }
00104   if (OP_calced_score[0] < score) {
00105     insertp = 0;
00106   } else {
00107     insertp = find_insert_point(score, len);
00108   }
00109   if (len < OP_gprune_num) {
00110     memmove(&(OP_calced_score[insertp+1]), &(OP_calced_score[insertp]), sizeof(LOGPROB)*(len - insertp));
00111     memmove(&(OP_calced_id[insertp+1]), &(OP_calced_id[insertp]), sizeof(int)*(len - insertp));    
00112   } else if (insertp < len - 1) {
00113     memmove(&(OP_calced_score[insertp+1]), &(OP_calced_score[insertp]), sizeof(LOGPROB)*(len - insertp - 1));
00114     memmove(&(OP_calced_id[insertp+1]), &(OP_calced_id[insertp]), sizeof(int)*(len - insertp - 1));
00115   }
00116   OP_calced_score[insertp] = score;
00117   OP_calced_id[insertp] = id;
00118   if (len < OP_gprune_num) len++;
00119   return(len);
00120 }
00121 

Juliusに対してTue Dec 26 16:19:28 2006に生成されました。  doxygen 1.5.0