ALGLIB, a free and commercial open source numerical library, provides the best implementation of the inverse distance weighting algorithm (IDW). ALGLIB is available in multiple programming languages, including C++, C#, Java, and Python.
Our implementation of IDW algorithm includes numerous improvements over both textbook and modified Shepard's methods, making it competitive with ALGLIB's thin plate splines and other scattered interpolation methods.
1 Using IDW models
Algorithms
API overview
Programming languages supported
2 Benchmarks
Model quality
3 Downloads section
Inverse distance weighting has several attractive properties:
ALGLIB includes several implementations of the inverse distance weighting algorithm:
Both the original and modified Shepard's methods suffer from the same problem: on datasets with non-uniform point densities, they tend to give either too little or too much weight to distant nodes. The former results in models with big, flat spots; the latter results in strange interpolation artifacts (see "benchmarks" section below). This problem is surprisingly difficult to solve by playing with the weight formula because any solution tends to flip between two extremes.
MSTAB is our improvement of the modified Shepard's method which borrows ideas from ALGLIB's hierarchical RBF's: the algorithm fits a sequence of smoothed IDW models with a progressively decreasing search radius and smoothing amount, and it then combines these models into a single IDW interpolant. Initial IDW layers capture global trends, and subsequent layers concentrate on local features of the interpolation landscape. The overall setup ensures balanced influence of distant and nearby points.
IDW interpolation functionality is provided by the idw subpackage. The first step is model construction, which involves the following steps:
After the model is built, the following operations can be performed:
The ALGLIB Reference Manual entry for idw subpackage also includes several examples of using IDW models.
ALGLIB supports many programming languages, including C++, C#, Java, Python, and others:
A distinctive feature of ALGLIB is that it provides the same API in all programming languages. This is achieved through our exclusive automatic code translation and wrapper generation technology.
We mentioned at the beginning of this article that both original and modified Shepard's methods have issues with interpolation quality and that our MSTAB algorithm solves the problem by using multilayered models.
The original IDW breaks down as soon as the points count increases beyond several hundred. Generally, the modified Shepard's method performs well when used on datasets of any size with uniform points distribution. Uniform geometry, even if highly irregular, is the easiest one—almost any point is surrounded by neighbors in all directions; one can achieve good results by using a search radius proportional to the mean inter-point distance. However, even the modified Shepard's method starts to perform poorly when confronted with highly nonuniform geometries:
Nonuniform geometries often arise in geospatial applications. The plot below visualizes results of three IDW algorithms (original, modified, and MSTAB) applied to a Gaussian-like bump function f=1/(1+5·x2+5·y2) densely sampled across seven parallel lines:
One can see that the original algorithm (on the left) produces strange ripple-like artifacts. As soon as we move away from interpolation nodes, the model rapidly shifts toward mean value over the entire dataset. The reason is that the total weight assigned to distant points outweighs nearby ones.
The modified Shepard's method (middle) with a small search radius goes to the other extreme—the model is mostly dominated by nearby points; it is almost flat when approaching its nearest neighbor. When the search radius is increased, the model shows somewhat better behavior until it rapidly breaks down in a way similar to that of the original IDW algorithm.
Finally, one can see that our MSTAB algorithm produces the best model, which is free from aforementioned artifacts.
ALGLIB Project offers you two editions of ALGLIB:
ALGLIB Free Edition:
+delivered for free
+offers full set of numerical functionality
+extensive algorithmic optimizations
-no multithreading
-non-commercial license
ALGLIB Commercial Edition:
+flexible pricing
+offers full set of numerical functionality
+extensive algorithmic optimizations
+high performance (SMP, SIMD)
+commercial license with support plan
Links to download sections for Free and Commercial editions can be found below: