fixes prune tool
authorPeng Wu <alexepico@gmail.com>
Fri, 29 Jul 2011 03:47:56 +0000 (11:47 +0800)
committerPeng Wu <alexepico@gmail.com>
Fri, 29 Jul 2011 03:47:56 +0000 (11:47 +0800)
utils/training/k_mixture_model.h
utils/training/prune_k_mixture_model.cpp

index 2d9816b..6e48796 100644 (file)
@@ -56,8 +56,10 @@ static inline parameter_t compute_B(corpus_count_t N,
                                     corpus_count_t n_1){
     /* Note: re-check this, to see if we can remove if statement. */
     /* Please consider B_2 is no less than 2 in paper. */
+#if 0
     if ( 0 == T - n_1 && 0 == N - n_0 - n_1 )
         return 2;
+#endif
 
     parameter_t B = (T - n_1 ) / (parameter_t) (N - n_0 - n_1);
     return B;
@@ -75,7 +77,7 @@ static inline parameter_t compute_Pr_G_3(corpus_count_t k,
         return alpha * (1 - gamma);
 
     if ( k > 1 ) {
-        return alpha * gamma / (B - 1) * pow((1 - 1 / (B - 1)) , k - 2);
+        return (alpha * gamma / (B - 1)) * pow((1 - 1 / (B - 1)) , k - 2);
     }
 
     assert(false);
index a602f14..832bddc 100644 (file)
@@ -52,9 +52,13 @@ bool prune_k_mixture_model(KMixtureModelMagicHeader * magic_header,
                  item->m_item.m_n_1);
         }
 
+        if ( fabs(remained_poss) < DBL_EPSILON )
+            remained_poss = 0.;
+
         /* wrong remained possibility. */
         if (remained_poss < 0) {
-            fprintf(stderr, "wrong remained possibility is found.\n");
+            fprintf(stderr, "wrong remained possibility is found:%f.\n",
+                    remained_poss);
             fprintf(stderr, "k:%d N:%d WC:%d n_0:%d n_1:%d\n",
                     g_prune_k, magic_header->m_N, item->m_item.m_WC,
                     magic_header->m_N - item->m_item.m_N_n_0,