Explore

See the ideas at work

Small interactive experiments built on the solver and the optimizer of the thesis. The first two run the Rust solver compiled to WebAssembly in your browser; the others replay precomputed runs ofoptimized-svm.

Regression

The ε-tube and sparse solutions

Points inside the tube do not contribute to the loss, so the model depends only on the points at or beyond its boundary. Draw your own data, widen the tube and watch the support vectors disappear.

Click to add a point, shift-click to remove the nearest one. With the keyboard: arrow keys move the cursor, Enter adds a point, Backspace removes the last one.

Data

samples
–
support vectors
–
SMO steps
–
training time
–
points inside the tube
–
mean absolute error
–
5-fold CV loss
–
CV evaluations
–

ε-insensitive regression with the Rust solver in WebAssembly. Points inside the tube cost nothing, so only the ringed points (on or outside its boundary) are support vectors; the segments show how far the others stick out. Increase ε and the model gets sparser.

Tune λ and γ minimizes the 5-fold cross-validation loss (smoothed absolute error on the held-out folds) with L-BFGS-B and exact gradients, keeping ε at the slider value. The gradient needs a smoothed loss, so a smoothing δ of 0 is raised to 0.05 for tuning.

Hard constraints · Sections 4.1.2 and 4.2.3

When every observation must fit

A maximal margin classifier requires every point to lie on the correct side of its margin. Hard ε-regression requires every target to lie inside its tube. Add conflicting observations and see when these requirements become impossible. Widening ε can restore feasibility; changing λ cannot.

Hard constraints compared with a soft SVMSwitch between a maximal margin classifier and hard epsilon regression. Conflicting observations at the same input make the hard constraints impossible unless the regression tubes overlap.

Blue: hard model. Orange dashed: soft model (λ = 4, no smoothing). Circles: training targets; rings: support vectors of the hard model. RBF kernel, scaling s = 1.

Hard problem
Loading…
Max. constraint violation
–
Change when λ = 0.01 or 100
–

Every training margin must be at least 1. The hard model minimizes its RKHS norm subject to these constraints; a soft model may pay a penalty to violate them.

These are precomputed fits of the hard-constraint models introduced in optimized-svm 0.6.0, with feasibility and λ invariance checked by the data generator. For a hard model, changing positive λ rescales the dual variables and leaves the prediction unchanged.

Try SmoothSVC(loss="hard_margin") orSmoothSVR(loss="hard_epsilon_insensitive", epsilon=0.15, normalize_y=False)in optimized-svm 0.6.0 or later. These models solve the constraints directly. The corresponding indicator losses are zero on the feasible set and infinite outside it.

Smoothing

Why a smoothed loss makes hyperparameters differentiable

The hinge and ε-insensitive losses have kinks, so the solution of the training problem is not differentiable in the hyperparameters. Replacing max(0, t) by a smooth approximation of width δ rounds the kinks; only the few terms inside the band of width 2δ have positive curvature and react to a change of the hyperparameters.

Smoothed loss, its derivative and its curvatureThree stacked plots of the smoothed loss function, its first derivative (the negative dual variable) and its second derivative, with the exact non-smooth loss dashed and the region of positive curvature shaded.

Dashed: the exact loss (δ = 0). Shaded: the terms with positive curvature — the only ones whose dual variables react when a hyperparameter changes.

Loss
Smoothing degree

Hyperparameter optimization

Follow the gradient instead of the grid

Because the smoothed solution is differentiable, the cross-validation error has an exact gradient with respect to λ and γ. A quasi-Newton method needs a handful of evaluations where a grid needs hundreds. Press replay and watch the model improve along the path.

You can run the same optimization live: press Tune λ and γ in theclassification demo on the home page (or in the regression demo above) and the optimizer runs in your browser, evaluating the CV error and its exact gradient for your own data.

