name: HiddenMarkovModel
synopsis:

>     g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_pr.a

>     #include <HiddenMarkovModel.h>

>     HiddenMarkovModel();
>     boolean setParamFile(const Filename& arg);
>     boolean setVerify(boolean verify);
>     boolean run(Sdb& sdb);

quick start:

>     HiddenMarkovModel hmm;
>     hmm.setParamFile(L"diagnose_params.sof");
>     Sdb raw_list_sdb;
>     boolean is_list = true;
>     raw_list_sdb.append(L"diagnose_mfcc_list.sof", is_list);
>     hmm.run(sdb);

description:
The HiddenMarkovModel class is used to implement Hidden Markov Model thechnology. It provides the Viterbi and Baum-Welch algorithms for decoding and training speech-to-text systems.
dependencies:

- Sdb
- FrontEnd
- HierarchicalSearch

public constants:

- define class name:

      static const String CLASS_NAME;

- define enumerations:

      enum ALGORITHM { DECODE = 0, TRAIN, INITIALIZE, MIXTURE_SPLITTING, CONTEXT_GENERATION, TRAIN_PARAMETER_TYING, TEST_PARAMETER_TYING, FORCED_ALIGNMENT, MLLR, MAP,SYMBOL_GRAPH_GENERATION, SYMBOL_GRAPH_RESCORING, NBEST_GENERATION, DEF_ALGORITHM = DECODE };

      enum IMPLEMENTATION { VITERBI = 0, STACK, BAUM_WELCH, GLOBAL, VARIANCE_SPLITTING, SYMBOL_GENERATION, ML, MODEL_GENERATION, WORD_DEPENDENT_NBEST, VITERBI_NBEST, RESCORE_ACOUSTIC, RESCORE_LANGUAGE, RESCORE_BOTH, DEF_IMPLEMENTATION = VITERBI };

      enum CONTEXT_MODE { SYMBOL_ONLY = 0, SYMBOL_INTERNAL, CROSS_SYMBOL, DEF_CONTEXT_MODE = SYMBOL_ONLY };

      enum FUNCTION_MODE { NONE = 0, GRAMMAR_DECODING, NETWORK_DECODING, ACCUMULATE, UPDATE, DEF_FUNCTION_MODE = NONE };

      enum MODE { FILE = 0, TRANSFORM, LIST, DEF_MODE = DATABASE };

      enum UPDATE_MODE { TRANSITIONS = 0, OBSERVATIONS, ALL, DEF_UPDATE_MODE = ALL };

      enum FORMAT { NIST_SCORE = 0, NATIVE, JSGF, DEF_FORMAT = NATIVE };

      enum TYPE { TEXT = 0, BINARY, DEF_TYPE = BINARY };

- define name maps:

      static const NameMap IMPL_MAP;

      static const NameMap ALGO_MAP;

      static const NameMap CONTEXT_MODE_MAP;

      static const NameMap FUNCTION_MODE_MAP;

      static const NameMap MODE_MAP;

      static const NameMap FORMAT_MAP;

      static const NameMap TYPE_MAP;

      static const NameMap UPDATE_MODE_MAP;

