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

    https://github.com/apache/spark/pull/13796#discussion_r75230308
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala
 ---
    @@ -982,45 +1275,13 @@ private class LogisticAggregator(
                 "coefficients only supports dense vector" +
                   s"but got type ${bcCoefficients.value.getClass}.")
           }
    -      val localGradientSumArray = gradientSumArray
    -
    -      val featuresStd = bcFeaturesStd.value
    -      numClasses match {
    -        case 2 =>
    -          // For Binary Logistic Regression.
    -          val margin = - {
    -            var sum = 0.0
    -            features.foreachActive { (index, value) =>
    -              if (featuresStd(index) != 0.0 && value != 0.0) {
    -                sum += coefficientsArray(index) * (value / 
featuresStd(index))
    -              }
    -            }
    -            sum + {
    -              if (fitIntercept) coefficientsArray(numFeatures) else 0.0
    -            }
    -          }
    -
    -          val multiplier = weight * (1.0 / (1.0 + math.exp(margin)) - 
label)
    -
    -          features.foreachActive { (index, value) =>
    -            if (featuresStd(index) != 0.0 && value != 0.0) {
    -              localGradientSumArray(index) += multiplier * (value / 
featuresStd(index))
    -            }
    -          }
    -
    -          if (fitIntercept) {
    -            localGradientSumArray(numFeatures) += multiplier
    -          }
     
    -          if (label > 0) {
    -            // The following is equivalent to log(1 + exp(margin)) but 
more numerically stable.
    -            lossSum += weight * MLUtils.log1pExp(margin)
    -          } else {
    -            lossSum += weight * (MLUtils.log1pExp(margin) - margin)
    -          }
    -        case _ =>
    -          new NotImplementedError("LogisticRegression with ElasticNet in 
ML package " +
    -            "only supports binary classification for now.")
    +      if (multinomial) {
    +        multinomialUpdateInPlace(features, weight, label, 
coefficientsArray, gradientSumArray,
    +          bcFeaturesStd.value, numFeaturesPlusIntercept)
    --- End diff --
    
    I removed the class variables from the functions. For the performance 
critical arrays, I make local copies to inside the functions.


---
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]

Reply via email to