SVD에서 분해 된 원본 행렬을 재구성하고 싶습니다. V factor
로컬 Matrix
을 DenseMatrix
으로 변환하지 않고도이 작업을 수행 할 수 있습니까? 여기 Spark를 사용하여 svd 구성 요소에서 원본 행렬을 재구성하는 방법
import org.apache.spark.mllib.linalg.Matrix
import org.apache.spark.mllib.linalg.SingularValueDecomposition
import org.apache.spark.mllib.linalg.Vector
import org.apache.spark.mllib.linalg.distributed.RowMatrix
val data = Array(
Vectors.dense(1.0, 0.0, 7.0, 0.0, 0.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, 2)
val mat: RowMatrix = new RowMatrix(dataRDD)
// Compute the top 5 singular values and corresponding singular vectors.
val svd: SingularValueDecomposition[RowMatrix, Matrix] = mat.computeSVD(5, 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.
원래 행렬을 재구성 (코멘트 사이먼 예로한다) V documentation에 기초하여 분해이고).
첫 번째 것은 특이 값 벡터 s
을 대각 매트릭스 S
으로 변환하는 것입니다.
import org.apache.spark.mllib.linalg.Matrices
val S = Matrices.diag(s)
하지만 U * diagonal (s) * transpose (V)를 계산하려고하면 다음 오류가 발생합니다. 나는 DenseMatrix
Vdense
import org.apache.spark.mllib.linalg.DenseMatrix
val Vdense = new DenseMatrix(V.numRows, V.numCols, V.toArray)
val dataApprox = U.multiply(S.multiply(Vdense.transpose))
에 Matrix
V
을 변환하면 원래 행렬의 약을 얻을 수있는 방법이 있나요
error: type mismatch; found: org.apache.spark.mllib.linalg.Matrix required: org.apache.spark.mllib.linalg.DenseMatrix
의미가 있습니다 :
val dataApprox = U.multiply(S.multiply(V.transpose))
는 나는 다음과 같은 오류가 발생합니다 dataApprox
이 변환하지 않고 svd의 출력?