Inverse Distance Weighting (IDW)

The Inverse Distance Weighting (IDW) is a deterministic interpolation method.

The assigned values to unknown points are calculated with a weighted average of the values available at the known points. The weights are calculated as a function of the distance between the known and unknown points. The function used is the inverse of the distance, elevated to a given power, to each known point.

The model can be tuned by the following parameters: - power: the power of the inverse distance function

Mathematical formulation

Given a set of sample points:

\(\{ \mathbf{x}_i, u_i | \text{for } \mathbf{x}_i \in \mathbb{R}^n, u_i \in \mathbb{R}\}_{i=1}^N\)

the IDW interpolation function \(u(\mathbf{x}): \mathbb{R}^n \to \mathbb{R}\) is defined as:

\(u(\mathbf{x}) = \begin{cases} \dfrac{\sum_{i = 1}^{N}{ w_i(\mathbf{x}) u_i } }{ \sum_{i = 1}^{N}{ w_i(\mathbf{x}) } }, & \text{if } d(\mathbf{x},\mathbf{x}_i) \neq 0 \text{ for all } i, \\ u_i, & \text{if } d(\mathbf{x},\mathbf{x}_i) = 0 \text{ for some } i, \end{cases}\)

where

\(w_i(\mathbf{x}) = \frac{1}{d(\mathbf{x},\mathbf{x}_i)^p}\)

Examples

[21]:
import py3dinterpolations as p3i
import pandas as pd
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
[22]:
df = pd.read_csv(
    "../../../tests/fixtures/griddata_default_colnames.csv"
)
df.tail()
[22]:
ID X Y Z V
278 ID00 15.194 0.0 12.0 9.047969
279 ID00 15.194 0.0 10.0 10.077271
280 ID00 15.194 0.0 8.0 20.082454
281 ID00 15.194 0.0 6.0 19.042223
282 ID00 15.194 0.0 4.0 12.889411
[23]:
gd = GridData(df)
gd.data
[23]:
V
ID X Y Z
ID30 62.163 14.336 20.0 7.523950
18.0 7.504403
16.0 12.431670
14.0 12.653931
12.0 17.956143
... ... ... ... ...
ID00 15.194 0.000 12.0 9.047969
10.0 10.077271
8.0 20.082454
6.0 19.042223
4.0 12.889411

283 rows × 1 columns

[24]:
interpolated, model = p3i.interpolate(
    gd,
    model_name = "idw",
    model_params = {
        "power": 2,
    },
    grid_resolution=5,
    preprocess_kwags={
        "normalize_xyz": True,
        "standardize_v": True,
    },
    return_model=True,
)
[25]:
fig = p3i.plot_3d_model(
    model,
    plot_points=True,
    scale_points=10,
    volume_kwargs={
        "surface_count": 10,
    }
)
fig.show()

Data type cannot be displayed: application/vnd.plotly.v1+json