Пример #1
0
  private static Map<String, Reward> loadTrainingData(final String inputFileName) {
    try (BufferedReader reader =
        new BufferedReader(
            new InputStreamReader(new GZIPInputStream(new FileInputStream(inputFileName))))) {
      Map<String, Reward> data = new TreeMap<>();
      String line;
      while ((line = reader.readLine()) != null) {
        if (line.startsWith("#")) {
          continue;
        }

        String[] tokens = line.split("\\s");
        String positionId = PositionId.positionIDFromKey(AuchKey.fromNnPosition(tokens[0]));
        Reward reward = new Reward();
        for (int i = 0; i < Constants.NUM_OUTPUTS; i++) {
          reward.data()[i] = Double.parseDouble(tokens[i + 1]);
        }

        data.put(positionId, reward);
      }

      addMissedInversions(data);
      return data;
    } catch (final Exception e) {
      throw new RuntimeException(e);
    }
  }
Пример #2
0
  private static void addMissedInversions(final Map<String, Reward> data) {
    Map<String, Reward> missed = new TreeMap<>();

    for (String key : data.keySet()) {
      Board board = Board.positionFromID(key);
      board.swapSides();
      String posRev = board.positionID();
      if (!data.containsKey(posRev)) {
        Reward reward = data.get(key);
        reward.invert();
        missed.put(posRev, reward);
      }
    }

    data.putAll(missed);
  }