【问题标题】:Torch - Lua / Get max index from matrixTorch - Lua / 从矩阵中获取最大索引
【发布时间】:2017-07-18 17:10:18
【问题描述】:

我正在尝试编写一个用于霸气的神经网络
输入是一个 8 x 8 x 3 的矩阵。我将矩阵组织如下:
第一个深度是游戏状态,第二个深度是翻转板,最后一个深度是玩家平面
输出是 8 x 8 是最好玩的游戏,也就是学习的移动(由蒙特卡洛树搜索生成)

那么网络是一个 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)

【问题讨论】:

    标签: matrix indexing lua max torch


    【解决方案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]
    

    你可以对目标做同样的事情。希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-11
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      • 2016-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多