# Indoor Positioning Integrating PDR/Geomagnetic Positioning Based on the Genetic-Particle Filter
## 2 Materials and Methods
### Fusion Positioning Module
#### 2.3.3 Optimization Mechanism for Classical Particle Filter  
The optimization mechanism aims at improving the diversity and reliability of the resampled particles to ameliorate the particle degradation. Therefore, we utilize the gene mutation method to increase the diversity and use the reconstruction particle set method by combining the geomagnetic positioning results to improve the reliability of particles. We can assume that the characteristics of each resampled particle are its coordinate values. Firstly, we should utilize the gene mutation method to transform the coordinates into binary codes. Since the coordinate values are decimal, the problem becomes the decimal-to-binary conversion question [46]. As shown in Algorithm 2, it gives the detailed transformation process of \(x\) value. It should be clear that we should output \(\mathbf{M}\) in the inverse order to obtain the binary codes.  
```
1:Input: coordinate value \(x\), empty set \(\mathbf{M}\), Boolean variable isRun
2: get the integer part of \(x\), \(x\_in\gets floor(x)\); isRun \(\leftarrow\) true
3:while (isRun)do
4: calculate the remainder \(r\), \(r\leftarrow\)x%2
5: calculate the quotient \(q\), \(q\leftarrow\left(x-r\right)/2\)
6:if\(q==0\)do
7: calculate the remainder \(r\), \(r\leftarrow\)x%2
8: add \(r\) to \(\mathbf{M}\), \(\mathbf{M}\gets r\); isRun \(\leftarrow\)false
9:elsedo
10: add \(r\) to \(\mathbf{M}\), \(\mathbf{M}\gets r\)
11:end
12:\(x\_in\gets q\)
13:end
14:\(binarycode\leftarrow\) reverse (\(\mathbf{M}\))
15: Output: binarycode
```  
**Algorithm 2** decimal-to-binary of \(x\) value  
The binary codes of \(y\) value can be obtained by using Algorithm 2. As shown in Figure 7, if we change the binary codes to imitate the gene mutation, we can get the particle swarms with different characteristics. Therefore, the resampled particles become various and the diversity is improved.  
Figure 6: Gene mutation.  
Apart from increasing the diversity, we should also assure the reliability of particles so that PF abandon fewer particles in the resampling step. In Section 2.2.2, we have pointed out that there are many geomagnetic positioning results rather than one result. In these results, we should select \(s\) results that are close to the PDR position. If the PDR positioning results are \(\mathbf{X}(k)=\{x_{k},y_{k}\}\) and the geomagnetic positioning results are \(\mathbf{Z}(k)=\{\mathbf{Z}_{1},\mathbf{Z}_{2},\cdots,\mathbf{Z}_{m}\},\mathbf{Z}_{1}=(x_{1},y_{1}),\cdots\), the Euclidean distance between \(\mathbf{Z}(k)\) and \(\mathbf{X}(k)\) can be computed by using Equation (24):  
\[D_{i}=\sqrt{(x_{i}-x_{k})^{2}+(y_{i}-y_{k})^{2}} \tag{24}\]  
Then, based on the system state \(\mathbf{X}(k)\), we can also use the KNN method in Section 2.2.2 to find \(s\) geomagnetic results that are close to the PDR position to replace the \(s\) particles. After this optimization, each generation particles are composed of the previous generation \"excellent\" particles after mutation and the geomagnetic positioning results of the current generation. These two methods assure the diversity and reliability of the particle set and avoid the \"excellent\" particles reduction of each generation. The particles of each generation seem to be in evolution rather than degradation in classical PF. Figure 8 shows the detailed process of the genetic-particle filter algorithm in this paper, and the size of different balls represents different characteristics of particles.