I was trying to separate the L2 hinge loss from the L2 weight regularization. One could use L2 hinge loss without any weight regularization or with L1 weight regularization. So I was trying to separate C from lambda, although it is not clear if it is the right approach. 

The idea of multiplying the loss by `0.5` instead of multiplying the gradient by `2` was to simplify the gradient computation and reduce the rounding errors.

I was following this implementation of L2svmloss
```
Y = bsxfun(@(y,ypos) 2*(y==ypos)-1, y, 1:K);

margin = max(0, 1 - Y .* (X*theta));
if reg
    loss = (0.5 * sum(theta.^2)) + C*mean(margin.^2);
else
    loss = C*mean(margin.^2);
end
loss = sum(loss);
if reg
    g = theta - 2*C/M * (X' * (margin .* Y));
else
    g = - 2*C/M * (X' * (margin .* Y));
end
```