spark git commit: [SPARK-11566] [MLLIB] [PYTHON] Refactoring GaussianMixtureModel.gaussians in Python

2015-11-10 Thread davies
Repository: spark
Updated Branches:
  refs/heads/master a3989058c -> c0e48dfa6


[SPARK-11566] [MLLIB] [PYTHON] Refactoring GaussianMixtureModel.gaussians in 
Python

cc jkbradley

Author: Yu ISHIKAWA 

Closes #9534 from yu-iskw/SPARK-11566.


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

Branch: refs/heads/master
Commit: c0e48dfa611fa5d94132af7e6f6731f60ab833da
Parents: a398905
Author: Yu ISHIKAWA 
Authored: Tue Nov 10 16:42:28 2015 -0800
Committer: Davies Liu 
Committed: Tue Nov 10 16:42:28 2015 -0800

--
 .../python/GaussianMixtureModelWrapper.scala| 21 ++--
 python/pyspark/mllib/clustering.py  |  2 +-
 2 files changed, 7 insertions(+), 16 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/spark/blob/c0e48dfa/mllib/src/main/scala/org/apache/spark/mllib/api/python/GaussianMixtureModelWrapper.scala
--
diff --git 
a/mllib/src/main/scala/org/apache/spark/mllib/api/python/GaussianMixtureModelWrapper.scala
 
b/mllib/src/main/scala/org/apache/spark/mllib/api/python/GaussianMixtureModelWrapper.scala
index 0ec88ef..6a3b20c 100644
--- 
a/mllib/src/main/scala/org/apache/spark/mllib/api/python/GaussianMixtureModelWrapper.scala
+++ 
b/mllib/src/main/scala/org/apache/spark/mllib/api/python/GaussianMixtureModelWrapper.scala
@@ -17,14 +17,11 @@
 
 package org.apache.spark.mllib.api.python
 
-import java.util.{List => JList}
-
-import scala.collection.JavaConverters._
-import scala.collection.mutable.ArrayBuffer
+import scala.collection.JavaConverters
 
 import org.apache.spark.SparkContext
-import org.apache.spark.mllib.linalg.{Vector, Vectors, Matrix}
 import org.apache.spark.mllib.clustering.GaussianMixtureModel
+import org.apache.spark.mllib.linalg.{Vector, Vectors}
 
 /**
   * Wrapper around GaussianMixtureModel to provide helper methods in Python
@@ -36,17 +33,11 @@ private[python] class GaussianMixtureModelWrapper(model: 
GaussianMixtureModel) {
   /**
 * Returns gaussians as a List of Vectors and Matrices corresponding each 
MultivariateGaussian
 */
