📄 model.h
字号:
/******************************************************************************* author : Bernd Wichern filename : ghmm/ghmm/model.h created : TIME: 10:47:27 DATE: Fri 19. December 1997 $Id: model.h,v 1.19.6.1 2004/06/11 13:24:49 wasinee Exp $Copyright (C) 1998-2001, ZAIK/ZPR, Universit鋞 zu K鰈nThis program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*******************************************************************************/#ifndef MODEL_H#define MODEL_H#ifdef __cplusplusextern "C" {#endif/**@name HMM-Modell *//*@{ (Doc++-Group: model) *//** @name background_distributions A container for background distributions to be used in the reestimation. Model has an ID (== index) to be used for the arrays background_distributions.order and background_distributions.b*/struct background_distributions { int n; /* Number of distributions */ int* order; /* Order of the respective distribution */ double **b; /* The probabilities */ };typedef struct background_distributions background_distributions;/** @name state The basic structure, keeps all parameters that belong to a state. */struct state { /** Initial probability */ double pi; /** Output probability */ double *b; int order; /** IDs of the following states */ int *out_id; /** IDs of the previous states */ int *in_id; /** transition probs to successor states. */ double *out_a; /** transition probs from predecessor states. */ double *in_a; /** Transition probability to a successor double *out_a; */ /** Transition probablity to a precursor double *in_a;*/ /** Number of successor states */ int out_states; /** Number of precursor states */ int in_states; /** if fix == 1 --> b stays fix during the training */ int fix; int label; };typedef struct state state;/** @name model The complete HMM. Contains all parameters, that define a HMM.*/struct model { /** Number of states */ int N; /** Number of outputs */ int M; /** Vector of the states */ state *s; /** The a priori probability for the model. A value of -1 indicates that no prior is defined. Note: this is not to be confused with priors on emission distributions*/ double prior; /* contains a arbitrary name for the model */ char* name; /** Contains bit flags for varios model extensions such as kSilentStates, kTiedEmissions (see ghmm.h for a complete list) */ int model_type; /** Flag variables for each state indicating whether it is emitting or not. Note: silent != NULL iff (model_type & kSilentStates) == 1 */ int* silent; /*AS*/ /** Flag variables for each state indicating whether the states emissions are tied to another state. Groups of tied states are represented by their tie group leader (the lowest numbered member of the group). tied_to[s] == kUntied : s is not a tied state tied_to[s] == s : s is a tie group leader tied_to[t] == s : t is tied to state s Note: tied_to != NULL iff (model_type & kTiedEmissions) == 1 */ int* tied_to; /** Note: State store order information of the emissions. Classic HMMS have emission order 0, that is the emission probability is conditioned only on the state emitting the symbol. For higher order emissions, the emission are conditioned on the state s as well as the previous emission_order[s] observed symbols. The emissions are stored in the state's usual double* b. The order is set state.order. Note: state.order != NULL iff (model_type & kHigherOrderEmissions) == 1 */ /** background_distributions is a pointer to a background_distributions structure, which holds (essentially) an array of background distributions (which are just vectors of floating point numbers like state.b). For each state the array background_id indicates which of the background distributions to use in parameter estimation. A value of kNoBackgroundDistribution indicates that none should be used. Note: background_id != NULL iff (model_type & kHasBackgroundDistributions) == 1 */ int *background_id; background_distributions* bp; /** (WR) added these variables for topological ordering of silent states Condition: topo_order != NULL iff (model_type & kSilentStates) == 1 */ int* topo_order; int topo_order_length;};typedef struct model model;/** @name model_direct The complete HMM. Keeps the model parameters in a matrix form. */struct model_direct { /** Number of states */ int N; /** Number of outputs */ int M; /** Prior for the a priori probability for the model. Gets the value -1 if no prior defined. */ double prior; /** Transition matrix */ double **A; /** Output matrix */ double **B; /** Initial matrix */ double* Pi; /** A vector to know the states where the output should not be trained. Default value is 0 for all states. */ int *fix_state; /* XXX additional struct members not addedd here; model_direct is depreciated anyways. Not used by C++ interface */};typedef struct model_direct model_direct;/** @name hmm_check_t Checks the consistence of the model */struct hmm_check_t { /** Number of rows in the A matrix */ int r_a; /** Number of columns in the A matrix */ int c_a; /** Number of rows in the B matrix */ int r_b; /** Number of columns in the B matrix */ int c_b; /** Length of the phi vector */ int len_pi; /** Length of the fix vector */ int len_fix;};typedef struct hmm_check_t hmm_check_t;#ifdef __cplusplus}#endif/* Important: The inclusion of sequence.h ist not done before this point in order to avoid error by compiling.*/#include <ghmm/sequence.h>#include <ghmm/scanner.h>#ifdef __cplusplusextern "C" {#endif/** Frees the memory of a model. @return 0 for succes; -1 for error @param mo: pointer to a model */int model_free(model **mo);/** Reads in ASCII data to initialize an array of models. Memory allocation for the models is done here. @return array of pointers to the models @param filename: the ASCII input file @param mo_number: filled with number of models read */model** model_read(char *filename, int *mo_number);/** Reads in a model, where the model parameters are explicit given in matrix form. Memory allocation for the model is also done here. @return pointer to the model @param s: scanner @param multip: multiplicity; gives how many copies should be made of the model */model* model_direct_read(scanner_t *s, int *multip);/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -