cont_mgau.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 1999-2004 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * This work was supported in part by funding from the Defense Advanced
19  * Research Projects Agency and the National Science Foundation of the
20  * United States of America, and the CMU Sphinx Speech Consortium.
21  *
22  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * ====================================================================
35  *
36  */
37 /*
38  * cont_mgau.h -- Mixture Gaussians for continuous HMM models.
39  *
40  * **********************************************
41  * CMU ARPA Speech Project
42  *
43  * Copyright (c) 1997 Carnegie Mellon University.
44  * ALL RIGHTS RESERVED.
45  * **********************************************
46  *
47  * HISTORY
48  * $Log$
49  * Revision 1.1 2006/04/05 20:27:30 dhdfu
50  * A Great Reorganzation of header files and executables
51  *
52  * Revision 1.15 2006/02/22 16:32:40 arthchan2003
53  * Merged from SPHINX3_5_2_RCI_IRII_BRANCH: 1, Dave's change in 1.18 for removing temp_hack is followed 2, The logic of uninit_compact is changed, by default the code will remove a Gaussian if it has zero mean AND zero variance. The old behavior (removal if Gaussian has zero mean.) could be retained if specifying -remove_zero_var_gau=1, 3, Fix issue in .
54  *
55  *
56  * Revision 1.13.4.3 2005/07/05 21:28:57 arthchan2003
57  * 1, Merged from HEAD. 2, Remove redundant keyword in cont_mgau.
58  *
59  * Revision 1.13.4.2 2005/07/05 06:48:54 arthchan2003
60  * Merged from HEAD.
61  *
62  * Revision 1.14 2005/07/04 20:57:53 dhdfu
63  * Finally remove the "temporary hack" for the endpointer, and do
64  * everything in logs3 domain. Should make it faster and less likely to
65  * crash on Alphas.
66  *
67  * Actually it kind of duplicates the existing GMM computation functions,
68  * but it is slightly different (see the comment in classify.c). I don't
69  * know the rationale for this.
70  *
71  * Revision 1.13.4.1 2005/07/05 05:47:59 arthchan2003
72  * Fixed dox-doc. struct level of documentation are included.
73  *
74  *
75  * Revision 1.13 2005/06/21 18:06:45 arthchan2003
76  *
77  * Log. 1, Fixed Doxygen documentation. 2, Added $Log$
78  * Revision 1.1 2006/04/05 20:27:30 dhdfu
79  * A Great Reorganzation of header files and executables
80  *
81  * Log. 1, Fixed Doxygen documentation. 2, Added Revision 1.15 2006/02/22 16:32:40 arthchan2003
82  * Log. 1, Fixed Doxygen documentation. 2, Added Merged from SPHINX3_5_2_RCI_IRII_BRANCH: 1, Dave's change in 1.18 for removing temp_hack is followed 2, The logic of uninit_compact is changed, by default the code will remove a Gaussian if it has zero mean AND zero variance. The old behavior (removal if Gaussian has zero mean.) could be retained if specifying -remove_zero_var_gau=1, 3, Fix issue in .
83  * Log. 1, Fixed Doxygen documentation. 2, Added
84  *
85  * Revision 1.4 2005/06/13 04:02:55 archan
86  * Fixed most doxygen-style documentation under libs3decoder.
87  *
88  * Revision 1.3 2005/03/30 01:22:46 archan
89  * Fixed mistakes in last updates. Add
90  *
91  *
92  * 20.Apr.2001 RAH (rhoughton@mediasite.com, ricky.houghton@cs.cmu.edu)
93  * Added mgau_free to free memory allocated by mgau_init()
94  * 15-Dec-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
95  * Added mgau_model_t.{frm_sen_eval,frm_gau_eval}.
96  * Added mgau_var_nzvec_floor().
97 
98  *
99  * 28-Mar-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
100  * Started.
101  */
102 
103 
104 #ifndef _S3_CONT_MGAU_H_
105 #define _S3_CONT_MGAU_H_
106 
107 #include <s3types.h>
108 #include <logmath.h>
109 
113 #ifdef __cplusplus
114 extern "C" {
115 #endif
116 #if 0
117 } /* Fool Emacs into not indenting things. */
118 #endif
119 
124 #define CONTHMM 10001
125 #define SEMIHMM 10002
127 #define FULL_INT_COMP 20001
128 #define FULL_FLOAT_COMP 20002
129 #define MIX_INT_FLOAT_COMP 20003
131 #define MGAU_MEAN 1
132 #define MGAU_VAR 2
133 #define MGAU_FULLVAR 3
135 #define NO_BSTIDX -1
136 #define NOT_UPDATED -100
157 /* 20040826 ARCHAN:
158  * Introduced hook to the GMM definition to allow gaussian computation using full float
159  * operations. Also added another hook that allows potential use of full covariance matrix.
160  * At this point, full covariance matrix computation was not fully implemented.
161  * If comp_type = MIX_INT_FLOAT_COMP, then the interger pointer will be used to store the
162  * mixture weight. It is also important to initialize the logs3 routine separately.
163  * If comp_type = FULL_FLOAT_COMP, then the floating point pointer will be used to store the mixture
164  * weights.
165  */
166 
171 typedef struct {
172  int32 n_comp;
175  int32 bstidx;
176  int32 bstscr;
177  int32 updatetime;
179  /* Definition for mean */
180  float32 **mean;
182  /* Definition for variances */
183  float32 **var;
186  float32 ***fullvar; /* The n_comp (full) variances of the Gaussians. */
187  /* A full co-variance matrix for a single mixture-Gaussian model for one senone */
188  /* Dimension: n_comp * dimension * dimension */
189 
190  /* Definition for the log reciprocal terms */
191  float32 *lrd;
194  /* Definitions for the mixture weights */
195  int32 *mixw;
197  float32 *mixw_f;
199 } mgau_t;
200 
201 
202 
207 typedef struct {
208  int32 n_mgau;
209  int32 max_comp;
210  int32 veclen;
212  float64 distfloor;
214  int32 comp_type;
215  int32 verbose;
217  /* Used only in the flat lexicon decoder, statistics */
218  int32 frm_sen_eval;
219  int32 frm_gau_eval;
223  int32 gau_type;
226  logmath_t *logmath;
227 } mgau_model_t;
228 
229 
257 #define mgau_n_mgau(g) ((g)->n_mgau)
258 #define mgau_max_comp(g) ((g)->max_comp)
259 #define mgau_veclen(g) ((g)->veclen)
260 #define mgau_n_comp(g,m) ((g)->mgau[m].n_comp)
261 #define mgau_mean(g,m,c) ((g)->mgau[m].mean[c])
262 #define mgau_var(g,m,c) ((g)->mgau[m].var[c])
263 #define mgau_fullvar(g,m,c) ((g)->mgau[m].fullvar[c])
264 #define mgau_mixw(g,m,c) ((g)->mgau[m].mixw[c])
265 #define mgau_mixw_f(g,m,c) ((g)->mgau[m].mixw_f[c])
266 #define mgau_lrd(g,m,c) ((g)->mgau[m].lrd[c])
267 #define mgau_lrdi(g,m,c) ((g)->mgau[m].lrdi[c])
268 #define mgau_frm_sen_eval(g) ((g)->frm_sen_eval)
269 #define mgau_frm_gau_eval(g) ((g)->frm_gau_eval)
270 #define mgau_frm_cisen_eval(g) ((g)->frm_ci_sen_eval)
271 #define mgau_frm_cigau_eval(g) ((g)->frm_ci_gau_eval)
272 
284 mgau_model_t *
285 mgau_init (const char *meanfile,
286  const char *varfile,
287  float64 varfloor,
288  const char *mixwfile,
289  float64 mixwfloor,
290  int32 precomp,
293  const char* senmgau,
295  int32 comp_type,
296  logmath_t *logmath);
297 
298 
304  float64 floor
305  );
306 
307 
315 /* The hybrid integer and floating point implementation of GMM computation */
316 
318 int32 mgau_eval (mgau_model_t *g,
319  int32 m,
320  int32 *active_comp,
323  float32 *x,
324  int32 fr,
325  int32 bUpdBstIdx
326  );
327 
334 int32 mgau_comp_eval (mgau_model_t *g,
335  int32 s,
336  float32 *x,
337  int32 *score
338  );
339 
345 int32 mgau_dump (mgau_model_t *g,
346  int32 type
349  );
350 
355 void mgau_free (mgau_model_t *g
356  );
357 
358 
364  const char* mean_file_name
365  );
366 
367 #if 0
368 { /* Stop indent from complaining */
369 #endif
370 #ifdef __cplusplus
371 }
372 #endif
373 
374 
375 #endif