# An Adaptive Moving Window Kriging Based on K-Means Clustering for Spatial Interpolation
## 2 Theoretical Background
### Ordinary Kriging  
In spatial interpolation, kriging is a method of estimating unknown values at unsampling positions of a random function or random process. Let \(\left\{Z(x),x\in D\subset\mathbb{R}^{d}\right\}\) be a random process over a spatial domain \(D\) and \(d\geq 1\). The random process can be expressed by the model  
\[Z(x)=\mu(x)+\epsilon(x), \tag{2}\]  
where \(\mu(x)\) is the mean of the process, also known as the deterministic trend function, and \(\epsilon(x)\) is a zero-mean random variable with stationary covariance. Let \(Z(x_{1}),Z(x_{2}),\ldots,Z(x_{n})\) be a collection of observations at \(n\) different positions, \(x_{1},x_{2},\ldots,x_{n}\). Ordinary kriging is the method of choice for many geostatistical interpolation problems. The model satisfies the intrinsic stationarity property, which means that the expected difference between each pair of random variables \(Z(x)\) and \(Z(x+\mathbf{h})\) is zero and the variance of \(Z(x)-Z(x+\mathbf{h})\) only depends on the lag vector \(\mathbf{h}\) for any position \(x\) and \(x+\mathbf{h}\) of the observations, respectively. In ordinary kriging, the value at a target point \(x_{0}\) is estimated by calculating a weighted average of \(n\) nearby points. The kriging estimator \(\hat{Z}(x_{0})\) is expressed in the form  
\[\hat{Z}(x_{0})=\sum_{i=1}^{n}\lambda_{i}Z(x_{i}), \tag{3}\]  
where \(\lambda_{i}\) is the kriging weight related to the observation at point \(x_{i}\). The OK model provides an unbiased estimator \(\hat{Z}(x_{0})\) with a minimum variance. Using the Lagrange multiplier method leads to the following equations:  
\[\left\{ \begin{aligned} &\sum_{j=1}^{n}\lambda_{j}\gamma(x_{i}-x_{j})+ \varphi=\gamma(x_{i}-x_{0}),\;i=1,2,\ldots,n,\\ &\sum_{i=1}^{n}\lambda_{i}=1,\end{aligned} \right. \tag{4}\]where \(\varphi\) represents the Lagrange multiplier, \(\gamma(x_{i}-x_{j})\) denotes the variogram of variable \(Z\) between the observation points \(x_{i}\) and \(x_{j}\), while \(\gamma(x_{i}-x_{0})\) signifies the variogram of variable \(Z\) between the observation point \(x_{i}\) and the target point \(x_{0}\). In ordinary kriging, the weights can be determined when a variogram is known. The variogram, denoted as \(\gamma(\mathbf{h})\), quantifies the spatial variability or spatial dependence of a random variable as a function of a lag vector \(\mathbf{h}\) between pairs of values \(Z(x)\) and \(Z(x+\mathbf{h})\) of two positions \(x\) and \(x+\mathbf{h}\), respectively. As \(Z(x)\) satisfies the condition of intrinsic stationarity, the theoretical variogram \(\gamma(\mathbf{h})\) is expressed as  
\[\gamma(\mathbf{h})=\frac{1}{2}\mathbf{E}\Big{\{}[Z(x)-Z(x+\mathbf{h})]^{2} \Big{\}}, \tag{5}\]  
where \(\mathbf{E}\) denotes the expectation operator. However, in most cases, it is difficult to compute the variogram model in Equation (5). The classical empirical variogram estimator introduced by [PERSON] [2] is unbiased but performs sensitively when the data include outliers due to the squared difference term. To reduce the effect of an outlier, [PERSON] and [PERSON], in 1980 [31], introduced a robust variogram, which is provided by  
\[\hat{\gamma}_{CH}(\mathbf{h})=\frac{\left\{\frac{1}{N(\mathbf{h})}\sum_{i=1}^ {N(\mathbf{h})}|Z(x_{i})-Z(x_{i}+\mathbf{h})|^{\frac{1}{2}}\right\}^{4}}{2 \bigg{(}0.457+\frac{0.494}{N(\mathbf{h})}+\frac{0.045}{N^{2}(\mathbf{h})} \bigg{)}}, \tag{6}\]  
where \(N(\mathbf{h})\) is the total number of pairs at a lag vector \(\mathbf{h}\). In many practical applications, the variogram is defined as a function of the Euclidean distance or length of the lag vector \(\mathbf{h}\) only, referred to as an isotropic variogram. That is, the empirical variogram \(\hat{\gamma}(\mathbf{h})\) can be denoted as \(\hat{\gamma}(h)\), where \(h\) is the Euclidean norm of \(\mathbf{h}\). The empirical variogram estimators in Equation (6) yield a set of point estimates of the variogram for observed lags \(h\), as opposed to the variogram in Equation (5) which is characterized by a continuous function.