Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Scattered data interpolation

ProblemInterpolate values given at arbitrary, irregularly placed points in two or three dimensions
Devised byInverse distance weighting: Donald Shepard (1968). Radial basis functions: Rolland Hardy’s multiquadrics (1971), Jean Duchon’s thin-plate splines (1976); theory by Charles Micchelli (1986)
AccuracyShepard: low, with flat spots at the data points. Radial basis functions: high for smooth functions, depending on the kernel and the point spacing
CostShepard: per evaluation, no set-up. RBF: an dense solve, then per evaluation
Read firstPolynomial interpolation, Gaussian elimination and LU factorisation
APIRadialBasisInterpolator, RadialKernel, Shepards

Overview

Measurements are often taken where they can be: weather stations, boreholes, sensors on a structure, samples of an expensive simulation. Such scattered data have no grid, so the tensor-product methods of the previous entry do not apply. Two families of methods build interpolants directly from the points and their distances.

Shepard’s method (inverse distance weighting) takes a weighted average of the data, with weights that grow without bound near each data point. It is simple and never overshoots, but crude. Radial basis functions write the interpolant as a sum of identical bumps centred at the data points, plus a low-degree polynomial, with coefficients chosen so that it passes through the data. They are accurate, smooth, work in any dimension, and underlie methods in machine learning, meshless PDE solvers and computer graphics.

Where it is used

Measurements are rarely taken on a neat grid.

  • Geosciences. Mapping elevation, rainfall, ore grades and contaminant concentrations from scattered boreholes and stations.
  • Engineering test data. Building a response surface from experiments at irregular operating points.
  • Computer graphics. Radial basis functions deform meshes and reconstruct surfaces from point clouds.
  • Sensor networks. Estimating a field everywhere from readings at a few places.

History

Donald Shepard, a student at Harvard’s Laboratory for Computer Graphics, proposed inverse distance weighting in 1968 for mapping geographic data, and it remains a default in geographic information systems. Rolland Hardy (1971), a geodesist at Iowa State University, introduced multiquadrics, , to interpolate topographic surfaces. Jean Duchon (1976) derived the thin-plate spline as the surface that interpolates the data with minimum bending energy, the two-dimensional analogue of the natural cubic spline. Charles Micchelli (1986) proved that the interpolation matrices of these kernels are invertible for any distinct points, which established radial basis functions as a sound general method.

The idea

Shepard’s inverse distance weighting

The data are values at points . A natural guess for the value at a new point is an average of the data in which nearby points count for more. Shepard weighted each point by an inverse power of its distance:

The exponent is chosen by the user; is common. Three properties follow directly from the formula.

  • It interpolates. As the weight grows without bound and dominates both sums, so . (This is the same argument as for the barycentric formula.)
  • It never overshoots. The weights are positive, and dividing by their sum makes them add up to 1. So is a weighted average of the data and lies between the smallest and the largest .
  • It is flat at the data points. For the gradient of vanishes at every data point. The surface has a little plateau at each point and bumps in between, which is a poor model of a smooth function: a smooth function generally has a nonzero slope at the places where it happens to have been measured.

Larger makes the weights fall off faster and so localises the influence of each point.

Radial basis functions

Radial basis functions (RBFs) take a different approach. Choose a function of one variable, the kernel, and centre a copy of it on every data point: the function depends only on the distance from (it is radial). The interpolant is a weighted sum of these functions plus a plane, written here for two dimensions with :

Unlike Shepard’s weights, the coefficients are not given by a formula. They are unknowns, found by requiring that the interpolant pass through the data.

Setting up the equations. There are unknowns: and . The interpolation conditions give equations, each linear in the unknowns. The remaining three are the side conditions

which say that the weights carry no constant or linear trend; that part of the data is left to the plane . Together they form a symmetric linear system:

The top block row is the interpolation conditions: is the sum of kernels evaluated at the data points, and with is the plane. The bottom block row is the side conditions. The matrix is dense, so solving the system costs operations, which limits the method to a few thousand points.

Why the plane? It has two purposes. It makes the interpolant reproduce planes exactly with any kernel: if the data lie on a plane, the solution is . And for some kernels it is needed for the system to have a solution at all. The cubic kernel and the thin-plate spline are only conditionally positive definite, which means the system is guaranteed to be solvable only together with the side conditions.

