Skip to content

Commit c1a8e16

Browse files
author
Travis Galoppo
committed
Made GaussianMixtureModel class serializable
Modified sum function for better performance
1 parent 5c96c57 commit c1a8e16

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

mllib/src/main/scala/org/apache/spark/mllib/clustering/GMMExpectationMaximization.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class GMMExpectationMaximization private (
201201
/** Sum the values in array of doubles */
202202
private def sum(x : Array[Double]) : Double = {
203203
var s : Double = 0.0
204-
x.foreach(u => s += u)
204+
(0 until x.length).foreach(j => s += x(j))
205205
s
206206
}
207207

mllib/src/main/scala/org/apache/spark/mllib/clustering/GaussianMixtureModel.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import org.apache.spark.mllib.linalg.Vector
2525
* from each Gaussian i=1..k with probability w(i); mu(i) and sigma(i) are the respective
2626
* mean and covariance for each Gaussian distribution i=1..k.
2727
*/
28-
class GaussianMixtureModel(val w: Array[Double], val mu: Array[Vector], val sigma: Array[Matrix]) {
28+
class GaussianMixtureModel(
29+
val w: Array[Double],
30+
val mu: Array[Vector],
31+
val sigma: Array[Matrix]) extends Serializable {
2932

3033
/** Number of gaussians in mixture */
3134
def k: Int = w.length;

0 commit comments

Comments
 (0)