final float gradient = -y * xi;
final float scaled_gradient = gradient * scaling;
float scaled_sum_sqgrad = 0.f;
float scaled_sum_grad = 0.f;
IWeightValue old = model.get(x);
if(old != null) {
scaled_sum_sqgrad = old.getSumOfSquaredGradients();
scaled_sum_grad = old.getSumOfGradients();
}
scaled_sum_grad += scaled_gradient;
scaled_sum_sqgrad += (scaled_gradient * scaled_gradient);
float sum_grad = scaled_sum_grad * scaling;
double sum_sqgrad = scaled_sum_sqgrad * scaling;
// sign(u_{t,i})
float sign = (sum_grad > 0.f) ? 1.f : -1.f;
// |u_{t,i}|/t - \lambda
float meansOfGradients = sign * sum_grad / t - lambda;
if(meansOfGradients < 0.f) {
// x_{t,i} = 0
model.delete(x);
} else {
// x_{t,i} = -sign(u_{t,i}) * \frac{\eta t}{\sqrt{G_{t,ii}}}(|u_{t,i}|/t - \lambda)
float weight = -1.f * sign * eta * t * meansOfGradients / (float) Math.sqrt(sum_sqgrad);
IWeightValue new_w = new WeightValueParamsF2(weight, scaled_sum_sqgrad, scaled_sum_grad);
model.set(x, new_w);
}
}