- define i/o constants:

      static const String DEF_PARAM;

      static const String PARAM_UPDATE_LEVELS;

      static const String PARAM_NUM_MIXTURES;

      static const String PARAM_NUM_ITERATIONS;

      static const String PARAM_VAR_FLOOR;

      static const String PARAM_VAR_FLOOR_FILE;

      static const String PARAM_BETA_THRESHOLD;

      static const String PARAM_TRANSCRIPTION_LEVEL;

      static const String PARAM_SYMBOL_GRAPH_LEVEL;

      static const String PARAM_FORCE_ALIGNMENT_LEVEL;

      static const String PARAM_TRANS_DB;

      static const String PARAM_AUDIO_DB;

      static const String PARAM_SYMBOL_GRAPH_DB;

      static const String PARAM_MIN_MPD;

      static const String PARAM_MIN_OCCUPANCY;

      static const String PARAM_MIN_MODEL_COUNT;

      static const String PARAM_ALGORITHM;

      static const String PARAM_IMPLEMENTATION;

      static const String PARAM_NBEST_PATHS;

      static const String PARAM_MAX_NBEST_PATHS;

      static const String PARAM_NBEST_BEAM;

      static const String PARAM_CONFIGURATION;

      static const String PARAM_FRONT_END;

      static const String PARAM_LANGUAGE_MODEL;

      static const String PARAM_STATISTICAL_MODEL_POOL;

      static const String PARAM_UPDATE_LANGUAGE_MODEL;

      static const String PARAM_UPDATE_STATISTICAL_MODEL_POOL;

      static const String PARAM_ACCUMULATOR;

      static const String PARAM_ACCUMULATOR_LIST;

      static const String PARAM_ALIGNMENT_LEVEL;

      static const String PARAM_INITIAL_LEVEL;

      static const String PARAM_OUTPUT_MODE;

      static const String PARAM_OUTPUT_FORMAT;

      static const String PARAM_UPDATE_MODE;

      static const String PARAM_FUNCTION_MODE;

      static const String PARAM_CONTEXT_MODE;

      static const String PARAM_CONTEXT_LEVEL;

      static const String PARAM_CONTEXT_ORDER;

      static const String PARAM_OUTPUT_FILE;

      static const String PARAM_OUTPUT_LIST;

      static const String PARAM_CONTEXT_LIST;

      static const String PARAM_QUES_ANS;

      static const String PARAM_PHONETIC_DT;

      static const String PARAM_PHONETIC_DT_SPLIT_THRESHOLD;

      static const String PARAM_PHONETIC_DT_MERGE_THRESHOLD;

      static const String PARAM_PHONETIC_DT_NUM_OCC_THRESHOLD;

      static const String PARAM_MLLR;

      static const String OPTION_MODE_FILE;

      static const String OPTION_MODE_TRANSFORM;

      static const String OPTION_MODE_LIST;

      static const String OPTION_FORM_NIST_SCORE;

      static const String OPTION_FORM_NATIVE;

      static const String OPTION_FORM_JSGF;

      static const String OPTION_TRANSCRIPTION_LEVEL;

      static const String OPTION_UPDATE_TRANSITIONS;

      static const String OPTION_UPDATE_OBSERVATIONS;

      static const String OPTION_UPDATE_ALL;

      static const String OPTION_FUNCTION_NONE;

      static const String OPTION_FUNCTION_GRAMMAR_DECODING;

      static const String OPTION_FUNCTION_NETWORK_DECODING;

      static const String OPTION_FUNCTION_ACCUMULATE;

      static const String OPTION_FUNCTION_UPDATE;

- define public constants:

      static const byte OFF = 0;

      static const byte ON = 1;

      static const float DEF_WEIGTH_ONE = 0;

      static const float DEF_WEIGTH_HALF = -0.693147;

      static const float DEF_BETA_PRUNING_THRESHOLD = 3.40282347e+38F;

      static const boolean DEF_VERIFY = false;

      static const boolean DEF_STREAM = false;

      static const long DEF_NBEST_PATHS = 10;

      static const long DEF_MAX_NBEST_PATHS = 50;

      static const long DEF_NBEST_BEAM = 100;

      static const long DEF_NUM_LEVELS = 3;

      static const long DEF_LEX_TREE_LEVEL = -1;

      static const long DEF_NUM_MIXTURES = 1;

      static const long DEF_NUM_ITERATIONS = 1;

      static const long DEF_ALIGNMENT_LEVEL = -1;

      static const long DEF_INITIAL_LEVEL = 0;

      static const long DEF_CONTEXT_LEVEL = 0;

      static const long DEF_CONTEXT_ORDER = 3;

      static const long DEF_CAPACITY = 12000;

      static const float DEF_MIN_MPD = 1000;

      static const float DEF_MIN_OCCUPANCY = 1.0e-10;

      static const float DEF_MIN_MODEL_COUNT = 1;

      static const float DEF_VAR_FLOOR = 2e-4;

error codes:

- error codes indicating general errors:

      static const long ERR = (long)100000;

      static const long ERR = (long)100050;

protected data:

- algorithm name:

      ALGORITHM algorithm_d;

