Advertisement
alkkofficial

Untitled

Apr 4th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. Line # Mem usage Increment Occurrences Line Contents
  2. =============================================================
  3. 37 277.3 MiB 277.3 MiB 1 @profile
  4. 38 def load():
  5. 39 277.3 MiB 0.0 MiB 1 train_data = np.empty((0, 833)) # 832+1 is the size of the flattened board in one hot encoding and move_turn is one feature
  6. 40 277.3 MiB 0.0 MiB 1 train_target = []
  7. 41 818.6 MiB -27.5 MiB 4 for file in files:
  8. 42 680.7 MiB 0.0 MiB 6 with open(file, "r") as f:
  9. 43 680.7 MiB 0.1 MiB 3 contents = f.read()
  10. 44 680.7 MiB 0.1 MiB 3 contents = contents.split(" \n")
  11. 45 846.1 MiB -1489.8 MiB 303 for game in tqdm.tqdm(contents, desc="each game"):
  12. 46 846.1 MiB -1353.6 MiB 300 game = game.split(" \n")
  13. 47 846.1 MiB -1353.6 MiB 300 g = "".join(game)
  14. 48 846.1 MiB -1353.6 MiB 300 game = g.split(" ")
  15. 49 846.1 MiB -101971.1 MiB 26530 game = [x for x in game if x] # remove empty strings
  16. 50 846.1 MiB -1353.6 MiB 300 MAX_MOMENTS = min(20, len(game))
  17. 51 846.1 MiB -29509.5 MiB 6566 unsampled_idx = [np.random.randint(1, len(game)) for _ in range(MAX_MOMENTS - 1)]
  18. 52 847.1 MiB -29603.5 MiB 5966 for move in range(MAX_MOMENTS - 1):
  19. 53 847.1 MiB -28232.5 MiB 5666 board = chess.Board()
  20. 54 847.1 MiB -28232.5 MiB 5666 up_to = unsampled_idx[move]
  21. 55 847.1 MiB -28232.5 MiB 5666 moment = game[:up_to]
  22. 56 847.1 MiB -1073576.1 MiB 252258 for counter, move in enumerate(moment):
  23. 57 847.1 MiB -1045299.8 MiB 246592 move = Move.from_uci(move)
  24. 58 847.1 MiB -1045334.6 MiB 246592 board.push(move)
  25. 59 847.1 MiB -28417.3 MiB 5666 matrix_game = np.array([board_data(board)]) # game after one hot encoding
  26. 60 # Add move_turn as a feature to matrix_game
  27. 61 847.1 MiB -28275.1 MiB 5666 move_turn = counter % 2
  28. 62 847.1 MiB -28275.9 MiB 5666 matrix_game = np.concatenate((matrix_game, np.array([[move_turn]])), axis=1)
  29. 63 847.1 MiB -27551.0 MiB 5666 train_data = np.concatenate((train_data, matrix_game), axis=0)
  30. 64 847.1 MiB -28249.4 MiB 5666 status = 0
  31. 65 847.1 MiB -28249.4 MiB 5666 if (move_turn == 0 and file == "./fracww.pgn") or (
  32. 66 847.1 MiB -27275.9 MiB 4733 move_turn == 1 and file == "./fracbw.pgn"):
  33. 67 680.7 MiB -10114.0 MiB 1859 status = 1
  34. 68 847.1 MiB -18089.1 MiB 3807 elif (move_turn == 0 and file == "./fracbw.pgn") or (
  35. 69 847.1 MiB -7747.9 MiB 2845 move_turn == 1 and file == "./fracww.pgn"):
  36. 70 680.6 MiB -11276.1 MiB 1907 status = -1
  37. 71 847.1 MiB -28106.1 MiB 5666 train_target.append(status)
  38. 72 818.6 MiB 0.0 MiB 1 return train_data, train_target
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement