diff --git a/mllib/src/main/scala/org/apache/spark/mllib/linalg/EigenValueDecomposition.scala b/mllib/src/main/scala/org/apache/spark/mllib/linalg/EigenValueDecomposition.scala index a571cc8a1c5b6..e6688c1ccbb22 100644 --- a/mllib/src/main/scala/org/apache/spark/mllib/linalg/EigenValueDecomposition.scala +++ b/mllib/src/main/scala/org/apache/spark/mllib/linalg/EigenValueDecomposition.scala @@ -30,6 +30,7 @@ import org.apache.spark.annotation.Experimental @Experimental case class EigenValueDecomposition[VType](s: Vector, V: VType) +@Experimental object EigenValueDecomposition { /** * Compute the leading k eigenvalues and eigenvectors on a symmetric square matrix using ARPACK. diff --git a/mllib/src/main/scala/org/apache/spark/mllib/linalg/distributed/RowMatrix.scala b/mllib/src/main/scala/org/apache/spark/mllib/linalg/distributed/RowMatrix.scala index 7e7d6e0d8ab6d..ecd25c1273cb4 100644 --- a/mllib/src/main/scala/org/apache/spark/mllib/linalg/distributed/RowMatrix.scala +++ b/mllib/src/main/scala/org/apache/spark/mllib/linalg/distributed/RowMatrix.scala @@ -245,6 +245,23 @@ class RowMatrix( RowMatrix.triuToFull(n, GU.data) } + /** + * Computes the singular value decomposition of this matrix, using default tolerance (1e-9). + * + * @param k number of singular values to keep. We might return less than k if there are + * numerically zero singular values. See rCond. + * @param computeU whether to compute U + * @param rCond the reciprocal condition number. All singular values smaller than rCond * sigma(0) + * are treated as zero, where sigma(0) is the largest singular value. + * @return SingularValueDecomposition(U, s, V) + */ + def computeSVD( + k: Int, + computeU: Boolean = false, + rCond: Double = 1e-9): SingularValueDecomposition[RowMatrix, Matrix] = { + computeSVD(k, computeU, rCond, 1e-9) + } + /** * Computes the singular value decomposition of this matrix. * Denote this matrix by A (m x n), this will compute matrices U, S, V such that A ~= U * S * V', @@ -281,9 +298,9 @@ class RowMatrix( */ def computeSVD( k: Int, - computeU: Boolean = false, - rCond: Double = 1e-9, - tol: Double = 1e-6): SingularValueDecomposition[RowMatrix, Matrix] = { + computeU: Boolean, + rCond: Double, + tol: Double): SingularValueDecomposition[RowMatrix, Matrix] = { val n = numCols().toInt require(k > 0 && k <= n, s"Request up to n singular values k=$k n=$n.")