wolffd@0: function Xi = lossHinge(W, Psi, M, gradient) wolffd@0: % wolffd@0: % Xi = lossHinge(W, Psi, M, gradient) wolffd@0: % wolffd@0: % W: d*d metric wolffd@0: % Psi: d*d feature matrix wolffd@0: % M: the desired margin wolffd@0: % gradient: if 0, returns the loss value wolffd@0: % if 1, returns the gradient of the loss WRT W wolffd@0: wolffd@0: Xi = max(0, M - sum(sum(W .* Psi))); wolffd@0: wolffd@0: if gradient & Xi > 0 wolffd@0: Xi = -Psi; wolffd@0: end wolffd@0: end