コード例 #1
0
ファイル: NBMain.java プロジェクト: vmohan7/Arimaa
  public static void main(String[] args) {
    final long totalStartTime = System.currentTimeMillis();

    if (RUN_FROM_COMMAND_LINE && args.length != 3) {
      System.out.println(
          "Error in NBMain: expects 3 arguments...\n"
              + "Arguments: <min-example-set-size> <max-example-set-size> <increment> \n"
              + "e.g. to train on example sets of size 10, 15, and 20, use arguments '10 20 5' \n"
              + "e.g. to train on a single example set of 20 games, use arguments '20 20 1'");
      return;
    }

    Utilities.PARSEABLE_OUTPUT = NBMain.PARSEABLE_OUTPUT;
    Utilities.PRINT_PERCENTILES = NBMain.PRINT_PERCENTILES;

    int startSize = RUN_FROM_COMMAND_LINE ? Integer.parseInt(args[0]) : START_SIZE;
    int endSize = RUN_FROM_COMMAND_LINE ? Integer.parseInt(args[1]) : END_SIZE;
    int increment = RUN_FROM_COMMAND_LINE ? Integer.parseInt(args[2]) : INCREMENT;

    for (int x = startSize; x <= endSize; x += increment) {
      trainAndTest(x);
    }

    MyDB.close();

    final long totalEndTime = System.currentTimeMillis();
    Utilities.printInfo(
        "\n\nTotal execution time (from process running to termination): "
            + Utilities.msToString(totalEndTime - totalStartTime));
  }
コード例 #2
0
ファイル: NBMain.java プロジェクト: vmohan7/Arimaa
  private static void trainAndTest(int numGames) {
    Utilities.printInfo("-------------------------------");
    Utilities.printInfo("------START OF ROUND (" + (numGames) + ")------");
    Utilities.printInfo("-------------------------------\n");
    final long startTime = System.currentTimeMillis();

    Utilities.printInfo("Training and testing on " + numGames + " games...");

    GameData myGameData = new GameData(numGames, TRAIN_FRACTION);
    Utilities.printInfo("Finished fetching game data");

    NBTrain trainingModel = new NBTrain();
    Utilities.printInfo("Created the NB model");

    long[][] frequencyTable = trainingModel.train(myGameData);
    Utilities.printInfo("Just finished training!");

    Utilities.printInfo("About to evaluate model: creating a hypothesis...");
    NBHypothesis myHypothesis =
        new NBHypothesis(
            frequencyTable,
            trainingModel.getNumNonExpertMoves(),
            trainingModel.getNumExpertMoves());

    Utilities.printInfo("\nTesting hypothesis on TEST set...");
    myGameData.setMode(GameData.Mode.TEST);
    HypothesisTest.test(myHypothesis, myGameData);

    //		Utilities.printInfo("\nTesting hypothesis on TRAIN set...");
    //		myGameData.setMode(GameData.Mode.TRAIN);
    //		HypothesisTest.test(myHypothesis, myGameData);

    final long endTime = System.currentTimeMillis();
    Utilities.printInfo("Round execution time: " + Utilities.msToString(endTime - startTime));
    Utilities.printInfo("\n------------------------");
    Utilities.printInfo("------END OF ROUND------");
    Utilities.printInfo("------------------------\n\n");

    myGameData.close();
  }