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,
TEST_F(TestBase,LaunchModePreservesEnvironment)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  * senone.h -- Mixture density weights associated with each tied state.
39  *
40  * **********************************************
41  * CMU ARPA Speech Project
42  *
43  * Copyright (c) 1996 Carnegie Mellon University.
44  * ALL RIGHTS RESERVED.
45  * **********************************************
46  *
47  * HISTORY
48  *
49  * $Log$
50  * Revision 1.1  2006/04/05  20:27:30  dhdfu
51  * A Great Reorganzation of header files and executables
52  *
53  * Revision 1.7  2006/02/22 17:27:39  arthchan2003
54  * Merged from SPHINX3_5_2_RCI_IRII_BRANCH: 1, NOT doing truncation in the multi-stream GMM computation \n. 2, Added .s3cont. to be the alias of the old multi-stream GMM computation routine \n. 3, Added license \n.  4, Fixed dox-doc. \n
55  *
56  * Revision 1.6.4.4  2006/01/16 19:47:05  arthchan2003
57  * Removed the truncation of senone probability code.
58  *
59  * Revision 1.6.4.3  2005/08/03 18:53:43  dhdfu
60  * Add memory deallocation functions.  Also move all the initialization
61  * of ms_mgau_model_t into ms_mgau_init (duh!), which entails removing it
62  * from decode_anytopo and friends.
63  *
64  * Revision 1.6.4.2  2005/07/20 19:39:01  arthchan2003
65  * Added licences in ms_* series of code.
66  *
67  * Revision 1.6.4.1  2005/07/05 05:47:59  arthchan2003
68  * Fixed dox-doc. struct level of documentation are included.
69  *
70  * Revision 1.6  2005/06/21 19:00:19  arthchan2003
71  * Add more detail comments  to ms_senone.h
72  *
73  * Revision 1.5  2005/06/21 18:57:31  arthchan2003
74  * 1, Fixed doxygen documentation. 2, Added $ keyword.
75  *
76  * Revision 1.2  2005/06/13 04:02:56  archan
77  * Fixed most doxygen-style documentation under libs3decoder.
78  *
79  * Revision 1.1.1.1  2005/03/24 15:24:00  archan
80  * I found Evandro's suggestion is quite right after yelling at him 2 days later. So I decide to check this in again without any binaries. (I have done make distcheck. ) . Again, this is a candidate for s3.6 and I believe I need to work out 4-5 intermediate steps before I can complete the first prototype.  That's why I keep local copies.
81  *
82  * Revision 1.4  2004/12/06 10:52:01  arthchan2003
83  * Enable doxygen documentation in libs3decoder
84  *
85  * Revision 1.3  2004/11/13 21:25:19  arthchan2003
86  * commit of 1, absolute CI-GMMS , 2, fast CI senone computation using svq, 3, Decrease the number of static variables, 4, fixing the random generator problem of vector_vqgen, 5, move all unused files to NOTUSED
87  *
88  * Revision 1.2  2004/08/31 08:43:47  arthchan2003
89  * Fixing _cpluscplus directive
90  *
91  * Revision 1.1  2004/08/09 00:17:11  arthchan2003
92  * Incorporating s3.0 align, at this point, there are still some small problems in align but they don't hurt. For example, the score doesn't match with s3.0 and the output will have problem if files are piped to /dev/null/. I think we can go for it.
93  *
94  * Revision 1.1  2003/02/14 14:40:34  cbq
95  * Compiles.  Analysis is probably hosed.
96  *
97  * Revision 1.1  2000/04/24 09:39:41  lenzo
98  * s3 import.
99  *
100  *
101  * 13-Dec-95	M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
102  * 		Added senone_eval_all().
103  *
104  * 12-Nov-95	M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
105  * 		Created.
106  */
107 
108 
109 #ifndef _LIBFBS_SENONE_H_
110 #define _LIBFBS_SENONE_H_
111 
112 
113 /* SphinxBase headers. */
114 #include <sphinxbase/err.h>
115 #include <sphinxbase/ckd_alloc.h>
116 #include <sphinxbase/cmd_ln.h>
117 #include <sphinxbase/logmath.h>
118 
119 /* Local headers. */
120 #include "ms_gauden.h"
121 #include "bin_mdef.h"
122 
123 /** \file ms_senone.h
124  *  \brief (Sphinx 3.0 specific) multiple streams senones. used with ms_gauden.h
125  *  In Sphinx 3.0 family of tools, ms_senone is used to combine the Gaussian scores.
126  *  Its existence is crucial in Sphinx 3.0 because 3.0 supports both SCHMM and CDHMM.
127  *  There are optimization scheme for SCHMM (e.g. compute the top-N Gaussian) that is
128  *  applicable to SCHMM than CDHMM.  This is wrapped in senone_eval_all.
129  */
130 
131 #ifdef __cplusplus
132 extern "C" {
133 #endif
134 #if 0
135 } /* Fool Emacs into not indenting things. */
136 #endif
137 
138 typedef uint8 senprob_t;	/**< Senone logs3-probs, truncated to 8 bits */
139 
140 /**
141  * \struct senone_t
142  * \brief 8-bit senone PDF structure.
143  *
144  * 8-bit senone PDF structure.  Senone pdf values are normalized, floored, converted to
145  * logs3 domain, and finally truncated to 8 bits precision to conserve memory space.
146  */
147 typedef struct {
148     senprob_t ***pdf;		/**< gaussian density mixture weights, organized two possible
149                                    ways depending on n_gauden:
150                                    if (n_gauden > 1): pdf[sen][feat][codeword].  Not an
151                                    efficient representation--memory access-wise--but
152                                    evaluating the many codebooks will be more costly.
153                                    if (n_gauden == 1): pdf[feat][codeword][sen].  Optimized
154                                    for the shared-distribution semi-continuous case. */
155     logmath_t *lmath;           /**< log math computation */
156     uint32 n_sen;		/**< Number senones in this set */
157     uint32 n_feat;		/**< Number feature streams */
158     uint32 n_cw;		/**< Number codewords per codebook,stream */
159     uint32 n_gauden;		/**< Number gaussian density codebooks referred to by senones */
160     float32 mixwfloor;		/**< floor applied to each PDF entry */
161     uint32 *mgau;		/**< senone-id -> mgau-id mapping for senones in this set */
162     int32 *featscr;              /**< The feature score for every senone, will be initialized inside senone_eval_all */
163     int32 aw;			/**< Inverse acoustic weight */
164 } senone_t;
165 
166 
167 /**
168  * Load a set of senones (mixing weights and mixture gaussian codebook mappings) from
169  * the given files.  Normalize weights for each codebook, apply the given floor, convert
170  * PDF values to logs3 domain and quantize to 8-bits.
171  * @return pointer to senone structure created.  Caller MUST NOT change its contents.
172  */
173 senone_t *senone_init (gauden_t *g,             /**< In: codebooks */
174                        char const *mixwfile,	/**< In: mixing weights file */
175 		       char const *mgau_mapfile,/**< In: file specifying mapping from each
176 						   senone to mixture gaussian codebook.
177 						   If NULL all senones map to codebook 0 */
178 		       float32 mixwfloor,	/**< In: Floor value for senone weights */
179                        logmath_t *lmath,        /**< In: log math computation */
180                        bin_mdef_t *mdef         /**< In: model definition */
181     );
182 
183 /** Release memory allocated by senone_init. */
184 void senone_free(senone_t *s); /**< In: The senone_t to free */
185 
186 /**
187  * Evaluate the score for the given senone wrt to the given top N gaussian codewords.
188  * @return senone score (in logs3 domain).
189  */
190 int32 senone_eval (senone_t *s, int id,		/**< In: senone for which score desired */
191 		   gauden_dist_t **dist,	/**< In: top N codewords and densities for
192 						   all features, to be combined into
193 						   senone score.  IE, dist[f][i] = i-th
194 						   best <codeword,density> for feaure f */
195 		   int n_top		/**< In: Length of dist[f], for each f */
196     );
197 
198 #if 0
199 { /* Stop indent from complaining */
200 #endif
201 #ifdef __cplusplus
202 }
203 #endif
204 
205 #endif
206