Efficient way to extract string and smooth out cosine

In the code below, I am getting a dense V matrix after SVD. I want to

  • Given a set of values ​​(e.g. 3,7,9).
  • I want to extract the 3.7 and 9 row of Matrix V.
  • I want to calculate the similarity of the cosines of these three rows with each row of the matrix V
  • I need to add three similarities of cosines obtained for each row.
  • Finally, I need the index of the row that has the maximum summation.
val data = Array(
      Vectors.sparse(5, Seq((1, 1.0), (3, 7.0))),
      Vectors.dense(2.0, 0.0, 3.0, 4.0, 5.0),
      Vectors.dense(4.0, 0.0, 0.0, 6.0, 7.0))

val dataRDD = sc.parallelize(data)

val mat: RowMatrix = new RowMatrix(dataRDD)

// Compute the top 4 singular values and corresponding singular vectors.

val svd: SingularValueDecomposition[RowMatrix, Matrix] = mat.computeSVD(4, computeU = true)

val U: RowMatrix = svd.U  // The U factor is a RowMatrix.

val s: Vector = svd.s  // The singular values are stored in a local dense vector.

val V: Matrix = svd.V  // The V factor is a local dense matrix.

      

Please recommend an effective method to do the same. I was thinking about converting the V matrix to an indexed row matrix, but when I use a row on V iterator how do I keep track of the row index? Is there a better way to do this?

+3


source to share





All Articles