Wireless Localization Method Based on AHP-WKNN and Amendatory AKF

In this paper, we propose an AHP-WKNN method for indoor localization which combines the Analytic Hierarchy Process (AHP) technique and the Weighted K-nearest Neighbor (WKNN) algorithm. AHP serves to assign weights when WKNN is employed to select fingerprints for indoor positioning. The AHP technique can reasonably enlarge the influence that the received signal strength (RSS) gap between reference points has on the weights, achieving better performance in positioning. This paper also modifies the adaptive Kalman filter (AKF) noise reduction method by correcting the output based on the error between the RSS measurement and the expected output. The modified AKF can track the changes of RSS more effectively and achieve better performance of noise reduction. The simulation result shows that the proposed AHP-WKNN method and the modified AKF can improve positioning accuracy effectively.


Introduction
The demand for high-precision positioning and navigation in the indoor scenario is increasing along with the popularization of the Internet of things. The WLAN-based indoor positioning can fully make use of the widely deployed Access Points (AP) to achieve high positioning performance [1,2]. So far, the localization based on WLAN has two main methods-the triangulation method and fingerprinting localization. The triangulation method uses the distances between the test point and three known APs to estimate the location of the test point. The distance here is estimated by measuring the received signal strength (RSS) of the APs. This method relies heavily on the accurate signal path loss model. There are a lot of factors that may affect the signal path. The signal path loss model varies under different environments, and building an accurate and suitable model can be very difficult. Therefore, it is very hard to apply the triangulation method based on indoor localization in reality. Recently, the indoor positioning system based on WLAN, which uses fingerprint (formed by the coordinates of the reference points (RPs) and the APs' signal strength received at RPs) as the recognition method, has become a research hotspot [3,4]. It involves two phases named the offline phase and the online phase. In the offline phase, the main task is to build a fingerprint database, which preserves the mapping between the RSS space and the location space. The location space is made up of all RPs' position coordinates, and the RSS space is made up of the AP's signal strength measured at RPs. The location of each RP corresponds to a group of RSS measured from APs. In the online phase, the user terminal senses the RSS and further matches it with the RSS space in the database; then, a suitable fingerprint matching method is applied to compute the user's position. The suitable fingerprint matching method is the Weighted K-nearest Neighbor (WKNN) algorithm, a machine learning-based algorithm. The localization process of the extant WKNN is to first measure the Euclidean distances between the RSS measured at the test points and the RSS of each RP in the fingerprint database. Then, the process sorts those Euclidean distances in ascending order. The first k coordinates of the RPs with the smallest Euclidean distances are chosen. Different weights are then assigned to those k coordinates. The weights are inversely proportional to the Euclidean distance of the RPs. Finally, the position of the test point is the weighted mean of the coordinates of k RPs.
However, the WKNN mentioned above is not optimal. In most precise positioning scenarios, the RPs are deployed with high density. The differences between the assorted k Euclidean distances are not big enough. The weights assigned to the k RPs in the existing papers [5][6][7][8][9] are thereby almost the same, and the weighted sum of the location coordinates is almost equal to the average of the location coordinates. Our simulation results show that this method leads to inaccurate location results. As a result, it is necessary to properly enlarge the effect that the differences between these selected k Euclidean distances have on the localization process. Therefore, this paper proposes an AHP-WKNN method which adopts the Analytic Hierarchy Process (AHP) technique [10][11][12][13][14] to assign weights to the k RPs. In this method, we choose the optimal position estimation of the test point as the target layer, the RSS value measured at all APs as the criterion layer, and the first k RPs' coordinates as the scheme layer. We then set the relative importance of elements in the positioning subjectively and determine whether this setting is consistent with mathematical logic by the consistency check. The weights of the k RPs' coordinates in the scheme layer can then be calculated through solving the judgment matrix. It is obvious that the AHP technique adds the subjective components in the objective mathematics framework; thus, it properly enhances the effect that RSS difference of k RPs has on weights and achieves a better effect on localization compared to the existing methods.
The second problem of indoor localization is that the noise in the measurement of the RSS will lower the accuracy of WKNN. The existing works [15,16] use the adaptive Kalman filter (AKF) to reduce the noise. AKF includes three phases: prediction, correction, and noise covariance estimation. In the prediction phase, AKF utilizes the estimation of the real RSS vector at the previous momentX t−1 to calculate the prior RSS vector estimationX t|t−1 at the current moment. During the correction phase, based on the current measurement of RSS Z t ,Ẑ t expectation ofX t|t−1 (the expected output of AKF at the current moment), and the Kalman gain matrix, AKF gives the current estimation of real RSSX t (the output of AKF); after that, AKF updates the covariance matrix of the noise and uses the result for the next iteration.
However, the estimation errors that exist during the iteration process are transitive, and the transition of these errors will affect the number of iterations that AKF needs to achieve the convergence state and the accuracy of the output result. Therefore, the AKF method in works [15,16] is not effective enough. From the iteration process of AKF, we can see thatX t|t−1 is determined by the outputX t−1 at moment t − 1. If ε t (the error between Z t andẐ t ) at moment t is too large, thenX t−1 is inaccurate.X t−1 should be corrected to prevent errors from passing to the next iterations. Based on the analysis above, an amendatory AKF method is proposed in this paper. We set a judgment rule for ε t . If jb ε t j (the covariance of ε t ) exceeds the judgment rule,X t|t−1 is inaccurate. We will adjustX t−1 and recalculateX t|t−1 [17]. Compared to the AKF in works [15,16], one comparison and one amendment are added to each iteration in the proposed algorithm, and the noise reduction effect of the amendatory AKF is higher than that of the AKF in [15,16], which leads to better performance of WKNN-based localization.
The main contributions of this paper are as follows. (i) This paper proposes an AHP-WKNN algorithm. The AHP technique is used to enhance the effect that the RSS difference between the test points and RPs has on the positioning process by assigning weights for different RP coordinates and thus improves the localization accuracy for the current WKNN algorithms. (ii) By setting a judgment rule to the error ε t between the expected outputs and measurements, this paper conducts an amendment to the prior estimation of real RSS vectors. Thus, it improves the accuracy of the output of the AKF method and thereby improves the accuracy of the WKNN algorithm.

System Model
The fingerprint-based indoor localization system includes the offline phase and the online phase. During the offline phase, the RSS from AP is collected at the known RPs to form the fingerprint database. One fingerprint includes the coordinate of one RP and a series of RSS from APs measured at this RP. Therefore, there are two spaces in the fingerprint database mapping to each other, and these two spaces are the location space and the RSS space, respectively. Assuming there are M APs and N RPs, then the fingerprint database is expressed as follows: where the location space L ∈ ℝ N×1 is made by N position coordinate vectors of RPs. RSS ∈ ℝ N×M is the RSS space, including M RSS vectors. RSS i ∈ ℝ 1×N records the observed RSS values from the ith AP as where rss ij represents the RSS from the ith AP measured at the jth RP (i = 1, ⋯, M, j = 1, ⋯N). ½· T represents the matrix transpose.
In the online phase, the user terminal compares the RSS measured at the test point with the RSS in the fingerprint database built in the offline phase and then chooses k RPs by considering the minimum Euclidean distance between the RSSs of these RPs and the RSS of the test point. Based on those k chosen RPs' coordinates and their weights, the optimal position of the test point could be expressed aŝ Wireless Communications and Mobile Computing whereP is the optimal position estimation of the test point, p i is the coordinates of the ith RP, k is the number of the chosen RPs, and β i is the weight assigned by the algorithm for the ith RP.

AHP-WKNN
where j = 1, ⋯N, N is the number of RPs. Those Euclidean distances are sorted in ascending order, and the first k coordinates of the RPs with the smallest Euclidean distances are chosen to estimate the position of the test point. Apparently, the coordinate with a smaller Euclidean distance has a larger weight, and the coordinate with a larger Euclidean distance has a smaller weight. In [5], the weight is equal to the normalized Euclidean distance and can be expressed as the following equation: Assuming that the coordinate of the ith RP is ðx i , y i Þ, i = 1, ⋯k, the position estimated by WKNN iŝ where ðx i ,ŷ i Þ is the coordinate of the test point's estimated position.

Problem Statement.
From Section 3.1, it is easy to see that the coordinate of the test point is the weighted mean of selected k RP coordinates. The weights are related to the RSS differences between the test point and the RPs. Since the differences of those Euclidean distances are not big enough, the differences of weights given by (5) are almost the same. According to our simulation, it is necessary to properly enhance the effect that the RSS difference has on the weights to improve the accuracy of the WKNN algorithm.

Hierarchical Model of AHP.
We propose to use the AHP technique to realize this goal. Based on their functions on the positioning, factors involved in the indoor localization process are separated into a target layer, criterion layer, and scheme layer [10]. The judgment matrix is formed subjectively based on the relative importance of factors. Then, the consistency check is applied to determine the mathematical rationality of the judgment matrix. The weight of factors in positioning is obtained through matrix calculation. This method can subjectively enhance the influence that RSS differences have on their weights within an objective mathematical framework. The main steps are shown as follows: (1) Constructing the hierarchical structure model: calculating the optimal position of the test point is the target layer. Here, we set 4 APs and select 3 nearest RPs to participate in the localization process. Then, the 4 RSS measured at the four APs (RSS1, RSS2, RSS3, and RSS4) constitute the criterion layer, and the coordinates of three RPs are the scheme layer. The system structure model is shown in Figure 1 (2) Constructing the judgment matrix: here, we denote C k as the kth judgment matrix in the scheme layer. When the scheme layer is making decisions based on the RSS received from the kth AP, the element c k ij (k = 1, 2, 3, 4, i, j = 1, 2, 3) in C k represents the degree of relative importance between the coordinate of RP i and the coordinate of RP j . We then denote B as the judgment matrix for the criterion layer. When RSS i and RSS j are used to make decisions by the target layer, the element b ij (i, j = 1, 2, 3) in B represents the degree of relative importance between RSS i and RSS j . The degree of relative importance is represented by integers from 1 to 9, and their reciprocal values are represented by one over 1 to 9. The possible values of the elements in the judgment matrix are shown in Table 1 Based on Table 1, since the four APs have the same contribution, all elements in B of the criterion layer are set subjectively to 1. The judgment matrix B of the criterion layer is shown in Table 2.
Since the four APs have the same contribution, C k is the same for different k, which means C 1 = C 2 = C 3 = C 4 . The weights of RP's coordinates in the positioning process are inversely proportional to the Euclidean distance between the RP and the test point. Hence, coordinate 1 is more important than coordinate 2 (with the middle Euclidean distance), and coordinate 2 is more important than coordinate 3 (with the largest Euclidean distance). Based on the analysis above, the effect that the RSS difference has on weights should be enhanced. Therefore, the judgment matrix for C k of the scheme layer is set subjectively in Table 3.
(3) Determining whether the elements in the judgment matrix are mathematically reasonable through the consistency check: assuming the weight of element i to element l is a il and the weight of element l to element j is a lj , then the weight of element i to element j should be a ij = a il * a lj . If that is the case, we say the matrix is mathematically consistent. Mathematically, for the matrix that satisfies a ij = 1/a ji , λ max = n is the necessary requirement for a ij = a il * a lj . Here, λ max is the largest eigenvalue for the judgment matrix 3 Wireless Communications and Mobile Computing and n is the dimension of the judgment matrix [10][11][12]. However, since the elements in the judgment matrix are set subjectively, it is likely that λ max ≠ n. We thus use CI = ðλ max − nÞ/ðn − 1Þ to measure how close λ max is to n, which means we are examining the consistency degree of the matrix. The degree can vary with n. Table 4 gives the average degree of consistency of RI for different n. We use the ratio CR = CI/RI to check the consistency of the judgment matrix. CR reflects the range of the matrix's consistency. If CR < 0:10, the judgment matrix can be adopted; if CR ≥ 0:10, the judgment matrix is not reasonable, and it needs to be kept adjusted until CR < 0:10.
(4) Since the final goal is to get the weight of each RP's coordinate (the bottom layer) for the target layer (the top layer), we then compute the weight of each element for the upper layer. Because the values of the judgment matrix in this layer reflect the relative importance of the elements in the current layer when making decisions against the upper layer, we can use the normalized vector W k ′ of the eigenvector W k , which corresponds to the largest eigenvalue λ k max of the judgment matrix in the current layer to represent the weight vector for the judgment matrix. The ith value w ki ′ of W k ′ represents the ith attribute's weight in the current layer for the kth attribute in the upper layer. For example, the weight vector of the judgment matrix C k is calculated as follows: (i) Calculating C k 's largest eigenvalue λ k max 's corresponding eigenvector W k , where λ k max and W k satisfy the following: (ii) Normalizing the ith value w ki of W k to get W k ′ 's ith value w ki ′ :   The two elements are equally important 3 When comparing two elements, the former one is slightly more important 5 When comparing two elements, the former one is more important 7 When comparing two elements, the former one is particularly more important 9 When comparing two elements, the former one is significantly more important 2, 4, 6, 8 Represents the median of adjacent values mentioned above Reciprocal When comparing element i to element j, if the importance ratio between them is a ij , then the ratio between j and i is 1/a ji  Wireless Communications and Mobile Computing w ki ′ represents the weight of the ith RP's coordinate in the scheme layer for the RSS from the kth AP in the criterion layer, where k = 1, 2, 3, 4, i = 1, 2, 3. The judgment matrices C k of the scheme layer are the same for k = 1, 2, 3, 4, so the corresponding weight vectors W k ′ are the same. Since there is only one attribute in the target layer, the judgment matrix B of the criterion layer only has one weight vector W B ′ , and its kth value w bk represents the weight of the RSS of the kth AP in the criterion layer for the target layer.
(5) Based on W B ′ and W k ′, we calculate the weights of three RPs' coordinates in the scheme layer to realize localization. Each weight of the 3 RPs' coordinates for the target layer could be expressed as where k = 1, 2, 3, 4 and i = 1, 2, 3. Those three weights then can be used in (6) to estimate the optimal position of the test point.

Amendatory AKF Method to Reduce Noise
We apply the amendatory AKF method to remove the noise in RSS. Generally, the estimation errors in the AKF iterations are transitive, and the accumulation of these errors will affect the number of iterations that AKF needs to achieve the convergence state as well as the accuracy of the output result. Therefore, we set judgment rules to reduce accumulation of these errors and make the output of AKF closer to the real value. The AKF method utilizes the output obtained from the previous moment to adjust the current filtering parameters and adapts the statistical characteristics of the signals and noise. The AKF method has two basic assumptions. (1) The RSS vector at moment t can be expressed by the RSS vector at moment t − 1, and the measured RSS vector at moment t can be expressed by the real RSS vector. (2) These expressions and measurements can be described by the linear algorithm.
We denote the real RSS vector and the measured RSS vector received from M APs at moment t as X t and Z t , respectively. They can be expressed as where X t−1 is the real RSS vector at moment t − 1. F is the state transition matrix. H is the measurement matrix, map-ping the real vector to the observation space, which means it expresses the unmeasurable real value as the measurable value. Since there is only noise between the real value and the measured value and the only difference between measurements at different moments is the different random value of noise, an M-order identity matrix is used to represent F and H. The vector N t is the process noise vector distributed with zero mean and the process covariance matrix Q t . The vector V t is the observation noise vector distributed with zero mean and the measurement covariance matrix R t . The AKF method includes three phases: prediction, correction, and noise covariance estimation. In the prediction phase, AKF calculates the prior RSS vector estimationX t|t−1 at moment t based on the real RSS vector estimationX t−1 at moment t − 1 and the prior estimation error covariance matrix P t|t−1 at the same time.
where P t−1 = cov ðX t−1 −X t−1 Þ. P t−1 is the posterior estimation error's covariance matrix at moment t − 1. It reflects the accuracy of the output at moment t − 1. Since the real RSS vector at any moment is not available, the initial value P 0 of P t−1 is difficult to obtain. Generally, when P 0 is not a zero matrix, it will not affect the convergence of AKF [18]. Therefore, an M-order identity matrix is used to represent P 0 . The initial value ofX t−1 will be the measured value at the first time.
During the update phase, we first calculate the expected measured RSS vectorẐ t at moment t, and then, we calculate the Kalman gain matrix K t . Finally, we calculate the posterior RSS vector estimationX t at moment t, which is the system output at moment t, and we update the posterior estimation error's covariance matrix P t at the same time:  Figure 2: The proposed amendment process.

Wireless Communications and Mobile Computing
Finally, we update Q t and R t for the next iteration: where ε t is the error between Z t andẐ t . ε t reflects the degree of the error between the expected output and measurement   (12), (14) and (16) and getting the outputX t ; 7. calculating the covariance b ε t of Equation (18); 8. comparing jb ε t j with gate t . If jb ε t j ≥ gate t , fixX t−1 to getX t−1 ′ based on Equations (23) and (24), and useX t−1 ′ for the next iteration. Otherwise, useX t−1 instead; 9. updating Equation (13), (17), (19) and (20); t ⟵ t + 1; 11. end while 12. Calculating the Euclidean distances between X∧′ and each fingerprint in the database. Sorting these distances and choose k nearest fingerprints' coordinates; 13. Based on X∧′ and k fingerprints, using AHP to build hierarchical model and judgment matrices; 14. Examining the consistency of each judgment matrix and determining the weight vector of each judgment matrix based on Equation (7) and (8); 15. Getting the weights of k fingerprints' coordinates that are needed to realize localization based on Equation (9); 16. Based on the k coordinates and their corresponding weights, using Equation (6) to estimate the optimal positionP; 17. returnP.
Pseudocode 1: The pseudocode of the proposed algorithm. 6 Wireless Communications and Mobile Computing value. b is the forgetting factor in d t = ð1 − bÞ/ð1 − b t+1 Þ. b is used to lower the influence that the output at the prior moment (old data) has on the input data (new data) which is needed for new iteration at moment t. As the number of iterations increases, the estimation error's covariance matrix will become smaller and closer to the zero matrix. From Equations (15) and (16), we could see that K t → 0 when P t|t−1 → 0, and K t will no longer work in the noise reduction    Wireless Communications and Mobile Computing process [19]. In another word, the old data will saturate AKF. Data saturation will cause new data to be ineffective in the iteration process. Therefore, in order to reduce the impact of old data, we introduce the forgetting factor b to fasten the convergence of AKF. The range for b is from 0.95 to 0.995, and we set it to be 0.975. ε t reflects the degree thatẐ t , the expected output at moment t, is away from the measurement value Z t . When the model parameters are not accurate or Z t fluctuates greatly (due to the existence of noise or the fluctuation of APs' signals), ε t will be large, and the output accuracy obtained by Equation (16) will be low. In order to improve the output accuracy, we should make a judgment rule based on ε t . If j b ε t j (the covariance of ε t ) is greater than a threshold,X t−1 should be amended, andX t|t−1 should be recalculated based on amendatoryX t−1 . The process is shown in Figure 2.
Based on the analysis above, we set the judgment rules and amendment criterion to reduce ε t , making the output of AKF closer to the real value. The amendment condition is based on the condition that the error between the expected value and the measurement is greater than a threshold. Define where R t ð1, 1Þ is the element of the first row and first column of R t and gate t is the threshold at moment t. The range of coefficient μ is 0.5~0.9, and it is used to balance the influence that the measurement value and expected output have on the AKF output. It is also used to increase trust in the measurement value. Since the AKF model is a simulation of the real environment, the coefficient cannot be exact; thus, the output relies on the measurement value. Therefore, increasing trust in the measurement value will make the output closer to the real value. In this paper, μ = 0:8. If jb ε t j ≥ gate t , it indicates thatX t−1 is inaccurate and should be adjusted asX where b ε t is the covariance of ε t .X t−1 ′ is used for the next iteration. We use Equations (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), and (24) to reduce the noise in RSS at the test point. The noise-reduced RSS will then be applied in AHP-WKNN.

