# An Aeromagnetic Compensation Algorithm Based on a Residual Neural Network
## 2 Compensation Model and Method  
### T-L Model  
The magnetic interference model of aircraft includes three components: the permanent (\(H_{p}\)) magnetic field generated by various parts of the aircraft, the induced (\(H_{i}\)) magnetic field produced by geomagnetic field magnetization, and the eddy-current (\(H_{\text{ec}}\)) magnetic field produced by aircraft motion, which can be expressed as:  
\[H_{p}=c_{1}cos\alpha+c_{2}cos\beta+c_{3}cos\gamma \tag{1}\]  
\[H_{i}=T_{t}\begin{pmatrix}c_{4}cos^{2}\alpha+c_{5}cosacos\beta+c_{6}cosacos \gamma\\ +c_{7}cos^{2}\beta+c_{8}cos\beta cos\gamma+c_{9}cos^{2}\gamma\end{pmatrix} \tag{2}\]\[H_{\text{ec}}=T_{t}\left(\begin{matrix}c_{10}cosacos^{\prime}\alpha+c_{11}cos \beta cos^{\prime}\alpha+c_{12}cos\gamma cos^{\prime}\alpha\\ +c_{13}cosacos^{\prime}\gamma+c_{14}cos\beta cos^{\prime}\gamma+c_{15}cos\gamma cos ^{\prime}\gamma\\ +c_{16}cosacos^{\prime}\beta+c_{17}cos\beta cos^{\prime}\beta+c_{18}cos\gamma cos ^{\prime}\beta\end{matrix}\right), \tag{3}\]  
where \(c_{1},\ c_{2},\ldots,\ c_{18}\) are compensation coefficients; \(cos^{\prime}\alpha,\ cos^{\prime}\beta,\ \text{and}\ cos^{\prime}\gamma\) are the derivatives of \(cosa,\ cos\beta,\ \text{and}\ cos\gamma\), respectively; and \(T_{t}\) is the Earth's magnetic field. \(cos\alpha,\ cos\beta,\ \text{and}\ cos\gamma\) can be calculated based on three-axis fluxgate magnetometer data as:  
\[cos\alpha=\frac{T_{x}}{T},\ cos\beta=\frac{T_{y}}{T},\ cos\gamma=\frac{T_{z}}{T },\ T_{t}=\sqrt{T_{x}{}^{2}+T_{y}{}^{2}+T_{z}{}^{2}}. \tag{4}\]  
The total magnetic interference field can be expressed as:  
\[\begin{split} H_{t}&=H_{p}+H_{i}+H_{ec}\\ &=\ c_{1}x_{1}\ +\ c_{2}x_{2}\ +\ c_{3}x_{3}\ +\ c_{4}x_{4}\ +\ c_{5}x_{5}\ +\ c_{6}x_{6}\\ &+c_{7}x_{7}\ +\ c_{8}x_{8}\ +\ c_{9}x_{9}\ +\ c_{10}x_{10}\ +\ c_{11}x_{11}\ +\ c_{12}x_{12}\\ &+c_{13}x_{13}\ +\ c_{14}x_{14}\ +\ c_{15}x_{15}\ +\ c_{16}x_{16}\ +\ c_{17}x_{17}\ +\ c_{18}x_{18}\end{split} \tag{5}\]  
The LS solution of the T-L equation is:  
\[XC=H_{t} \tag{6}\]  
\[C_{LS}=\left(X^{T}X\right)^{-1}X^{T}H_{t}, \tag{7}\]  
where \(H_{t}\) is a column vector, \(C\) consists of \(c_{i}(i=1,\ 2,\ \ldots,\ 18)\), and:  
\[X=\begin{bmatrix}X_{1,1}&X_{1,2}&\ldots&X_{1,18}\\ X_{2,1}&X_{2,2}&\ldots&X_{2,18}\\ \vdots&\vdots&&\vdots\\ X_{n,1}&X_{n,2}&\ldots&X_{n,18}\end{bmatrix}, \tag{8}\]  
where \(X_{n,1},\ X_{n,2},\ldots,\ X_{n,18}\) are the variables in Equation (5), and the column vector of \(X\) has multicollinearity.  
When the independent variable has multicollinearity (\(\left|X^{T}X\right|\approx 0\)), due to the singularity of \(X^{T}X\), there is a strong correlation between variables, which results in a considerable distance between the estimated and true values. There is a deviation in the LS algorithm, which affects the compensation accuracy. Ridge regression (RR) [16] is based on LS, adding an identity matrix to the coefficient matrix to improve stability. Its solution is expressed as:  
\[C_{RR}=\left(X^{T}X+\lambda I\right)^{-1}X^{T}H_{t}, \tag{9}\]  
where \(\lambda\) is a positive constant, and \(I\) is the identity matrix.