Skip to content
Closed
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 @@ -477,7 +477,8 @@ class IsotonicRegression private (private var isotonic: Boolean) extends Seriali
private def parallelPoolAdjacentViolators(
input: RDD[(Double, Double, Double)]): Array[(Double, Double, Double)] = {
val keyedInput = input.keyBy(_._2)
val parallelStepResult = keyedInput

keyedInput
// Points with same or adjacent features must collocate within the same partition.
.partitionBy(new RangePartitioner(keyedInput.getNumPartitions, keyedInput))
.values
Expand All @@ -486,10 +487,10 @@ class IsotonicRegression private (private var isotonic: Boolean) extends Seriali
// Aggregate points with equal features into a single point.
.map(makeUnique)
.flatMap(poolAdjacentViolators)
// Sort partial results with a spill-capable shuffle before the final PAV pass.
.sortBy(_._2, ascending = true, numPartitions = 1)
.mapPartitions(p => poolAdjacentViolators(p.toArray).iterator)
.collect()
// Sort again because collect() doesn't promise ordering.
.sortBy(_._2)
poolAdjacentViolators(parallelStepResult)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ class IsotonicRegressionSuite extends SparkFunSuite with MLlibTestSparkContext w
assert(model.predictions === Array(1, 2, 3, 4, 5))
}

test("isotonic regression merges partial results across partitions") {
val model = runIsotonicRegressionOnInput(generateIsotonicInput(Seq(1, 3, 2, 4)), true, 2)

assert(model.boundaries === Array(0, 1, 2, 3))
assert(model.predictions === Array(1, 2.5, 2.5, 4))
}

test("weighted isotonic regression") {
val model = runIsotonicRegression(Seq(1, 2, 3, 4, 2), Seq(1, 1, 1, 1, 2), true)

Expand Down