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:
- Write down the three functions. peaks at , peaks at , and peaks at . Check: at , equals 1 and the other two equal 0.
- Build a new function by weighting them. Let . The weights are 4, 2 and 6. Check: the recipe is just three numbers, so it is cheap to store.
- Evaluate at . Here , , and , because is still zero there. So . Check: the answer lies between and .
- Evaluate at . Only is nonzero, so , which is the weight of . Check: at the peak points, each weight is exactly the value of the function there.
- Evaluate at . Here , , and . So . Check: 4 is halfway between and , 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.
- h0
- h1
- h2
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
Let be functions on a fixed domain. They are basis functions for a family of functions when every function in the family can be written as
for one choice of numbers . The numbers are the coefficients, or weights.
Step 1 in symbols: the hat family
The hat functions are defined for every real . Each is zero for , so it touches only its two neighbouring integers. At an integer point the values are
This is the property used in steps 3 to 5.
Step 2 in symbols: a weighted sum
For , the coefficients are , and . The value of at any is the sum , so it needs only three weights and three evaluations.
Step 4 in symbols: the weights are the values at the peaks
Evaluate at the integer . Using the property above, every term with vanishes and the term with equals :
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 and , only and are nonzero, and each is a straight line on that interval. The function is therefore the straight line joining and . For this gives
Why the hats are independent
Suppose for every . Put for . The identity above gives 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
Use from the walkthrough.
- At : , , .
- Multiply and add: .
- At : , , .
- Multiply and add: .
- Check: the value at is the average of and , which is 3. The value at is the average of and , which is 4.
Interpretation: the weights are enough to compute the function everywhere, and the peaks show the weights directly.
Take the function on the interval from 0 to 2. Two different bases can describe it.
- In the polynomial basis , the function is . The coefficients are .
- In the hat basis , the values at the peaks are , and . So the coefficients are .
- Check the hat recipe at : , which equals .
- Check the polynomial recipe at : .
- Interpretation: the two recipes have different numbers but describe the same function. The choice of basis changes the coefficients, not the function.
A solver models a bar at positions centimetres, with hat functions placed at those positions. The solver has computed temperatures of 20, 35, 50 and 40 degrees at the four points.
- The temperature function is , so the four weights are the four temperatures.
- At only and are nonzero, and each equals : and .
- So degrees.
- Check: 45 lies between the two neighbouring temperatures, 50 and 40, as expected.
Try it: find , the temperature at 1.25 centimetres, using the same four weights.
Answer: at , and , and the other two hats are zero. So 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 , the coefficient of 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 , what is ?Show answer
, and . So .
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 , every term of the sum vanishes except the one with weight , which is then the value .
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.