Last active
November 29, 2023 16:15
-
-
Save suragnair/3bd7c64fb4b838c4e21d0d490308f621 to your computer and use it in GitHub Desktop.
MCTS for Alpha Zero
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search(s, game, nnet): | |
if game.gameEnded(s): return -game.gameReward(s) | |
if s not in visited: | |
visited.add(s) | |
P[s], v = nnet.predict(s) | |
return -v | |
max_u, best_a = -float("inf"), -1 | |
for a in game.getValidActions(s): | |
u = Q[s][a] + c_puct*P[s][a]*sqrt(sum(N[s]))/(1+N[s][a]) | |
if u>max_u: | |
max_u = u | |
best_a = a | |
a = best_a | |
sp = game.nextState(s, a) | |
v = search(sp, game, nnet) | |
Q[s][a] = (N[s][a]*Q[s][a] + v)/(N[s][a]+1) | |
N[s][a] += 1 | |
return -v |
We use 1 as a default but I don’t know how sensitive training is to this parameter. Best to try a handful of values.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the optimal value you are using for c_puct hyperparameter in your code.