Мне трудно читать код с открытым исходным кодом mllib для SGD с регуляцией L2.SGD с регуляцией L2 в mllib
Код
class SquaredL2Updater extends Updater {
override def compute(
weightsOld: Vector,
gradient: Vector,
stepSize: Double,
iter: Int,
regParam: Double): (Vector, Double) = {
// add up both updates from the gradient of the loss (= step) as well as
// the gradient of the regularizer (= regParam * weightsOld)
// w' = w - thisIterStepSize * (gradient + regParam * w)
// w' = (1 - thisIterStepSize * regParam) * w - thisIterStepSize * gradient
val thisIterStepSize = stepSize/math.sqrt(iter)
val brzWeights: BV[Double] = weightsOld.toBreeze.toDenseVector
brzWeights :*= (1.0 - thisIterStepSize * regParam)
brzAxpy(-thisIterStepSize, gradient.toBreeze, brzWeights)
val norm = brzNorm(brzWeights, 2.0)
(Vectors.fromBreeze(brzWeights), 0.5 * regParam * norm * norm)
}
Часть У меня возникли проблемы с является
brzWeights :*= (1.0 - thisIterStepSize * regParam)
ветер Lib содержит документацию, которая объясняет: * = оператор
/** Mutates this by element-wise multiplication of b into this. */
final def :*=[TT >: This, B](b: B)(implicit op: OpMulScalar.InPlaceImpl2[TT, B]): This = {
op(repr, b)
repr
}
это выглядит как его простое умножение вектора на скаляр.
Формула я нашел для градиента в случае регуляризации L2 является
Как код представляет этот градиент в этом обновлении? Может кто-то помочь, пожалуйста.