# A Weighted and Distributed Algorithm for Range-Based Multi-Hop Localization Using a Newton Method
## 4 A Robust and Distributed Localization Algorithm Based on the Newton Method  
Due to the high cost in processing data, energy consumption in wireless transmissions, and security of collected data, Equation (9) tends to be programmed in a distributed way instead of being solved in a central node [30]. The robust-weighted Newton method (RWNM) algorithm, proposed here, breaks down (9) into subproblems that can be implemented in unknown sensors of a distributed manner [25]. Thus, each sensor \(s_{i}\) can minimize its distance error with one-hop neighboring sensors and n-hops anchors by solving the following optimization problem:  
\[\min_{\textbf{p}_{i}}F(\textbf{p}_{i}) \tag{10}\]  
with \(F(\textbf{p}_{i})\) defined as  
\[F(\textbf{p}_{i}):=\sum_{j\in\textbf{\Omega}_{i}}f\Big{(}\big{(}\textbf{r}_{ij }-\left\|\textbf{p}_{i}-\textbf{p}_{j}\right\|\big{)}w_{j}\Big{)}+\sum_{k\in \textbf{B}}f\Big{(}(\textbf{r}_{ik}-\left\|\textbf{p}_{i}-\textbf{q}_{k}\right\| )w_{k}\Big{)}. \tag{11}\]  
Here, each distance error sensor-sensor is multiplied by a weighted value \(w_{j}\), which represents the inverse of the average of the minimum number of hops between the sensor \(s_{j}\) and each anchor, stated as  
\[w_{j}=\frac{1}{\frac{1}{\left\|\textbf{B}\right\|}\sum\limits_{k\in\textbf{B} }hops(j,k)}, \tag{12}\]where \(hops(j,k)\) represents the minimum number of hops between the sensor \(s_{i}\) and the anchor \(a_{k}\). It is easy to define the set of weights corresponding to the neighbors of the sensor \(s_{i}\) as  
\[\mathbf{W}_{i}=\{w_{j}:j\in\mathbf{\Omega}_{i}\}. \tag{13}\]  
On the other hand, for sensor-anchor distance errors, the weighted value \(w_{k}\) is set to one. To minimize (11) in a distributed way, a sensor \(s_{i}\) employs the Newton method using the \(\ell^{2}\) norm as  
\[f(e,c)=\frac{1}{2}\Big{(}\frac{e}{c}\Big{)}^{2}, \tag{14}\]  
where \(e=e_{ih}\cdot w_{h}\), \(\forall\ h\ \in\mathbf{\Omega}_{i}\cup\textbf{B}\) stands for either the distance error between sensor-sensor or sensor-anchor, \(c\) is a scaling factor which controls the broadness of the function shape around the origin and mitigates the effect of large errors as explained in Section 2. On the other hand, any sensor \(s_{i}\) that minimizes position estimates with neighboring sensors must first calculate the scaling parameter \(c_{i}\) as described next. First, using distance errors with neighboring sensors, the median is calculated as  
\[\widetilde{e}_{i}=\text{med}\big{(}E_{\mathbf{\Omega}_{i}}\big{)}, \tag{15}\]  
where the set of errors \(E_{\mathbf{\Omega}_{i}}\) is defined as  
\[E_{\mathbf{\Omega}_{i}}=\{|\mathbf{r}_{ij}-\|\mathbf{p}_{i}-\mathbf{p}_{j}\|\mid :j\in\mathbf{\Omega}_{i}\}, \tag{16}\]  
then, a new set of neighboring sensor of \(s_{i}\) that presents less error in distance estimates than \(\widetilde{e}_{i}\) is obtained as  
\[\widetilde{\Omega}_{i}=\{j\in\Omega_{i}:|r_{ij}-\big{\|}\mathbf{p}_{i}- \mathbf{p}_{j}\big{\|}\big{|}\leq\widetilde{e}_{i}\}. \tag{17}\]  
Next, using (13) with the new set of neighbors of (17), \(\widetilde{\mathbf{W}}_{i}=\{w_{j}:j\in\widehat{\mathbf{\Omega}}_{i}\}\), the maximum weight value is obtained in Equation (18):  
\[w_{max_{i}}=\max_{w\in\widehat{\mathbf{W}}_{i}}w. \tag{18}\]  
Finally, the scaling parameter vector for neighboring sensors of \(s_{i}\) and anchor nodes is computed according to Equation (19):  
\[c_{j}= \begin{cases}w_{max_{i}},&j\in\ \widetilde{\Omega}_{i},\\ \infty,&j\in\ \Omega_{i}\backslash\widetilde{\Omega}_{i},\\ 1,&j\in\ \textbf{B}.\end{cases}  \tag{19}\]  
It is remarkable to mention that \(c_{j}=\infty\), which implies that the sensor \(s_{j}\) will be discarded in the minimization process. The Hessian and the gradient for the Newton method process are described as follows. For clarity, consider that the position \(\mathbf{p}_{r}\) can be used indistinctly for both anchor and unknown sensor positions.