RBF: building surfaces from bell-shaped bumps

You have a few points and want to fill in the values between them. Put a bell-shaped bump on each point, set each bump's height, and add them up: you get a smooth curve through every point. Drag the points and change the width to see how the bumps overlap.

Short answer. An RBF (radial basis function) is a bump that gets smaller the farther you go from its center. The most common one, the Gaussian RBF, is φ(x) = exp(−‖x − c‖² ÷ (2σ²)). It is 1 at the center c and drops quickly toward 0 once you are more than the width σ away. Put bumps like this in several places, multiply each by a weight, and add them up (f(x) = Σ wᵢ·φᵢ(x)), and you get a curve or surface through the points. The same bump is the hidden layer of an RBF network, the RBF kernel of an SVM, and the tool that fills in values between scattered measurements (interpolation).

( , )

The green circles are the points (6 made-up values). Drag them, or pick one and type new numbers. Purple thin lines are the bumps wᵢ·φᵢ(x), one per point. The thick dark line is their sum f(x). The orange bar is the width σ measured from the chosen point. "Narrow" and "wide" are rough rules for this experiment only: narrow if σ is less than 1/3 of the average gap between points, wide if the curve misses a point by more than 0.3. The weights are solved with a tiny extra number λ = 0.01 (section 5), so even with a good width the curve can pass a hair away from a point.

Try this. ① At the start (σ = 1) the curve passes almost through all six points (largest miss 0.05). The weights are −0.2, 3.74, −0.82, 5.02, −1.18, 3.29, so points 1, 3 and 5 get negative weights. They take away the height that the overlapping neighbor bumps added. ② Shrink σ to 0.3 and you get "narrow". Each point gets its own spike, and halfway between points 1 and 2 (x = 1.75) the curve drops to 0.2, while those two points sit at 1 and 3.5. The weights 0.99, 3.47, 1.98, 4.46, 1.49, 2.97 are almost the point heights 1, 3.5, 2, 4.5, 1.5, 3, because the bumps no longer overlap and each one only handles its own point. ③ Widen σ to 2 and you get "wide". The curve misses a point by up to 0.68, and the largest |w| grows to 67.63. At 3 the miss is 1.43, the largest |w| is 143.27, and the curve flattens out. ④ Drag one point straight above or below another so both share the same x. Thanks to λ the math still works.

Definitions

The text below mostly uses points on a line. These are the textbook definitions. The input x, the center c and the data points xᵢ are d-dimensional vectors, and ‖·‖ is the Euclidean distance.

radial basis function (RBF)
A function whose value depends only on the distance to a center c. That is, there is a function g on the non-negative real numbers such that the function can be written as below.

φ(𝐱)=g(‖𝐱−𝐜‖)

Gaussian RBF
An RBF where g is a Gaussian function. The larger the width σ > 0, the wider it spreads, and its value at the center is 1.

φ(𝐱)=exp(−‖𝐱−𝐜‖22σ2)

RBF interpolation
For n data points (xᵢ, yᵢ), put an RBF φᵢ centered at each xᵢ and choose the weights w so that the weighted sum f below satisfies f(xᵢ) = yᵢ at every point. These conditions are the linear system Φw = y with the interpolation matrix Φ, whose (i, j) entry is φⱼ(xᵢ).

f(𝐱)=∑i=1nwiφi(𝐱)

RBF network
A neural network with one hidden layer. Each hidden neuron has one center and outputs the RBF value of the input for that center. The output is the weighted sum f(x) of the hidden neuron values. Unlike interpolation, it uses fewer centers than data points, so it usually cannot pass through every point. Once the centers and the width are fixed, the weights can be found by least squares.
RBF kernel
The kernel an SVM defines for two points x and x′ by the first formula below. γ > 0 sets the width and is tied to σ of the Gaussian RBF by the second formula. An SVM with the RBF kernel classifies a new point x by the sign of Σ yᵢαᵢK(xᵢ, x) + b.

K(𝐱,𝐱′)=exp(−γ‖𝐱−𝐱′‖2)

γ=12σ2

1. What an RBF is: a bump that shrinks with distance

A radial basis function (RBF) is a function whose value depends only on the distance to a center c. It ignores direction. Every x at the same distance from the center gets the same value. So in 1D the shape is the same on the left and the right, and in 2D its contour lines are circles.

The most common shape is the Gaussian RBF, a bell.

φ(x) = exp(−‖x − c‖² ÷ (2σ²))
   c       the center
   σ       the width. Larger means more spread out
   ‖x − c‖ the distance between x and c. In 1D it is |x − c|, in more dimensions √((x₁ − c₁)² + (x₂ − c₂)² + …)

One bump alone cannot do much. Put centers in several places, multiply each bump by a weight wᵢ, and add them up, and you can build many shapes.

f(x) = w₁·φ₁(x) + w₂·φ₂(x) + … + w_n·φ_n(x) = Σ wᵢ·exp(−‖x − cᵢ‖² ÷ (2σ²))

The experiment above is this formula. Each point gets a bump centered at its x (purple), and the sum is the dark curve. With 2D inputs each bump becomes a round hill and the sum becomes a surface. That is the "building surfaces" in the title.

There are other RBFs besides the Gaussian. With distance r, there is the thin-plate spline r²·log r and the multiquadric −√(1 + r²), among others, and SciPy's RBFInterpolator uses the thin-plate spline by default. This page only covers the Gaussian.

2. How the formula is built

Start from a plain distance, change it five times to get the bell, then add the bumps together. The center c is the x of the point you chose in the experiment above (point 3 at the start, x = 4), and the width σ is the slider value from that experiment.

  1. Distance ‖x − c‖. Drop the direction and keep only how far away x is. A V with its corner at c.
  2. Square ‖x − c‖². A smooth bowl with no corner, and in more dimensions the square root goes away.
  3. Make it negative −‖x − c‖². Flip the bowl so the center is the highest point.
  4. exp exp(−‖x − c‖²). 0 becomes 1 and far away goes to 0. You get a bell between 0 and 1.
  5. Divide by the width exp(−‖x − c‖² ÷ (2σ²)). σ sets how wide the bell is. At distance σ from c the height is always exp(−1/2) ≈ 0.61.
  6. Weighted sum f(x) = Σ wᵢ·φᵢ(x). Give each bump a height and add them up. The weights come from a system of equations, as in section 4.

Try this. At step ⑤, move the width slider in the experiment above to 0.3 or 3. The bell gets narrower or wider, but at distance σ from c the height stays 0.61. Pick a different point in the experiment above and the center c moves to that point.

3. Properties worth knowing

PropertyIn plain wordsIn the experiment
1 at the center, toward 0 far away1 at distance 0, 0.607 at σ, 0.135 at 2σ, 0.011 at 3σ. Points far away barely feel itSection 2, steps ④ and ⑤
Only distance mattersSame distance, same value, whatever the direction. So the formula is the same in 1D or 100DSection 2, step ①
One width sets the reachLarge σ reaches far, small σ stays close. Also written as γ = 1 ÷ (2σ²). Double σ and γ becomes 1/4The width slider
If all points are at different places, there is exactly one answerThe matrix built from Gaussian bumps is positive definite, so the equations for the weights always have exactly one solution. Two points at the same x give two clashing equations that cannot both holdTry this ④
Theory and computation differWith a wide bump the answer exists, but the matrix is nearly impossible to solve (ill-conditioned) and the weights blow upSection 5

4. Work it by hand: two points

Join the two points (1, 2) and (3, 1) with two bumps of width σ = 1. The centers are c₁ = 1 and c₂ = 3. Here we solve without λ.

  1. How much the bumps overlap. The two centers are 2 apart: exp(−2² ÷ (2·1²)) = exp(−2) ≈ 0.1353. Each center is 0 away from itself, so exp(0) = 1.
  2. Write the equations. "At x = 1 the curve is 2" and "at x = 3 the curve is 1": w₁·1 + w₂·0.1353 = 2, w₁·0.1353 + w₂·1 = 1.
  3. Solve. w₁ = (2 − 0.1353·1) ÷ (1 − 0.1353²) = 1.8647 ÷ 0.9817 ≈ 1.8995, w₂ = (1 − 0.1353·2) ÷ 0.9817 ≈ 0.7429.
  4. Check. At x = 1: 1.8995·1 + 0.7429·0.1353 = 1.8995 + 0.1005 = 2. The curve goes through the point.
  5. Between the points. x = 2 is 1 away from both centers, so both bumps are exp(−1/2) ≈ 0.6065. f(2) = 0.6065 × (1.8995 + 0.7429) ≈ 1.603, a value between 2 and 1.

With n points there are n equations, and the table of how much the bumps overlap (the matrix Φ) is n × n. The experiment above has 6 points, so it solves a 6 × 6 system the same way (Gaussian elimination).

5. Picking the wrong width σ (γ)

λ: the curve does not have to hit every point

The experiment adds a small number λ = 0.01 to the diagonal of Φ and solves (Φ + λI)·w = y. It lets the curve pass slightly off the points. In return, two points at the same x still work, and the weights do not blow up for wide bumps. Without λ, at σ = 3 the curve goes through every point but the largest |w| is 4147.74. With λ = 0.01 it drops to 143.27, but the curve now misses a point by up to 1.43 and flattens out. In SciPy's RBFInterpolator the smoothing value plays this role. In the words of the docs, 0 fits the data exactly, and large values approach a least squares fit of a polynomial.

How to choose the width

No formula gives the right answer. Try a few values and keep the one that does best on data you held out. The SciPy docs name cross-validation as a way to do it. The bumps measure distance, so if the inputs use different scales, standardize them first. In this experiment the curve went through the points smoothly with σ around 1, a bit less than the average gap of 1.5.

6. One bump, three jobs

Interpolation: filling in between scattered points

This is the experiment above. The centers are the data points and the weights are the solution of the equations. You get a curve (or surface) through the points. The points do not have to sit on a grid, and in 2D or 3D you only change how distance is measured.

RBF networks

