Search

Search papers and lessons

Basis Function

Level 2 · 11 min read

A basis function is one simple function chosen as a building block, so that any function of interest can be written as a weighted sum of such blocks.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • ReadReady to readNot yet

TL;DR

A basis function is one function from a chosen family of simple building blocks, such as a constant, a straight line, a sine wave or a small bump. Any function in the family's reach can be written as a weighted sum of these blocks, and the weights are the only numbers that need to be stored. Choosing the blocks well turns curve fitting into choosing a short list of numbers.

Builds on: Vector Space Basis · Leads to: Basis Expansion, Finite Element Method

Where it's used

Signal processing and audio. The Fourier transform uses sine and cosine waves as its basis functions. A one-second audio clip sampled 44,100 times can be described by the strength of each pure tone it contains, and an equaliser works on those strengths directly. An MP3 encoder uses a close relative of this transform.

Engineering simulation. The Finite Element Method splits a metal part into small pieces and uses simple hat-shaped functions as its basis. A solver then stores one number per point of the mesh, for example one temperature per point, and the temperature everywhere else is built from those numbers.

Machine learning with fixed features. A model can transform each input by a set of basis functions, such as bumps centred at chosen points, and then fit a straight line in the transformed space. The radial basis function networks of the 1980s and 1990s worked this way, and the same idea reappears wherever a feature map is fixed in advance.

How it works

Take three simple functions on the number line, called hat functions. Each one is a peak of height 1 at a single point, and it falls to zero one unit away on each side:

hk(x)=max⁡(0,1−∣x−k∣),k=0,1,2.h_k(x) = \max(0, 1 - |x - k|), \qquad k = 0, 1, 2.

  1. Write down the three functions. h0h_0 peaks at x=0x = 0, h1h_1 peaks at x=1x = 1, and h2h_2 peaks at x=2x = 2. Check: at x=1x = 1, h1h_1 equals 1 and the other two equal 0.
  2. Build a new function by weighting them. Let f=4h0+2h1+6h2f = 4h_0 + 2h_1 + 6h_2. The weights are 4, 2 and 6. Check: the recipe is just three numbers, so it is cheap to store.
  3. Evaluate ff at x=0.5x = 0.5. Here h0(0.5)=0.5h_0(0.5) = 0.5, h1(0.5)=0.5h_1(0.5) = 0.5, and h2(0.5)=0h_2(0.5) = 0, because h2h_2 is still zero there. So f(0.5)=4⋅0.5+2⋅0.5+6⋅0=3f(0.5) = 4 \cdot 0.5 + 2 \cdot 0.5 + 6 \cdot 0 = 3. Check: the answer lies between f(0)=4f(0) = 4 and f(1)=2f(1) = 2.
  4. Evaluate ff at x=1x = 1. Only h1h_1 is nonzero, so f(1)=2f(1) = 2, which is the weight of h1h_1. Check: at the peak points, each weight is exactly the value of the function there.
  5. Evaluate ff at x=1.5x = 1.5. Here h1(1.5)=0.5h_1(1.5) = 0.5, h2(1.5)=0.5h_2(1.5) = 0.5, and h0(1.5)=0h_0(1.5) = 0. So f(1.5)=2⋅0.5+6⋅0.5=4f(1.5) = 2 \cdot 0.5 + 6 \cdot 0.5 = 4. Check: 4 is halfway between f(1)=2f(1) = 2 and f(2)=6f(2) = 6, so the curve is a straight line between the peaks.

The plot shows the three blocks and their weighted sum at the points used above.

−0.500.511.522.500.51xvalue
  • h0
  • h1
  • h2
Each hat function is 1 at its own point and 0 at the others. A weighted sum of hats is a piecewise straight line.

The walkthrough shows two facts. A function built from blocks is fixed by its weights. And the blocks have a special property: each one is zero at the peaks of the others, so the weights can be read straight off the function at those points. The math section writes both facts in symbols.

The math

Definition: Basis function

Let ϕ1,ϕ2,…,ϕn\phi_1, \phi_2, \ldots, \phi_n be functions on a fixed domain. They are basis functions for a family of functions when every function ff in the family can be written as

f(x)=c1ϕ1(x)+c2ϕ2(x)+⋯+cnϕn(x)f(x) = c_1 \phi_1(x) + c_2 \phi_2(x) + \cdots + c_n \phi_n(x)

for one choice of numbers c1,…,cnc_1, \ldots, c_n. The numbers ckc_k are the coefficients, or weights.

Step 1 in symbols: the hat family

The hat functions hk(x)=max⁡(0,1−∣x−k∣)h_k(x) = \max(0, 1 - |x - k|) are defined for every real xx. Each is zero for ∣x−k∣≥1|x - k| \ge 1, so it touches only its two neighbouring integers. At an integer point jj the values are

