PocketSphinx  0.6
ms_gauden.c
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  * gauden.c -- gaussian density module.
39  *
40  ***********************************************
41  * CMU ARPA Speech Project
42  *
43  * Copyright (c) 1996 Carnegie Mellon University.
44  * ALL RIGHTS RESERVED.
45  ***********************************************
46  *
47  * HISTORY
48  * $Log$
49  * Revision 1.7 2006/02/22 17:09:55 arthchan2003
50  * Merged from SPHINX3_5_2_RCI_IRII_BRANCH: 1, Followed Dave's change, keep active to be uint8 instead int8 in gauden_dist_norm.\n 2, Introdued gauden_dump and gauden_dump_ind. This allows debugging of ms_gauden routine. \n 3, Introduced gauden_free, this fixed some minor memory leaks. \n 4, gauden_init accept an argument precompute to specify whether the distance is pre-computed or not.\n 5, Added license. \n 6, Fixed dox-doc.
51  *
52  *
53  * Revision 1.5.4.7 2006/01/16 19:45:59 arthchan2003
54  * Change the gaussian density dumping routine to a function.
55  *
56  * Revision 1.5.4.6 2005/10/09 19:51:05 arthchan2003
57  * Followed Dave's changed in the trunk.
58  *
59  * Revision 1.5.4.5 2005/09/25 18:54:20 arthchan2003
60  * Added a flag to turn on and off precomputation.
61  *
62  * Revision 1.6 2005/10/05 00:31:14 dhdfu
63  * Make int8 be explicitly signed (signedness of 'char' is
64  * architecture-dependent). Then make a bunch of things use uint8 where
65  * signedness is unimportant, because on the architecture where 'char' is
66  * unsigned, it is that way for a reason (signed chars are slower).
67  *
68  * Revision 1.5.4.4 2005/09/07 23:29:07 arthchan2003
69  * Added FIXME warning.
70  *
71  * Revision 1.5.4.3 2005/09/07 23:25:10 arthchan2003
72  * 1, Behavior changes of cont_mgau, instead of remove Gaussian with zero variance vector before flooring, now remove Gaussian with zero mean and variance before flooring. Notice that this is not yet synchronize with ms_mgau. 2, Added warning message in multi-stream gaussian distribution.
73  *
74  * Revision 1.5.4.2 2005/08/03 18:53:44 dhdfu
75  * Add memory deallocation functions. Also move all the initialization
76  * of ms_mgau_model_t into ms_mgau_init (duh!), which entails removing it
77  * from decode_anytopo and friends.
78  *
79  * Revision 1.5.4.1 2005/07/20 19:39:01 arthchan2003
80  * Added licences in ms_* series of code.
81  *
82  * Revision 1.5 2005/06/21 18:55:09 arthchan2003
83  * 1, Add comments to describe this modules, 2, Fixed doxygen documentation. 3, Added $ keyword.
84  *
85  * Revision 1.3 2005/03/30 01:22:47 archan
86  * Fixed mistakes in last updates. Add
87  *
88  *
89  * 20-Dec-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
90  * Changed gauden_param_read to use the new libio/bio_fread functions.
91  *
92  * 26-Sep-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
93  * Added gauden_mean_reload() for application of MLLR; and correspondingly
94  * made gauden_param_read allocate memory for parameter only if not
95  * already allocated.
96  *
97  * 09-Sep-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
98  * Interleaved two density computations for speed improvement.
99  *
100  * 19-Aug-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
101  * Added compute_dist_all special case for improving speed.
102  *
103  * 26-Jan-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
104  * Added check for underflow and floor insertion in gauden_dist.
105  *
106  * 20-Jan-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
107  * Added active argument to gauden_dist_norm and gauden_dist_norm_global,
108  * and made the latter a static function.
109  *
110  * 07-Nov-95 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
111  * Initial version created.
112  * Very liberally borrowed/adapted from Eric's S3 trainer implementation.
113  */
114 
115 /* System headers. */
116 #include <assert.h>
117 #include <string.h>
118 #include <math.h>
119 #include <float.h>
120 
121 /* SphinxBase headers. */
122 #include <sphinxbase/bio.h>
123 #include <sphinxbase/err.h>
124 #include <sphinxbase/ckd_alloc.h>
125 
126 /* Local headesr. */
127 #include "ms_gauden.h"
128 
129 #define GAUDEN_PARAM_VERSION "1.0"
130 
131 #ifndef M_PI
132 #define M_PI 3.1415926535897932385e0
133 #endif
134 
135 #define WORST_DIST (int32)(0x80000000)
136 
137 void
139 {
140  int32 c;
141 
142  for (c = 0; c < g->n_mgau; c++)
143  gauden_dump_ind(g, c);
144 }
145 
146 
147 void
148 gauden_dump_ind(const gauden_t * g, int senidx)
149 {
150  int32 f, d, i;
151 
152  for (f = 0; f < g->n_feat; f++) {
153  E_INFO("Codebook %d, Feature %d (%dx%d):\n",
154  senidx, f, g->n_density, g->featlen[f]);
155 
156  for (d = 0; d < g->n_density; d++) {
157  printf("m[%3d]", d);
158  for (i = 0; i < g->featlen[f]; i++)
159  printf(" %7.4f", MFCC2FLOAT(g->mean[senidx][f][d][i]));
160  printf("\n");
161  }
162  printf("\n");
163 
164  for (d = 0; d < g->n_density; d++) {
165  printf("v[%3d]", d);
166  for (i = 0; i < g->featlen[f]; i++)
167  printf(" %d", (int)g->var[senidx][f][d][i]);
168  printf("\n");
169  }
170  printf("\n");
171 
172  for (d = 0; d < g->n_density; d++)
173  printf("d[%3d] %d\n", d, (int)g->det[senidx][f][d]);
174  }
175  fflush(stderr);
176 }
177 
178 static int32
179 gauden_param_read(float32 ***** out_param, /* Alloc space iff *out_param == NULL */
180  int32 * out_n_mgau,
181  int32 * out_n_feat,
182  int32 * out_n_density,
183  int32 ** out_veclen, const char *file_name)
184 {
185  char tmp;
186  FILE *fp;
187  int32 i, j, k, l, n, blk;
188  int32 n_mgau;
189  int32 n_feat;
190  int32 n_density;
191  int32 *veclen;
192  int32 byteswap, chksum_present;
193  float32 ****out;
194  float32 *buf;
195  char **argname, **argval;
196  uint32 chksum;
197 
198  E_INFO("Reading mixture gaussian parameter: %s\n", file_name);
199 
200  if ((fp = fopen(file_name, "rb")) == NULL)
201  E_FATAL_SYSTEM("Failed to open file '%s' for reading", file_name);
202 
203  /* Read header, including argument-value info and 32-bit byteorder magic */
204  if (bio_readhdr(fp, &argname, &argval, &byteswap) < 0)
205  E_FATAL("Failed to read header from file '%s'\n", file_name);
206 
207  /* Parse argument-value list */
208  chksum_present = 0;
209  for (i = 0; argname[i]; i++) {
210  if (strcmp(argname[i], "version") == 0) {
211  if (strcmp(argval[i], GAUDEN_PARAM_VERSION) != 0)
212  E_WARN("Version mismatch(%s): %s, expecting %s\n",
213  file_name, argval[i], GAUDEN_PARAM_VERSION);
214  }
215  else if (strcmp(argname[i], "chksum0") == 0) {
216  chksum_present = 1; /* Ignore the associated value */
217  }
218  }
219  bio_hdrarg_free(argname, argval);
220  argname = argval = NULL;
221 
222  chksum = 0;
223 
224  /* #Codebooks */
225  if (bio_fread(&n_mgau, sizeof(int32), 1, fp, byteswap, &chksum) != 1)
226  E_FATAL("fread(%s) (#codebooks) failed\n", file_name);
227  *out_n_mgau = n_mgau;
228 
229  /* #Features/codebook */
230  if (bio_fread(&n_feat, sizeof(int32), 1, fp, byteswap, &chksum) != 1)
231  E_FATAL("fread(%s) (#features) failed\n", file_name);
232  *out_n_feat = n_feat;
233 
234  /* #Gaussian densities/feature in each codebook */
235  if (bio_fread(&n_density, sizeof(int32), 1, fp, byteswap, &chksum) != 1)
236  E_FATAL("fread(%s) (#density/codebook) failed\n", file_name);
237  *out_n_density = n_density;
238 
239  /* #Dimensions in each feature stream */
240  veclen = ckd_calloc(n_feat, sizeof(uint32));
241  *out_veclen = veclen;
242  if (bio_fread(veclen, sizeof(int32), n_feat, fp, byteswap, &chksum) !=
243  n_feat)
244  E_FATAL("fread(%s) (feature-lengths) failed\n", file_name);
245 
246  /* blk = total vector length of all feature streams */
247  for (i = 0, blk = 0; i < n_feat; i++)
248  blk += veclen[i];
249 
250  /* #Floats to follow; for the ENTIRE SET of CODEBOOKS */
251  if (bio_fread(&n, sizeof(int32), 1, fp, byteswap, &chksum) != 1)
252  E_FATAL("fread(%s) (total #floats) failed\n", file_name);
253  if (n != n_mgau * n_density * blk) {
254  E_FATAL
255  ("%s: #mfcc_ts(%d) doesn't match dimensions: %d x %d x %d\n",
256  file_name, n, n_mgau, n_density, blk);
257  }
258 
259  /* Allocate memory for mixture gaussian densities if not already allocated */
260  if (!(*out_param)) {
261  out = (float32 ****) ckd_calloc_3d(n_mgau, n_feat, n_density,
262  sizeof(float32 *));
263  buf = (float32 *) ckd_calloc(n, sizeof(float32));
264  for (i = 0, l = 0; i < n_mgau; i++) {
265  for (j = 0; j < n_feat; j++) {
266  for (k = 0; k < n_density; k++) {
267  out[i][j][k] = &buf[l];
268  l += veclen[j];
269  }
270  }
271  }
272  }
273  else {
274  out = (float32 ****) *out_param;
275  buf = out[0][0][0];
276  }
277 
278  /* Read mixture gaussian densities data */
279  if (bio_fread(buf, sizeof(float32), n, fp, byteswap, &chksum) != n)
280  E_FATAL("fread(%s) (densitydata) failed\n", file_name);
281 
282  if (chksum_present)
283  bio_verify_chksum(fp, byteswap, chksum);
284 
285  if (fread(&tmp, 1, 1, fp) == 1)
286  E_FATAL("More data than expected in %s\n", file_name);
287 
288  fclose(fp);
289 
290  *out_param = out;
291 
292  E_INFO("%d codebook, %d feature, size: \n", n_mgau, n_feat);
293  for (i = 0; i < n_feat; i++)
294  E_INFO(" %dx%d\n", n_density, veclen[i]);
295 
296  return 0;
297 }
298 
299 static void
300 gauden_param_free(mfcc_t **** p)
301 {
302  ckd_free(p[0][0][0]);
303  ckd_free_3d(p);
304 }
305 
306 /*
307  * Some of the gaussian density computation can be carried out in advance:
308  * log(determinant) calculation,
309  * 1/(2*var) in the exponent,
310  * NOTE; The density computation is performed in log domain.
311  */
312 static int32
313 gauden_dist_precompute(gauden_t * g, logmath_t *lmath, float32 varfloor)
314 {
315  int32 i, m, f, d, flen;
316  mfcc_t *meanp;
317  mfcc_t *varp;
318  mfcc_t *detp;
319  int32 floored;
320 
321  floored = 0;
322  /* Allocate space for determinants */
323  g->det = ckd_calloc_3d(g->n_mgau, g->n_feat, g->n_density, sizeof(***g->det));
324 
325  for (m = 0; m < g->n_mgau; m++) {
326  for (f = 0; f < g->n_feat; f++) {
327  flen = g->featlen[f];
328 
329  /* Determinants for all variance vectors in g->[m][f] */
330  for (d = 0, detp = g->det[m][f]; d < g->n_density; d++, detp++) {
331  *detp = 0;
332  for (i = 0, varp = g->var[m][f][d], meanp = g->mean[m][f][d];
333  i < flen; i++, varp++, meanp++) {
334  float32 *fvarp = (float32 *)varp;
335 
336 #ifdef FIXED_POINT
337  float32 *fmp = (float32 *)meanp;
338  *meanp = FLOAT2MFCC(*fmp);
339 #endif
340  if (*fvarp < varfloor) {
341  *fvarp = varfloor;
342  ++floored;
343  }
344  *detp += (mfcc_t)logmath_log(lmath,
345  1.0 / sqrt(*fvarp * 2.0 * M_PI));
346  /* Precompute this part of the exponential */
347  *varp = (mfcc_t)logmath_ln_to_log(lmath,
348  (1.0 / (*fvarp * 2.0)));
349  }
350  }
351  }
352  }
353 
354  E_INFO("%d variance values floored\n", floored);
355 
356  return 0;
357 }
358 
359 
360 gauden_t *
361 gauden_init(char const *meanfile, char const *varfile, float32 varfloor, logmath_t *lmath)
362 {
363  int32 i, m, f, d, *flen;
364  float32 ****fgau;
365  gauden_t *g;
366 
367  assert(meanfile != NULL);
368  assert(varfile != NULL);
369  assert(varfloor > 0.0);
370 
371  g = (gauden_t *) ckd_calloc(1, sizeof(gauden_t));
372  g->lmath = lmath;
373 
374  /* Read means and (diagonal) variances for all mixture gaussians */
375  fgau = NULL;
376  gauden_param_read(&fgau, &g->n_mgau, &g->n_feat, &g->n_density,
377  &g->featlen, meanfile);
378  g->mean = (mfcc_t ****)fgau;
379  fgau = NULL;
380  gauden_param_read(&fgau, &m, &f, &d, &flen, varfile);
381  g->var = (mfcc_t ****)fgau;
382 
383  /* Verify mean and variance parameter dimensions */
384  if ((m != g->n_mgau) || (f != g->n_feat) || (d != g->n_density))
385  E_FATAL
386  ("Mixture-gaussians dimensions for means and variances differ\n");
387  for (i = 0; i < g->n_feat; i++)
388  if (g->featlen[i] != flen[i])
389  E_FATAL("Feature lengths for means and variances differ\n");
390  ckd_free(flen);
391 
392  /* Floor variances and precompute variance determinants */
393  gauden_dist_precompute(g, lmath, varfloor);
394 
395  return g;
396 }
397 
398 void
400 {
401  if (g == NULL)
402  return;
403  if (g->mean)
404  gauden_param_free(g->mean);
405  if (g->var)
406  gauden_param_free(g->var);
407  if (g->det)
408  ckd_free_3d(g->det);
409  if (g->featlen)
410  ckd_free(g->featlen);
411  ckd_free(g);
412 }
413 
414 /* See compute_dist below */
415 static int32
416 compute_dist_all(gauden_dist_t * out_dist, mfcc_t* obs, int32 featlen,
417  mfcc_t ** mean, mfcc_t ** var, mfcc_t * det,
418  int32 n_density)
419 {
420  int32 i, d;
421 
422  for (d = 0; d < n_density; ++d) {
423  mfcc_t *m;
424  mfcc_t *v;
425  mfcc_t dval;
426 
427  m = mean[d];
428  v = var[d];
429  dval = det[d];
430 
431  for (i = 0; i < featlen; i++) {
432  mfcc_t diff;
433 #ifdef FIXED_POINT
434  /* Have to check for underflows here. */
435  mfcc_t pdval = dval;
436  diff = obs[i] - m[i];
437  dval -= MFCCMUL(MFCCMUL(diff, diff), v[i]);
438  if (dval > pdval) {
439  dval = WORST_SCORE;
440  break;
441  }
442 #else
443  diff = obs[i] - m[i];
444  /* The compiler really likes this to be a single
445  * expression, for whatever reason. */
446  dval -= diff * diff * v[i];
447 #endif
448  }
449 
450  out_dist[d].dist = dval;
451  out_dist[d].id = d;
452  }
453 
454  return 0;
455 }
456 
457 
458 /*
459  * Compute the top-N closest gaussians from the chosen set (mgau,feat)
460  * for the given input observation vector.
461  */
462 static int32
463 compute_dist(gauden_dist_t * out_dist, int32 n_top,
464  mfcc_t * obs, int32 featlen,
465  mfcc_t ** mean, mfcc_t ** var, mfcc_t * det,
466  int32 n_density)
467 {
468  int32 i, j, d;
469  gauden_dist_t *worst;
470 
471  /* Special case optimization when n_density <= n_top */
472  if (n_top >= n_density)
473  return (compute_dist_all
474  (out_dist, obs, featlen, mean, var, det, n_density));
475 
476  for (i = 0; i < n_top; i++)
477  out_dist[i].dist = WORST_DIST;
478  worst = &(out_dist[n_top - 1]);
479 
480  for (d = 0; d < n_density; d++) {
481  mfcc_t *m;
482  mfcc_t *v;
483  mfcc_t dval;
484 
485  m = mean[d];
486  v = var[d];
487  dval = det[d];
488 
489  for (i = 0; (i < featlen) && (dval >= worst->dist); i++) {
490  mfcc_t diff;
491 #ifdef FIXED_POINT
492  /* Have to check for underflows here. */
493  mfcc_t pdval = dval;
494  diff = obs[i] - m[i];
495  dval -= MFCCMUL(MFCCMUL(diff, diff), v[i]);
496  if (dval > pdval) {
497  dval = WORST_SCORE;
498  break;
499  }
500 #else
501  diff = obs[i] - m[i];
502  /* The compiler really likes this to be a single
503  * expression, for whatever reason. */
504  dval -= diff * diff * v[i];
505 #endif
506  }
507 
508  if ((i < featlen) || (dval < worst->dist)) /* Codeword d worse than worst */
509  continue;
510 
511  /* Codeword d at least as good as worst so far; insert in the ordered list */
512  for (i = 0; (i < n_top) && (dval < out_dist[i].dist); i++);
513  assert(i < n_top);
514  for (j = n_top - 1; j > i; --j)
515  out_dist[j] = out_dist[j - 1];
516  out_dist[i].dist = dval;
517  out_dist[i].id = d;
518  }
519 
520  return 0;
521 }
522 
523 
524 /*
525  * Compute distances of the input observation from the top N codewords in the given
526  * codebook (g->{mean,var}[mgau]). The input observation, obs, includes vectors for
527  * all features in the codebook.
528  */
529 int32
531  int mgau, int32 n_top, mfcc_t** obs, gauden_dist_t ** out_dist)
532 {
533  int32 f;
534 
535  assert((n_top > 0) && (n_top <= g->n_density));
536 
537  for (f = 0; f < g->n_feat; f++) {
538  compute_dist(out_dist[f], n_top,
539  obs[f], g->featlen[f],
540  g->mean[mgau][f], g->var[mgau][f], g->det[mgau][f],
541  g->n_density);
542  E_DEBUG(3, ("Top CW(%d,%d) = %d %d\n", mgau, f, out_dist[f][0].id,
543  (int)out_dist[f][0].dist >> SENSCR_SHIFT));
544  }
545 
546  return 0;
547 }
548 
549 int32
550 gauden_mllr_transform(gauden_t *g, ps_mllr_t *mllr, cmd_ln_t *config)
551 {
552  int32 i, m, f, d, *flen;
553  float32 ****fgau;
554 
555  /* Free data if already here */
556  if (g->mean)
557  gauden_param_free(g->mean);
558  if (g->var)
559  gauden_param_free(g->var);
560  if (g->det)
561  ckd_free_3d(g->det);
562  if (g->featlen)
563  ckd_free(g->featlen);
564  g->mean = NULL;
565  g->var = NULL;
566  g->det = NULL;
567  g->featlen = NULL;
568 
569  /* Reload means and variances (un-precomputed). */
570  fgau = NULL;
571  gauden_param_read(&fgau, &g->n_mgau, &g->n_feat, &g->n_density,
572  &g->featlen, cmd_ln_str_r(config, "-mean"));
573  g->mean = (mfcc_t ****)fgau;
574  fgau = NULL;
575  gauden_param_read(&fgau, &m, &f, &d, &flen, cmd_ln_str_r(config, "-var"));
576  g->var = (mfcc_t ****)fgau;
577 
578  /* Verify mean and variance parameter dimensions */
579  if ((m != g->n_mgau) || (f != g->n_feat) || (d != g->n_density))
580  E_FATAL
581  ("Mixture-gaussians dimensions for means and variances differ\n");
582  for (i = 0; i < g->n_feat; i++)
583  if (g->featlen[i] != flen[i])
584  E_FATAL("Feature lengths for means and variances differ\n");
585  ckd_free(flen);
586 
587  /* Transform codebook for each stream s */
588  for (i = 0; i < g->n_mgau; ++i) {
589  for (f = 0; f < g->n_feat; ++f) {
590  float64 *temp;
591  temp = (float64 *) ckd_calloc(g->featlen[f], sizeof(float64));
592  /* Transform each density d in selected codebook */
593  for (d = 0; d < g->n_density; d++) {
594  int l;
595  for (l = 0; l < g->featlen[f]; l++) {
596  temp[l] = 0.0;
597  for (m = 0; m < g->featlen[f]; m++) {
598  /* FIXME: For now, only one class, hence the zeros below. */
599  temp[l] += mllr->A[f][0][l][m] * g->mean[i][f][d][m];
600  }
601  temp[l] += mllr->b[f][0][l];
602  }
603 
604  for (l = 0; l < g->featlen[f]; l++) {
605  g->mean[i][f][d][l] = (float32) temp[l];
606  g->var[i][f][d][l] *= mllr->h[f][0][l];
607  }
608  }
609  ckd_free(temp);
610  }
611  }
612 
613  /* Re-precompute (if we aren't adapting variances this isn't
614  * actually necessary...) */
615  gauden_dist_precompute(g, g->lmath, cmd_ln_float32_r(config, "-varfloor"));
616  return 0;
617 }
void gauden_dump(const gauden_t *g)
Dump the definitionn of Gaussian distribution.
Definition: ms_gauden.c:138
logmath_t * lmath
log math computation
Definition: ms_gauden.h:90
int32 n_density
Number gaussian densities in each codebook-feature stream.
Definition: ms_gauden.h:93
void gauden_free(gauden_t *g)
Release memory allocated by gauden_init.
Definition: ms_gauden.c:399
int32 id
Index of codeword (gaussian density)
Definition: ms_gauden.h:75
mfcc_t *** det
log(determinant) for each variance vector; actually, log(sqrt(2*pi*det))
Definition: ms_gauden.h:88
Structure to store distance (density) values for a given input observation wrt density values in some...
Definition: ms_gauden.h:74
float32 *** h
Diagonal transformation of variances.
Definition: acmod.h:89
int32 gauden_mllr_transform(gauden_t *s, ps_mllr_t *mllr, cmd_ln_t *config)
Transform Gaussians according to an MLLR matrix (or, eventually, more).
Definition: ms_gauden.c:550
float32 *** b
Bias part of mean transformations.
Definition: acmod.h:88
gauden_t * gauden_init(char const *meanfile, char const *varfile, float32 varfloor, logmath_t *lmath)
Read mixture gaussian codebooks from the given files.
Definition: ms_gauden.c:361
#define WORST_SCORE
Large "bad" score.
Definition: hmm.h:88
int32 * featlen
feature length for each feature
Definition: ms_gauden.h:94
int32 n_mgau
Number codebooks.
Definition: ms_gauden.h:91
(Sphinx 3.0 specific) Gaussian density module.
Feature space linear transform structure.
Definition: acmod.h:82
float32 **** A
Rotation part of mean transformations.
Definition: acmod.h:87
#define SENSCR_SHIFT
Shift count for senone scores.
Definition: hmm.h:77
mfcc_t **** mean
mean[codebook][feature][codeword] vector
Definition: ms_gauden.h:86
int32 n_feat
Number feature streams in each codebook.
Definition: ms_gauden.h:92
mfcc_t dist
Density value for input observation wrt above codeword; NOTE: result in logs3 domain, but var_t used for speed.
Definition: ms_gauden.h:76
void gauden_dump_ind(const gauden_t *g, int senidx)
Dump the definition of Gaussian distribution of a particular index to the standard output stream...
Definition: ms_gauden.c:148
Multivariate gaussian mixture density parameters.
Definition: ms_gauden.h:85
int32 gauden_dist(gauden_t *g, int mgau, int n_top, mfcc_t **obs, gauden_dist_t **out_dist)
Compute gaussian density values for the given input observation vector wrt the specified mixture gaus...
mfcc_t **** var
like mean; diagonal covariance vector only
Definition: ms_gauden.h:87