Skip to content

Commit

Permalink
rename rcond
Browse files Browse the repository at this point in the history
  • Loading branch information
rezazadeh committed Mar 20, 2014
1 parent ea223a6 commit 2e1cf43
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions mllib/src/main/scala/org/apache/spark/mllib/linalg/SVD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.jblas.{DoubleMatrix, Singular, MatrixFunctions}
class SVD {
private var k: Int = 1
private var computeU: Boolean = true
private var RCOND: Double = 1e-9
private var smallestSigma: Double = 1e-9

/**
* Set the number of top-k singular vectors to return
Expand All @@ -43,8 +43,8 @@ class SVD {
/**
* Singular values smaller than this value are considered zero
*/
def setReciprocalConditionNumber(rcond: Double): SVD = {
this.RCOND = rcond
def setReciprocalConditionNumber(smallS: Double): SVD = {
this.smallestSigma = smallS
this
}

Expand All @@ -67,7 +67,7 @@ class SVD {
* Compute SVD using the current set parameters
*/
def compute(matrix: TallSkinnyDenseMatrix) : TallSkinnyMatrixSVD = {
SVD.denseSVD(matrix, k, computeU, RCOND)
SVD.denseSVD(matrix, k, computeU, smallestSigma)
}

/**
Expand All @@ -80,7 +80,7 @@ class SVD {
*/
def compute(matrix: RDD[Array[Double]]) :
(RDD[Array[Double]], Array[Double], Array[Array[Double]]) = {
SVD.denseSVD(matrix, k, computeU, RCOND)
SVD.denseSVD(matrix, k, computeU, smallestSigma)
}
}

Expand Down Expand Up @@ -334,11 +334,10 @@ object SVD {
// prepare V for returning
val retV = Array.tabulate(n, sk)((i, j) => V.get(i, j))

// Compute U as U = A V S^-1
// Compute VS^-1
val vsinv = new DoubleMatrix(Array.tabulate(n, sk)((i, j) => V.get(i, j) / sigma(j)))

if (computeU) {
// Compute U as U = A V S^-1
// Compute VS^-1
val vsinv = new DoubleMatrix(Array.tabulate(n, sk)((i, j) => V.get(i, j) / sigma(j)))
val retU = matrix.map { x =>
val v = new DoubleMatrix(Array(x))
v.mmul(vsinv).data
Expand Down

0 comments on commit 2e1cf43

Please sign in to comment.