Doctoral thesis · TU Dresden · 2023

Duality, Derivative-Based Training Methods and Hyperparameter Optimization for Support Vector Machines

Nico Strasdat

Support vector machines are trained by solving a convex optimization problem and tuned by searching a grid of hyperparameters. This thesis shows that with suitably smoothed losses the cross-validation error becomes differentiable in the hyperparameters, so that gradient-based optimization can replace grid search — even with one kernel width per feature.

11 instead of 625
CV evaluations: gradient method vs. grid
exact
hypergradients, checked against finite differences
≈ LIBSVM
speed of the Rust SMO solver
Decision boundary of an optimized SVM on a checkerboard dataset
Checkerboard data of the computational study, classified with hyperparameters found by gradient descent on the CV error (λ = 0.071, γ = 40.9).

Main ideas

From duality to differentiable hyperparameters

The thesis follows one training problem through theory, algorithms and practice.

1

A general duality framework

Fenchel duality is applied to a general training problem. For the standard problem the dual reads

covering classification, regression, multi-class, ν- and subspace SVMs — together with optimality conditions, representer theorem and uniqueness results (Ch. 2–6).

2

SMO, revisited

A general convergence framework for decomposition methods proves convergence of SMO under mild assumptions. A new bound-aware violation measure

leads to working set rules and to a theoretically founded detection of variables that can be fixed — the basis of shrinking (Ch. 7).

3

Newton's method for the primal

Smoothing the loss with turns the primal training problem into a (semi)smooth system of equations

which a Newton method solves accurately in few steps, efficiently restricted to the terms with positive curvature (Ch. 4, 6, 8).

4

Hyperparameters by gradient descent

Hyperparameter selection is a bilevel problem. The implicit function theorem applied to the smoothed optimality system yields exact gradients of the validation error,

with a single adjoint system per fold — so λ and one kernel scaling per feature can be optimized with quasi-Newton methods (Ch. 9, 10).

Interactive

Train an SVM in your browser

Move the sliders to see how regularization λ and kernel width γ shape the decision function — the trade-off that hyperparameter optimization has to resolve. With δ > 0 the hinge loss is smoothed, which makes the solution differentiable in the hyperparameters. Let the gradient tune λ and γ for you, replay the solver step by step, or switch to the logistic loss for class probabilities.

Click to add a point of the selected class, right-click (or shift-click) for the other class. With the keyboard: arrow keys move the cursor (hold Shift for larger steps), Enter adds a point, Shift+Enter adds one of the other class, Backspace removes the last point. With the logistic loss, the probability at the pointer or cursor is shown in the panel.

Data
Loss
Click adds

samples
–
support vectors
–
SMO steps
–
training time
–
training accuracy
–
duality gap
–
5-fold CV loss
–
CV evaluations
–

Runs the Rust solver smo-solver compiled to WebAssembly (167 KB) directly in your browser. Ringed points are support vectors.

Tune λ and γ minimizes the 5-fold cross-validation loss (smoothed hinge loss on the held-out folds) with L-BFGS-B, using the exact gradient with respect to log λ and log γ, in a background thread. The gradient needs a smoothed loss, so a smoothing δ of 0 is raised to 0.2 for tuning. Watch SMO replays the solver iteration by iteration for the current parameters.

Hyperparameter optimization

Follow the gradient instead of the grid

The figure shows the 5-fold cross-validation error of a smoothed SVM on the checkerboard data as a function of λ and γ, computed on a 19×19 grid (361 evaluations). The gradient-based method (L-BFGS-B on ) reaches the optimum after only 21 evaluations of the CV error and its gradient.

The cost of a gradient is that of one additional linear system per fold, independent of the number of hyperparameters. This makes per-feature kernel scalings (automatic relevance determination) practical: on the Friedman #1 benchmark the optimized scalings of the five noise features drop to near zero.

from optimized_svm import OptimizedSVR

