예제 #1
0
  @Override
  public void OutputTestResults() throws Exception {
    Integer testId = new Integer(this.testResultsMap.GetBestId());

    if (testId == null || testId < 0) {
      String msg = "No test results to output.";
      Exception e = new Exception(msg);
      throw (e);
    }

    StringBuilder msg = new StringBuilder();

    String outputDirPath = this.inputParameters.GetStringValue("outputDir");
    // file to output parameters used
    String testParamsFilePath =
        "test_fold_" + String.valueOf(this.GetFoldId()) + "_params_used.txt";
    File outputParamsFile = new File(outputDirPath, testParamsFilePath);
    // file to output detailed per file results
    String testDetailedFilePath = "test_fold_" + String.valueOf(this.GetFoldId()) + "_details.txt";
    File outputDetailedFile = new File(outputDirPath, testDetailedFilePath);

    ArrayList<String> paramNames = new ArrayList<String>();
    //		paramNames.add("useSegmentDf");
    //		paramNames.add("numTFIDFsegments");
    paramNames.add("smoothing");
    paramNames.add("smoothingAlpha");
    paramNames.add("smoothingWindow");
    paramNames.add("windowRatio");
    paramNames.add("damping");
    paramNames.add("preference_level0");
    paramNames.add("preference_level1");
    paramNames.add("preference_level2");

    for (String name : paramNames) {
      msg.append(name);
      msg.append("\t");
    }

    EvalResultSet result = this.testResultsMap.GetResult(testId);
    String metricName = result.GetMetricName();

    msg.append(metricName);
    msg.append("\t");
    msg.append("std.dev");
    msg.append("\n");

    AbstractParameterDictionary params = this.testResultsMap.GetParams(testId);

    for (String name : paramNames) {
      ArrayList<Object> paramValues = params.GetObjectList(name);
      for (Object obj : paramValues) {
        String item = obj.toString();
        msg.append(item);
        // msg.append("_");
      }
      msg.append("\t");
    }
    msg.append(result.GetAverageValue().toString());
    msg.append("\t");
    msg.append(result.GetStdDev().toString());
    msg.append("\n");

    TextFileIO.OutputFile(outputParamsFile, msg.toString());

    // now output details per file
    TextFileIO.OutputFile(outputDetailedFile, result.GetResultsString());
  }
예제 #2
0
  @Override
  public void OutputTrainResults() throws Exception {

    Set<Integer> idSet = this.trainResultsMap.GetAllIds();

    if (idSet == null || idSet.size() <= 0) {
      String msg = "No training results to output.";
      Exception e = new Exception(msg);
      throw (e);
    }

    StringBuilder msg = new StringBuilder();

    String outputDirPath = this.inputParameters.GetStringValue("outputDir");
    // String trainFilePath = this.inputParameters.GetStringValue("trainResultsFile");
    String trainFilePath = "train_fold_" + String.valueOf(this.GetFoldId()) + ".txt";
    File outputFile = new File(outputDirPath, trainFilePath);

    ArrayList<String> paramNames = new ArrayList<String>();
    //		paramNames.add("useSegmentDf");
    //		paramNames.add("numTFIDFsegments");
    paramNames.add("smoothing");
    paramNames.add("smoothingAlpha");
    paramNames.add("smoothingWindow");
    paramNames.add("windowRatio");
    paramNames.add("damping");
    paramNames.add("preference_level0");
    paramNames.add("preference_level1");
    paramNames.add("preference_level2");
    // paramNames.add("inputDir");

    for (String name : paramNames) {
      msg.append(name);
      msg.append("\t");
    }

    Iterator<Integer> it = idSet.iterator();

    Integer firstId = it.next();
    EvalResultSet first = this.trainResultsMap.GetResult(firstId);
    String metricName = first.GetMetricName();

    msg.append(metricName);
    msg.append("\t");
    msg.append("std.dev");
    msg.append("\n");

    it = idSet.iterator();

    // for (AbstractParameterDictionary param: this.trainResults.keySet())

    while (it.hasNext()) {
      Integer curId = it.next();
      EvalResultSet result = this.trainResultsMap.GetResult(curId);
      AbstractParameterDictionary params = this.trainResultsMap.GetParams(curId);

      for (String name : paramNames) {
        ArrayList<Object> paramValues = params.GetObjectList(name);
        for (Object obj : paramValues) {
          String item = obj.toString();
          msg.append(item);
          // msg.append("_");
        }
        msg.append("\t");
      }
      msg.append(result.GetAverageValue().toString());
      msg.append("\t");
      msg.append(result.GetStdDev().toString());
      msg.append("\n");
    }

    TextFileIO.OutputFile(outputFile, msg.toString());
  }