Colour: 5-fold CV error on a 25 × 25 grid; the most saturated basin is the optimum. The line is the path of the gradient method (L-BFGS-B); the triangle marks the best grid point.

log₁₀ λ
–
log₁₀ γ
–
CV error
–
evaluations
–

Objective function

The cross-validation error and its gradient

The hyperparameter objective is the cross-validation error as a function of λ and γ. Every point of this map carries an exact gradient, computed without finite differences. Follow the arrows downhill, or click to start plain gradient descent and L-BFGS from the same point and compare them.

Click anywhere to start the selected optimizer from that point. With the keyboard: arrow keys move the cursor, Enter starts it.

Method
Start from
log₁₀ λ
–
log₁₀ γ
–
CV error
–
‖gradient‖
–
∂E / ∂log₁₀ λ
–
∂E / ∂log₁₀ γ
–

Hover over the map to read the exact gradient at a point.

Arrows show the negative gradient (steepest descent), longer where it is steeper. Error and gradient were computed with optimized-svm at the 625 grid nodes — every gradient is exact, from one adjoint system per fold. Both methods run on the same interpolated surface, a bicubic Hermite interpolant built from the exact node gradients, so its value and gradient are consistent, which the L-BFGS line search needs. The runs are replays on this precomputed surface. Plain gradient descent zig-zags in the narrow valley; L-BFGS is what the library uses.

Hypergradient

An exact gradient of the validation error

The implicit function theorem turns the optimality conditions of the smoothed training problem into an exact derivative of the cross-validation error with respect to the hyperparameters. Move the marker along the curve: the tangent always has the slope of the gradient.

Cross-validation error as a function of the regularization, with the exact gradient as tangentThe 5-fold cross-validation error of a smoothed SVM over log λ at a fixed kernel width. A marker moves along the curve; its tangent has the slope of the exact hypergradient.

Slice of the CV error through the optimum (kernel width fixed). The tangent at the marker is drawn from the hypergradient, which is computed with one adjoint linear system per fold — no finite differences.

CV error
–
exact hypergradient
–
finite difference (neighbours)
–
direction of descent
–

The gradient is taken with respect to log₁₀ λ. A finite difference needs two more trainings for every hyperparameter; the adjoint gradient costs one extra linear system per fold for all of them together, which is what makes one kernel width per feature affordable.

Many hyperparameters

One kernel width per feature

Because the cost of the gradient does not grow with the number of hyperparameters, every feature can get its own kernel scaling. Irrelevant features are switched off automatically. Replay a precomputed run, or tune one on fresh data right here in your browser.

Optimized kernel widths per featureBar chart of the logarithm of the kernel width γ of each feature during the optimization. The informative features keep a large width while the noise features shrink towards zero.

Blue: features that enter the function; grey: pure noise. Shown: a precomputed run (Python reference implementation) on synthetic data y = 10 sin(π x₁ x₂) + 20 (x₃ − ½)² + noise with five additional noise features (n = 400).

Run it live in your browser
seed 1

Not started. The picture shows the precomputed run.

CV error
–
log₁₀ λ
–

Automatic relevance determination gives every feature its own kernel width and tunes all of them by gradient descent. A width near zero switches a feature off. Here the optimizer needs a few dozen CV evaluations for eight widths; a grid over eight dimensions is out of the question. The adjoint gradient costs the same for one hyperparameter or for hundreds.

Run live generates a fresh data set and tunes λ and all per-feature widths γd with L-BFGS-B on the 5-fold CV loss, in a Web Worker (log₁₀ γd between −4 and 2). It then tunes one common width the same way and compares both on 1000 held-out test points. To keep a run within a few seconds, the live data are smaller than the precomputed ones: n = 240 (classification, logistic loss) or n = 160 (regression, ε-SVR with ε = 0.1 on standardized targets and smoothing δ = 0.2, which the exact gradient needs). Labels are flipped with probability 8 %; the radius of the circle is chosen so that the classes are balanced.