当前位置: 首页>>代码示例>>C++>>正文


C++ ME_Model::classify方法代码示例

本文整理汇总了C++中ME_Model::classify方法的典型用法代码示例。如果您正苦于以下问题:C++ ME_Model::classify方法的具体用法?C++ ME_Model::classify怎么用?C++ ME_Model::classify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ME_Model的用法示例。


在下文中一共展示了ME_Model::classify方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: classify_samples

RcppExport SEXP classify_samples(int nrows, int ncols, vector<double> ia, vector<string> ja, vector<double> ra, string model_data) {
	new_model();
	model.load_from_string(model_data);
	vector<string> results;
	vector<string> probability_names;
	
	NumericMatrix probability_matrix(nrows,model.num_classes());
	
	for (int i=0; i < nrows; i++) { // for each document
		//Rprintf("Document %d\n",i); // debug output
		ME_Sample newSample; // create new sample for code
		for (int j=ia[i]-1; j < ia[i+1]-1; j++) { // for each feature
			newSample.add_feature(ja[j],ra[j]);
		}
		
		vector<double> prob = model.classify(newSample);
		for (int k=0; k < model.num_classes(); k++) {
			probability_matrix(i,k) = prob[k];
		}
		
		results.push_back(newSample.label);
	}
	
	for (int k=0; k < model.num_classes(); k++) {
		probability_names.push_back(model.get_class_label(k));
	}
	
	List rs = List::create(results,probability_matrix,probability_names);
	
	return rs;
}
开发者ID:bpgriner01,项目名称:maxent,代码行数:31,代码来源:rmaxent.cpp

示例2: mesample

static void
decode_no_context(vector<Token> & vt, const ME_Model & me_none)
{
  int n = vt.size();
  if (n == 0) return;

  for (size_t i = 0; i < n; i++) {
    ME_Sample mes = mesample(vt, i, "", "", "", "");
    me_none.classify(mes);
    vt[i].prd = mes.label;
  }
  
  for (size_t k = 0; k < n; k++) {
    cout << vt[k].str << "/" << vt[k].prd << " ";
  }
  cout << endl;

}
开发者ID:Klim314,项目名称:Quetzalcoatl,代码行数:18,代码来源:bidir.cpp

示例3: test

void test(const ME_Model & model, const string & filename) 
{
  ifstream ifile(filename.c_str());
  
  if (!ifile) {
    cerr << "error: cannot open " << filename << endl; 
    exit(1); 
  }

  int num_correct = 0;
  int num_tokens = 0;
  string line;
  while (getline(ifile, line)) {
    vector<Token> vs = read_line(line);
    for (int j = 0; j < (int)vs.size(); j++) {
      ME_Sample mes = sample(vs, j);
      model.classify(mes);
      if (mes.label == vs[j].pos) num_correct++;
      num_tokens++;
    }
  }    
  cout << "accuracy = " << num_correct << " / " << num_tokens << " = " 
       << (double)num_correct / num_tokens << endl;
}
开发者ID:Ericva,项目名称:sentiment,代码行数:24,代码来源:postagging.cpp

示例4: main

