# An Adaptive Moving Window Kriging Based on K-Means Clustering for Spatial Interpolation
## 3 Methodology
### Window Selection Based on K-Means Clustering  
The process of choosing a window member is of the utmost importance in the context of kriging with movable windows. Numerous factors demand careful consideration during the selection of a window. Nevertheless, there are no precise recommendations for determining the appropriate window for the moving window kriging interpolation method with different data sets. This work arose from the need to solve this practical problem. By integrating K-means clustering into the window selection process of moving window kriging, we aimed to enhance the accuracy and efficiency of spatial interpolation.  
Let \(Z(x_{1}),Z(x_{2}),\ldots,Z(x_{n})\) be the observations at \(n\) different positions \(x_{1},x_{2},\ldots,x_{n}\) in the spatial domain \(D\). Let \(x_{0i}\) for \(i=1,2,\ldots,p\) be target positions, which in this study is defined as \(x_{0i}=(\lambda_{x_{0i}},\phi_{x_{0i}})\), where \(\lambda_{x_{0i}}\) is the longitude and \(\phi_{x_{0i}}\) is the latitude at the \(i\)th target point. The objective of the present work, known as Adaptive Moving Window Kriging using K-means Clustering (AMWKK), is to improve the cluster-based kriging introduced by [PERSON] et al. Instead of using centroids in a fixed manner throughout the simulation, each target site served as a cluster centroid, leading to a new set of clusters being sequentially formed. The moving window ordinary kriging method then proceeds within a cluster where the target point is located. The outline of AMWKK method for assigning appropriate neighboring points based on K-means clustering in the context of moving window ordinary kriging is presented in Algorithm 4.  
```
1:sampling positions \(X=\{x_{1},\dots,x_{n}\}\);
2:number of clusters \(k\);
3:target points \(x_{0i}\) for \(i=1,2,\dots,p\)
4:windows \(W_{0i}\) of the points \(x_{0i}\) for \(i=1,2,\dots,p\)
5:apply K-means algorithm to obtain \(k\) clusters \(C_{1},\dots,C_{k}\) with the set of its centroids \(c=\{c_{1},\dots,c_{k}\}\)
6:for\(i=1\) to \(p\)do
7:if\(x_{0i}\in C_{m}\) for some \(m\in\{1,2,\dots,k\}\)then
8:\(c_{m}=x_{0i}\)
9:\(c=\{c_{1},\dots,c_{m-1},x_{0i},c_{m+1},\dots,c_{k}\}\)
10:endif
11:for\(q=1\) to \(n\)do
12:for\(j=1\) to \(k\)do
13:assign \(x_{j}\) to closest centroid:
14:if\(||x_{q}-c_{j}||<||x_{q}-c_{i}||,j\
eq l\) and \(1\leq j,l\leq k\)then
15:\(C_{j}=C_{j}\cup\{x_{q}\}\)
16:endif
17:endfor
18:\(W_{0i}=C_{m}\)
19:endfor
```  
**Algorithm 4** Window selection based on the K-means clustering algorithm  
Figure 1 depicts the conceptual difference in window selection between the Abedini et al. technique and the AMWKK approach. A pragmatic issue regarding the cluster-based kriging of Abedini et al. can be seen in Figure 0(a) when the target point, denoted by a star, is situated near the cluster borders. More specifically, the target point is in cluster 3, and all data belonging to this cluster are required for the estimation. However, there are points near the borders that reside in other clusters and are closer to the target point than some cluster 3 members. An adaptation of AMWKK is to select the target point to be a new centroid for the cluster instead, as shown in Figure 0(b). This allows for more suitable observed data that has similar characteristics to the target point to be included through the K-means clustering algorithm.