{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Inverse Distance Weighting (IDW)\n", "\n", "The **Inverse Distance Weighting (IDW)** is a deterministic interpolation method.\n", "\n", "The assigned values to unknown points are calculated with a *weighted average* of the values available at the known points. \n", "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.\n", "\n", "The model can be tuned by the following parameters:\n", "- `power`: the power of the inverse distance function" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Mathematical formulation\n", "\n", "Given a set of sample points:\n", "\n", "$\\{ \\mathbf{x}_i, u_i | \\text{for } \\mathbf{x}_i \\in \\mathbb{R}^n, u_i \\in \\mathbb{R}\\}_{i=1}^N$\n", "\n", "\n", "the IDW interpolation function $u(\\mathbf{x}): \\mathbb{R}^n \\to \\mathbb{R}$ is defined as:\n", "\n", "$u(\\mathbf{x}) = \\begin{cases}\n", " \\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, \\\\\n", " u_i, & \\text{if } d(\\mathbf{x},\\mathbf{x}_i) = 0 \\text{ for some } i,\n", "\\end{cases}$\n", "\n", "where\n", "\n", "$w_i(\\mathbf{x}) = \\frac{1}{d(\\mathbf{x},\\mathbf{x}_i)^p}$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Examples" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The autoreload extension is already loaded. To reload it, use:\n", " %reload_ext autoreload\n" ] } ], "source": [ "import py3dinterpolations as p3i\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | ID | \n", "X | \n", "Y | \n", "Z | \n", "V | \n", "
---|---|---|---|---|---|
278 | \n", "ID00 | \n", "15.194 | \n", "0.0 | \n", "12.0 | \n", "9.047969 | \n", "
279 | \n", "ID00 | \n", "15.194 | \n", "0.0 | \n", "10.0 | \n", "10.077271 | \n", "
280 | \n", "ID00 | \n", "15.194 | \n", "0.0 | \n", "8.0 | \n", "20.082454 | \n", "
281 | \n", "ID00 | \n", "15.194 | \n", "0.0 | \n", "6.0 | \n", "19.042223 | \n", "
282 | \n", "ID00 | \n", "15.194 | \n", "0.0 | \n", "4.0 | \n", "12.889411 | \n", "
\n", " | \n", " | \n", " | \n", " | V | \n", "
---|---|---|---|---|
ID | \n", "X | \n", "Y | \n", "Z | \n", "\n", " |
ID30 | \n", "62.163 | \n", "14.336 | \n", "20.0 | \n", "7.523950 | \n", "
18.0 | \n", "7.504403 | \n", "|||
16.0 | \n", "12.431670 | \n", "|||
14.0 | \n", "12.653931 | \n", "|||
12.0 | \n", "17.956143 | \n", "|||
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
ID00 | \n", "15.194 | \n", "0.000 | \n", "12.0 | \n", "9.047969 | \n", "
10.0 | \n", "10.077271 | \n", "|||
8.0 | \n", "20.082454 | \n", "|||
6.0 | \n", "19.042223 | \n", "|||
4.0 | \n", "12.889411 | \n", "
283 rows × 1 columns
\n", "