Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeroDivisionError: float division by zero #288

Open
visuallization opened this issue Jan 6, 2023 · 7 comments
Open

ZeroDivisionError: float division by zero #288

visuallization opened this issue Jan 6, 2023 · 7 comments

Comments

@visuallization
Copy link

visuallization commented Jan 6, 2023

Hey there,

First of all thank you for sharing this repo with the public. Really cool project!

Rearding the opened issue: I experience currently a problem with MCTS in def getActionProb, namely the error ZeroDivisionError: float division by zero. It originates from probs = [x / counts_sum for x in counts] and the problem is that all the elements in counts are 0 because the state/action pair has not been discovered and saved in self.Nsa yet (counts = [self.Nsa[(s, a)] if (s, a) in self.Nsa else 0 for a in range(self.game.getActionSize())]).

Any ideas what might be causing the issue & how to fix it? I see in the other projects (e.g Othello) no such problems, so I am wondering what might be culprit here. I am currently trying to make the game of hex work in the project.

Cheers

@goshawk22
Copy link
Contributor

#191 might help

@visuallization
Copy link
Author

Yes, thanks for pointing this out. However I already dicovered this one and I couldn't find anything similiar in my code. I made sure that I always copy the pieces in the game code. It just seems that mcts is not exploring edges which the players in the arena then want to play. But I guess it should only play discovered moves (s/a) in the arena since it uses greedy search, right?

@goshawk22
Copy link
Contributor

Could you share your code?

@visuallization
Copy link
Author

Could you share your code?

I gladly do: https://github.com/visuallization/alpha-zero-general-hex/tree/master/hex
The relevant files are HexGame.py and HexBoard.py. Furthermore it currently uses the NeuralNet architecture from Othello.

@visuallization
Copy link
Author

I am not working with pass though, like Othello does because there is no pass in Hex.

@visuallization
Copy link
Author

visuallization commented Jan 6, 2023

Okay there might be an issue how I represent the canonicalBoard in getCanonicalForm. If I just return the board without inverting it, the issue of not finding the state in self.Nsa does not arise anymore.

def getCanonicalForm(self, positions, player):
        board = HexBoard(self.size)
        board.positions = np.copy(positions)
        return board.positions
        #return player * board.positions

@jamesbraza
Copy link

@visuallization did you ever figure this out?

I believe from looking at your fork that this issue was resolved, and is a dupe of #191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants