# Reducing GPS Error for Smart Collars Based on Animal's Behavior
## 2 Materials and Methods
### Behavior Based Algorithm
#### 2.3.2 Distance Estimation Using GPS Data  
To achieve our aim, it is required to have one more critical distance measuring technique between the two received GPS points and the distance between the maximum probable traveled distance from \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Evaluation Report** & **Standing** & **Walking** & **Running** & **Grazing** & **Lying** & **Total Accuracy** \\ \hline Precision & 0.93 & 0.75 & 1 & 0.9 & 1 & 0.92 \\ Recall & 0.7 & 0.9 & 0.95 & 1 & 1 & 0.91 \\ F-score & 0.8 & 0.81 & 0.97 & 0.95 & 1 & 0.91 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Accuracy of the RBF based SVM classification. the last received GPS point. In general, the closest distance between the two points \(A(x_{1},y_{1})\) and \(B(x_{2},y_{2})\) calculates by the formula below:  
\[\overline{AB}=\sqrt{\left(x_{1}-x_{2}\right)^{2}+\left(y_{1}-y_{2}\right)^{2}}. \tag{6}\]  
However, this approach will not work for the simple reason that the Euclidean metric is designed to calculate the distance on the plane, and the surface of the Earth is still a figure very close to the sphere. To solve this problem, we need to turn to the frequently used algorithm called Haversine. To project the distances with higher precision, we used Google Maps API, which provides ready functions that can be used to calculate distances on the Earth surface using Haversine algorithm. The coordinates such as latitude and longitude are used as a coordinate system of Google Maps. The Haversine technique is applied to measure the length of two geolocations on the surface of the Earth, based on a 2-D geoposition. To solve many problems of navigation and mapping of small scale, the Earth is taken as a sphere (as a ball). The position of a point on the earth's sphere is determined by spherical coordinates: spherical latitude and spherical longitude (the term \"geographical coordinates\" is used in cartography). To determine the distance between two points, the latitude and longitude of the first point and second points are needed. The calculations are complicated by the fact that the Earth is not an ideal sphere and its radius varies slightly. We use the average radius value, which, in accordance with WGS84, is approximately 6367.45 km, which allows is to get a result with an accuracy of 99.5%. [32]. The principle work of the Haversine method is described in Figure 3. The operation of the Haversine algorithm, demonstrates the direct distance between points as a given separate sphere. A \"triangle\" on the surface of the sphere is defined by great circles connecting the three points u, v, and w on the sphere, where a, b and c are the distances that must be calculated [35; 36]. For any two points on the Haversine sphere of the central angle between them is calculated by the formula:  
\[\mathit{hav}\left(\frac{d}{r}\right)=\mathit{hav}(\varphi_{2}-\varphi_{1})+ \cos(\varphi_{1})\cos(\varphi_{2})\mathit{hav}(\lambda_{2}-\lambda_{1}), \tag{7}\]  
where \(\mathit{hav}\) is haversine function, \(d\) is the central angle between two points lying on the large circle, \(r\) is the sphere radius, \(\varphi_{1}\) and \(\varphi_{2}\) are the latitude of the first and second points in radians, \(\lambda_{1}\) and \(\lambda_{2}\) are the longitude of the first and second points in radians [32; 33]. The Haversine length-to-radius ratio sign as a \(d/r\), on the left side of the Equation (4). To determine the distance \(d\), it applies the archaversine (reverse haversine) or uses the arcsine function (inverse sine) [35; 36]:  
Figure 3: Spherical triangle determined by the law of haversines. u, v, and w: three point on the sphere; _a_: length (from u to v); _b_: length (from u to w); _c_: length (from w to v); _C_: the angle of the corner opposite c.  
\[d=2\text{r-arcsin}\left(\sqrt{sin^{2}\left(\frac{\Delta latt}{2}\right)+\cos( latt_{1})\cos(latt_{2})sin^{2}\left(\frac{\Delta long}{2}\right)}\right). \tag{8}\]  
The smart collar of our virtual fence system was developed to transmit data at 1 Hz (a data per second).