⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 train_hmm.cpp

📁 一个用于 词性标注的 HMM程序。 包含 训练和测试功能。
💻 CPP
字号:
#include <stdio.h>#include <stdlib.h>#include <iostream.h>#include <fstream.h>#include <string.h>#include "hmm.h"void main(int argc, char* argv[]){  // get command line parms
  char* train_file=argv[1];
  char* initial_model;
  double min_delta_psum;
  int states,symbols,seed;
  // check args  if (argc != 4 && argc != 6) {    cerr << "ERROR: Too few arguments.\n\n" <<     "Usage: "<< argv[0]<<" <train_file> <hmm_model> <min_delta_psum> or \n" <<    "       "<< argv[0]<<" <train_file> <seed> <nstates> <nsymbols> <min_delta_psum>\n\n";    exit (-1);  }    if (argc==4) {    initial_model=argv[2];    min_delta_psum=atof(argv[3]);  }  if (argc==6) {    seed = atoi(argv[2]);    states = atoi(argv[3]);    symbols = atoi(argv[4]);    min_delta_psum=atof(argv[5]);  }  HMM *hmm;

   //测试模型是否能够正确被保存 并读取
   //hmm=new HMM("test.hmm.seq.hmm");
   // hmm->dump_model("test.hmm.seq.hmm1");

  if (argc==4) {    // initialize model from model file    hmm = new HMM(initial_model);    // train model on data    hmm->batch_train(train_file,min_delta_psum);  }  else {    // initialize model randomly    hmm = new HMM(symbols, states, seed);    // train model on data    hmm->batch_train(train_file,min_delta_psum);  }

  ///////////////////////////测试viterbi
   int *out =new int[hmm->string_len[0]];
   hmm->viterbi(hmm->strings[0],hmm->string_len[0],&out);
  ///////////////////////////测试viterbi结束    // dump the resulting model to a file  char newfilename[100];  sprintf(newfilename,"%s.hmm",train_file);  hmm->dump_model(newfilename);    delete hmm;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -