Foundations to Frontier
Tests
E. Deep Learning › E2 Loss Functions (one page each)

Hinge and squared hinge losses

The hinge loss, max(0, 1 − y·f(x)), charges nothing to examples classified correctly with a margin of at least 1 and grows linearly for the rest; the squared hinge squares that penalty. They are the losses of support vector machines: only examples inside the margin, the support vectors, affect the solution. This page covers both losses, their subgradients, the multiclass hinge, the SVM objective, and how they compare with logistic loss. In the exercises you implement the hinge family and the soft-margin SVM objective, then train linear classifiers with 0%, 10% and 20% flipped labels and find that plain hinge was the most robust of the three by a small but consistent margin, while squared hinge let misfitted points push about four times harder.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Right is not enough: right by a margin

A classifier’s margin for an example is y·f(x), the score multiplied by the true label (±1). It is positive when the example is classified correctly, and larger when it is classified confidently. The hinge loss charges nothing once the margin reaches 1, and charges linearly below that. Examples that are comfortably right are ignored completely; only those near or across the boundary shape the classifier. Squared hinge charges the shortfall squared.

Classification losses: who gets pushed, and how hard?
margin y·f(x) from −4 to 4
hinge: test accuracy 0.909 · recall of the orange class 0.920
Right: the loss against the margin (solid orange), minus its derivative, the push an example receives (dashed blue), and the 0–1 loss (grey step). Cross-entropy pushes every example, most those badly misclassified. Hinge losses stop pushing once the margin passes 1. Squared error on a probability barely pushes badly misclassified examples, since the sigmoid has saturated. Focal loss turns down the push on easy examples (large margin) by the factor (1 − p)^γ. Make the orange class rare and watch its recall; add label noise and watch which losses chase the flipped points.
Why engineers care

Support vector machines with hinge loss remain strong, fast, well-understood classifiers for small and medium datasets, such as fault detection from engineered features or terrain classification from spectral signatures. Their solutions depend only on the support vectors, which makes them compact and easy to inspect, and the margin gives a built-in safety buffer.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Hinge loss for an example with margin 2 is…
  2. 2. Hinge loss for margin −1 (misclassified) is…
  3. 3. Which examples shape an SVM's solution?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Margin: m = y·f(x) with y ∈ ±1. For w = (1, −1), b = 0.5, x = (1, 0) and y = 1, the margin is 1.5.
  • Hinge: max(0, 1 − m). Margins (−1, 0, 0.5, 1, 2) give (2, 1, 0.5, 0, 0).
  • Squared hinge: max(0, 1 − m)². The same margins give (4, 1, 0.25, 0, 0).
  • Subgradients: hinge −1 for m < 1 and 0 for m > 1, the same size for every violator; squared hinge −2(1 − m), growing with the violation.
  • Upper bounds: both are at least the 0–1 loss 1[m ≤ 0], so minimising them bounds the training error.
  • Multiclass (Weston–Watkins): the sum over wrong classes j of max(0, 1 + s_j − s_y). Scores (3, 1, 2.5) with true class 0 give 0 + 0.5 = 0.5.
  • Soft-margin SVM: ½‖w‖² + C·Σ hinge(mᵢ).
📝 Quick check (Level 1)
0/3 answered
  1. 1. Squared hinge at margin 0.5 is…
  2. 2. The hinge subgradient for a badly misclassified example is…
  3. 3. The SVM parameter C trades margin width against…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Implementing the hinge family

Exercise 1.

  • Hinge, squared hinge and the hinge subgradient give the values above.
  • Both losses upper-bound the 0–1 loss.
  • The Weston–Watkins multiclass hinge sums margin violations.
  • The soft-margin SVM objective adds ½‖w‖² to C times the summed hinge losses.

Training.

  • The hinge loss is convex but not differentiable at m = 1. Subgradient descent works with a decaying step size; dual solvers (SMO, liblinear) are faster for linear and kernel SVMs.
  • Squared hinge is differentiable and penalises violations more strongly, so it is often slightly faster to optimise (liblinear’s default L2-loss SVM).
  • Hinge outputs scores, not probabilities. Calibrate them afterwards (Platt scaling) if probabilities are needed.
  • In deep networks, hinge losses are used in some GAN discriminators (hinge GAN loss) and in metric learning (E2-10, E2-11).
nn.MultiMarginLoss()           # multiclass hinge
sklearn.svm.LinearSVC(loss='hinge')  # or 'squared_hinge' (default)
🐍 Exercise 1: the hinge family
Implement hinge and squared hinge, the hinge subgradient, the Weston–Watkins multiclass hinge and the soft-margin SVM objective.
📝 Quick check (Level 2)
0/3 answered
  1. 1. SVM scores can be turned into probabilities by…
  2. 2. liblinear's default linear SVM loss is…
  3. 3. Where is the hinge loss non-differentiable?

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Maximum margin. For separable data, minimising ½‖w‖² subject to every margin being at least 1 gives the hyperplane with the largest geometric margin 1/‖w‖ (Vapnik). The hinge loss relaxes the constraints: slack ξᵢ = max(0, 1 − mᵢ) is paid at rate C.

