我在Windows 10机器上使用深度Q学习。我使用的是0.4.1版本的pytorch,并配备了NVIDA显卡。
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"
如果需要其他信息,我会很快提供。
回答:
根据文档,您没有为multinomial
函数指定num_samples
来抽取多项式分布。
torch.multinomial(input, num_samples, replacement=False, out=None)
返回一个张量,其中每一行包含从输入张量对应行的多项式概率分布中抽取的num_samples个索引。
请将代码修改如下:
def select_action(self, state): probs = F.softmax(self.model(Variable(state, volatile = True))*7) action = probs.multinomial(1) # 1 是要抽取的样本数量 return action.data[0,0]