- implementation name:

      IMPLEMENTATION implementation_d;

- context mode:

      CONTEXT_MODE context_mode_d;

- cross-word mode:

      FUNCTION_MODE function_mode_d;

- output mode:

      MODE output_mode_d;

- output level string:

      String output_levels_str_d;

- output level indices:

      Vector output_levels_d;

- update mode:

      UPDATE_MODE update_mode_d;

- output format:

      FORMAT output_format_d;

- output type:

      TYPE output_type_d;

- parameter file:

      Filename param_file_d;

- alignment file:

      Filename alignment_file_d;

- language model file:

      Filename lm_file_d;

- statistical model file:

      Filename smp_file_d;

- configuration file:

      Filename cnfg_file_d;

- fornt-end file:

      Filename fend_file_d;

- updated model file:

      Filename update_lm_file_d;

- updated statistics file:

      Filename update_smp_file_d;

- transcription file:

      Filename transcription_db_file_d;

- audio database file:

      Filename audio_db_file_d;

- symbol graph database file

      Filename symbol_graph_db_file_d;

- output file:

      Filename output_file_d;

- accumulator file:

      Filename accum_file_d;

- accumulator list:

      Filename accum_list_d;

- accumulator path:

      Filename accum_path_d;

- accumulator name:

      Filename accum_name_d;

- output list file:

      Filename output_list_d;

- context generation file:

      Filename context_list_d;

- variance floor file:

      Filename variance_floor_file_d;

- phonetic question-answers file:

      Filename ques_ans_file_d;

- phonetic decision-tree file:

      Filename phonetic_dt_file_d;

- split-threshold for the phonetic-decision-tree:

      Float phonetic_dt_split_threshold_d;

- merge-threshold for the phonetic-decision-tree:

      Float phonetic_dt_merge_threshold_d;

- num_occ-threshold for the phonetic-decision-tree:

      Float phonetic_dt_num_occ_threshold_d;

- variance floor:

      Float variance_floor_d;

- beta pruning threshold:

      Float beta_threshold_d;

- transcription level:

      String transcription_level_d;

- symbol graph level:

      String symbol_graph_level_d;

- alignment level:

      Long alignment_level_d;

- initial level:

      Long initial_level_d;

- context level:

      Long context_level_d;

- context order:

      Long context_order_d;

- n-best hypothesis generation parameters:

      Long nbest_paths_d;

      Long max_nbest_paths_d;

  Long nbest_beam_d;
- streaming input mode flag:

      boolean stream_d;

- verification mode flag:

      boolean verify_d;

- front end:

      Vectorlt&;FrontEnd> vector_fe_d;

- hash table of state transitions:

      HashTable<Accumulator, Double> accumulator_d;

      HashTable<HashKey<GraphVertex<SearchNode> >, Ulong> mapping_d;

- utterance trellis:

      BiGraph<TrainNode>* trellis_d;

- hierarchical search:

      HierarchicalSearch search_engine_d;

- language model:

      LanguageModel lm_d;

- stack search:

      StackSearch stack_engine_d;

- number of search levels:

      Long num_levels_d;

- the level that lexical tree is used:

      Long lex_tree_level_d;

- number of mixtures:

      Long num_mixtures_d;

- update levels:

      VectorByte update_levels_d;

- number of iterations of training:

      Long num_iterations_d;

- minimum model probability deviance:

      Float min_mpd_d;

- floor on the occupancy probability:

      Float min_occupancy_d;

- minimum number of times a model must occur before update:

      Long min_model_count_d;

- transcription database:

      TranscriptionDatabase transcription_db_d;

- audio database:

      AudioDatabase audio_db_d;

- Maximum likelihood linear regression object:

      MaximumLikelihoodLinearRegression mllr_d;

- symbol graph database:

      SymbolGraphDatabase symbol_graph_db_d;

- declare the debugging parameters:

      static Integral::DEBUG debug_level_d;

- define the verbosity parameters:

      static Integral::DEBUG verbosity_d;

- declare the memory manager:

      static MemoryManager mgr_d;

required public methods:

- static methods:

      static const String& name();

- debug methods:

      static boolean diagnose(Integral::DEBUG debug_level);

      boolean setDebug(Integral::DEBUG debug_level);

