python - 为什么在使用 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"
如果需要任何其他信息,将很快提供。
解决方案
根据文档,您没有指定num_samples
ofmultinomial
函数来绘制多项分布。
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]
推荐阅读
- flutter - “uses-material-design: true”不能与 pubspec.yaml 中的其他资产一起使用
- android - proguard如何将我的所有项目文件与项目库合并到一个包中
- javascript - 如何将@testing-library/jest-dom 添加到 svelte 中的每个测试文件中?
- python - 如何从我拥有的这个函数创建一个 n-gram 函数?
- javascript - 在材质 ui 文本字段中聚焦输入需要延迟
- react-native - Agora - React Native 中的点对点视频通话
- python - 无法将字符串正确格式化为日期时间
- html - 自动包装 CSS3-grid(自动调整)和各种宽度
- python - 从 csv 文件替换 yaml 中的每个出现
- sql - delta - 表合并 sql - 我如何更新目标中的所有列,除了一列仅用于更新子句