Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/15018#discussion_r92298473
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/regression/IsotonicRegression.scala
---
@@ -344,27 +344,30 @@ class IsotonicRegression private (private var
isotonic: Boolean) extends Seriali
}
var i = 0
- val len = input.length
- while (i < len) {
- var j = i
-
- // Find monotonicity violating sequence, if any.
- while (j < len - 1 && input(j)._1 > input(j + 1)._1) {
- j = j + 1
- }
+ val n = input.length - 1
+ var notFinished = true
+
+ while (notFinished) {
+ i = 0
+ notFinished = false
+
+ // Iterate through the data, fix any monotonicity violations we find
+ // We may need to do this multiple times, as pooling can introduce
violations
+ // at locations that were previously fine.
+ while (i < n) {
+ var j = i
+
+ // Find next monotonicity violating sequence, if any.
+ while (j < n && input(j)._1 >= input(j + 1)._1) {
+ j = j + 1
+ }
- // If monotonicity was not violated, move to next data point.
- if (i == j) {
- i = i + 1
- } else {
- // Otherwise pool the violating sequence
- // and check if pooling caused monotonicity violation in
previously processed points.
- while (i >= 0 && input(i)._1 > input(i + 1)._1) {
+ // Pool the violating sequence with the data point preceding it
+ if (input(i)._1 != input(j)._1) {
--- End diff --
I believe the logic is:
* If equality holds here, then either (a) i = j or (b) the block [i,j] has
equal elements.
* A violation could be introduced but will be caught on the next iteration
of the outer loop.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]