示例#1
0
 public void rank(String modelFile, String testFile, String indriRanking) {
   Ranker ranker = rFact.loadRanker(modelFile);
   int[] features = ranker.getFeatures();
   List<RankList> test = readInput(testFile);
   if (normalize) normalize(test, features);
   try {
     BufferedWriter out =
         new BufferedWriter(new OutputStreamWriter(new FileOutputStream(indriRanking), "ASCII"));
     for (int i = 0; i < test.size(); i++) {
       RankList l = test.get(i);
       double[] scores = new double[l.size()];
       for (int j = 0; j < l.size(); j++) scores[j] = ranker.eval(l.get(j));
       int[] idx = MergeSorter.sort(scores, false);
       for (int j = 0; j < idx.length; j++) {
         int k = idx[j];
         String str =
             l.getID()
                 + " Q0 "
                 + l.get(k).getDescription().replace("#", "").trim()
                 + " "
                 + (j + 1)
                 + " "
                 + SimpleMath.round(scores[k], 5)
                 + " indri";
         out.write(str);
         out.newLine();
       }
     }
     out.close();
   } catch (Exception ex) {
     System.out.println("Error in Evaluator::rank(): " + ex.toString());
   }
 }
示例#2
0
  public void test(String modelFile, String testFile) {
    Ranker ranker = rFact.loadRanker(modelFile);
    int[] features = ranker.getFeatures();
    List<RankList> test = readInput(testFile);
    if (normalize) normalize(test, features);

    double rankScore = evaluate(ranker, test);
    System.out.println(testScorer.name() + " on test data: " + SimpleMath.round(rankScore, 4));
  }
示例#3
0
  public void rank(String modelFile, String testFile) {
    Ranker ranker = rFact.loadRanker(modelFile);
    int[] features = ranker.getFeatures();
    List<RankList> test = readInput(testFile);
    if (normalize) normalize(test, features);

    for (int i = 0; i < test.size(); i++) {
      RankList l = test.get(i);
      double[] scores = new double[l.size()];
      for (int j = 0; j < l.size(); j++) scores[j] = ranker.eval(l.get(j));
      int[] idx = Sorter.sort(scores, false);
      List<Integer> ll = new ArrayList<Integer>();
      for (int j = 0; j < idx.length; j++) ll.add(idx[j]);
      for (int j = 0; j < l.size(); j++) {
        int index = ll.indexOf(j) + 1;
        System.out.print(index + ((j == l.size() - 1) ? "" : " "));
      }
      System.out.println("");
    }
  }
示例#4
0
 public void score(String modelFile, String testFile, String outputFile) {
   Ranker ranker = rFact.loadRanker(modelFile);
   int[] features = ranker.getFeatures();
   List<RankList> test = readInput(testFile);
   if (normalize) normalize(test, features);
   try {
     BufferedWriter out =
         new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "ASCII"));
     for (int i = 0; i < test.size(); i++) {
       RankList l = test.get(i);
       for (int j = 0; j < l.size(); j++) {
         out.write(ranker.eval(l.get(j)) + "");
         out.newLine();
       }
     }
     out.close();
   } catch (Exception ex) {
     System.out.println("Error in Evaluator::rank(): " + ex.toString());
   }
 }
示例#5
0
  public void test(String modelFile, String testFile, boolean printIndividual) {
    Ranker ranker = rFact.loadRanker(modelFile);
    int[] features = ranker.getFeatures();
    List<RankList> test = readInput(testFile);
    if (normalize) normalize(test, features);

    double rankScore = 0.0;
    double score = 0.0;
    for (int i = 0; i < test.size(); i++) {
      RankList l = ranker.rank(test.get(i));
      score = testScorer.score(l);
      if (printIndividual)
        System.out.println(
            testScorer.name() + "   " + l.getID() + "   " + SimpleMath.round(score, 4));
      rankScore += score;
    }
    rankScore /= test.size();
    if (printIndividual)
      System.out.println(testScorer.name() + "   all   " + SimpleMath.round(rankScore, 4));
    else System.out.println(testScorer.name() + " on test data: " + SimpleMath.round(rankScore, 4));
  }