{"id":64,"date":"2020-11-05T19:33:42","date_gmt":"2020-11-05T19:33:42","guid":{"rendered":"https:\/\/ml-gis-service.com\/?p=64"},"modified":"2021-07-18T09:50:39","modified_gmt":"2021-07-18T09:50:39","slug":"spatial-interpolation-101-introduction-to-inverse-distance-weighting-interpolation-technique","status":"publish","type":"post","link":"https:\/\/ml-gis-service.com\/index.php\/2020\/11\/05\/spatial-interpolation-101-introduction-to-inverse-distance-weighting-interpolation-technique\/","title":{"rendered":"Spatial Interpolation 101: Introduction to Inverse Distance Weighting Interpolation Technique"},"content":{"rendered":"\n<p>Do you think that points on a map are not enough to tell your story? Me too. Year ago, I\u2019d prepared a presentation for GIS conference and I\u2019d had a point map of measurements. \u201cIt won\u2019t be visible\u201d \u2013 I thought \u2013 \u201cI must do something with it\u201d. Then I spent half the night before presentation on the problem how to interpolate values in locations where measurements were not taken. I\u2019ve used kriging for it, but nowadays I rather focus on simpler approach. This is the<strong> Inverse Distance Weighting<\/strong> interpolation technique.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The First Law of Geography<\/h2>\n\n\n\n<p>Do you know the first law of geography proposed by Tobler? If not, here it is:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Everything is related to everything else, but near things are more related than distant things.<\/p><cite><strong>W.Tobler<\/strong><\/cite><\/blockquote>\n\n\n\n<p>What does it mean in practice?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Temperature in your city is similar to temperature in neighboring city, but it is probably very different than temperature in the city 1000 km South (spatial distance);<\/li><li>Mean humidity tomorrow will be similar to mean humidity today, but it\u2019ll be different than mean humidity month ago (temporal distance);<\/li><li>Your closest friends have similar interests and worldview as you, but friends of your friends are dedicated to other things than geostatistics and geography (social distance).<\/li><\/ul>\n\n\n\n<p>We stick to the spatial distance case and skip other distances, but it is nice to see common ground between different dimensions of our reality. Ok, time to <em>think physics<\/em> and build our inverse distance weighted interpolation (IDW) model. We have one BIG assumption. That every point is a weighted sum of all other points\u2019 values. What does it mean? We\u2019re going through a specific story to uncover IDW.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The story of shared mood and crocs<\/h2>\n\n\n\n<p>IDW concept may be described in two sentences:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>To get value at unseen location you weight values of known locations and sum them.&nbsp;<\/li><li>Weighting is a function of distance to the unseen location.<\/li><\/ul>\n\n\n\n<p>That\u2019s it! But still it is hard to understand underlying concept. Thus we will start from the IDW equation (1) and then move to the specific application of IDW to understand its power.<\/p>\n\n\n\n<p>$$f(m) = \\frac{\\sum_{i}\\lambda_{i}*f(m_{i})}{\\sum_{i}\\lambda{i}}; (1)$$<\/p>\n\n\n\n<p>where:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>$f(m)$ is a value at unknown location,<\/li><li>$i$ is i-th known location,<\/li><li>$f(m_{i})$ is a value at known location,<\/li><li>$\\lambda$ is a weight assigned to the known location.<\/li><\/ul>\n\n\n\n<p>We must assign specific weight to get proper results. And weight depends on the distance between known point and unknown point (2).<\/p>\n\n\n\n<p>$$\\lambda_{i} = \\frac{1}{d_{i}^{p}}; (2)$$<\/p>\n\n\n\n<p>where:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>$d$ is a distance from known point&nbsp;$i$ to the unknown point,<\/li><li>$p$ is a hyperparameter which controls how strong is a relationship between known point and unknown point. You may set large&nbsp;$p$ if you want to show strong relationship between closest point and very weak influence of distant points. On the other hand, you may set small&nbsp; $p$&nbsp;to emphasize fact that points are influencing each other with the same power irrespectively of their distance.<\/li><\/ul>\n\n\n\n<p>Specific example helps to better understand how lambda parameter affects our analysis. Let\u2019s imagine that you are living in&nbsp;<em>flatland<\/em>. This land is very strange because your mood is proportional to the mood of your neighbors. Proportion of it may be controlled by some super-three-dimensional entity which changes parameter&nbsp;$p$&nbsp;of your universe. Larger&nbsp;$p$&nbsp;increases effective distance between you and your neighbors; their mood is transferred by the valley full of&nbsp;<em>mood-crocs<\/em>&nbsp;which are eating it. Larger&nbsp;$p$&nbsp;literally increases number of&nbsp;<em>mood-crocs<\/em>&nbsp;per each mood route, and if route is longer then more&nbsp;<em>mood-crocs<\/em>&nbsp;may fit into it (look into the Figures 1-3 if you feel lost here). What happens when&nbsp;$p$&nbsp;is set to zero (0), one (1) and (2)? We analyze it and with this example you hopefully understand how IDW works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Set p to 0<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"889\" height=\"500\" src=\"https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd1-500.png\" alt=\"\" class=\"wp-image-70\" srcset=\"https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd1-500.png 889w, https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd1-500-300x169.png 300w, https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd1-500-768x432.png 768w\" sizes=\"auto, (max-width: 889px) 100vw, 889px\" \/><figcaption>Figure 1: Flatland mood transfer. Hyperparameter p is set to 0, what is the mood value of a flatman m?&nbsp;Credits: S. Moli\u0144ski.<\/figcaption><\/figure>\n\n\n\n<p>Figure 1 shows three known&nbsp;<em>flatmen<\/em>&nbsp;with their moods. We have distance between them and the unknown&nbsp;<em>flatman<\/em>&nbsp;too. In the first step we calculate how many&nbsp;<em>mood-crocs<\/em>&nbsp;are placed between missing value $m$ and known values $m_{1}$, $m_{2}$ and $m_{3}$ per each&nbsp;<em>mood-transfer<\/em>&nbsp;route. Those crocs represent weights assigned to the known values; and you may place more crocs (smaller weight, we lost a lot of information on a larger distance) if distance is long. Our distance for every route is different, but if we assume that weighting factor is equal to 0 then our weight (number of crocs) is always one. You should remember from the school algebra that every value raised to 0 gives 1. Weight is always 1 \u2013 we set one&nbsp;<em>mood-croc<\/em>&nbsp;(denominator in $\\lambda_{i}$) for every distance. Mood of&nbsp;<em>flatman m<\/em>&nbsp;is simple average of the other moods and it is equal to 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Set p to 1<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"889\" height=\"500\" src=\"https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd2-500.png\" alt=\"\" class=\"wp-image-71\" srcset=\"https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd2-500.png 889w, https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd2-500-300x169.png 300w, https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd2-500-768x432.png 768w\" sizes=\"auto, (max-width: 889px) 100vw, 889px\" \/><figcaption>Figure 2: Flatland mood transfer. Hyperparameter p is set to 1, what is the mood value of a flatman m?&nbsp;Credits: S. Moli\u0144ski<\/figcaption><\/figure>\n\n\n\n<p>Scenario in Figure 2 is more complicated. We have multiple&nbsp;<em>mood-crocs<\/em>&nbsp;here because we have set $p$ parameter. As you remember from school algebra, if we raise number to the power of 1 then we get the same number. That\u2019s why number of&nbsp;<em>mood-crocs<\/em>&nbsp;(weights assigned to each distance) is an inverse proportion of the distance itself. This time we get weighted average of moods in the form:<\/p>\n\n\n\n<p>$$\\frac{(1*1+\\frac{1}{2}*3+\\frac{1}{3}*2)}{(1+\\frac{1}{2}+\\frac{1}{3})}=\\frac{(1+1.5+0.67)}{1.83}=1.73; (3)$$<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Set p to 2<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"889\" height=\"500\" src=\"https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd3-500.png\" alt=\"\" class=\"wp-image-72\" srcset=\"https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd3-500.png 889w, https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd3-500-300x169.png 300w, https:\/\/ml-gis-service.com\/wp-content\/uploads\/2020\/11\/Slajd3-500-768x432.png 768w\" sizes=\"auto, (max-width: 889px) 100vw, 889px\" \/><figcaption>Figure 3: Flatland mood transfer. Hyperparameter p is set to 2, what is the mood value of a flatman m?&nbsp;Credits: S. Moli\u0144ski<\/figcaption><\/figure>\n\n\n\n<p>Now interesting story begins. Number of m<em>ood-crocs<\/em>&nbsp;is expanding with the power assigned to the distance. What is the mood of the unknown<em>&nbsp;flatman<\/em>?<\/p>\n\n\n\n<p>$$\\frac{(1*1+\\frac{1}{4}*3+\\frac{1}{9}*2)}{(1+\\frac{1}{4}+\\frac{1}{9})}=\\frac{(1+0.75+0.22)}{1.36}=1.45; (4)$$<\/p>\n\n\n\n<p>Do you see how power affects effective&nbsp;<em>mood-transfer<\/em>? Lower mood value is closer to the unknown point, but it still has greatest impact on the final value. And other moods impact decreases quickly with rising power. It is especially visible if you look into the middle part of equation (3) and equation (4). The conclusion is simple: if you want to emphasize close-neighbors interaction then set power to the larger number. But if points in your research area probably interact at a large distance then set power to the small value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Exercises<\/h2>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\"><li>Think of one example of measurements where observations are spatially correlated.<\/li><li>Why should we care about spatial interpolation?<\/li><li>What will happen if power is set to the value between 0 and 1? What will happen if power is negative?<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Next lesson:<\/h2>\n\n\n\n<p>>> <a href=\"https:\/\/ml-gis-service.com\/index.php\/2021\/05\/20\/spatial-interpolation-101-interpolation-of-mercury-concentrations-in-the-mediterranean-sea-with-idw-and-python\/\">Prediction of mercury concentrations in Mediterranean Sea with IDW in Python<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Changelog<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>2021-07-18: Update of the link to the next lesson.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Spatial interpolation 101: Inverse Distance Weighting Explained<\/p>\n","protected":false},"author":1,"featured_media":76,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,31],"tags":[35,32,33,34],"class_list":["post-64","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spatial-statistics","category-tutorials","tag-how-to-calculate-inverse-distance-weighting","tag-inverse-distance-weighting","tag-spatial-interpolation","tag-spatial-statistics"],"_links":{"self":[{"href":"https:\/\/ml-gis-service.com\/index.php\/wp-json\/wp\/v2\/posts\/64","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ml-gis-service.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ml-gis-service.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ml-gis-service.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ml-gis-service.com\/index.php\/wp-json\/wp\/v2\/comments?post=64"}],"version-history":[{"count":10,"href":"https:\/\/ml-gis-service.com\/index.php\/wp-json\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":360,"href":"https:\/\/ml-gis-service.com\/index.php\/wp-json\/wp\/v2\/posts\/64\/revisions\/360"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ml-gis-service.com\/index.php\/wp-json\/wp\/v2\/media\/76"}],"wp:attachment":[{"href":"https:\/\/ml-gis-service.com\/index.php\/wp-json\/wp\/v2\/media?parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ml-gis-service.com\/index.php\/wp-json\/wp\/v2\/categories?post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ml-gis-service.com\/index.php\/wp-json\/wp\/v2\/tags?post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}