The Complete Algorithm
The module of the proposed algorithm is shown in Figure 3. First, the amendatory AKF is used to reduce the noise of the RSS in the test point. AHP is then applied to assign weights for the chosen k RPs' coordinates, and WKNN is used to estimate the optimal position.

Simulation Result Analysis
We simulate a 30-meter * 30-meter room with 4 APs in its corners. 957 RPs are set in the room with a one-meter interval between them unless otherwise stated. The static propagation model [20] and the RSS measured at each RP are shown as follows: where loss ij represents the path loss from the ith AP to the jth RP and dis ij represents the distance between the ith AP and the jth RP (i = 1, 2, 3, 4, j = 1, ⋯, 957). P L ðd 0 Þ is the received power with distance d 0 , where d 0 is 2 meters. G t and G r are the gain of the transmitting antenna and receiving antenna, respectively. G t = G r = 1 in the paper. λ is the wavelength, and λ = c/f , where c is the velocity of light in vacuum and f is the 2.4 GHz of the carrier. n is the channel fading factor with range 2 to 5, and n = 2 in this paper. rss ij represents the RSS from the ith AP measured at the jth RP. P AP represents the transmit power of AP. P AP = 30 dBm without specific indication in this paper. noise is the white Gaussian noise with a mean of 0 and a variance of 0.1. A stationary test point is randomly set in the simulated room, and the signal strength received at the test point also follows the static propagation model [20] described by Equations (25), (26), and (27). We employ two methods to evaluate the accuracy of the localization: (1) the root-mean-square error (RMSE) expressed in Equation (28) between the estimated position and the actual position of the test point: where ðx, yÞ and ðx,ŷÞ are the coordinates of the test point's actual position and estimated position, respectively, and (2) the probability of positioning error to assess the accuracy. The comparison of the noise reduction performance achieved by the standard KF, the existing AKF, and the amendatory AKF is shown in Figure 4.
From Figure 4, it can be seen that the result of the standard KF is not convergent. The existing AKF is better than   The amendatory AKF adds one comparison and one amendment process during every iteration. Thus, it can better track the change of RSS and achieve better performance of noise reduction. Figure 5 reflects the effects that different noise reduction algorithms have on localization. The abscissa is the allowable positioning error (x), and its unit is meter; the ordinate is the probability that the error between the estimated position of the test point and the real position is smaller than x, i.e., Pðerror ≤ xÞ.
From Figure 5, we can see that after using the amendatory AKF method to reduce noise at the test point, the positioning accuracy is better than that of having no noise reduction. When using the existing AKF, however, the positioning result fluctuates. Table 5 shows the comparison result of the RMSE generated by the existing AKF and amendatory AKF and without reducing noise, respectively. Figure 6 shows the influence that the intervals between RPs have on the positioning results.
It is straightforward that the average RMSEs are inversely proportional to the distance between RPs. From the point of view of machine learning, the smaller the distance is, the more fingerprints and information there are. Thus, when there is more training data for WKNN, the positioning accuracy is higher. We compare the RMSE between different algorithms, including WKNN, KNN (using the average coordinates of the K nearest neighbors to locate the test point), and NN (using the coordinate of the nearest neighbors to locate the test point). As can be seen from Figure 6, the average RMSE of the proposed algorithm is generally lower than that of the extant WKNN under different RP distances. The AHP technique reasonably expands the weight of the first RP during the positioning process, so that the difference between the weights of the k RPs is more obvious. The AHP technique adds the subjective components in the objective mathematics framework; thus, it properly enhances the effect that RSS difference of k RPs has on weights and helps to achieve a better effect on localization. Figure 7 demonstrates the influence of different μ on the positioning results of the proposed algorithm.
It can be concluded from Figure 7 that the proposed algorithm has a better positioning performance when μ is around 0.8. As μ is used to balance the influence that the measurement value and expected output have on the AKF output, relatively higher value of μ means that the output of AKF relies more on measurements. Figure 8 shows the influence of different transmit powers of APs on the localization performance of the proposed algorithm.
From Figure 8, we can see that the transmit powers of different APs have little influence on the positioning performance. This is because the factor that determines the positioning accuracy is the differences of the RSS between fingerprints. The fingerprints and their weights are chosen based on this difference. However, this difference is not affected by the transmit power. Thus, there is no point to adjust transmit power for positioning accuracy.

Conclusions
This paper proposes an AHP-WKNN method for indoor localization in which the AHP technique is designed to assign weights for selecting RPs to locate the position of the test point. We can subjectively enhance the effect that the differences between RSS have on the weights during positioning by employing AHP. To deal with the noises that exist in the indoor positioning system, this paper proposes an amendatory  10 Wireless Communications and Mobile Computing AKF method to reduce the noise, which introduces one comparison and one amendment in each iteration. The simulation results suggest that compared to the original AKF, the amendatory AKF can better fulfill the requirements of noise reduction at the test point, and the AHP-WKNN method thus can help achieve a higher positioning accuracy.

Data Availability
The data used to support the findings of this study are available from the corresponding authors upon request.

Conflicts of Interest
The authors declare no conflict of interest.