spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From feynmanliang <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-5016][MLLib] Distribute GMM mixture com...
Date Wed, 08 Jul 2015 01:18:18 GMT
Github user feynmanliang commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7166#discussion_r34108772
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/clustering/GaussianMixture.scala
---
    @@ -171,14 +185,30 @@ class GaussianMixture private (
           // Create new distributions based on the partial assignments
           // (often referred to as the "M" step in literature)
           val sumWeights = sums.weights.sum
    -      var i = 0
    -      while (i < k) {
    -        val mu = sums.means(i) / sums.weights(i)
    -        BLAS.syr(-sums.weights(i), Vectors.fromBreeze(mu),
    -          Matrices.fromBreeze(sums.sigmas(i)).asInstanceOf[DenseMatrix])
    -        weights(i) = sums.weights(i) / sumWeights
    -        gaussians(i) = new MultivariateGaussian(mu, sums.sigmas(i) / sums.weights(i))
    -        i = i + 1
    +
    +      if (distributeGaussians) {
    +        val (ws, gs) = sc.parallelize(0 until k).map { i =>
    +          val mu = sums.means(i) / sums.weights(i)
    +          BLAS.syr(-sums.weights(i), Vectors.fromBreeze(mu),
    +            Matrices.fromBreeze(sums.sigmas(i)).asInstanceOf[DenseMatrix])
    +          val weight = sums.weights(i) / sumWeights
    +          val gaussian = new MultivariateGaussian(mu, sums.sigmas(i) / sums.weights(i))
    +          (weight, gaussian)
    +        }.collect.unzip
    +        (0 until k).foreach { i =>
    +          weights(i) = ws(i)
    +          gaussians(i) = gs(i)
    +        }
    +      } else {
    +        var i = 0
    +        while (i < k) {
    +          val mu = sums.means(i) / sums.weights(i)
    +          BLAS.syr(-sums.weights(i), Vectors.fromBreeze(mu),
    +            Matrices.fromBreeze(sums.sigmas(i)).asInstanceOf[DenseMatrix])
    +          weights(i) = sums.weights(i) / sumWeights
    +          gaussians(i) = new MultivariateGaussian(mu, sums.sigmas(i) / sums.weights(i))
    --- End diff --
    
    OK.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message