@@ -370,7 +370,7 @@ private[ml] class LogisticAggregator(
370370 * BlockLogisticAggregator computes the gradient and loss used in Logistic classification
371371 * for blocks in sparse or dense matrix in an online fashion.
372372 *
373- * Two BlockLogisticAggregator can be merged together to have a summary of loss and gradient of
373+ * Two BlockLogisticAggregators can be merged together to have a summary of loss and gradient of
374374 * the corresponding joint dataset.
375375 *
376376 * NOTE: The feature values are expected to be standardized before computation.
@@ -413,8 +413,8 @@ private[ml] class BlockLogisticAggregator(
413413 }
414414
415415 @ transient private lazy val binaryLinear = (multinomial, fitIntercept) match {
416- case (false , true ) => Vectors .dense(coefficientsArray.take(numFeatures)).toDense
417- case (false , false ) => Vectors .dense(coefficientsArray).toDense
416+ case (false , true ) => Vectors .dense(coefficientsArray.take(numFeatures))
417+ case (false , false ) => Vectors .dense(coefficientsArray)
418418 case _ => null
419419 }
420420
@@ -428,11 +428,11 @@ private[ml] class BlockLogisticAggregator(
428428 }
429429
430430 /**
431- * Add a new training instance block to this LogisticAggregator , and update the loss and gradient
432- * of the objective function.
431+ * Add a new training instance block to this BlockLogisticAggregator , and update the loss and
432+ * gradient of the objective function.
433433 *
434434 * @param block The instance block of data point to be added.
435- * @return This LogisticAggregator object.
435+ * @return This BlockLogisticAggregator object.
436436 */
437437 def add (block : InstanceBlock ): this .type = {
438438 require(block.matrix.isTransposed)
@@ -467,7 +467,6 @@ private[ml] class BlockLogisticAggregator(
467467 // in-place convert margins to multiplier
468468 // then, vec represents multiplier
469469 var i = 0
470- var interceptGradSum = 0.0
471470 while (i < size) {
472471 val weight = block.getWeight(i)
473472 if (weight > 0 ) {
@@ -482,7 +481,6 @@ private[ml] class BlockLogisticAggregator(
482481 }
483482 val multiplier = weight * (1.0 / (1.0 + math.exp(margin)) - label)
484483 vec.values(i) = multiplier
485- if (fitIntercept) interceptGradSum += multiplier
486484 } else { vec.values(i) = 0.0 }
487485 i += 1
488486 }
@@ -494,19 +492,19 @@ private[ml] class BlockLogisticAggregator(
494492 case dm : DenseMatrix =>
495493 BLAS .nativeBLAS.dgemv(" N" , dm.numCols, dm.numRows, 1.0 , dm.values, dm.numCols,
496494 vec.values, 1 , 1.0 , gradientSumArray, 1 )
497- if (fitIntercept) gradientSumArray(numFeatures) += interceptGradSum
498495
499496 case sm : SparseMatrix if fitIntercept =>
500497 val linearGradSumVec = Vectors .zeros(numFeatures).toDense
501498 BLAS .gemv(1.0 , sm.transpose, vec, 0.0 , linearGradSumVec)
502499 BLAS .getBLAS(numFeatures).daxpy(numFeatures, 1.0 , linearGradSumVec.values, 1 ,
503500 gradientSumArray, 1 )
504- gradientSumArray(numFeatures) += interceptGradSum
505501
506502 case sm : SparseMatrix if ! fitIntercept =>
507503 val gradSumVec = new DenseVector (gradientSumArray)
508504 BLAS .gemv(1.0 , sm.transpose, vec, 1.0 , gradSumVec)
509505 }
506+
507+ if (fitIntercept) gradientSumArray(numFeatures) += vec.values.sum
510508 }
511509
512510 /** Update gradient and loss using multinomial (softmax) loss function. */
0 commit comments