hmm.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  * hmm.h -- HMM data structure.
00039  *
00040  * **********************************************
00041  * CMU ARPA Speech Project
00042  *
00043  * Copyright (c) 1997 Carnegie Mellon University.
00044  * ALL RIGHTS RESERVED.
00045  * **********************************************
00046  *
00047  * HISTORY
00048  * $Log$
00049  * Revision 1.1  2006/04/05  20:27:30  dhdfu
00050  * A Great Reorganzation of header files and executables
00051  * 
00052  * Revision 1.9  2006/02/22 16:46:38  arthchan2003
00053  * Merged from SPHINX3_5_2_RCI_IRII_BRANCH: 1, Added function hmm_vit_eval, a wrapper of computing the hmm level scores. 2, Fixed issues in , 3, Fixed issues of dox-doc
00054  *
00055  * Revision 1.8.4.6  2005/09/25 18:53:36  arthchan2003
00056  * Added hmm_vit_eval, in lextree.c, hmm_dump and hmm_vit_eval is now separated.
00057  *
00058  * Revision 1.8.4.5  2005/07/26 02:17:44  arthchan2003
00059  * Fixed  keyword problem.
00060  *
00061  * Revision 1.8.4.4  2005/07/17 05:15:47  arthchan2003
00062  * Totally removed the data members in hmm_t structure
00063  *
00064  * Revision 1.8.4.3  2005/07/05 05:47:59  arthchan2003
00065  * Fixed dox-doc. struct level of documentation are included.
00066  *
00067  * Revision 1.8.4.2  2005/07/04 07:15:55  arthchan2003
00068  * Removed fsg compliant stuff from hmm_t
00069  *
00070  * Revision 1.8.4.1  2005/06/27 05:38:54  arthchan2003
00071  * Added changes to make libsearch/fsg_* family of code to be compiled.
00072  *
00073  * Revision 1.8  2005/06/21 18:34:41  arthchan2003
00074  * Log. 1, Fixed doxygen documentation for all functions. 2, Add $Log$
00075  * Revision 1.1  2006/04/05  20:27:30  dhdfu
00076  * A Great Reorganzation of header files and executables
00077  * 
00078  * Log. 1, Fixed doxygen documentation for all functions. 2, Add Revision 1.9  2006/02/22 16:46:38  arthchan2003
00079  * Log. 1, Fixed doxygen documentation for all functions. 2, Add Merged from SPHINX3_5_2_RCI_IRII_BRANCH: 1, Added function hmm_vit_eval, a wrapper of computing the hmm level scores. 2, Fixed issues in , 3, Fixed issues of dox-doc
00080  * Log. 1, Fixed doxygen documentation for all functions. 2, Add
00081  *
00082  * Revision 1.4  2005/06/13 04:02:55  archan
00083  * Fixed most doxygen-style documentation under libs3decoder.
00084  *
00085  * Revision 1.3  2005/03/30 01:22:46  archan
00086  * Fixed mistakes in last updates. Add
00087  *
00088  * 
00089  * 29-Feb-2000  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
00090  *              Modified hmm_t.state to be a run-time array instead of a compile-time
00091  *              one.  Modified compile-time 3 and 5-state versions of hmm_vit_eval
00092  *              into hmm_vit_eval_3st and hmm_vit_eval_5st, to allow run-time selection.
00093  *              Removed hmm_init().
00094  * 
00095  * 08-Dec-1999  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
00096  *              Added HMM_SKIPARCS compile-time option and hmm_init().
00097  * 
00098  * 10-May-1999  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University.
00099  *              Started, based on an earlier version.
00100  */
00101 
00102 
00103 #ifndef _S3_HMM_H_
00104 #define _S3_HMM_H_
00105 
00106 #include <stdio.h>
00107 
00108 #include "s3types.h"
00109 
00110 #ifdef __cplusplus
00111 extern "C" {
00112 #endif
00113 #if 0
00114 } /* Fool Emacs into not indenting things. */
00115 #endif
00116 
00118 #define MAX_HMM_NSTATE 5
00119 
00156 typedef struct hmm_context_s {
00157     int32 n_emit_state;    
00158     const int32 ***tp;     
00159     const int32 *senscore; 
00160     const s3senid_t **sseq;
00161     int32 *st_sen_scr;     
00162     void *udata;           
00163 } hmm_context_t;
00164 
00168 typedef struct {
00169     int32 score;        
00170     union {
00171         long id;        
00172         void *ptr;      
00173     } history;
00174 } hmm_state_t;
00175 
00184 typedef struct hmm_s {
00185     hmm_context_t *ctx;                
00186     hmm_state_t state[MAX_HMM_NSTATE]; 
00187     hmm_state_t out;                   
00188     union {
00189         int32 *mpx_ssid; 
00190         int32 ssid;      
00191     } s;
00192     int32 bestscore;    
00193     s3tmatid_t tmatid;  
00194     s3frmid_t frame;    
00195     uint8 mpx;          
00196     uint8 n_emit_state; 
00197 } hmm_t;
00198 
00200 #define hmm_context(h) ((hmm_t *)(h))->ctx
00201 #define hmm_is_mpx(h) ((hmm_t *)(h))->mpx
00202 #define hmm_state(h,st) ((hmm_t *)(h))->state[st]
00203 
00204 #define hmm_in_score(h) hmm_state(h,0).score
00205 #define hmm_score(h,st) hmm_state(h,st).score
00206 #define hmm_out_score(h) ((hmm_t *)(h))->out.score
00207 
00208 #define hmm_in_history(h) hmm_state(h,0).history.id
00209 #define hmm_history(h,st) hmm_state(h,st).history.id
00210 #define hmm_out_history(h) ((hmm_t *)(h))->out.history.id
00211 
00212 #define hmm_in_histobj(h) hmm_state(h,0).history.ptr
00213 #define hmm_histobj(h,st) hmm_state(h,st).history.ptr
00214 #define hmm_out_histobj(h) ((hmm_t *)(h))->out.history.ptr
00215 
00216 #define hmm_bestscore(h) ((hmm_t *)(h))->bestscore
00217 #define hmm_frame(h) ((hmm_t *)(h))->frame
00218 #define hmm_mpx_ssid(h,st) ((hmm_t *)(h))->s.mpx_ssid[st]
00219 #define hmm_nonmpx_ssid(h) ((hmm_t *)(h))->s.ssid
00220 #define hmm_ssid(h,st) (hmm_is_mpx((hmm_t *)(h))                        \
00221                         ? hmm_mpx_ssid(h,st) : ((hmm_t *)(h))->s.ssid)
00222 #define hmm_senid(h,st) (hmm_ssid(h,st) == -1                           \
00223                          ? -1 : ((hmm_t *)(h))->ctx->sseq[hmm_ssid(h,st)][st])
00224 #define hmm_senscr(h,st) (hmm_ssid(h,st) == -1                          \
00225                           ? S3_LOGPROB_ZERO                             \
00226                           : ((hmm_t *)(h))->ctx->senscore[hmm_senid(h,st)])
00227 #define hmm_tmatid(h) ((hmm_t *)(h))->tmatid
00228 #define hmm_tprob(h,i,j) ((hmm_t *)(h))->ctx->tp[hmm_tmatid(h)][i][j]
00229 #define hmm_n_emit_state(h) (((hmm_t *)(h))->n_emit_state)
00230 #define hmm_n_state(h) (((hmm_t *)(h))->n_emit_state + 1)
00231 
00235 hmm_context_t *hmm_context_init(int32 n_emit_state,
00236                                 int32 ***tp,
00237                                 int32 *senscore,
00238                                 s3senid_t **sseq);
00239 
00243 #define hmm_context_set_senscore(ctx, senscr) ((ctx)->senscore = (senscr))
00244 
00252 void hmm_context_free(hmm_context_t *ctx);
00253 
00257 void hmm_init(hmm_context_t *ctx, hmm_t *hmm, int mpx,
00258               int32 ssid, s3tmatid_t tmatid);
00259 
00263 void hmm_deinit(hmm_t *hmm);
00264 
00269 void hmm_clear(hmm_t *h);
00270 
00274 void hmm_clear_scores(hmm_t *h);
00275 
00279 void hmm_normalize(hmm_t *h, int32 bestscr);
00280 
00284 void hmm_enter(hmm_t *h, int32 score,
00285                int32 histid, int32 frame);
00286 
00290 void hmm_enter_obj(hmm_t *h, int32 score,
00291                    void *histobj, int32 frame);
00292 
00301 int32 hmm_vit_eval(hmm_t *hmm);
00302   
00303 
00307 int32 hmm_dump_vit_eval(hmm_t *hmm,  
00308                         FILE *fp 
00309     );
00310 
00315 void hmm_dump(hmm_t *h,  
00316               FILE *fp 
00317     );
00318 
00319 
00320 #if 0
00321 { /* Stop indent from complaining */
00322 #endif
00323 #ifdef __cplusplus
00324 }
00325 #endif
00326 
00327 #endif

Generated on 7 Mar 2010 by  doxygen 1.6.1