# Machine Learning-Based 3D Soil Layer Reconstruction in Foundation Pit Engineering
## 4 Machine Learning Models for Soil Layer Reconstruction  
### Sparse borehole Encoding  
A large amount of soil layer and borehole data can be obtained through the soil layer generation algorithm and the borehole generation algorithm. However, this information  
Figure 7: Schematic diagram of the borehole generation algorithm. cannot be directly used as the characteristics of the soil layers to train the network. To reconstruct a 3D soil layer model, it is essential to determine the attributes of each voxel within the soil layer being modeled. This involves dividing the soil layer into a three-dimensional grid and using the grid points as sample locations. Given the deterministic nature of the soil layer generation algorithm, each sample point belongs to a unique soil layer type, thereby defining its label. To characterize these samples, we devised an encoding method that links borehole data with the sample points, facilitating the acquisition of their properties. The algorithm has the following definition:  
**Definition 9** (Sample points of soil layer). : _These are three-dimensional grid points. The method of selecting sample points is to randomly select the entire soil layer grid. The coordinates of sample points are represented by \(P\), \(P\) = (\(X\), \(Y\), \(Z\))._  
**Definition 10** (Borehole dimension). : _The borehole dimension is the amount of data contained in a borehole. It is represented by \(Z_{d}\). It can be known from the borehole generation algorithm that the borehole data consist of four sets of data._  
If there are a total of three data amounts for the borehole coordinate and elevation, then the dimension of the borehole is calculated according to Formula (3):  
\[z_{d}=n_{s}+3, \tag{3}\]  
where \(n_{s}\) represents the number of soil layers penetrated by a borehole. The schematic diagram of the algorithm is presented in Figure 8. The algorithm procedure is divided into three main steps, as outlined below:  
Step 1. Uniform Borehole Dimension. Due to the presence of hiatuses and faults in soil layers, boreholes passing through these layers may lack thickness information for certain soil layers. Since the number of missing layers can vary, the dimensions of borehole data may become inconsistent. This inconsistency results in a mismatch between the dimensions of sample features and the input requirements of neural network models. To resolve this issue, we apply zero-padding to the missing data layers, assigning a thickness value of zero to the positions where borehole data are absent. Assuming the number of soil layers that need zero-padding is \(Z_{b}\), then \(Z_{b}\) can be derived from the following formula:  
\[z_{b}= \begin{cases}s_{num}-n_{s},&n_{s}<s_{num}\\ 0,&n_{s}\geq s_{num}\end{cases} , \tag{4}\]  
Figure 8: Schematic diagram of the coding algorithm. where \(n_{s}\) is the number of soil layers passed by a borehole; \(s_{sum}\) is the number of generated soil layers input in the algorithm. Step 2. Acquiring the Coordinates of the Soil Layer Interface at the Borehole Position. After determining the thickness of the soil layer, the spatial distribution information of the soil layer is required. This spatial information is described by the coordinates of the soil layer interface. As derived from the borehole generation algorithm, the thickness of the soil layer is calculated based on the height coordinates of the boundary surface at the borehole position. The height coordinates of the soil interface at the borehole position can be obtained using Formula (5). \[z_{sn}=\sum_{i=1}^{n-1}h_{i}, \tag{5}\]  
where \(h_{i}\) is the thickness of the \(n^{th}\) soil layer; \(Z_{sn}\) is the height coordinate of the interface between the \(n^{th}\) soil layer and the \((n+1)^{th}\) soil layer at a borehole location. Step 3. The distance from the soil layer boundary point to the sample point is calculated: We select the \(k\) boreholes closest to the sampling point and then obtain the coordinates of the soil interface at the borehole location.