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