问题描述
我正在尝试为霸气的神经网络编写代码
输入是8 x 8 x 3的矩阵.我按如下方式组织矩阵:
第一个深度表示游戏状态,第二个深度表示翻转状态,最后一个深度表示玩家平面
输出为8 x 8是最好的游戏,又称学习游戏(由Monte Carlo Tree Search生成)
I am trying to code a neural net for domineering
The input is a matrix of 8 x 8 x 3. I organised the matrix as following :
The first depth is for the state of the game, the second depth is flipped board and the last depth is the player plane
The output is 8 x 8 is the best game to play aka the move to learn (generated by Monte Carlo Tree Search)
那么网络是一个8 x 8张量,可能是最好玩的游戏,我需要获取张量最大概率的指数(x,y)
Then the network is a 8 x 8 tensor with the probability of being the best game to play,I need to get the index (x,y) of the max probability of the tensor for me to
我尝试使用函数torch.max(tensor,2)和torch.max(tensor?1),但是我没有得到所需的东西.
I tried with the function torch.max(tensor, 2) and torch.max(tensor?1) but I didn't get what I need.
有人可以帮助我吗?
非常感谢!
#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)
推荐答案
要获取最大元素(best_row,best_col),
To get the maximum element (best_row, best_col) of out,
-- 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]
您可以对目标执行相同的操作.希望这会有所帮助.
You can do the same for target. Hope this helps.
这篇关于火炬-Lua/从矩阵获取最大索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!