An RBF network is a neural network with one hidden layer, where each hidden unit is one bump. Each unit has its own center and outputs a bell of how close the input is to it. The output unit multiplies those values by weights and adds them up, which is exactly f(x) = Σ wᵢ·φᵢ(x). The difference from interpolation: instead of a center at every data point, you pick only a few (for example, split the data into a few groups and use one center per group). With fewer centers than points the curve cannot hit every point, so the weights are chosen to make the sum of squared misses as small as possible (least squares). Once the centers and the width are fixed, that is one system of equations too, so no long training with gradient descent is needed. The paper by Broomhead and Lowe looked at learning in a network as fitting a surface in many dimensions to the data, and at generalization as interpolating between known points, and it described a network that makes this interpolation explicit.

The RBF kernel in an SVM

An SVM (support vector machine) finds a boundary between two groups. With the RBF kernel, the score of a new point x is (scikit-learn docs):

score(x) = Σ yᵢ·αᵢ·K(xᵢ, x) + b      K(xᵢ, x) = exp(−γ‖xᵢ − x‖²),  γ > 0
a positive score means one group, a negative score the other

It has the same shape as the weighted sum above. Each training point xᵢ gets a bump, multiplied by its group label yᵢ (+1 or −1) and by αᵢ, and everything is added up. The boundary is where the score is 0. There are two differences. First, the weights αᵢ come from an optimization that widens the margin between the two groups, not from a system of equations. Second, most αᵢ end up 0, so only the points on or inside the margin (the support vectors) keep a bump. Since γ = 1 ÷ (2σ²), a large γ means a narrow bump. The scikit-learn example describes γ as how far the influence of a single training example reaches.

Books explain this with the "kernel trick": it does the same job as moving the inputs into a space with very many dimensions and splitting them there with a flat plane, but without moving them, by computing only K. The result is a curved boundary in the original inputs. Compare it with logistic regression, which splits with a straight line.

7. Lots of data or many dimensions

Where it is used

When to use what

OptionGoodBadUse it when
RBF interpolationGoes exactly through the points. Same formula for scattered points and for 2D or 3D. One system of equations, no trainingn points need an n × n table (memory n²). You must pick a width, and wide ones make the math shaky. It follows measurement errors tooFilling in between measurement sites. At most a few thousand points, inputs in 2 or 3 dimensions
RBF networkOnce the centers and width are fixed, the output weights are one least squares solve. Each unit has a readable meaning (is the input near this center?)You have to decide where to put the centers and how many. Many dimensions need a huge number of bumpsSmooth function fitting with few inputs. Quick first models
RBF kernel SVMDraws curved boundaries. Mainly two values to choose, C and γ. Only the support vectors are keptTraining time grows at least with the square of the number of samples, hard beyond tens of thousands. Sensitive to γ and CClassification with up to tens of thousands of samples. Table data with standardized inputs
Regular neural networkLearns from big data in small batches. Learns its own features from large inputs like images and textMany choices (number of layers, learning rate, and so on), and training takes long. It does not aim to hit every point exactlyLots of data. Images, sound, text

Frequently asked questions

What is the difference between σ and γ?

They are two ways to write the same width. γ = 1 ÷ (2σ²), so a large σ (a wide bump) means a small γ. scikit-learn's SVC takes gamma. SciPy's RBFInterpolator takes an epsilon that multiplies the distance and uses exp(−(ε·r)²), so ε = 1 ÷ (√2·σ). When you switch libraries, first check which way the width is written.

How do I choose the width?

No formula gives the right answer. Try a few values and keep the one that does best on data you held out (cross-validation). Because the bumps measure distance, standardize the inputs first if they use different scales. Too narrow and you get a spike at each point. Too wide and the math gets shaky or the curve flattens out.

How is an RBF network different from a regular neural network?

A hidden unit in an RBF network outputs a bell of how close the input is to its own center, so it only reacts near that center. A unit in a regular neural network multiplies the inputs by weights, adds them up, and bends the result (for example with ReLU), so it reacts on a whole side of some boundary. In an RBF network, once you fix the centers and the width, you can solve for the output weights in one go with a system of equations. A regular neural network learns all its weights together with gradient descent.

Words

Words used hereWhat books call it
bell-shaped bumpGaussian radial basis function (Gaussian RBF), Gaussian kernel
a function that only looks at distanceradial function
where the bump sitscenter
the width σ, γ, εwidth, shape parameter. In SVMs, gamma (γ)
the number each bump is multiplied byweight, coefficient
making a curve (surface) through the pointsinterpolation, scattered data interpolation
the table of how much the bumps overlap, Φinterpolation matrix, kernel matrix
the small number λ added to the diagonalsmoothing, regularization
has an answer but is nearly impossible to solveill-conditioned
the matrix property that guarantees one answerpositive definite
make the sum of squared misses as small as possibleleast squares
the points inside the margin that keep a bumpsupport vectors
the SVM scoredecision function
computing only K instead of moving the inputskernel trick
choosing with held-out datacross-validation
aligning imagesimage registration
the number of cells to cover multiplying with each dimensioncurse of dimensionality

Sources

← Support vector machinesNeural networks →