首页 > 解决方案 > 为什么在使用 Deep Q 学习时会弹出此错误?

问题描述

我一直在 Windows 10 机器上使用 Deep Q Learning。我有带有 NVIDA 显卡的 0.4.1 版 pytorch。

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

从这部分代码中,我不断收到此错误:

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

如果需要任何其他信息,将很快提供。

标签: pythondeep-learningartificial-intelligencepytorch

解决方案


根据文档,您没有指定num_samplesofmultinomial函数来绘制多项分布。

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

返回一个张量,其中每一行包含从位于张量input 的相应行中的多项概率分布中采样的num_samples个索引。

更改代码如下:

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]

推荐阅读