How to compute the inverse of a RowMatrix in Apache Spark?

前端 未结 3 1545
天涯浪人
天涯浪人 2020-12-06 18:41

I have a X, distributed matrix, in RowMatrix form. I am using Spark 1.3.0. I need to be able to calculate X inverse.

3条回答
  •  离开以前
    2020-12-06 19:16

    Matrix U returned by X.computeSVD has dimensions m x k where m is the number of rows of the original (distributed) RowMatrix X. One would expect m to be large (possibly larger than k), so it is not advisable to collect it in the driver if we want our code to scale to really large values of m.

    I would say both of the solutions below suffer from this flaw. The answer given by @Alexander Kharlamov calls val U = svd.U.toBlockMatrix().toLocalMatrix() which collects the matrix in the driver. The same happens with the answer given by @Climbs_lika_Spyder (btw your nick rocks!!), which calls svd.U.rows.collect.flatMap(x => x.toArray). I would rather suggest to rely on a distributed matrix multiplication such as the Scala code posted here.

提交回复
热议问题