Support vectors. By the KKT conditions, the solution is w = Σ αᵢyᵢxᵢ with αᵢ > 0 only for examples with margin at most 1. Every other example could be removed without changing the classifier. This sparsity is unique to the hinge: logistic and squared-error losses give nonzero weight to every example.

Consistency. The hinge loss is classification-calibrated (Bartlett, Jordan and McAuliffe, 2006): minimising it over all functions gives the Bayes classifier sign(2η(x) − 1). Unlike the logistic loss, it does not estimate the probability η(x) itself; its minimiser is just ±1.

Robustness. Hinge and logistic losses grow linearly for very negative margins, so a mislabelled point exerts a bounded push. Squared hinge grows quadratically, so mislabelled points far on the wrong side pull hard. None of these convex losses is fully robust to label noise: bounded, non-convex losses such as the ramp loss are needed for that.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The SVM solution depends only on…
  2. 2. Minimising the hinge loss over all functions gives…
  3. 3. Full robustness to label noise needs…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Which loss resists flipped labels?

History.

  • V. Vapnik and A. Chervonenkis (1964) introduced the maximal-margin hyperplane.
  • B. Boser, I. Guyon and V. Vapnik (1992) added kernels.
  • C. Cortes and V. Vapnik (1995) introduced the soft margin with the hinge loss.
  • J. Weston and C. Watkins (1999) and K. Crammer and Y. Singer (2001) gave multiclass hinge losses.
  • J. H. Lim and J. C. Ye (2017) and T. Miyato et al. (2018) used the hinge loss for GANs.

Exercise 2. Linear classifiers on two Gaussian classes in 10 dimensions, 200 training points, with 0%, 10% or 20% of the training labels flipped. Training uses L2-regularised (sub)gradient descent with a decaying step. Accuracy is measured on 5000 clean test points. “Margin < 1” is the share of training examples the loss is still pushing (for logistic loss every example gets some push; the share is shown for comparison). “Largest push” is the largest |∂loss/∂m| at the end.

loss label noise clean test accuracy per seed mean margin < 1 largest push
hinge 0 0.877, 0.869, 0.875, 0.871, 0.863 0.871 0.30 1.00
squared hinge 0 0.871, 0.872, 0.874, 0.870, 0.862 0.870 0.55 4.09
logistic 0 0.875, 0.875, 0.878, 0.871, 0.863 0.872 0.25 0.93
hinge 0.2 0.859, 0.858, 0.870, 0.794, 0.838 0.844 0.62 1.00
squared hinge 0.2 0.840, 0.851, 0.867, 0.766, 0.836 0.832 0.96 3.99
logistic 0.2 0.841, 0.851, 0.866, 0.763, 0.837 0.831 0.60 0.91

(At 10% noise: hinge 0.867, squared hinge 0.859, logistic 0.859.)

  • Without noise, the three losses tied (within 0.002).
  • With 20% flipped labels, hinge was best in all five paired seeds, by about one point.
  • Squared hinge kept almost every example active (96%), and its largest push was about four times the hinge’s: misfitted points, many of them the flipped ones, pull quadratically.
  • The differences were small. With linear models and a fixed regularisation strength, the choice of convex loss mattered less than the noise itself (all lost 3–4 points from 0% to 20%). Cleaning labels, or using a bounded loss, matters more.
🐍 Exercise 2 (research): which loss resists flipped labels?
Train L2-regularised linear classifiers with hinge, squared hinge and logistic loss on data with 0%, 10% and 20% flipped labels; compare clean test accuracy, the share of examples with margin below 1 and the largest push.

Hinge losses in AI, robotics and aerospace

  • SVM classifiers on engineered features remain common for fault detection, spectral terrain classification and small-sample problems where deep networks overfit.
  • Hinge GAN losses train discriminators in image generators used for synthetic training data.
  • Margins as safety buffers: requiring margins, not just correct signs, makes classifiers less sensitive to small input perturbations.

References

  1. C. Cortes, V. Vapnik (1995). “Support-vector networks.” Machine Learning 20(3).
  2. B. E. Boser, I. M. Guyon, V. N. Vapnik (1992). “A training algorithm for optimal margin classifiers.” Proc. COLT.
  3. J. Weston, C. Watkins (1999). “Support vector machines for multi-class pattern recognition.” Proc. ESANN.
  4. P. L. Bartlett, M. I. Jordan, J. D. McAuliffe (2006). “Convexity, classification, and risk bounds.” Journal of the American Statistical Association 101.
  5. R.-E. Fan et al. (2008). “LIBLINEAR: a library for large linear classification.” Journal of Machine Learning Research 9.