コード例 #1
0
  public static Map<String, List<String>> test(
      String test_data_file, Classifier model, int task, Map<String, Double> idfs)
      throws Exception {
    System.err.println("## Testing with feature_file=" + test_data_file + " ... \n");
    Map<String, List<String>> ranked_queries = new HashMap<String, List<String>>();
    Learner learner = null;
    if (task == 1) {
      learner = new PointwiseLearner();
    } else if (task == 2) {
      double C = 1.0;
      double gamma = 0.25;
      boolean isLinearKernel = false;
      learner = new PairwiseLearner(C, gamma, isLinearKernel);
    } else if (task == 3) {
      double C = 1.0;
      double gamma = 0.25;
      boolean isLinearKernel = false;
      learner = new PairwiseAddedFeatures(C, gamma, isLinearKernel);
    } else if (task == 4) {

      /*
       * @TODO: Your code here, extra credit
       * */
      System.err.println("Extra credit");
    }

    /* Step (1): construct your test feature matrix here */
    TestFeatures tf = learner.extract_test_features(test_data_file, idfs);

    /* Step (2): implement your prediction and ranking code here */
    ranked_queries = learner.testing(tf, model);

    return ranked_queries;
  }
コード例 #2
0
  public static Classifier train(
      String train_data_file, String train_rel_file, int task, Map<String, Double> idfs)
      throws Exception {
    System.err.println(
        "## Training with feature_file ="
            + train_data_file
            + ", rel_file = "
            + train_rel_file
            + " ... \n");
    Classifier model = null;
    Learner learner = null;

    if (task == 1) {
      learner = new PointwiseLearner();
    } else if (task == 2) {

      double C = 1.0;
      double gamma = 0.25;
      // String line;
      // BufferedReader reader = new BufferedReader(new FileReader("svmtemp.txt"));
      // try {
      // 	line = reader.readLine();
      // 	C = Double.parseDouble(line);
      // 	line = reader.readLine();
      // 	gamma = Double.parseDouble(line);
      // } catch (Exception e) {
      // 	System.err.println("Error while getting C and gamma.");
      // 	System.exit(1);
      // }
      boolean isLinearKernel = false;
      learner = new PairwiseLearner(C, gamma, isLinearKernel);
    } else if (task == 3) {
      // boolean isLinearKernel = true;
      // learner = new PairwiseAddedFeatures(isLinearKernel);
      double C = 1.0;
      double gamma = 0.25;
      boolean isLinearKernel = false;
      String line;
      // BufferedReader reader = new BufferedReader(new FileReader("svmtemp.txt"));
      // try {
      //   	line = reader.readLine();
      //   	C = Double.parseDouble(line);
      //   	line = reader.readLine();
      //   	gamma = Double.parseDouble(line);
      //  } catch (Exception e) {
      //   	System.err.println("Error while getting C and gamma.");
      //  }
      learner = new PairwiseAddedFeatures(C, gamma, isLinearKernel);

    } else if (task == 4) {

      /*
       * @TODO: Your code here, extra credit
       * */
      System.err.println("Extra credit");
    }

    /* Step (1): construct your feature matrix here */
    Instances data = learner.extract_train_features(train_data_file, train_rel_file, idfs);

    /* Step (2): implement your learning algorithm here */
    model = learner.training(data);

    return model;
  }