- destructor/constructor(s):

      ~HiddenMarkovModel();

      HiddenMarkovModel();

      HiddenMarkovModel(const HiddenMarkovModel& arg);

- assign methods:

      boolean assign(const HiddenMarkovModel& arg);

- operator= method:

      not present.

- i/o methods:

      long sofSize() const;

      boolean read(Sof& sof, long tag, const String& name = CLASS_NAME);

      boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const;

      boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);

      boolean writeData(Sof& sof, const String& param = DEF_PARAM) const;

- equality methods:

      not present.

- memory management methods:

      static void* operator new(size_t size);

      static void* operator new[](size_t size);

      static void operator delete(void* ptr);

      static void operator delete[](void* ptr);

      static boolean setGrowSize(long grow_size);

class-specific public methods:

- declare configuration methods:

      ALGORITHM getAlgorithm();

      boolean setAlgorithm(ALGORITHM arg);

      IMPLEMENTATION getImplementation();

      boolean setImplementation(IMPLEMENTATION arg);

      CONTEXT_MODE getContextMode();

      boolean setContextMode(CONTEXT_MODE arg);

      boolean setFunctionMode(const String& arg);

      FUNCTION_MODE getFunctionMode();

      boolean setOutputMode(const String& arg);

      MODE getOutputMode();

      boolean setOutputType(const String& arg);

      Type getOutputType();

      boolean setUpdateMode(const String& arg);

      UPDATE_MODE getUpdateMode();

      boolean setOutputFormat(const String& arg);

      FORMAT getOutputFormat();

      boolean setOutputLevelString(const String& arg);

      boolean setUpdateLevelString(const String& arg);

      boolean setAccumulatorPath(const Filename& arg);

      boolean setAccumulatorName(const String& arg);

      boolean getStream();

      boolean setStream(boolean arg);

- declare parameter file methods:

      Filename& getParamFile();

      boolean setParamFile(const Filename& arg);

      Filename& getAlignmentFile();

      boolean setAlignmentFile(const Filename& arg);

      Filename& getLanguageModelFile();

      boolean setLanguageModelFile(const Filename& arg);

      Filename& getStatisticalModelPoolFile();

      boolean setStatisticalModelPoolFile(const Filename& arg);

      Filename& getConfigFile();

      boolean setConfigFile(const Filename& arg);

      Filename& getFrontEndFile();

      boolean setFrontEndFile(const Filename& arg);

      Filename& getLanguageModelUpdateFile();

      boolean setLanguageModelUpdateFile(const Filename& arg);

      Filename& getStatisticalModelPoolUpdateFile();

      boolean setStatisticalModelPoolUpdateFile(const Filename& arg);

      Filename& getAccumulatorFile();

      boolean setAccumulatorFile(const Filename& arg);

      Filename& getAccumulatorList();

      boolean setAccumulatorList(const Filename& arg);

      Filename& getOutputFile();

      boolean setOutputFile(const Filename& arg);

      Filename& getOutputList();

      boolean setOutputList(const Filename& arg);

      Filename& getContextList();

      boolean setContextList(const Filename& arg);

      Filename& getVarianceFloorFile();

      boolean setVarianceFloorFile(const Filename& arg);

- declare re-estimation methods:

      float getVarianceFloor();

      boolean setVarianceFloor(float arg);

      float getBetaThreshold();

      boolean setBetaThreshold(float arg);

      long getNumMixtures();

      boolean setNumMixtures(long arg);

      long getNumIterations();

      boolean setNumIterations(long arg);

      float getMinProbabilityDeviance();

      boolean setMinProbabilityDeviance(float arg);

      float getMinOccupancy();

      boolean setMinOccupancy(float arg);

      long getMinModelCount();

      boolean setMinModelCount(long arg);

      boolean loadAccumulators(Sdb& sdb);

      boolean storeAccumulators();

      boolean accumulate(float utter_prob, Vector<VectorFloat>& data);

      boolean accumulateStateTransTrace(float utter_prob, Vector<VectorFloat>& data);

      boolean accumulateStateTransInstance(float utter_prob, Vector<VectorFloat>& data);

      boolean accumulateStatModels(float utter_prob, Vector<VectorFloat>& data);

      boolean update();

      boolean updateStateTrans(SearchLevel& search_level);

      boolean updateStatModels(SearchLevel& search_level);

      boolean adapt(Vector<StatisticalModel>& stat_models_a);

      boolean insertNonSpeechSymbols(Vector<SearchSymbol>& boundary_symbols, Vector<SearchSymbol>& internal_symbols,DiGraph<SearchNode>& graph, SearchLevel& level);

      boolean initTranscription(String& id, long arg);

      boolean initSymbolGraph(Filename& symbol_graph_file);

      boolean computeUtterProb(double& utter_prob);

