## 4 Physics-Constrained Loss Function  
To enhance the physical consistency and accuracy of the inversion results, we propose a physics-constrained loss function, \(L\), that combines a prediction error component with a physics-based constraint derived from the forward model. This dual-component structure enforces adherence to the underlying physical principles governing magnetic and electromagnetic field responses, thereby improving the reliability and generalizability of the model.  
The physics-constrained loss function, \(L\), is formulated as follows:  
\[L=\frac{1}{N}\sum_{i=1}^{N}\Bigl{(}\mathbf{p}_{\text{pred},i}-\mathbf{p}_{ \text{true},i}\Bigr{)}^{2}+\frac{\lambda}{M}\sum_{i=1}^{M}\Bigl{(}d_{i}-F_{EM} (\mathbf{p}_{\text{pred}})\Bigr{)}^{2} \tag{9}\]  
where  
* \(\mathbf{p}_{\text{pred},i}\) represents the predicted target parameters for the \(i\)-th data sample, which include spatial coordinates and physical characteristics: \([x,y,z,L_{1},L_{2},L_{3},\alpha,\beta]\).
* \(\mathbf{p}_{\text{true},i}\) is the true target parameter vector for the \(i\)-th data sample, containing the known values for \([x,y,z,L_{1},L_{2},L_{3},\alpha,\beta]\).
* \(\lambda\) is a weighting factor that balances the contributions of the prediction error and the physics-based constraint in the total loss function.
* \(F_{EM}\) is the forward operator that applies the physics-based model to predict the electromagnetic anomaly response vector \(\mathbf{Y}_{\text{EM}}\), represented as \(1\times 49\) vectors for each observation point on the grid.
* \(d_{i}\) denotes the actual observed electromagnetic field data at the \(i\)-th observation point, serving as a reference to evaluate the accuracy of the model's predictions.  
The first term in the loss function quantifies the mean squared error (MSE) between predicted and actual responses, aiming to minimize the direct difference between the model's output and the observed data. This term enables the model to closely matchthe actual data distribution, thereby reducing general predictive error and improving the overall performance.  
The second term imposes a physics-based constraint by assessing the difference between observed surface data \(d\) and simulated responses \(F_{EM}(\mathbf{p}_{\text{pred},i})\), calculated through the forward model. The forward operator \(F_{EM}\), based on our three-dimensional orthogonal dipole model, serves as a link between the predicted response and the underlying physical properties. This component enforces that the estimated subsurface parameters align with known physical behaviors, as dictated by the forward model.  
The total loss function, \(L\), is a linear combination of the prediction error and physics-based constraint terms, balancing between data accuracy and adherence to physical laws. The scaling factor \(\lambda\) regulates the influence of the physics constraint relative to the prediction error.  
By optimizing this loss function, the model achieves both accuracy and physical consistency, making it well suited for real-world applications where physical laws must be respected. This approach not only enhances predictive reliability but also supports stable inversion by ensuring that model predictions conform to established geophysical principles.