new example file

Project: http://git-wip-us.apache.org/repos/asf/incubator-spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-spark/commit/e9bd6cb5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-spark/tree/e9bd6cb5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-spark/diff/e9bd6cb5

Branch: refs/heads/master
Commit: e9bd6cb51dce9222a5a284cd171b299b0169852b
Parents: 8bfcce1
Author: Reza Zadeh <riz...@gmail.com>
Authored: Sat Jan 4 12:33:22 2014 -0800
Committer: Reza Zadeh <riz...@gmail.com>
Committed: Sat Jan 4 12:33:22 2014 -0800

----------------------------------------------------------------------
 .../org/apache/spark/examples/SparkSVD.scala    | 58 ++++++++++++++++++++
 .../org/apache/spark/mllib/linalg/SVD.scala     |  1 -
 2 files changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-spark/blob/e9bd6cb5/examples/src/main/scala/org/apache/spark/examples/SparkSVD.scala
----------------------------------------------------------------------
diff --git a/examples/src/main/scala/org/apache/spark/examples/SparkSVD.scala 
b/examples/src/main/scala/org/apache/spark/examples/SparkSVD.scala
new file mode 100644
index 0000000..5590ee7
--- /dev/null
+++ b/examples/src/main/scala/org/apache/spark/examples/SparkSVD.scala
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.examples
+      
+import org.apache.spark.SparkContext
+import org.apache.spark.mllib.linalg.SVD
+import org.apache.spark.mllib.linalg.MatrixEntry
+
+/**
+ * Compute SVD of an example matrix
+ * Input file should be comma separated, 1 indexed of the form
+ * i,j,value
+ * Where i is the column, j the row, and value is the matrix entry
+ * 
+ * For example input file, see:
+ * mllib/data/als/test.data
+ */
+object SparkSVD {
+  def main(args: Array[String]) {
+   if (args.length < 3) {
+      System.err.println("Usage: SVD <master> <file>")
+      System.exit(1)
+    }
+    val sc = new SparkContext(args(0), "SVD",
+      System.getenv("SPARK_HOME"), Seq(System.getenv("SPARK_EXAMPLES_JAR")))
+
+    // Load and parse the data file
+    val data = sc.textFile(args(1)).map { line =>
+      val parts = line.split(',')
+      MatrixEntry(parts(0).toInt, parts(1).toInt, parts(2).toDouble)
+    }
+    val m = 4
+    val n = 4
+
+    // recover largest singular vector
+    val decomposed = SVD.sparseSVD(data, m, n, 1)
+    val u = decomposed.U
+    val s = decomposed.S
+    val v = decomposed.V
+
+    println("singular values = " + s.toArray.mkString)
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-spark/blob/e9bd6cb5/mllib/src/main/scala/org/apache/spark/mllib/linalg/SVD.scala
----------------------------------------------------------------------
diff --git a/mllib/src/main/scala/org/apache/spark/mllib/linalg/SVD.scala 
b/mllib/src/main/scala/org/apache/spark/mllib/linalg/SVD.scala
index d1ee6c6..e58b8e8 100644
--- a/mllib/src/main/scala/org/apache/spark/mllib/linalg/SVD.scala
+++ b/mllib/src/main/scala/org/apache/spark/mllib/linalg/SVD.scala
@@ -24,7 +24,6 @@ import org.apache.spark.rdd.RDD
 import org.jblas.{DoubleMatrix, Singular, MatrixFunctions}
 
 
-
 /**
  * Class used to obtain singular value decompositions
  * @param data Matrix in sparse matrix format

Reply via email to