Choosing a kernel. The thin-plate spline is the two-dimensional analogue of the natural cubic spline: it minimises the bending energy of a thin plate pinned at the data. It has no parameter and is a robust default.

Other kernels contain a shape parameter that sets their width: the Gaussian , the multiquadric and the inverse multiquadric . They can be very accurate for smooth functions, but they pose a dilemma. As the kernels become wide and flat and the interpolant becomes more accurate. But wide, flat kernels centred at different points look almost alike, so the rows of become almost equal and the matrix becomes catastrophically ill-conditioned: rounding errors destroy the solution before the theoretical accuracy is reached. Choosing is an art. A common rule is to make the kernel width comparable to the typical distance between points.

Comparison

Franke’s function, a standard test surface with two peaks and a dip, sampled at 100 Halton points in the unit square:

Table 3.11. Accuracy of scattered-data interpolation methods.

methodRMS errormaximum error
RBF, Gaussian (ε = 5)4.1e-32.6e-2
RBF, multiquadric (ε = 3)2.7e-32.0e-2
RBF, inverse multiquadric (ε = 3)2.7e-31.8e-2
RBF, cubic6.0e-31.0e-1
RBF, thin-plate spline4.8e-32.8e-2
Shepard, power 27.3e-23.1e-1
Shepard, power 43.7e-21.7e-1

Figure 3.12. A slice through the interpolants.

All the radial basis functions reach errors of a few thousandths; Shepard’s method is ten times worse and visibly bumpy, with flat spots wherever the slice passes near a data point.

Algorithm

Shepard. There is no set-up. For each evaluation point :

  1. loop over the data points, computing the distance ;
  2. if some is zero, return at once;
  3. otherwise accumulate and , and return their ratio.

Cost: per point.

Radial basis functions.

  1. Set-up. Fill the block with the kernel evaluated at every pair of data points, and the block with the rows . Solve the resulting system by LU factorisation for the weights and the coefficients . Report an error if the matrix is singular. Cost: , once.
  2. Evaluation. Sum the kernels centred on the data points, weighted by the , and add the plane . Cost: per point.

Implementation

        let m = n + 3;
        let mut a = Array2::<f64>::zeros((m, m));
        for i in 0..n {
            for j in 0..n {
                a[[i, j]] = kernel.value(((centers[i][0] - centers[j][0]).powi(2) + (centers[i][1] - centers[j][1]).powi(2)).sqrt());
            }
            let row = [1.0, centers[i][0], centers[i][1]];
            for (q, v) in row.into_iter().enumerate() {
                a[[i, n + q]] = v;
                a[[n + q, i]] = v;
            }
        }
        let mut rhs = Array1::<f64>::zeros(m);
        rhs.slice_mut(ndarray::s![..n]).assign(&f);
        let sol = a.solve(&rhs).map_err(|_| ErrorsJSL::RuntimeError("singular RBF system (duplicate or collinear points?)"))?;
  • The RBF system is dense: fine for a few thousand points, too slow beyond. Large problems use compactly supported kernels (sparse systems) or fast multipole methods.
  • Duplicate points make the RBF system singular; collinear points make the affine part undetermined. Both are reported as errors.
  • Shepard’s method is implemented in three dimensions; two-dimensional data can use a constant third coordinate, as in the examples.

In practice

//! Interpolating scattered data: radial basis functions and Shepard's method.
//!
//! Run with `cargo run -p lib_jsl_interpolation --example interpolation_scattered`.

use lib_jsl_core::R1D;
use lib_jsl_interpolation::three_d::Interpolation3D;
use lib_jsl_interpolation::three_d::shepards::Shepards;
use lib_jsl_interpolation::two_d::Interpolation2D;
use lib_jsl_interpolation::two_d::radial_basis_functions::{RadialBasisInterpolator, RadialKernel};