-  val gaussians: JList[Object] = {
-val modelGaussians = model.gaussians
-var i = 0
-var mu = ArrayBuffer.empty[Vector]
-var sigma = ArrayBuffer.empty[Matrix]
-while (i < k) {
-  mu += modelGaussians(i).mu
-  sigma += modelGaussians(i).sigma
-  i += 1
+  val gaussians: Array[Byte] = {
+val modelGaussians = model.gaussians.map { gaussian =>
+  Array[Any](gaussian.mu, gaussian.sigma)
 }
-List(mu.toArray, sigma.toArray).map(_.asInstanceOf[Object]).asJava
+SerDe.dumps(JavaConverters.seqAsJavaListConverter(modelGaussians).asJava)
   }
 
   def save(sc: SparkContext, path: String): Unit = model.save(sc, path)

http://git-wip-us.apache.org/repos/asf/spark/blob/c0e48dfa/python/pyspark/mllib/clustering.py
--
diff --git a/python/pyspark/mllib/clustering.py 
b/python/pyspark/mllib/clustering.py
index 1fa061d..c9e6f1d 100644
--- a/python/pyspark/mllib/clustering.py
+++ b/python/pyspark/mllib/clustering.py
@@ -266,7 +266,7 @@ class GaussianMixtureModel(JavaModelWrapper, JavaSaveable, 
JavaLoader):
 """
 return [
 MultivariateGaussian(gaussian[0], gaussian[1])
-for gaussian in zip(*self.call("gaussians"))]
+for gaussian in self.call("gaussians")]
 
 @property
 @since('1.4.0')


-
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org



spark git commit: [SPARK-11566] [MLLIB] [PYTHON] Refactoring GaussianMixtureModel.gaussians in Python

2015-11-10 Thread davies
Repository: spark
Updated Branches:
  refs/heads/branch-1.6 9ccd1bb80 -> d8bfc025c


[SPARK-11566] [MLLIB] [PYTHON] Refactoring GaussianMixtureModel.gaussians in 
Python

cc jkbradley

Author: Yu ISHIKAWA 

Closes #9534 from yu-iskw/SPARK-11566.

(cherry picked from commit c0e48dfa611fa5d94132af7e6f6731f60ab833da)
Signed-off-by: Davies Liu 


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

Branch: refs/heads/branch-1.6
Commit: d8bfc025c0855af0e7dcd1b9b1efdb43e3fba794
Parents: 9ccd1bb
Author: Yu ISHIKAWA 
Authored: Tue Nov 10 16:42:28 2015 -0800
Committer: Davies Liu 
Committed: Tue Nov 10 16:44:45 2015 -0800

--
 .../python/GaussianMixtureModelWrapper.scala| 21 ++--
 python/pyspark/mllib/clustering.py  |  2 +-
 2 files changed, 7 insertions(+), 16 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/spark/blob/d8bfc025/mllib/src/main/scala/org/apache/spark/mllib/api/python/GaussianMixtureModelWrapper.scala
--
diff --git 
a/mllib/src/main/scala/org/apache/spark/mllib/api/python/GaussianMixtureModelWrapper.scala
 
b/mllib/src/main/scala/org/apache/spark/mllib/api/python/GaussianMixtureModelWrapper.scala
index 0ec88ef..6a3b20c 100644
--- 
a/mllib/src/main/scala/org/apache/spark/mllib/api/python/GaussianMixtureModelWrapper.scala
+++ 
b/mllib/src/main/scala/org/apache/spark/mllib/api/python/GaussianMixtureModelWrapper.scala
@@ -17,14 +17,11 @@
 
 package org.apache.spark.mllib.api.python
 
-import java.util.{List => JList}
-
-import scala.collection.JavaConverters._
-import scala.collection.mutable.ArrayBuffer
+import scala.collection.JavaConverters
 
 import org.apache.spark.SparkContext
-import org.apache.spark.mllib.linalg.{Vector, Vectors, Matrix}
 import org.apache.spark.mllib.clustering.GaussianMixtureModel
+import org.apache.spark.mllib.linalg.{Vector, Vectors}
 
 /**
   * Wrapper around GaussianMixtureModel to provide helper methods in Python
@@ -36,17 +33,11 @@ private[python] class GaussianMixtureModelWrapper(model: 
GaussianMixtureModel) {
   /**
 * Returns gaussians as a List of Vectors and Matrices corresponding each 
MultivariateGaussian
 */
-  val gaussians: JList[Object] = {
-val modelGaussians = model.gaussians
-var i = 0
-var mu = ArrayBuffer.empty[Vector]
-var sigma = ArrayBuffer.empty[Matrix]
-while (i < k) {
-  mu += modelGaussians(i).mu
-  sigma += modelGaussians(i).sigma
-  i += 1
+  val gaussians: Array[Byte] = {
+val modelGaussians = model.gaussians.map { gaussian =>
+  Array[Any](gaussian.mu, gaussian.sigma)
 }
-List(mu.toArray, sigma.toArray).map(_.asInstanceOf[Object]).asJava
+SerDe.dumps(JavaConverters.seqAsJavaListConverter(modelGaussians).asJava)
   }
 
   def save(sc: SparkContext, path: String): Unit = model.save(sc, path)

http://git-wip-us.apache.org/repos/asf/spark/blob/d8bfc025/python/pyspark/mllib/clustering.py
--
diff --git a/python/pyspark/mllib/clustering.py 
b/python/pyspark/mllib/clustering.py
index 1fa061d..c9e6f1d 100644
--- a/python/pyspark/mllib/clustering.py
+++ b/python/pyspark/mllib/clustering.py
@@ -266,7 +266,7 @@ class GaussianMixtureModel(JavaModelWrapper, JavaSaveable, 
JavaLoader):
 """
 return [
 MultivariateGaussian(gaussian[0], gaussian[1])
-for gaussian in zip(*self.call("gaussians"))]
+for gaussian in self.call("gaussians")]
 
 @property
 @since('1.4.0')


-
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org