hk(j)={1if j=k,0otherwise.h_k(j) = \begin{cases} 1 & \text{if } j = k, \\ 0 & \text{otherwise.} \end{cases}

This is the property used in steps 3 to 5.

Step 2 in symbols: a weighted sum

For f=4h0+2h1+6h2f = 4h_0 + 2h_1 + 6h_2, the coefficients are c0=4c_0 = 4, c1=2c_1 = 2 and c2=6c_2 = 6. The value of ff at any xx is the sum c0h0(x)+c1h1(x)+c2h2(x)c_0 h_0(x) + c_1 h_1(x) + c_2 h_2(x), so it needs only three weights and three evaluations.

Step 4 in symbols: the weights are the values at the peaks

Evaluate ff at the integer jj. Using the property above, every term with k≠jk \ne j vanishes and the term with k=jk = j equals cjc_j:

f(j)=cj.f(j) = c_j.

So the weights are read off directly from the values at the peaks. This is why the hat family is convenient for interpolation.

Step 5 in symbols: a straight line between peaks

Between two neighbouring integers jj and j+1j + 1, only hjh_j and hj+1h_{j+1} are nonzero, and each is a straight line on that interval. The function ff is therefore the straight line joining (j,cj)(j, c_j) and (j+1,cj+1)(j+1, c_{j+1}). For x=1.5x = 1.5 this gives

f(1.5)=f(1)+f(2)2=2+62=4.f(1.5) = \frac{f(1) + f(2)}{2} = \frac{2 + 6}{2} = 4.

Why the hats are independent

Suppose c0h0(x)+c1h1(x)+c2h2(x)=0c_0 h_0(x) + c_1 h_1(x) + c_2 h_2(x) = 0 for every xx. Put x=jx = j for j=0,1,2j = 0, 1, 2. The identity above gives cj=0c_j = 0 each time. No nonzero combination is zero, so the three hats are linearly independent, which is the condition that makes them a basis for the functions they span.

Worked examples

Example
1. Three hat weights at three points (tiny)

Use f=4h0+2h1+6h2f = 4h_0 + 2h_1 + 6h_2 from the walkthrough.

  1. At x=0.5x = 0.5: h0=0.5h_0 = 0.5, h1=0.5h_1 = 0.5, h2=0h_2 = 0.
  2. Multiply and add: 4⋅0.5+2⋅0.5+6⋅0=2+1+0=34 \cdot 0.5 + 2 \cdot 0.5 + 6 \cdot 0 = 2 + 1 + 0 = 3.
  3. At x=1.5x = 1.5: h0=0h_0 = 0, h1=0.5h_1 = 0.5, h2=0.5h_2 = 0.5.
  4. Multiply and add: 2⋅0.5+6⋅0.5=1+3=42 \cdot 0.5 + 6 \cdot 0.5 = 1 + 3 = 4.
  5. Check: the value at x=0.5x = 0.5 is the average of f(0)=4f(0) = 4 and f(1)=2f(1) = 2, which is 3. The value at x=1.5x = 1.5 is the average of f(1)=2f(1) = 2 and f(2)=6f(2) = 6, which is 4.

Interpretation: the weights are enough to compute the function everywhere, and the peaks show the weights directly.

Example
2. The same function in two bases (standard)

Take the function g(x)=xg(x) = x on the interval from 0 to 2. Two different bases can describe it.

  1. In the polynomial basis 1,x1, x, the function is g=0⋅1+1⋅xg = 0 \cdot 1 + 1 \cdot x. The coefficients are (0,1)(0, 1).
  2. In the hat basis h0,h1,h2h_0, h_1, h_2, the values at the peaks are g(0)=0g(0) = 0, g(1)=1g(1) = 1 and g(2)=2g(2) = 2. So the coefficients are (0,1,2)(0, 1, 2).
  3. Check the hat recipe at x=1.5x = 1.5: g(1.5)=0⋅h0(1.5)+1⋅h1(1.5)+2⋅h2(1.5)=0+0.5+1=1.5g(1.5) = 0 \cdot h_0(1.5) + 1 \cdot h_1(1.5) + 2 \cdot h_2(1.5) = 0 + 0.5 + 1 = 1.5, which equals g(1.5)=1.5g(1.5) = 1.5.
  4. Check the polynomial recipe at x=1.5x = 1.5: 0+1⋅1.5=1.50 + 1 \cdot 1.5 = 1.5.
  5. Interpretation: the two recipes have different numbers but describe the same function. The choice of basis changes the coefficients, not the function.
Example
3. A temperature profile on a metal bar (realistic)

A solver models a bar at positions x=0,1,2,3x = 0, 1, 2, 3 centimetres, with hat functions h0,h1,h2,h3h_0, h_1, h_2, h_3 placed at those positions. The solver has computed temperatures of 20, 35, 50 and 40 degrees at the four points.

  1. The temperature function is T(x)=20h0(x)+35h1(x)+50h2(x)+40h3(x)T(x) = 20 h_0(x) + 35 h_1(x) + 50 h_2(x) + 40 h_3(x), so the four weights are the four temperatures.
  2. At x=2.5x = 2.5 only h2h_2 and h3h_3 are nonzero, and each equals 0.50.5: h2(2.5)=1−0.5=0.5h_2(2.5) = 1 - 0.5 = 0.5 and h3(2.5)=1−0.5=0.5h_3(2.5) = 1 - 0.5 = 0.5.
  3. So T(2.5)=50⋅0.5+40⋅0.5=25+20=45T(2.5) = 50 \cdot 0.5 + 40 \cdot 0.5 = 25 + 20 = 45 degrees.
  4. Check: 45 lies between the two neighbouring temperatures, 50 and 40, as expected.

Try it: find T(1.25)T(1.25), the temperature at 1.25 centimetres, using the same four weights.

Answer: at x=1.25x = 1.25, h1=0.75h_1 = 0.75 and h2=0.25h_2 = 0.25, and the other two hats are zero. So T(1.25)=35⋅0.75+50⋅0.25=26.25+12.5=38.75T(1.25) = 35 \cdot 0.75 + 50 \cdot 0.25 = 26.25 + 12.5 = 38.75 degrees.

Common mistakes and tradeoffs

It is tempting to think that a basis function must be a polynomial or a sine wave. In fact any family of functions can serve, as long as the target functions can be written as weighted sums of it. The hat functions above are neither.

It is tempting to think that the coefficients are always the values of the function. In fact that holds only for the hat family at its peaks. For the basis 1,x1, x, the coefficient of xx is the slope, not a value of the function at a point.

It is tempting to think that more basis functions always fit better. In fact extra blocks can chase noise in the data, which is overfitting, and they also cost storage and computation.

Use global blocks, such as polynomials or sines, when the function is smooth everywhere and a change in one weight may affect the whole curve; the Fourier basis is also orthogonal, which makes its weights easy to compute. Use local blocks, such as hats or small bumps, when the function has sharp features or when a change should affect only a small region. Consider learned features, such as neural network layers, when no fixed family is a good fit.

History

Joseph Fourier used sums of sine and cosine waves to describe heat flow, and published the work in 1822. The idea that a function can be built from simple waves led to the modern theory of Fourier series.

In the 1940s, engineers and mathematicians began solving equations for structures by splitting them into pieces and using simple piecewise functions on each piece. That approach grew into the finite element method, which uses hat-like basis functions on a mesh.

In the early 1970s, Rolland Hardy used sums of radial functions to fit smooth surfaces through scattered measurements. Radial basis functions became a standard tool in approximation and, later, in machine learning.

Recap

  • A basis function is one simple building block, and a function is a weighted sum of such blocks.
  • The blocks must be able to build the target functions, and each function has a recipe made of its weights.
  • The hat functions are zero at each other's peaks, so their weights are the values at the peaks.
  • Changing the basis changes the weights but not the function; global blocks and local blocks suit different problems.

Read next: Basis Expansion for the full method of fitting a function as a weighted sum, and Finite Element Method for the solver that uses hat-shaped blocks.

Check yourself

QuestionRecall: what two things must a basis of functions do for a family of functions?Show answer

It must be able to build every function in the family as a weighted sum, and the blocks must be linearly independent so each function has only one set of weights.

QuestionComputation: with f=4h0+2h1+6h2f = 4h_0 + 2h_1 + 6h_2, what is f(0.5)f(0.5)?Show answer

h0(0.5)=0.5h_0(0.5) = 0.5, h1(0.5)=0.5h_1(0.5) = 0.5 and h2(0.5)=0h_2(0.5) = 0. So f(0.5)=4⋅0.5+2⋅0.5+6⋅0=3f(0.5) = 4 \cdot 0.5 + 2 \cdot 0.5 + 6 \cdot 0 = 3.

QuestionWhy: why are the weights of the hat family equal to the function's values at the peaks?Show answer

Each hat is zero at the peaks of the other hats and equal to 1 at its own peak. So at a peak jj, every term of the sum vanishes except the one with weight cjc_j, which is then the value f(j)f(j).

QuestionApplied: an engineer chooses hat functions for a sensor model that must match sharp changes in a signal, but wants a small change at one point not to disturb the whole model. Is the hat family a good choice?Show answer

Yes. Each hat is nonzero only near its own peak, so changing one weight changes the model only in a small region. A global basis such as polynomials would spread the effect of one change across the whole curve.

Sources