坐标矩阵 Spark 的行方式最大值
Row wise maximum of Coordinate Matrix Spark
我有一个名为 mat 的 spark.mllib.linalg.distributed.CoordinateMatrix
,我想计算这个稀疏矩阵的行最大值。我知道 mat.entries 是将 mat 的内容存储为 MatrixEntry(i,j,v)
的 rdd。现在我希望找到 mat 的行最大值。即我需要为每个 i 找到所有 j 的最大值 v。我应该怎么做?
到目前为止我有这个:
val mat_RowMatrix = mat.toRowMatrix() // found function toRowMatrix on github
val max_entries = mat_RowMatrix.rows.map{_.toArray.max}
但我需要找到 argmax(最大值的索引)而不是值本身。我在哪里可以找到这方面的文档?我想我必须使用 maxBy 但不知道如何使用它。另外,有没有更好的方法来做这一切?
一些指导会有很大帮助。
RowMatrix.rows
gives you an RDD[Vector]
, and a Vector
already provides this functionality by the argmax
函数。所以你可以这样做:
val maxEntries = matRowMatrix.rows.map{_.argmax}
我有一个名为 mat 的 spark.mllib.linalg.distributed.CoordinateMatrix
,我想计算这个稀疏矩阵的行最大值。我知道 mat.entries 是将 mat 的内容存储为 MatrixEntry(i,j,v)
的 rdd。现在我希望找到 mat 的行最大值。即我需要为每个 i 找到所有 j 的最大值 v。我应该怎么做?
到目前为止我有这个:
val mat_RowMatrix = mat.toRowMatrix() // found function toRowMatrix on github
val max_entries = mat_RowMatrix.rows.map{_.toArray.max}
但我需要找到 argmax(最大值的索引)而不是值本身。我在哪里可以找到这方面的文档?我想我必须使用 maxBy 但不知道如何使用它。另外,有没有更好的方法来做这一切?
一些指导会有很大帮助。
RowMatrix.rows
gives you an RDD[Vector]
, and a Vector
already provides this functionality by the argmax
函数。所以你可以这样做:
val maxEntries = matRowMatrix.rows.map{_.argmax}