fn main() {
    // Rainfall (mm) measured at eight weather stations (positions in km).
    let east = R1D::from_vec(vec![2.0, 15.0, 8.0, 22.0, 30.0, 5.0, 18.0, 27.0]);
    let north = R1D::from_vec(vec![3.0, 4.0, 12.0, 10.0, 6.0, 25.0, 20.0, 28.0]);
    let rain = R1D::from_vec(vec![31.0, 27.0, 40.0, 33.0, 22.0, 48.0, 45.0, 38.0]);
    let tps = RadialBasisInterpolator::new(east.view(), north.view(), rain.view(), RadialKernel::ThinPlateSpline).unwrap();
    let gauss = RadialBasisInterpolator::new(east.view(), north.view(), rain.view(), RadialKernel::Gaussian(0.1)).unwrap();
    // Shepard's method in 3D works on 2D data with a constant third coordinate.
    let flat = R1D::zeros(8);
    let shepard = Shepards::new(east.view(), north.view(), flat.view(), rain.view(), 2.0).unwrap();
    println!("estimated rainfall (mm):   thin-plate   Gaussian   Shepard");
    for (e, n) in [(10.0, 10.0), (20.0, 15.0), (12.0, 22.0), (35.0, 30.0)] {
        println!(
            "  at ({e:4.1}, {n:4.1}) km:  {:10.2} {:10.2} {:9.2}",
            tps.interpolate_at(e, n).unwrap(),
            gauss.interpolate_at(e, n).unwrap(),
            shepard.interpolate_at(e, n, 0.0).unwrap()
        );
    }
    // Every method reproduces the measurements exactly.
    println!("at station 3: thin-plate {:.6}, Shepard {:.6} (measured 40)", tps.interpolate_at(8.0, 12.0).unwrap(), shepard.interpolate_at(8.0, 12.0, 0.0).unwrap());
}

Strengths

  • Any point locations, any dimension, no mesh.
  • RBFs are smooth and accurate; the thin-plate spline needs no parameter.
  • Shepard’s method is trivial to implement and never overshoots.

Weaknesses

  • RBFs cost to set up, and shape-parameter kernels can be ill-conditioned.
  • Shepard’s method is inaccurate, with flat spots at the data.
  • Extrapolation far from the data is unreliable for every method.

Exercises

  1. Show that Shepard’s interpolant with has zero gradient at each data point.
  2. Solve the RBF system for three points and show why the side conditions are needed for the thin-plate spline.
  3. Vary for the Gaussian kernel on Franke’s function from 0.5 to 20. Plot the error and the condition number of . Where is the best ?
  4. Compare RBF interpolation on 100 random points with 100 Halton points. Which gives the smaller maximum error, and why?
  5. Interpolate the rainfall data of the example with Shepard’s method for and describe how the surface changes.
Hints and answers
  1. Near a data point the weights are , so . For this has zero gradient at , giving flat spots at every data point.
  2. For three points the TPS system is equations in unknowns; the kernel is only conditionally positive definite, so the polynomial part and the side conditions are needed to make the system nonsingular and to reproduce linear functions.
  3. Small (flat Gaussians) gives small error but a hopelessly ill-conditioned ; large gives a well-conditioned but inaccurate fit. The best lies in between, at a condition number far above 1.
  4. Halton points usually give the smaller maximum error because they have a smaller fill distance (no large gaps), which governs the interpolation error.
  5. With the surface has cusps at the data; is smoother with flat spots; approaches a piecewise-constant nearest-neighbour surface.

Further reading

  • D. Shepard, “A two-dimensional interpolation function for irregularly-spaced data”, Proceedings of the 1968 ACM National Conference, 517–524.
  • R. L. Hardy, “Multiquadric equations of topography and other irregular surfaces”, Journal of Geophysical Research 76 (1971) 1905–1915.
  • J. Duchon, “Interpolation des fonctions de deux variables suivant le principe de la flexion des plaques minces”, RAIRO Analyse Numérique 10 (1976) 5–12.
  • C. A. Micchelli, “Interpolation of scattered data: distance matrices and conditionally positive definite functions”, Constructive Approximation 2 (1986) 11–22.
  • G. E. Fasshauer, Meshfree Approximation Methods with MATLAB, World Scientific, 2007.
  • R. Franke, “Scattered data interpolation: tests of some methods”, Mathematics of Computation 38 (1982) 181–200. The source of the test function.