Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15018#discussion_r92232757
  
    --- 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 --
    
    This condition is "if there was any decrease, not just == from i to j" 
right? and `pool` makes everything in [i,j] non-violating.
    
    Comments from the previous code note that this could introduce a violation 
-- is this still possible? it wasn't obvious why it can't happen now.


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

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

Reply via email to