Skip to content
Closed
Changes from 1 commit
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 @@ -241,16 +241,28 @@ object LBFGS extends Logging {
val bcW = data.context.broadcast(w)
val localGradient = gradient

val (gradientSum, lossSum) = data.treeAggregate((Vectors.zeros(n), 0.0))(
seqOp = (c, v) => (c, v) match { case ((grad, loss), (label, features)) =>
val l = localGradient.compute(
features, label, bcW.value, grad)
(grad, loss + l)
},
combOp = (c1, c2) => (c1, c2) match { case ((grad1, loss1), (grad2, loss2)) =>
axpy(1.0, grad2, grad1)
(grad1, loss1 + loss2)
})
/** Given (current accumulated gradient, current loss) and (label, features)
* tuples, updates the current gradient and current loss
*/
val seqOp = (c: (Vector, Double), v: (Double, Vector)) => {
(c, v) match { case ((grad, loss), (label, features)) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: unindent 2 spaces and you can remove the outer braces? same in the next function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will do it.

val l = localGradient.compute(features, label, bcW.value, grad)
(grad, loss + l)
}
}

// Adds two (gradient, loss) tuples
val combOp = (c1: (Vector, Double), c2: (Vector, Double)) => {
(c1, c2) match { case ((grad1, loss1), (grad2, loss2)) =>
axpy(1.0, grad2, grad1)
(grad1, loss1 + loss2)
}
}

val (gradientSum, lossSum) = data.mapPartitions(it => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: .mapPartitions { it =>

val inPartitionAggregated = it.aggregate((Vectors.zeros(n), 0.0))(seqOp, combOp)
Iterator(inPartitionAggregated)
}).treeReduce(combOp)

/**
* regVal is sum of weight squares if it's L2 updater;
Expand Down