Torch - Lua / 从矩阵获取最大索引
Torch - Lua / Get max index from matrix
我正在努力编写一个神经网络来霸气
输入是一个 8 x 8 x 3 的矩阵。我组织矩阵如下:
第一个深度为游戏状态,第二个深度为翻转板,最后一个深度为玩家平面
输出是 8 x 8 是最好玩的游戏,也就是学习的移动(由 Monte Carlo 树搜索生成)
那么网络是一个8 x 8的张量,有可能是最好玩的游戏,
我需要得到张量的最大概率的索引 (x,y) 对我来说
我尝试使用函数 torch.max(tensor, 2) 和 torch.max(tensor?1) 但我没有得到我需要的东西。
有人可以帮助我吗?
非常感谢!
#out = output of the neural net and output is the target output[indice][1]
# need to check if the target is the same as prediction
max, bestTarget = torch.max(output[index][1],2)
maxP, bestPrediction = torch.max(out,2)
max, indT = torch.max(max,1)
maxP, indP = torch.max(maxP,1)
获取out的最大元素(best_row,best_col),
-- First get the maximum element and indices per row
maxP_per_row, bestColumn_per_row = torch.max(out,2)
-- then get the best element and the best row
best_p, best_row = torch.max(maxP_per_row, 1)
-- then find the best column for the best row
best_col = bestColumn_per_row[best_row]
您可以对目标执行相同的操作。希望这有帮助。
我正在努力编写一个神经网络来霸气
输入是一个 8 x 8 x 3 的矩阵。我组织矩阵如下:
第一个深度为游戏状态,第二个深度为翻转板,最后一个深度为玩家平面
输出是 8 x 8 是最好玩的游戏,也就是学习的移动(由 Monte Carlo 树搜索生成)
那么网络是一个8 x 8的张量,有可能是最好玩的游戏, 我需要得到张量的最大概率的索引 (x,y) 对我来说
我尝试使用函数 torch.max(tensor, 2) 和 torch.max(tensor?1) 但我没有得到我需要的东西。
有人可以帮助我吗?
非常感谢!
#out = output of the neural net and output is the target output[indice][1]
# need to check if the target is the same as prediction
max, bestTarget = torch.max(output[index][1],2)
maxP, bestPrediction = torch.max(out,2)
max, indT = torch.max(max,1)
maxP, indP = torch.max(maxP,1)
获取out的最大元素(best_row,best_col),
-- First get the maximum element and indices per row
maxP_per_row, bestColumn_per_row = torch.max(out,2)
-- then get the best element and the best row
best_p, best_row = torch.max(maxP_per_row, 1)
-- then find the best column for the best row
best_col = bestColumn_per_row[best_row]
您可以对目标执行相同的操作。希望这有帮助。