# Indoor Positioning Integrating PDR/Geomagnetic Positioning Based on the Genetic-Particle Filter
## 2 Materials and Methods
### Fusion Positioning Module  
#### 2.3.1 Classical Particle Filter  
The particle filter (PF) is an algorithm based on the Monte Carlo method [44] and the Bayesian approach [45], which has good performance in solving non-linear problems. Generally, a dynamic system can be assumed that it obeys the Markov process of order one, it can be modeled as follows:  
\[\left\{ \begin{array}{l}\mathbf{X}_{k}=f_{k}(\mathbf{X}_{k-1})+\delta_{k-1}\\ \mathbf{Z}_{k}=\mathbf{h}_{k}(\mathbf{X}_{k})+\sigma_{k}\end{array} \right. \tag{16}\]where \(\mathbf{X}(k)\) and \(\mathbf{Z}(k)\) are the system state and observation at time \(k\), \(\delta_{k-1}\) and \(\sigma_{k}\) are the process noise and measurement noise at time \(k-1\) and \(k\), respectively. \(\mathbf{f}_{k}\) reflects the relationship between the current and previous state. \(\mathbf{h}_{k}\) expresses the relationship between states and observations. The posterior probability density function (pdf) \(p(\mathbf{X}_{k}|\mathbf{Z}_{1:k})\) is usually used to calculate the optimal estimation and predict the appearance probability of \(\mathbf{X}(k)\), which is called as the prediction in PF. \(p(\mathbf{X}_{k}|\mathbf{Z}_{1:k})\) relies on the previous posterior pdf \(p(\mathbf{X}_{k}|\mathbf{Z}_{1:k-1})\) based on the Bayesian theory, which can be calculated by using Equation (17) if there are observations available:  
\[P(\mathbf{X}_{k}|\mathbf{Z}_{1:k-1})=\int p(\mathbf{X}_{k},\mathbf{X}_{k-1}|\mathbf{Z}_{1:k-1})d \mathbf{X}_{k-1}=\int p(\mathbf{X}_{k}|\mathbf{X}_{k-1})p(\mathbf{X}_{k-1}|\mathbf{Z}_{1:k-1})d\bm {X}_{k-1} \tag{17}\]  
where \(p(\mathbf{X}_{k}|\mathbf{X}_{k-1})\) is the transition probability distribution defined by \(\mathbf{X}(k)\), \(p(\mathbf{X}_{k-1}|\mathbf{Z}_{1:k-1})\) is the previous posterior, respectively. Assuming the previous posterior is known, the current posterior is defined as follows:  
\[P(\mathbf{X}_{k}|\mathbf{Z}_{1:k})=\frac{p(\mathbf{Z}_{k}|\mathbf{X}_{k},\mathbf{Z}_{1:k-1})p(\bm {X}_{k}|\mathbf{Z}_{1:k-1})}{p(\mathbf{Z}_{k}|\mathbf{Z}_{1:k-1})}=\frac{p(\mathbf{Z}_{k}|\mathbf{ X}_{k})p(\mathbf{X}_{k}|\mathbf{Z}_{1:k-1})}{p(\mathbf{Z}_{k}|\mathbf{Z}_{1:k-1})} \tag{18}\]  
where \(p(\mathbf{Z}_{k}|\mathbf{Z}_{1:k-1})\) is the normalizing constant, it is calculated by using Equation (19):  
\[p(\mathbf{Z}_{k}|\mathbf{Z}_{1:k-1})=\int p(\mathbf{Z}_{k}|\mathbf{X}_{k})p(\mathbf{X}_{k}|\mathbf{Z}_ {1:k-1})d\mathbf{X}_{k} \tag{19}\]  
We can use Equation (18) to update the current posterior probability and this is an important step in PF. But it is difficult for us to solve Equations (17) and (19) due to the complex integral operation. The Monte Carlo method provides an effective approach for solving this problem. This method uses a sequence of weighted samples to represent the posterior pdf and the mean value of these samples is substituted for the integration. If the sample set has \(N\) samples, \(p(\mathbf{X}_{k}|\mathbf{Z}_{1:k})\) can be calculated by:  
\[p(X_{k}|Z_{1:k})\approx\frac{1}{N}\sum\
olimits_{i=1}^{N}\omega_{k}^{j}\delta (\mathbf{X}_{k}-\mathbf{X}_{k}^{i}) \tag{20}\]  
where \(\omega_{k}^{j}\) and \(\mathbf{X}_{k}^{i}\) are the weight and the state of \(i\)-th sample, \(\delta(\cdot)\) is the Dirac delta function. The update formula of \(\omega_{k}^{i}\) is defined as follows:  
\[\omega_{k}^{j}\propto\omega_{k-1}^{j}\frac{p(\mathbf{Z}_{k}|\mathbf{X}_{k}^{i})p(\mathbf{ X}_{k}^{i}|\mathbf{X}_{k-1}^{i})}{q(\mathbf{X}_{k}^{i}|\mathbf{X}_{k-1}^{i},\mathbf{Z}_{k})} \tag{21}\]  
where \(q(\cdot)\) is the importance density. When \(N\rightarrow\infty\), the result of Equation (20) approaches the true posterior density [45]. PF will resample a different set at each timestamp \(k\) based on the updated posterior probability, which can also be called weight. Resampling will copy large-weight samples and abandon the small-weight ones to obtain the optimal estimation. But this will decrease the diversity of samples if the system runs for a long time.