# Three-Dimension Inversion of Magnetic Data Based on Multi-Constraint UNet++
## 2 Materials and Methods  
### Inversion Problem and Loss Function  
In the field of deep learning, the loss function controls the training direction of the network. The purpose of parameter iteration in the training process of the network is to minimize the loss function. The smaller the loss function, the closer the predicted value of the model is to the real label [10]. Therefore, it is very important to design a reasonable loss function. When deep learning tools are used for physical property inversion, we find that the results obtained using the commonly used \(MSE\) as the loss function are not ideal, with poor model fitting and data fitting, as set out below:  
\[MSE=\frac{1}{N}\|m_{1}-m_{2}\|_{L_{2}}^{2} \tag{1}\]  
In Formula (1), \(m_{1}\) represents the training label, \(m_{2}\) represents the prediction result of the network, \(MSE\) can be obtained by calculating the \(L_{2}\) norm between them and then calculating the average value, and \(N\) represents the number of elements in the training label (\(N=32\times 32\times 16\)). The data involved in the calculation of the \(MSE\) include both abnormal bodies and surrounding rock. The abnormal bodies we are interested in only account for a small part of the entire underground space (about 5%). However, in order to minimize the loss function during the training process, the network will be able to perform the following operations: First, the data fitting to the surrounding rock, that is, the position of the non-abnormal body, is given priority. This often leads to a set of parameters being applied in the background bias of the prediction results of the loss function during the process of the gradient descent solution [11]. As a result, the information obtained from the anomalous body source may be either lost or miscalibrated. In order to solve this problem, we adopted the compound loss function method, added the _Dice_ coefficient (a loss function that only takes the physical parameters of the abnormal body into the calculation) onto the basis of a single-constraint \(MSE\), and successfully improved the model-fitting accuracy. The _Dice_ coefficient, which measures the similarity of two sets of data, ranges from 0 to 1 and reaches its maximum value only when the two sets of data are identical. The calculation formula is as follows:  
\[Dice=\frac{2m_{1}m_{2}}{m_{1}^{2}+m_{2}^{2}} \tag{2}\]  
The main idea of the dice coefficient is to help the model focus on the location of the anomalous body source and prevent the loss function from reaching the local minimum [12]. After improving the model-fitting difference in the deep learning network inversion, we identified that the data-fitting difference in the inversion results decreased. In order to solve this problem, we added another constraint, which used the three-dimensional model predicted by the network for the forward modeling, then obtained the forward magnetic anomaly data of the inversion results, and at last calculated the error between the model and the real magnetic anomaly data. Finally, the forward constraint term \(FFit\) was obtained. The main function of the forward-fitting constraint term \(FFit\) is to improve the accuracy of the data fitting. The calculation formula is as follows:  
\[FFit=\|d_{1}-Sm_{2}\|_{L_{2}}^{2} \tag{3}\]  
In this formula, \(d_{1}\) is the real magnetic anomaly of the training set; \(S\) is the forward sensitivity matrix of the magnetic anomaly in the region; and \(m_{2}\) is the result after network prediction. Finally, the loss function that we adopted included the conventional mean square error term, _Dice_ coefficient term, and forward-fitting term. The _Dice_ coefficient, which measures the similarity between two sets of data, ranges from 0 to 1 and reaches its maximum value only when the two sets of data are identical.