Suppose you’re doing some typical supervised learning on a gigantic dataset where the total loss over all samples for parameter \(w\) is simply the sum of the losses of each sample \(i\), i.e.,

Basically any loss function you can think of in the i.i.d sample regime can be composed this way. Since we assumed that your dataset was huge, there's no way you’re going to be able to load it all into memory for BFGS, so you choose to use Stochastic Gradient Descent. The update for sample \(i\) with step size \(\eta_t\) would then be,

So far, so good. If \(\nabla_w l(x_i, y_i, w)\) is sparse, then you only need to change a handful of \(w\)'s components. Of course, being the astute Machine Learning expert that you are, you know that you’re going to need some regularization. Let's redefine the total loss and take a look at our new update equation,

Uh oh. Now that \(w\) appears in our Stochastic Gradient Descent update equation, you’re going to have change every non-zero element of \(w\) at every iteration, even if \(\nabla_w l(x_i, y_i, w)\) is sparse! Whatever shall you do?

The answer isn't as scary as you might think. Let’s do some algebraic manipulation from \(t = 0\),

Do you see it now? \(L_2\) regularization is really just a rescaling of \(w_t\) at every iteration. Thus instead of keeping \(w_t\), let’s keep track of,

where you update \(\bar{w}_t\) and \(c_t\) by,

And that’s it! As a final note, depending what value you choose for \(\lambda\), \(c_t\) is going to get really big or really small pretty fast. The usual "take the log" tricks aren't going to fly, either, as \(c_t\) need not be positive. The only way around it I’ve found is to check every iteration if \(c_t\) is getting out of hand, then transform \(\bar{w}_{t} \leftarrow \bar{w}_t c_t\) and \(c_t \leftarrow 1\) if it is.

Finally, credit should be given where credit is due. This is a slightly more detailed explanation of Alex Smola blog post from about a year ago, which in turn is accredited to Leon Bottou.

## Comments