Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,22 @@ class GaussianMixture private (
val compute = sc.broadcast(ExpectationSum.add(weights, gaussians)_)

// aggregate the cluster contribution for all sample points
// Avoid allocating and serializing a large zero value for empty partitions.
val sums = breezeData.treeAggregate[ExpectationSum](
zeroValue = ExpectationSum.zero(k, d),
seqOp = (agg: ExpectationSum, v: BV[Double]) => compute.value(agg, v),
combOp = (agg1: ExpectationSum, agg2: ExpectationSum) => agg1 += agg2,
zeroValue = null.asInstanceOf[ExpectationSum],
seqOp = (maybeAgg: ExpectationSum, v: BV[Double]) => {
val agg = if (maybeAgg == null) ExpectationSum.zero(k, d) else maybeAgg
compute.value(agg, v)
},
combOp = (agg1: ExpectationSum, agg2: ExpectationSum) => {
if (agg1 == null) {
agg2
} else if (agg2 == null) {
agg1
} else {
agg1 += agg2
}
},
depth = 2,
finalAggregateOnExecutor = true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class GaussianMixtureSuite extends SparkFunSuite with MLlibTestSparkContext {
}
}

test("single cluster") {
test("single cluster with empty partitions") {
val data = sc.parallelize(Seq(
Vectors.dense(6.0, 9.0),
Vectors.dense(5.0, 10.0),
Vectors.dense(4.0, 11.0)
))
), 4)

// expectations
val Ew = 1.0
Expand Down