Search code examples
pythondeep-learningartificial-intelligencepytorch

Why does this error pop up while working with Deep Q learning?


I have been working with Deep Q Learning on Windows 10 Machine. I have version 0.4.1 of pytorch with NVIDA graphics card.

def select_action(self, state):
    probs = F.softmax(self.model(Variable(state, volatile = True))*7)
    action = probs.multinomial()
    return action.data[0,0]

From this section of the code, I keep getting this error:

TypeError: multinomial() missing 1 required positional arguments: "num_samples"

If any other information is needed, It will be very quickly provided.


Solution

  • Based on the documentation you didn't specify the num_samples of multinomial function to draw your multinomial distribution.

    torch.multinomial(input, num_samples, replacement=False, out=None)

    Returns a tensor where each row contains num_samples indices sampled from the multinomial probability distribution located in the corresponding row of tensor input.

    Change the code as below:

    def select_action(self, state):
        probs = F.softmax(self.model(Variable(state, volatile = True))*7)
        action = probs.multinomial(1) # 1 is the number of samples to draw
        return action.data[0,0]