# An Earthquake Forecast Model Based on Multi-Station PCA Algorithm
## 4 PCA Extraction for Single Station
### PCA Algorithm of Single Station  
Based on the assumption that local underground variation may cause some detailed changes of the local geomagnetic field, the analysis of the local AETA geomagnetic signal may capture earthquakes. \[X=[X_{1},X_{2},X_{3},\ldots,X_{n}]^{T} \tag{2}\]  
\[\Sigma_{ij}=cov(X_{i},X_{j})=E\big{[}(X_{i}-E[X_{i}])(X_{j}-E[X_{j}])\big{]} \tag{3}\]  
Figure 4: MNLG low-frequency electromagnetic feature. Figure 3: Workflow of the process of AETA raw data. \[\Sigma=E[(\mathbf{X}-E[\mathbf{X}])(\mathbf{X}-E[\mathbf{X}])^{T}]= \begin{bmatrix}cov(X_{1},X_{1})& cov(X_{1},X_{2})&\ldots&cov(X_{1},X_{n})\\ cov(X_{2},X_{1})&cov(X_{2},X_{2})&\ldots&cov(X_{2},X_{n})\\ \vdots&\vdots&\ddots&\vdots\\ cov(X_{n},X_{1})&cov(X_{n},X_{2})&\ldots&cov(X_{n},X_{n})\end{bmatrix}  \tag{4}\]  
In the PCA algorithm, a co-variance matrix \(\Sigma\) of matrix \(A_{24\times 27}\). As Equation (2), for a multidimensional random variable \(X\) that is length \(n\), the co-variance matrix is a symmetric matrix of \(n\times n\), and the elements on the diagonal are the variances of the random variables in each dimension. For the \(A_{24\times 27}\), its co-variance matrix is \(\Sigma_{27\times 27}\). Element \(\Sigma_{ij}\) in matrix \(\Sigma\) is as Equation (3), so matrix \(\Sigma\) is as Equation (4). The procedure of the PCA algorithm is as follows:  
1. Calculate the co-variance matrix \(\Sigma\) of \(A_{24\times 27}\);
2. Calculate the eigenvalue \(\lambda_{1},\lambda_{2},\ldots,\lambda_{n}\) of \(\Sigma\) and the related eigenvector matrix \((\zeta_{1},\zeta_{2},\ldots,\zeta_{n})\);
3. Choose \(K\) eigenvectors with the largest eigenvalues as row vectors and use the corresponding eigenvectors as row vectors of new matrix P. The \(K\) should be chosen to make the cumulative contribution eigenvector rate a of eigenvalue a more than 85%. The contribution is calculated as shown in Equation (5);
4. Take the eigenvector matrix P to reconstruct the original data matrix \(A_{24\times 27}\); first, calculate the projection values of \(A_{24\times 27}\) on these eigenvectors, and then inverse transform them to the original coordinate system to obtain the reconstruction matrix \(A^{\prime}_{24\times 27}\);
5. Use the last line of the original data matrix \(A_{24\times 27}\) to be vector L, which is related to the last day in 27 days and its length is 24, and use the last line of the reconstructed data matrix \(A^{\prime}_{24\times 27}\) to be vector L\({}^{\prime}\). Take the difference of the two vectors. Take the difference between the original data matrix \(A_{24\times 27}\) and the related element of the last row of the reconstructed data matrix \(A^{\prime}_{24\times 27}\) (the last day of the selected 27 days). Then, set all elements of this line to zero except the one with the largest absolute value. This will generate a vector named \"feature vector\" of length 24 as the eigenvector of the matrix \(A^{\prime}_{24\times 27}\), and it is the output vector of this algorithm. In addition to this, the largest K eigenvalues are also output. \[P_{i}=\frac{\lambda_{i}}{\sum_{m=1}^{n}\lambda_{m}} \tag{5}\]  
This algorithm is suitable for our data, which have large information redundancy. The data matrix of one sample is a \(24\times 27\) matrix, the 24 is related to 24 h per day, and the 27 is related to the 27 days of one sample according to the sun's activity period. A PCA algorithm is used to extract the eigenvectors, which make up more than 85% of the energy and reconstruct them. The reconstructed matrix contains the main signals in the data matrix. After subtracting them from the original matrix, some subtle changes of the periodic signals will be captured. Based on the matrix \(A_{24\times 27}\) of each time step, we can get several features related to the last day of the 27 days of its time step. Based on the matrix of each \(A_{24\times 27}\), we can get several features related to the last day of the 27 days. The features contain a vector generated in Step 5, which is called \"feature vector\".