int main(int argc, char* argv[])
{
	if (argc < 3 || argc > 4) {
		cerr << "Usage: " << argv[0] << "input output [path-to-ruby]" << endl;
		exit(1);
	}

    ME_Model model;

    string inFile = argv[1];
    string outFile = argv[2];
    //string modelFile = argv[3];
    string modelFile = "model1-1.0";
	string rubyCommand = (argc == 4) ? argv[3] : "ruby";

	string eventFile = inFile + ".event";
	string resultFile = inFile + ".result";

    cerr << "Extracting events.";

	string extractionCommand = 
    	rubyCommand + " EventExtracter.rb " + inFile + " " + eventFile;
    system(extractionCommand.c_str());

    cerr << "roading model file." << endl;
    model.load_from_file(modelFile.c_str());
    //model.load_from_file("model" + setID + "-" + ineq);
    //ifstream fileIn(string("/home/users/y-matsu/private/workspace/eclipse-workspace/GENIASS/" + setID + "/test.txt").c_str());
    //ofstream fileOut(string("/home/users/y-matsu/private/workspace/eclipse-workspace/GENIASS/" + setID + "/test-" + ineq + ".prob").c_str());

    ifstream fileIn(eventFile.c_str());
    ofstream fileOut(resultFile.c_str());

    string line, markedTxt;

    getline(fileIn, markedTxt);
    cerr << "start classification." << endl;
    while (getline(fileIn, line)){
        vector<string> tokens;
        split(line, tokens);
        ME_Sample s;

        for(vector<string>::const_iterator token = tokens.begin() + 1;
				token != tokens.end(); ++token){
            s.add_feature(*token);
        }

        (void) model.classify(s);
        fileOut << s.label << endl;
    }
    fileOut.close();
    fileIn.close();

    remove(eventFile.c_str());

	string splitCommand =
    	rubyCommand + " Classifying2Splitting.rb "
		+ resultFile + " " + markedTxt + " " + outFile;

    system(splitCommand.c_str());

	return 0;
}
开发者ID:TPNguyen,项目名称:ucleed,代码行数:63,代码来源:sample.cpp

示例5: vd

void
viterbi(vector<Token> & vt, const ME_Model & me)
{
  if (vt.size() == 0) return;
  
  vector< vector<double> > mat;
  vector< vector<int> > bpm;
    
  vector<double> vd(me.num_classes());
  for (size_t j = 0; j < vd.size(); j++) vd[j] = 0;

  mat.push_back(vd);

  for (size_t i = 0; i < vt.size(); i++) {

    vector<double> vd(me.num_classes());
    for (size_t j = 0; j < vd.size(); j++) vd[j] = -999999;
    vector<int> bp(me.num_classes());

    double maxl = -999999;
    for (size_t j = 0; j < vd.size(); j++) {
      if (mat[i][j] > maxl) maxl = mat[i][j];
    }
    
    for (size_t j = 0; j < vd.size(); j++) {
      if (mat[i][j] < maxl - BEAM_WIDTH) continue; // beam thresholding
      
      string prepos = me.get_class_label(j);
      if (i == 0) {
        if (j > 0) continue;
        prepos = "BOS";
      }
      //      prepos = me.get_class_name(j);
      //      if (i == 0 && prepos != "BOS") continue;

      ME_Sample mes = mesample(vt, i, prepos);
      vector<double> membp = me.classify(mes);
      for (size_t k = 0; k < vd.size(); k++) {
        double l = mat[i][j] + log(membp[k]);
        if (l > vd[k]) {
          bp[k] = j;
          vd[k] = l;
        }
      }
    }
    mat.push_back(vd);
    //    for (int k = 0; k < vd.size(); k++) cout << bp[k] << " ";
    //    cout << endl;
    bpm.push_back(bp);
  }
  /*
  for (int i = 0; i < vt.size(); i++) {
    int max_prd = 0;
    for (int j = 0; j < vd.size(); j++) {
      double l = mat[i+1][j];
      if (l > mat[i+1][max_prd]) {
        max_prd = j;
      }
    }
    vt[i].prd = me.get_class_name(max_prd);
  }
  */  

  //  cout << "viterbi ";
  int max_prd = 0;
  int n = vt.size();
  for (size_t j = 0; j < vd.size(); j++) {
    double l = mat[n][j];
    if (l > mat[n][max_prd]) {
      max_prd = j;
    }
  }
  vt[n-1].prd = me.get_class_label(max_prd);
  for (int i = vt.size() - 2; i >= 0; i--) {
    //    cout << max_prd << " ";
    //    cerr << max_prd << " ";
    if (max_prd < 0 || max_prd >= me.num_classes()) exit(0);
    max_prd = bpm[i+1][max_prd];
    vt[i].prd = me.get_class_label(max_prd);
  }
  //  cout << endl;

}
开发者ID:atante,项目名称:nersuite,代码行数:83,代码来源:postag.cpp


注:本文中的ME_Model::classify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。