vector.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
00002 /* ====================================================================
00003  * Copyright (c) 1999-2004 Carnegie Mellon University.  All rights
00004  * reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer. 
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  * This work was supported in part by funding from the Defense Advanced 
00019  * Research Projects Agency and the National Science Foundation of the 
00020  * United States of America, and the CMU Sphinx Speech Consortium.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
00023  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00024  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00025  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
00026  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * ====================================================================
00035  *
00036  */
00037 /*
00038  * vector.h -- vector routines.
00039  * 
00040  * **********************************************
00041  * CMU ARPA Speech Project
00042  *
00043  * Copyright (c) 1997 Carnegie Mellon University.
00044  * ALL RIGHTS RESERVED.
00045  * **********************************************
00046  * 
00047  * HISTORY
00048  * 
00049  * 10-Mar-1999  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
00050  *              Added vector_accum(), vector_vqlabel(), and vector_vqgen().
00051  * 
00052  * 09-Mar-1999  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
00053  *              Added vector_is_zero(), vector_cmp(), and vector_dist_eucl().
00054  *              Changed the name vector_dist_eval to vector_dist_maha.
00055  * 
00056  * 30-Dec-95    M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
00057  *              Created from Eric Thayer's version.
00058  */
00059 
00060 
00061 #ifndef _S3_VECTOR_H_
00062 #define _S3_VECTOR_H_
00063 
00067 #include <stdio.h>
00068 
00069 #include <s3types.h>
00070 #include <logmath.h>
00071 
00072 #ifdef __cplusplus
00073 extern "C" {
00074 #endif
00075 #if 0
00076 } /* Fool Emacs into not indenting things. */
00077 #endif
00078 
00079 typedef float32 *vector_t;
00080 
00081 
00082 /* Why do these belong here?? */
00086 typedef struct {
00087     int32 r;            
00088     int32 c;            
00089 } arraysize_t;
00090 
00095 typedef struct {
00096     int32 x;            
00097     int32 y;            
00098 } point_t;
00099 
00104 typedef struct {
00105     float32 x;          
00106     float32 y;          
00107 } fpoint_t;             
00117 void vector_floor(vector_t v,  
00118                   int32 dim,     
00119                   float64 f      
00120     );
00121 
00122 
00124 void vector_nz_floor(vector_t v, int32 dim, float64 f);
00125 
00126 
00128 int32 vector_normalize(vector_t v,  
00129                        uint32 dim    
00130     );
00131 
00132 
00138 float64 vector_sum_norm(vector_t v, int32 dim);
00139 
00140 
00142 S3DECODER_EXPORT
00143 void vector_print(FILE *fp, vector_t v, int32 dim);
00144 
00145 
00147 S3DECODER_EXPORT
00148 int32 vector_is_zero (float32 *vec,     
00149                       int32 len 
00150     );
00151 
00153 int32 vector_is_nan (float32 *vec, 
00154                      int32 len     
00155     );
00156 
00163 int32 vector_maxcomp_int32 (int32 *val, int32 len);
00164 int32 vector_mincomp_int32 (int32 *val, int32 len);
00165 int32 vector_maxcomp_float32 (float32 *val, int32 len);
00166 int32 vector_mincomp_float32 (float32 *val, int32 len);
00167 
00168 
00170 void vector_accum (float32 *dst,        
00171                    float32 *src,        
00172                    int32 len            
00173     );
00174 
00179 int32 vector_cmp (float32 *v1, float32 *v2,     
00180                   int32 len             
00181     );
00182 
00187 int32 vector_mean (float32 *mean,       
00189                    float32 **data,      
00190                    int32 n_vec,         
00191                    int32 n_dim  
00192     );
00193 
00197 float64 vector_dist_eucl (float32 *v1, float32 *v2,     
00198                           int32 len     
00199     );
00200 
00215 float64
00216 vector_maha_precomp (float32 *var,      
00217                      int32 len  
00218     );
00219 
00226 float64
00227 vector_dist_maha (float32 *vec,         
00229                   float32 *mean,        
00230                   float32 *varinv,      
00232                   float64 norm,         
00234                   int32 len             
00235     );
00236 
00242 S3DECODER_EXPORT
00243 float64 vector_vqgen (float32 **data,   
00244                       int32 rows,       
00245                       int32 cols,       
00246                       int32 vqrows,     
00247                       float64 epsilon,  
00251                       int32 maxiter,    
00252                       float32 **mean,   
00254                       int32 *map,       
00258                       int32 seed      
00264     );
00265 
00270 int32 vector_vqlabel (float32 *vec,     
00271                       float32 **mean,   
00272                       int32 rows,       
00273                       int32 cols,       
00274                       float64 *sqerr    
00276     );
00277 
00282 float64 vector_pdf_entropy (float32 *p, 
00283                             int32 len   
00284     );
00285 
00290 float64 vector_pdf_cross_entropy (float32 *p1,
00291                                   float32 *p2,  
00292                                   int32 len);
00293 
00298 typedef struct {
00299     int32 n_gau;        
00300     int32 veclen;       
00301     float32 **mean;     
00302     float32 **var;      
00303     float32 *lrd;       
00304     float64 distfloor;  
00306 } vector_gautbl_t;
00307 
00308 
00313 void vector_gautbl_alloc (vector_gautbl_t *gautbl,
00314                           int32 n_gau, int32 veclen, logmath_t *logmath);
00315 void vector_gautbl_free (vector_gautbl_t *gautbl);
00316 
00317 
00321 void vector_gautbl_var_floor (vector_gautbl_t *gautbl,  
00322                               float64 floor             
00323     );
00324 
00329 void vector_gautbl_maha_precomp (vector_gautbl_t *gau);
00330 
00331 
00338 void
00339 vector_gautbl_eval_logs3 (vector_gautbl_t *gau, 
00340                           int32 offset, 
00341                           int32 count,  
00342                           float32 *x,   
00343                           int32 *scr,   
00346                           logmath_t *logmath
00347     );
00348 
00349 #if 0
00350 { /* Stop indent from complaining */
00351 #endif
00352 #ifdef __cplusplus
00353 }
00354 #endif
00355 
00356 #endif /* VECTOR_H */ 
00357 
00358 
00359 /*
00360  * Log record.  Maintained by RCS.
00361  *
00362  * $Log$
00363  * Revision 1.2  2006/04/19  18:59:37  arthchan2003
00364  * 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.
00365  * 
00366  * Revision 1.1  2006/04/05 20:27:30  dhdfu
00367  * A Great Reorganzation of header files and executables
00368  *
00369  * Revision 1.13  2006/02/22 20:35:17  arthchan2003
00370  * Merge from branch SPHINX3_5_2_RCI_IRII_BRANCH:
00371  * 1, Not allocated lrd in vector.c because its only consumer subvq.c has done it. 2, Fixed dox-doc.
00372  *
00373  * Revision 1.12.4.1  2005/07/05 06:25:40  arthchan2003
00374  * Fixed dox-doc.
00375  *
00376  * Revision 1.12  2005/06/21 21:00:44  arthchan2003
00377  * Add a statistics inventory structure, it takes care of 1, counters, 2, timers. Interfaces are provided to allow convenient clearing and updating of structures
00378  *
00379  * Revision 1.2  2005/06/13 04:02:57  archan
00380  * Fixed most doxygen-style documentation under libs3decoder.
00381  *
00382  * Revision 1.1.1.1  2005/03/24 15:24:00  archan
00383  * 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. 
00384  *
00385  * Revision 1.11  2004/12/06 10:52:01  arthchan2003
00386  * Enable doxygen documentation in libs3decoder
00387  *
00388  * Revision 1.10  2004/12/05 12:01:31  arthchan2003
00389  * 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
00390  *
00391  * Revision 1.9  2004/11/16 05:13:18  arthchan2003
00392  * 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
00393  * 2, Refactor the ep code and put a lot of stuffs into fe.c (should be renamed to something else.
00394  * 3, Check-in codes of wave2feat and cepview. (cepview will not dump core but Evandro will kill me)
00395  * 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.
00396  * 5, Make changes in test such that test-allphone becomes a repeatability test.
00397  * 6, cepview, wave2feat and decode_anytopo will not be installed in 3.5 RCIII
00398  * (Known bugs after this commit)
00399  * 1, decode_anytopo has strange bugs in some situations that it cannot find the end of the lattice. This is urgent.
00400  * 2, default argument file's mechanism is not yet supported, we need to fix it.
00401  * 3, the bug discovered by SonicFoundry is still not fixed.
00402  *
00403  * Revision 1.8  2004/11/13 21:25:19  arthchan2003
00404  * 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
00405  *
00406  * Revision 1.7  2004/09/13 08:13:26  arthchan2003
00407  * update copyright notice from 200x to 2004
00408  *
00409  * Revision 1.6  2004/07/27 21:53:05  yitao
00410  *
00411  * weird.  i only changed kb.c to fix a small bug.  why so many changes?
00412  *
00413  * Revision 1.5  2004/07/21 06:12:47  arthchan2003
00414  * add precompiler directive __cplusplus to all header files
00415  *
00416  * Revision 1.2  2004/07/21 05:11:46  archan
00417  * all sphinx 3.4 files with proper extern C headers
00418  *
00419  * Revision 1.1  2004/07/15 08:21:19  archan
00420  * All header files for sphinx3.4
00421  *
00422  * Revision 1.4  2004/05/27 22:47:43  arthchan2003
00423  * Sphinx 3.4 code commit
00424  *
00425  * Revision 1.3  2004/03/11 21:47:57  archan
00426  * Check-in code for dynamic LM and fixes in Gaussian Selection. Temporarily cover J's change. Waiting for more stable code
00427  *
00428  * Revision 1.3  2001/12/11 04:40:56  lenzo
00429  * License cleanup.
00430  *
00431  * Revision 1.2  2001/12/04 02:57:47  egouvea
00432  * Merged memory leak fixes from RAH  (egouvea@cs.cmu.edu)
00433  *
00434  * Revision 1.1.1.1  2001/01/17 05:17:15  ricky
00435  * Initial Import of the s3.3 decoder, has working decodeaudiofile, s3.3_live
00436  *
00437  * Revision 1.1.1.1  2000/02/28 18:05:54  rkm
00438  * Imported Sources
00439  *
00440  * Revision 1.1.1.1  1999/11/23 20:24:18  rkm
00441  * imported sources
00442  *
00443  * Revision 1.2  1995/10/09  20:55:35  eht
00444  * Changes for prim_type.h
00445  *
00446  * Revision 1.1  1995/08/15  13:44:14  eht
00447  * Initial revision
00448  *
00449  *
00450  */

Generated on 7 Mar 2010 by  doxygen 1.6.1