简体   繁体   English

RowMatrix,MLlib,Java Spark

[英]RowMatrix, MLlib, Java Spark

I have RowMatrix and my question is, how I can manipulate it by indicies? 我有RowMatrix ,我的问题是,如何通过索引来操纵它? This question is very simillar to this one: 这个问题与这个问题非常相似:

Matrix Operation in Spark MLlib in Java Java的Spark MLlib中的矩阵运算

Finally, everything, what I need is to have the Matrix with the good class library. 最后,我需要的是拥有具有良好类库的Matrix。 Currently I can't manipulate this object. 目前,我无法操纵该对象。

As the JavaDocs of RowMatrix indicate RowMatrix的JavaDocs所示

:: Experimental :: Represents a row-oriented distributed Matrix with no meaningful row indices. ::实验::表示没有有意义的行索引的面向行的分布式矩阵。

There is no ordering on the rows. 行上没有排序。 You can obtain a breeze.linalg.DenseMatrix from it by calling toBreeze , but you have no guaranteed ordering of the rows. 您可以获得一个breeze.linalg.DenseMatrix从它通过调用toBreeze ,但你有行无确定排序。 They are just inserted in the resulting matrix as they arrive at the master. 当它们到达母版时,它们只是插入到结果矩阵中。 This means that the results of this operation can vary from time to time. 这意味着此操作的结果可能会不时变化。

If you need a deterministic outcome of the toBreeze operation, then you have to use an IndexedRowMatrix . 如果需要toBreeze操作的确定性结果,则必须使用IndexedRowMatrix There every row has a row index assigned which is used to build the breeze.linalg.DenseMatrix . 在那里,每行都分配有一个行索引,该索引用于构建breeze.linalg.DenseMatrix

From there you can then use the solution proposed here , which is 然后,您可以使用此处提出的解决方案,即

import no.uib.cipr.matrix.DenseMatrix;
// ...
IndexedRowMatrix U = svd.U();
DenseMatrix U_mtj = new DenseMatrix((int) U.numCols(), (int) U.numRows(), U.toBreeze().toArray$mcD$sp(), true);
// From there, matrix operations are available on U_mtj

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM