Github user mengxr commented on a diff in the pull request: https://github.com/apache/spark/pull/4059#discussion_r23943123 --- Diff: mllib/src/main/scala/org/apache/spark/mllib/api/python/PythonMLLibAPI.scala --- @@ -285,6 +286,59 @@ class PythonMLLibAPI extends Serializable { } /** + * Java stub for Python mllib GaussianMixture.run() + * Returns a list containing weights, mean and covariance of each mixture component. + */ + def trainGaussianMixture( + data: JavaRDD[Vector], + k: Int, + convergenceTol: Double, + maxIterations: Int, + seed: Long): JList[Object] = { + val gmmAlg = new GaussianMixture() + .setK(k) + .setConvergenceTol(convergenceTol) + .setMaxIterations(maxIterations) + .setSeed(seed) + try { + val model = gmmAlg.run(data.rdd.persist(StorageLevel.MEMORY_AND_DISK)) + + var wtArray:Array[Double] = Array() + var muArray:Array[Vector] = Array() + var siArray :Array[Matrix] = Array() + + for (i <- 0 until model.k) { + wtArray = wtArray ++ Array(model.weights(i)) + muArray = muArray ++ Array(model.gaussians(i).mu) + siArray = siArray ++ Array(model.gaussians(i).sigma) + } + + List(wtArray, muArray, siArray).map(_.asInstanceOf[Object]).asJava + } finally { + data.rdd.unpersist(blocking = false) + } + } + + /** + * Java stub for Python mllib GaussianMixtureModel.predictSoft() + */ + def predictSoftGMM( + data: JavaRDD[Vector], + wt: Object, + mu: Array[Object], + si: Array[Object]): RDD[Array[Double]] = { + val weight = wt.asInstanceOf[Array[Double]] + val mean = mu.map(_.asInstanceOf[DenseVector]) + val sigma = si.map(_.asInstanceOf[DenseMatrix]) + + val gaussians = Array.tabulate(weight.length){ + i => new MultivariateGaussian(mean(i),sigma(i)) --- End diff -- space after `,`
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org