vector.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  * vector.h -- vector routines.
39  *
40  * **********************************************
41  * CMU ARPA Speech Project
42  *
43  * Copyright (c) 1997 Carnegie Mellon University.
44  * ALL RIGHTS RESERVED.
45  * **********************************************
46  *
47  * HISTORY
48  *
49  * 10-Mar-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
50  * Added vector_accum(), vector_vqlabel(), and vector_vqgen().
51  *
52  * 09-Mar-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
53  * Added vector_is_zero(), vector_cmp(), and vector_dist_eucl().
54  * Changed the name vector_dist_eval to vector_dist_maha.
55  *
56  * 30-Dec-95 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
57  * Created from Eric Thayer's version.
58  */
59 
60 
61 #ifndef _S3_VECTOR_H_
62 #define _S3_VECTOR_H_
63 
67 #include <stdio.h>
68 
69 #include <s3types.h>
70 #include <logmath.h>
71 
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75 #if 0
76 } /* Fool Emacs into not indenting things. */
77 #endif
78 
79 typedef float32 *vector_t;
80 
81 
82 /* Why do these belong here?? */
86 typedef struct {
87  int32 r;
88  int32 c;
89 } arraysize_t;
90 
95 typedef struct {
96  int32 x;
97  int32 y;
98 } point_t;
99 
104 typedef struct {
105  float32 x;
106  float32 y;
107 } fpoint_t;
117 void vector_floor(vector_t v,
118  int32 dim,
119  float64 f
120  );
121 
122 
124 void vector_nz_floor(vector_t v, int32 dim, float64 f);
125 
126 
128 int32 vector_normalize(vector_t v,
129  uint32 dim
130  );
131 
132 
138 float64 vector_sum_norm(vector_t v, int32 dim);
139 
140 
143 void vector_print(FILE *fp, vector_t v, int32 dim);
144 
145 
148 int32 vector_is_zero (float32 *vec,
149  int32 len
150  );
151 
153 int32 vector_is_nan (float32 *vec,
154  int32 len
155  );
156 
163 int32 vector_maxcomp_int32 (int32 *val, int32 len);
164 int32 vector_mincomp_int32 (int32 *val, int32 len);
165 int32 vector_maxcomp_float32 (float32 *val, int32 len);
166 int32 vector_mincomp_float32 (float32 *val, int32 len);
167 
168 
170 void vector_accum (float32 *dst,
171  float32 *src,
172  int32 len
173  );
174 
179 int32 vector_cmp (float32 *v1, float32 *v2,
180  int32 len
181  );
182 
187 int32 vector_mean (float32 *mean,
189  float32 **data,
190  int32 n_vec,
191  int32 n_dim
192  );
193 
197 float64 vector_dist_eucl (float32 *v1, float32 *v2,
198  int32 len
199  );
200 
215 float64
216 vector_maha_precomp (float32 *var,
217  int32 len
218  );
219 
226 float64
227 vector_dist_maha (float32 *vec,
229  float32 *mean,
230  float32 *varinv,
232  float64 norm,
234  int32 len
235  );
236 
243 float64 vector_vqgen (float32 **data,
244  int32 rows,
245  int32 cols,
246  int32 vqrows,
247  float64 epsilon,
251  int32 maxiter,
252  float32 **mean,
254  int32 *map,
258  int32 seed
264  );
265 
270 int32 vector_vqlabel (float32 *vec,
271  float32 **mean,
272  int32 rows,
273  int32 cols,
274  float64 *sqerr
276  );
277 
282 float64 vector_pdf_entropy (float32 *p,
283  int32 len
284  );
285 
290 float64 vector_pdf_cross_entropy (float32 *p1,
291  float32 *p2,
292  int32 len);
293 
298 typedef struct {
299  int32 n_gau;
300  int32 veclen;
301  float32 **mean;
302  float32 **var;
303  float32 *lrd;
304  float64 distfloor;
307 
308 
314  int32 n_gau, int32 veclen, logmath_t *logmath);
315 void vector_gautbl_free (vector_gautbl_t *gautbl);
316 
317 
322  float64 floor
323  );
324 
330 
331 
338 void
340  int32 offset,
341  int32 count,
342  float32 *x,
343  int32 *scr,
346  logmath_t *logmath
347  );
348 
349 #if 0
350 { /* Stop indent from complaining */
351 #endif
352 #ifdef __cplusplus
353 }
354 #endif
355 
356 #endif /* VECTOR_H */
357 
358 
359 /*
360  * Log record. Maintained by RCS.
361  *
362  * $Log$
363  * Revision 1.2 2006/04/19 18:59:37 arthchan2003
364  * Check whether nan appear explicitly in the acoustic models and vector.c, this will make gausubvq works. This shouldn't break the VQ generated in the past. Because if nan exists in any of the past models, gausubvq will give abnormal results and some of us should have observed.
365  *
366  * Revision 1.1 2006/04/05 20:27:30 dhdfu
367  * A Great Reorganzation of header files and executables
368  *
369  * Revision 1.13 2006/02/22 20:35:17 arthchan2003
370  * Merge from branch SPHINX3_5_2_RCI_IRII_BRANCH:
371  * 1, Not allocated lrd in vector.c because its only consumer subvq.c has done it. 2, Fixed dox-doc.
372  *
373  * Revision 1.12.4.1 2005/07/05 06:25:40 arthchan2003
374  * Fixed dox-doc.
375  *
376  * Revision 1.12 2005/06/21 21:00:44 arthchan2003
377  * Add a statistics inventory structure, it takes care of 1, counters, 2, timers. Interfaces are provided to allow convenient clearing and updating of structures
378  *
379  * Revision 1.2 2005/06/13 04:02:57 archan
380  * Fixed most doxygen-style documentation under libs3decoder.
381  *
382  * Revision 1.1.1.1 2005/03/24 15:24:00 archan
383  * 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.
384  *
385  * Revision 1.11 2004/12/06 10:52:01 arthchan2003
386  * Enable doxygen documentation in libs3decoder
387  *
388  * Revision 1.10 2004/12/05 12:01:31 arthchan2003
389  * 1, move libutil/libutil.h to s3types.h, seems to me not very nice to have it in every files. 2, Remove warning messages of main_align.c 3, Remove warning messages in chgCase.c
390  *
391  * Revision 1.9 2004/11/16 05:13:18 arthchan2003
392  * 1, s3cipid_t is upgraded to int16 because we need that, I already check that there are no magic code using 8-bit s3cipid_t
393  * 2, Refactor the ep code and put a lot of stuffs into fe.c (should be renamed to something else.
394  * 3, Check-in codes of wave2feat and cepview. (cepview will not dump core but Evandro will kill me)
395  * 4, Make the same command line frontends for decode, align, dag, astar, allphone, decode_anytopo and ep . Allow the use a file to configure the application.
396  * 5, Make changes in test such that test-allphone becomes a repeatability test.
397  * 6, cepview, wave2feat and decode_anytopo will not be installed in 3.5 RCIII
398  * (Known bugs after this commit)
399  * 1, decode_anytopo has strange bugs in some situations that it cannot find the end of the lattice. This is urgent.
400  * 2, default argument file's mechanism is not yet supported, we need to fix it.
401  * 3, the bug discovered by SonicFoundry is still not fixed.
402  *
403  * Revision 1.8 2004/11/13 21:25:19 arthchan2003
404  * 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
405  *
406  * Revision 1.7 2004/09/13 08:13:26 arthchan2003
407  * update copyright notice from 200x to 2004
408  *
409  * Revision 1.6 2004/07/27 21:53:05 yitao
410  *
411  * weird. i only changed kb.c to fix a small bug. why so many changes?
412  *
413  * Revision 1.5 2004/07/21 06:12:47 arthchan2003
414  * add precompiler directive __cplusplus to all header files
415  *
416  * Revision 1.2 2004/07/21 05:11:46 archan
417  * all sphinx 3.4 files with proper extern C headers
418  *
419  * Revision 1.1 2004/07/15 08:21:19 archan
420  * All header files for sphinx3.4
421  *
422  * Revision 1.4 2004/05/27 22:47:43 arthchan2003
423  * Sphinx 3.4 code commit
424  *
425  * Revision 1.3 2004/03/11 21:47:57 archan
426  * Check-in code for dynamic LM and fixes in Gaussian Selection. Temporarily cover J's change. Waiting for more stable code
427  *
428  * Revision 1.3 2001/12/11 04:40:56 lenzo
429  * License cleanup.
430  *
431  * Revision 1.2 2001/12/04 02:57:47 egouvea
432  * Merged memory leak fixes from RAH (egouvea@cs.cmu.edu)
433  *
434  * Revision 1.1.1.1 2001/01/17 05:17:15 ricky
435  * Initial Import of the s3.3 decoder, has working decodeaudiofile, s3.3_live
436  *
437  * Revision 1.1.1.1 2000/02/28 18:05:54 rkm
438  * Imported Sources
439  *
440  * Revision 1.1.1.1 1999/11/23 20:24:18 rkm
441  * imported sources
442  *
443  * Revision 1.2 1995/10/09 20:55:35 eht
444  * Changes for prim_type.h
445  *
446  * Revision 1.1 1995/08/15 13:44:14 eht
447  * Initial revision
448  *
449  *
450  */