- declare recognition methods:

      boolean nonLinearDecoder(Sdb& sdb);

      boolean grammarDecoder(Sdb& sdb);

      boolean networkDecoder(Sdb& sdb);

      boolean linearDecoder(Sdb& sdb);

- declare state-tying methods:

      boolean parameterTying(Sdb& sdb);

      boolean parameterTyingTrain();

      boolean parameterTyingTest();

      boolean loadOccupancies();

- declare search-engine methods:

      long getInitialLevel();

      boolean setInitialLevel(long arg);

      long getAlignmentLevel();

      boolean setAlignmentLevel(long arg);

      long getContextLevel();

      boolean setContextLevel(long arg);

      long getContextOrder();

      boolean setContextOrder(long arg);

      long getNumLevels();

      boolean setNumLevels(long arg);

      long getNumLexicalTreeLevels();

      boolean setNumLexicalTreeLevels(long arg);

      boolean setVerbosity(Integral::DEBUG verbosity);

      boolean setVerify(boolean verify);

      boolean run(Sdb& sdb);

      boolean checkParams();

      boolean load();

      boolean store();

      boolean initialize(Sdb& sdb);

      boolean extractFeatures(long fe_index, Vector<VectorFloat>& data);

      boolean initializeMappingTable();

- declare annotation graph methods:

      boolean agToDigraph(DiGraph<SearchNode>& digraph, AnnotationGraph& ag, long& channel, float& start_time, float& stop_time, boolean& is_conversation);

      boolean agToSegment(AnnotationGraph& ag, long& channel, float& start_time, float& stop_time);

      boolean resetAccumulators();

      boolean createAnnotationGraph(AnnotationGraph& anno_a, DoubleLinkedList<Trace>& trace_path_a);

      boolean createAnnotationGraph(AnnotationGraph& anno_a, DoubleLinkedList<Instance>& instance_path_a);

      boolean pruneAnnotationGraph(AnnotationGraph& anno_a);

      boolean parseLevels(const String& output_levels_str, VectorByte& output_levels);

private methods:

- declare private methods:

      boolean setVector(const String& source, VectorByte& vector);

      boolean setOutputLevels(const String& source, Vector<Long>& vector);

      boolean insert(VectorByte& src, long start_index, long num_elem, byte mode);

      boolean createContexts(Vector<SearchSymbol>& symbols, long order, Vector<SearchSymbol>& all_contexts);

      boolean appendContexts(Vector<SearchSymbol>& symbols, SearchSymbol symbol_a, long curr_order, long order, Vector<SearchSymbol>& all_contexts);

      boolean writeNBest(Filename& output_file_name, NBestPath* final_plist, SymbolGraphNode* start_node);

      boolean adaptPart(Vector<MatrixDouble>& g_a, MatrixFloat& z_a, GaussianModel& gm_a);

examples:

- This example shows how to run the HiddenMarkovModel recognizer using Viterbi algorithm

      // declare a HiddenMarkovModel object
      //
      HiddenMarkovModel hmm;

      // set up the param file for hmm and front end specification
      //
      hmm.setParamFile(L"diagnose_params.sof");

      // setup the input speech file list
      //
      Sdb raw_list_sdb;
      boolean is_list = true;
      raw_list_sdb.append(L"diagnose_raw_list.sof", is_list);

      // run the HiddenMarkovModel recongizer on the input speech file list
      //
      hmm.run(raw_list_sdb);

notes:

- none