# Research on a Wi-Fi RSSI Calibration Algorithm Based on WOA-BPNN for Indoor Positioning
## 2 Methods and Algorithms
### Algorithms
#### 2.2.1 Calibration Algorithm Based on WOA-BPNN
* **Step 2:** Initialise the weight \(w_{ij}^{0}\) and threshold \(\theta_{j}^{0}\) of each layer randomly to build the BPNN, which also means initialising the whale group position \(X_{i}\). Next, set the size of the whale population \(N\), the current number of iterations of the whale population \(t=0\), the maximum number of iterations of the whale population \(t_{\text{max}}\), the current number of iterations of the BPNN model \(T\), and the maximum number of iterations of the BPNN model \(T_{\text{max}}\). * **Step 3:** When the current number of iterations of the whale population \(t\) is less than the maximum iteration number \(t_{\text{max}}\) of the whale population, according to the fitness function formula, as Equation (2), calculate the fitness value of each whale, obtain the position of the optimal fitness value, and then find the best fitness and the corresponding optimal whale position \(X_{best}\). \[f(X_{i})=\sum_{i=1}^{N_{sample}}\left|y_{i}-y_{i}^{\prime}\right|\] (2) where \(y_{i}\) is the real value of the \(i\)th RSSI, \(y_{i}^{\prime}\) is the predicted value of the \(i\)th RSSI and \(N_{sample}\) is the number of samples. * **Step 4:** To speed up the establishment and optimisation of the calibration algorithm and upgrade the updating and iterating speed, use the proposed nonlinear convergence factor \(a\) to simulate the shrinking behaviour of the surrounding prey of the whales. The convergence factor \(a\) changes dynamically only with the current iteration times \(t\) and effectively prevents the algorithm from falling into the local optimum. The formula of the nonlinear convergence factor \(a\) is shown as Equation (1). Update the whale position parameters \(A\) and \(C\). The formulas are shown in Equations (3) and (4). \[A=2 ar-a\] (3) \[C=2r\] (4) where \(r\) is a random value of [0, 1]. * **Step 5:** Randomly generate probability \(p\) and judge whether it is less than 0.5. If \(p\geq 0.5\), then update the position by shrinking and surrounding, as shown in Equation (5). \[X_{i}^{t+1}=X_{best}^{t}-A\left|C\cdot X_{best}^{t}-X_{i}^{t}\right|\] (5) where \(t\) is current number of iterations of the whale population, \(X_{best}^{t}\) is the optimal whale position, \(X_{i}^{t}\) is the current whale position and \(A\) and \(C\) are the whale position parameters obtained in **Step 4**, else if \(p<0.5\), then select the swimming mode accord ing to the value of \(\mid A\mid\): when \(\mid A\mid<1\), the whales will choose to update their position by swimming in a circular motion, as shown in Equation (6). \[X_{i}^{t+1}=\left|X_{best}^{t}-X_{i}^{t}\right|e^{\eta l}\cdot\cos(2\pi l)+X_{ best}^{t} \tag{6}\]  
where \(\left|X_{best}^{t}-X_{i}^{t}\right|\) indicates the distance between the whale and the optimal position, \(b\) is a constant that defines the logarithmic spiral shape and \(l\) is a random value in \([-1,1]\); when \(\mid A\mid\geq 1\), the whales choose to swim randomly according to Equation (7):  
\[X_{i}^{t+1}=X_{rand}^{t}-A\left|C\cdot X_{rand}^{t}-X_{i}^{t}\right| \tag{7}\]  
where \(X_{rand}^{t}\) is the randomly selected position of a whale. * **Step 6:** The current number of iterations of the whale population \(t\) increases automatically, and the optimal position is updated according to **Step 2**. When the maximum number of iterations of the whale population \(t_{\max}\) is reached, it outputs \(X_{best}\), which represents the optimal weight and threshold as the optimal initial parameters of the BPNN model. * **Step 7:** The BPNN performs forward propagation, processing data through the connection weight \(w_{ij}\) between the neuron \(i\) and the neuron \(j\) and threshold \(\theta_{j}\) of the neuron \(j\).