Skip to content

UnboundLocalError: local variable 'simulationAction' referenced before assignment #30

Open

Description

@archcra

In this file: MCTS.py, there is such code snippet:

                            if Q + U > maxQU:
					maxQU = Q + U
					simulationAction = action
					simulationEdge = edge

			lg.logger_mcts.info('action with highest Q + U...%d', simulationAction)

There will be error when "if" not hold:

UnboundLocalError: local variable 'simulationAction' referenced before assignment

I encountered such error, was it a problem in game.py, or in this MCTS.py?

Activity

  1. archcra commented on Dec 17, 2018

    @archcra
    Author

    I encountered this error only when set MCTS_SIMS = 1000. Does that mean, when in such case, I should change maxQU's initial value more smaller, such as -999999 ( one more 9)?

  2. LeeTaeHoon97 commented on Apr 10, 2022

    @LeeTaeHoon97

    hi archcra, have you checked your vh_loss or ph_loss?
    in my case,
    when i face this error, my vh_loss and ph_loss values show NaN,
    so, I changed Nan values to 0

    i wish you solved this problem

  3. archcra commented on Apr 10, 2022

    @archcra
    Author
  4. tian-jie commented on Apr 7, 2024

    @tian-jie

    hi archcra, have you checked your vh_loss or ph_loss? in my case, when i face this error, my vh_loss and ph_loss values show NaN, so, I changed Nan values to 0

    i wish you solved this problem

    Can you explain more, I don't find vh_loss or ph_loss in code. I am also facing this issue now.
    I tried to comment out if clause, but now it doesn't predict any more, it shows:

    MCTS perceived value for O: nan
    NN perceived value for O: nan

  5. LeeTaeHoon97 commented on Apr 7, 2024

    @LeeTaeHoon97

    hi archcra, have you checked your vh_loss or ph_loss? in my case, when i face this error, my vh_loss and ph_loss values show NaN, so, I changed Nan values to 0
    i wish you solved this problem

    Can you explain more, I don't find vh_loss or ph_loss in code. I am also facing this issue now. I tried to comment out if clause, but now it doesn't predict any more, it shows:

    MCTS perceived value for O: nan NN perceived value for O: nan

    Here is the training content I wrote down as I don't remember the details of a project I attempted a long time ago. Please understand that this translation is done using GPT.

    Case1 - When initially training, errors occurred during the training process. Unsure where the problem originated, I printed out the cost values and observed that the pH values diverged in the negative direction, eventually resulting in NaN values. It appeared to be a gradient exploding problem. While I knew that conventional CNNs typically use techniques like dropout to address this, I was unsure how to handle it in a self-learning scenario. Through searching online, I found that inserting code to replace NaN values with 0 could sometimes resolve the issue. Subsequently, the code proceeded without errors. However, the loss function appeared to fluctuate erratically in the output (loss could decrease to negative values, but NaN values caused it to be converted to 0, resulting in erratic behavior). Further investigation revealed that the problem occurred during the backward pass. It turned out that the issue stemmed from a custom loss function implemented in Keras. Switching to a PyTorch loss function resolved the problem, and training commenced smoothly.

    I hope it helped you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions