Search

Search papers and lessons

Vicinal Risk Minimization

Level 4 · 12 min read

Vicinal risk minimization trains a model on random neighbours of each training example, not only on the examples, so that small input changes are built into the training objective.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Calculus
  • Losses & regularization
  • Learning basics
  • ReadReady to readNot yet

TL;DR

Empirical risk minimization fits a model by averaging its loss on the training examples, which are only a few points in a large space. Vicinal risk minimization replaces each training point with a small cloud of nearby points, drawn from a chosen neighbourhood, and averages the loss over those clouds. It solves the problem that a model can fit the exact training points while behaving badly just next to them. It matters because it states, as a training objective, the idea that a prediction should stay the same for inputs that are close together.

Builds on: Empirical Risk Minimization, Gaussian (Normal) Distribution · Leads to: Mixup, Data Augmentation

Where it's used

  • Image classifiers. A photograph of a cat stays a cat after a small shift, a slight change in brightness, or a little pixel noise. Training on random versions of each photo, with the same label, is the everyday form of vicinal training. Most data augmentation pipelines for image networks do this without naming the objective.
  • Sensor data. A thermometer reading of 20.0 degrees may really be anywhere within half a degree of that. A model that predicts heating demand from temperature should not change its answer sharply over that range. Training on noisy copies of each reading is a direct way to encode that the reading is only approximate.
  • Mixup training. In 2018, Hongyi Zhang and colleagues proposed mixup, which blends two training examples and their labels. Their paper describes mixup as a particular choice of vicinal distribution, so the method is a concrete case of this idea where the neighbourhood is a line segment between two points.

How it works

Take a one-dimensional problem with one training example, x=2x = 2 and target y=4y = 4. The model is the rule f(x)=2xf(x) = 2x, which fits the example exactly. Empirical risk minimization would say that this model has zero loss, and stop there. The loss is a number that measures how wrong a prediction is. Here it is the squared loss, the square of the gap between the prediction and the target. Vicinal training asks what happens near x=2x = 2.

  1. Start with the training point. The pair is (x,y)=(2,4)(x, y) = (2, 4). The model predicts f(2)=4f(2) = 4, so the squared loss is (4−4)2=0(4 - 4)^2 = 0. Check: the prediction matches the target exactly.
  2. Choose a neighbourhood. Draw a small random offset ε\varepsilon from a normal distribution with mean 0 and standard deviation σ=0.5\sigma = 0.5. The neighbour is x~=2+ε\tilde{x} = 2 + \varepsilon. The label stays 44, because a small change in the input does not change the answer we want. Check: the offset is usually within about a unit of 0 when σ=0.5\sigma = 0.5.
  3. Look at two neighbours. Take ε=+0.5\varepsilon = +0.5, so x~=2.5\tilde{x} = 2.5. The model predicts f(2.5)=5f(2.5) = 5, and the loss is (4−5)2=1(4 - 5)^2 = 1. Take ε=−0.5\varepsilon = -0.5, so x~=1.5\tilde{x} = 1.5. The model predicts f(1.5)=3f(1.5) = 3, and the loss is (4−3)2=1(4 - 3)^2 = 1. Check: both neighbours have loss 1, not 0. The model is wrong just next to its training point.
  4. Average over the neighbourhood. Each offset has the same chance of being chosen as its negative, so the average loss of the two neighbours is (1+1)/2=1(1 + 1)/2 = 1. Check: this average is the vicinal risk for this one training point, and it is much larger than the empirical risk of 0.
  5. Find the reason. The model has slope 2. Moving the input by ε\varepsilon moves the prediction by 2ε2\varepsilon, and the squared error of that move averages to 22×0.52=12^2 \times 0.5^2 = 1. The steeper the model, the more its predictions move under noise, and the more vicinal training penalises it.
flowchart LR
  P["Training point (x, y)"] --> N["Random neighbour x plus noise"]
  N --> F["Model prediction f(neighbour)"]
  F --> L["Loss against the same y"]
  L --> A["Average over neighbours"]

The diagram shows the path for one training point. The loss is computed on the neighbour, against the original label, and the average over neighbours is what the training objective minimises.

The math

Definition: Vicinal risk

Let (x1,y1),…,(xN,yN)(x_1, y_1), \dots, (x_N, y_N) be training pairs. A vicinal distribution ν\nu is an average of local distributions, one per training point, ν(x~,y~)=1N∑i=1Nν(x~,y~∣xi,yi),\nu(\tilde{x}, \tilde{y}) = \frac{1}{N} \sum_{i=1}^{N} \nu(\tilde{x}, \tilde{y} \mid x_i, y_i), where ν(⋅∣xi,yi)\nu(\cdot \mid x_i, y_i) is the vicinity of the ii-th point. The vicinal risk of a rule ff is the expected loss under this distribution,

Here LL is the loss, which scores how wrong the prediction f(x~)f(\tilde{x}) is against the label y~\tilde{y}.

Step 1 in symbols: the vicinity

A common choice for the vicinity of a point with continuous inputs is a Gaussian cloud, with the label kept fixed: ν(x~,y~∣xi,yi)=N(x~; xi,σ2) δ(y~−yi).\nu(\tilde{x}, \tilde{y} \mid x_i, y_i) = \mathcal{N}(\tilde{x};\, x_i, \sigma^2)\, \delta(\tilde{y} - y_i). Here N(x~;xi,σ2)\mathcal{N}(\tilde{x}; x_i, \sigma^2) is the normal density centred on xix_i with variance σ2\sigma^2, and δ\delta is the Dirac delta, which puts all the label mass on yiy_i. The width σ\sigma sets the size of the neighbourhood.

Step 2 in symbols: the risk as an average over neighbourhoods

Substituting the vicinity into the definition gives Rν(f)=1N∑i=1NEε[L(yi, f(xi+ε))],ε∼N(0,σ2).R_\nu(f) = \frac{1}{N} \sum_{i=1}^{N} \mathbb{E}_{\varepsilon}\big[L\big(y_i,\, f(x_i + \varepsilon)\big)\big], \qquad \varepsilon \sim \mathcal{N}(0, \sigma^2). Each training point contributes the average loss over its own cloud. The expectation here is an average over the random offset ε\varepsilon.

Step 3 in symbols: the linear case

Take f(x)=wxf(x) = wx and squared loss L(y,y^)=(y−y^)2L(y, \hat{y}) = (y - \hat{y})^2. For one point, (yi−w(xi+ε))2=(yi−wxi)2−2(yi−wxi) w ε+w2ε2.(y_i - w(x_i + \varepsilon))^2 = (y_i - w x_i)^2 - 2 (y_i - w x_i)\, w\, \varepsilon + w^2 \varepsilon^2. Take the expectation. The middle term has E[ε]=0\mathbb{E}[\varepsilon] = 0, so it vanishes, and E[ε2]=σ2\mathbb{E}[\varepsilon^2] = \sigma^2 because the offset has variance σ2\sigma^2. This gives Eε[(yi−w(xi+ε))2]=(yi−wxi)2+w2σ2.\mathbb{E}_{\varepsilon}\big[(y_i - w(x_i + \varepsilon))^2\big] = (y_i - w x_i)^2 + w^2 \sigma^2.

Step 4 in symbols: the penalty

Averaging over the NN points gives the exact identity Rν(f)=R^N(f)+w2σ2,R_\nu(f) = \hat{R}_N(f) + w^2 \sigma^2, where R^N\hat{R}_N is the ordinary empirical risk. The extra term w2σ2w^2 \sigma^2 depends only on the slope and the noise size. It grows with the square of the slope, so steep rules pay more. Setting σ=0\sigma = 0 removes the term, and the vicinity collapses to the training points themselves. That is the ERM case, which is why ERM is the limit of vicinal risk minimization as the neighbourhood shrinks to a point.

Worked examples

Example
Example 1: one point and a neighbourhood
  1. Take one training pair (x,y)=(2,4)(x, y) = (2, 4), the model f(x)=2xf(x) = 2x, and noise with σ=0.5\sigma = 0.5.
  2. The empirical risk is (4−2⋅2)2=0(4 - 2 \cdot 2)^2 = 0.
  3. Apply the identity from Step 4 with N=1N = 1: Rν=0+w2σ2=22×0.52=4×0.25=1R_\nu = 0 + w^2 \sigma^2 = 2^2 \times 0.5^2 = 4 \times 0.25 = 1.
  4. Check by hand: the neighbours 2.52.5 and 1.51.5 have losses (4−5)2=1(4 - 5)^2 = 1 and (4−3)2=1(4 - 3)^2 = 1. Their average is 11.
  5. Interpretation: the model fits the training point perfectly, but a random neighbour is off by one unit of squared error on average. Vicinal training sees this and penalises the slope.
Example
Example 2: two points and the penalty
  1. Take two training pairs (1,1)(1, 1) and (2,3)(2, 3), and the rule f(x)=xf(x) = x, so w=1w = 1. Use noise with σ=0.5\sigma = 0.5, so σ2=0.25\sigma^2 = 0.25.
  2. The empirical risk is the average of (1−1)2=0(1 - 1)^2 = 0 and (3−2)2=1(3 - 2)^2 = 1, which is R^2=0.5\hat{R}_2 = 0.5.
  3. The penalty is w2σ2=1×0.25=0.25w^2 \sigma^2 = 1 \times 0.25 = 0.25.
  4. The vicinal risk is Rν=0.5+0.25=0.75R_\nu = 0.5 + 0.25 = 0.75.
  5. Check by hand: for the first point, E[(1−(1+ε))2]=E[ε2]=0.25\mathbb{E}[(1 - (1 + \varepsilon))^2] = \mathbb{E}[\varepsilon^2] = 0.25. For the second, E[(3−(2+ε))2]=E[(1−ε)2]=1+0.25=1.25\mathbb{E}[(3 - (2 + \varepsilon))^2] = \mathbb{E}[(1 - \varepsilon)^2] = 1 + 0.25 = 1.25, because the cross term has mean 0. The average is (0.25+1.25)/2=0.75(0.25 + 1.25)/2 = 0.75, which agrees with step 4.
  6. Interpretation: the penalty is the same for every point, because it depends only on the slope. Training on the vicinal risk therefore prefers rules whose slope is not too large.
Example
Example 3: a realistic sensor model
  1. A home-energy model predicts daily heating use E^=wT\hat{E} = w T from the outside temperature reading TT, in degrees, with slope w=0.8w = 0.8 kWh per degree.
  2. The thermometer error is roughly Gaussian with standard deviation σ=0.5\sigma = 0.5 degrees, so σ2=0.25\sigma^2 = 0.25.
  3. The penalty term is w2σ2=0.64×0.25=0.16w^2 \sigma^2 = 0.64 \times 0.25 = 0.16 kWh squared.
  4. Suppose the model is refitted with slope w=1.5w = 1.5 kWh per degree and the same noise. The penalty becomes 1.52×0.25=2.25×0.25=0.56251.5^2 \times 0.25 = 2.25 \times 0.25 = 0.5625 kWh squared.
  5. Interpretation: a steeper slope is more sensitive to the thermometer error, and the vicinal objective charges for that sensitivity. A flatter slope is cheaper under noise, but it may fit the real data worse.
  6. Try it: with w=1.5w = 1.5 and σ=0.5\sigma = 0.5, the penalty is 0.56250.5625. What is the penalty if the thermometer error doubles to σ=1.0\sigma = 1.0 degree, with the same slope w=1.5w = 1.5? Answer: 2.25×1.0=2.252.25 \times 1.0 = 2.25 kWh squared. Doubling the noise multiplies the penalty by four, because the penalty depends on σ2\sigma^2.

Common mistakes and tradeoffs

It is tempting to think that vicinal risk minimization is the same as data augmentation. In fact data augmentation is a practical recipe, which trains on random transformed copies of the data, and vicinal risk is the objective that such training approximately minimises. The objective fixes what the neighbourhood means, while augmentation is a way of sampling from it.

It is also tempting to think that a larger neighbourhood always helps. In fact the neighbourhood must be one where the label really does not change. A neighbourhood that moves points across a decision boundary asks the model to predict a label that the new point does not have, and this can hurt accuracy. The penalty in the linear case also shows the tradeoff: a larger noise width σ\sigma adds a larger penalty, which can underfit a model that needs its slope.

Use vicinal training when you know which changes should not alter the answer, such as small shifts of an image, or small errors in a sensor. Do not use it when the neighbourhood is not known, or when a small change does change the label, such as a single pixel that decides between two digits. Alternatives include plain empirical risk minimization with an explicit penalty on the weights, which is simpler but encodes smoothness only through the penalty, and Dropout, which adds noise inside the network rather than to the inputs.

History

Vladimir Vapnik's work on statistical learning theory in the 1990s made empirical risk minimization the central principle of the field, together with the question of when the training average can be trusted on new data. Vapnik and colleagues asked whether a better training objective could use knowledge about the neighbourhood of each point, and in 2001 Olivier Chapelle, Jason Weston, Léon Bottou and Vapnik published the vicinal risk formulation with the vicinity written as a distribution around each training point.

The idea was used in practice for many years under the name of input noise and data augmentation, which made models more robust to small changes. The 2018 mixup paper by Zhang and colleagues gave a simple vicinal distribution based on blending pairs of examples, and it became a widely used training method for image classifiers. Its popularity made the vicinal view a common way to explain augmentation and regularisation.

Recap

  • Empirical risk minimization averages the loss on the training points only.
  • Vicinal risk minimization averages the loss over a random neighbourhood of each training point, with the label kept or blended.
  • For a linear model with squared loss and Gaussian input noise, the vicinal risk equals the empirical risk plus w2σ2w^2 \sigma^2.
  • Shrinking the neighbourhood to zero recovers ERM, and a larger neighbourhood adds a larger penalty.
  • Read next: Mixup, which uses a blend of two examples as its neighbourhood, and Data Augmentation, the practical recipe that samples from neighbourhoods like these.

Check yourself

QuestionWhy does ERM stop at zero loss for a model that fits its training points exactly, and why does vicinal training not?Show answer

ERM only evaluates the loss at the training points, so an exact fit gives zero empirical risk. Vicinal training also evaluates the loss at random neighbours of each point. For a model with a non-zero slope, the neighbours are not fitted exactly, so their loss is positive and the vicinal risk is larger than zero.

QuestionA linear model has slope w=3w = 3, the noise width is σ=0.2\sigma = 0.2, and the empirical risk is 0.40.4. What is the vicinal risk under squared loss?Show answer

The penalty is w2σ2=9×0.04=0.36w^2 \sigma^2 = 9 \times 0.04 = 0.36. The vicinal risk is 0.4+0.36=0.760.4 + 0.36 = 0.76.

QuestionWhy does the penalty term w2σ2w^2 \sigma^2 get larger when the slope gets steeper?Show answer

Under noise, the prediction moves by ww times the offset, so a larger slope moves the prediction further. The squared error of that move is w2ε2w^2 \varepsilon^2, and its average is w2σ2w^2 \sigma^2. The penalty grows with the square of the slope because the prediction is linear in the slope.

QuestionA team adds random rotations of up to 90 degrees to training images of handwritten digits, keeping the labels. A digit 6 rotated by 180 degrees can look like a 9. Is this a good vicinity, and why?Show answer

Not for this task. The vicinity should be a set of inputs where the label does not change. A large rotation can turn a 6 into a 9, so the label is no longer correct for the neighbour. Small rotations may be fine, but the team must pick the range so that the label stays true across it.

QuestionA model is trained on a vicinal objective with a very small neighbourhood. What does its behaviour approach, and why?Show answer

It approaches ordinary empirical risk minimization. As σ\sigma goes to 0, the Gaussian vicinity collapses onto the training points, and the average over neighbours becomes the average over the points themselves. The penalty w2σ2w^2 \sigma^2 also goes to 0.

Sources