model = OptimizedSVR(blocks="features").fit(X, y)
model.lam_, model.scaling_opt_   # optimized hyperparameters
model.history_                   # every CV evaluation
Contour plot of the cross-validation error over log lambda and log gamma with the optimization path
CV error landscape and the path of the gradient-based optimizer.

Computational study

Selected results

Hyperparameter optimization on real regression data (Table 10.4.1)

Test errors (mean over 30 random 80/20 splits) of the smoothed ε-SVR and the LS-SVM with λ and γ optimized by the gradient method. Best value per row in bold. * random subsample of 1,000 points. The protocol is reproducible with benchmarks/thesis_regression.py inoptimized-svm.

datasetnMSEMAE
ε = 0.1ε = 0.25ε = 0.5LS-SVMε = 0.1ε = 0.25ε = 0.5LS-SVM
pyrim740.006560.006250.006450.005970.05320.05120.05260.0491
triazines1860.02440.02390.02370.02320.1070.1090.1110.11
mpg3926.56.587.376.631.811.841.981.82
housing50610.810.911.99.542.12.172.432.07
space_ga1,000*0.01330.01270.01280.01270.08490.08450.08540.0845
abalone1,000*4.724.614.564.531.51.51.521.53
cpusmall1,000*19.12032.618.72.72.963.662.7

Open source

Software

The methods of the thesis are available as two tested, documented packages.

smo-solver Rust · Python

Fast SMO solver for a general class of SVM duals: smoothed hinge and ε-insensitive losses, least squares, sample weights and a ν-type constraint. Second-order working sets, shrinking, kernel cache, warm starts; scikit-learn estimators; also compiled to WebAssembly for the demo above.

pip install smo-solver

from smo_solver import SmoSVC
SmoSVC(lam=0.01, smoothing=0.1).fit(X, y)

optimized-svm Python

SVMs whose regularization and kernel scalings are tuned by exact gradients of the cross-validation error. SMO warm start plus Newton refinement, ARD kernels, Poisson regression, time limits and full optimization history.

pip install optimized-svm

from optimized_svm import OptimizedSVC
OptimizedSVC(blocks="features").fit(X, y)

The thesis

Contents

  1. Introduction — Motivation and structure of the work.
  2. Basics of Support Vector Machines — Learning problems, kernels, losses, and a general training problem.
  3. Application of Convex Duality Theory — Fenchel dual, optimality conditions, representer theorem, existence and uniqueness.
  4. Examples of Classification and Regression Problems — SVC, LS-SVM, ε-SVR and smooth approximations of loss functions.
  5. Examples of Non-Standard Training Problems — Multi-class SVMs, generalised ν-SVMs and subspace SVMs.
  6. Reformulations of the Primal Training Problem — Finite-dimensional formulations and a system of nonlinear equations.
  7. Sequential Minimal Optimization — Convergence framework, bound-aware violation measure, working set rules and detection of fixed variables for shrinking.
  8. Descent-Based Methods for the Primal Problem — Preconditioned gradient methods and an efficient Newton method.
  9. Hyperparameter Optimization — Bilevel formulation and an implicit function approach for exact gradients.
  10. Computational Study — SMO measures and shrinking, primal methods, hyperparameter optimization in practice.
  11. Summary and Outlook

Which parts of the thesis does the software cover? →

Cite

N. Strasdat. Duality, Derivative-Based Training Methods and Hyperparameter Optimization for Support Vector Machines. Dissertation, Technische Universität Dresden,2023. urn:nbn:de:bsz:14-qucosa2-874731

@phdthesis{strasdat2023,
  author = {Nico Strasdat},
  title  = {Duality, Derivative-Based Training Methods and
            Hyperparameter Optimization for Support Vector Machines},
  school = {Technische Universit{\"a}t Dresden},
  type   = {Dissertation},
  year   = {2023},
  url    = {https://nbn-resolving.org/urn:nbn:de:bsz:14-qucosa2-874731},
  note   = {urn:nbn:de:bsz:14-qucosa2-874731}
}