# Research on Wellbore Trajectory Prediction Based on a Pi-GRU Model
## 2 Materials and Methods
### Constructing the Pi-GRU Model  
The GRU model, as a variant of a recurrent neural network (RNN), was proposed by [PERSON] et al. [18] in 2014. Its core lies in the introduction of a gating mechanism to regulate information flows, which helps the network capture medium- and long-term dependencies. The GRU model consists of a hidden state and two gating units: a reset gate and an update gate. The reset gate is used to adjust the degree to which the current state is influenced by the previous state; the update gate controls the influences of the current input and the previous state on the present state. The structure of the GRU model is shown in Figure 5. Compared with the traditional BP neural network, the GRU performs better in terms of extracting temporal information [19]; compared with LSTM, the GRU has fewer parameters [20] and a simpler structure and is suitable for short sequences or scenarios with limited computing resources. Figure 5 shows the structural diagram of the GRU network. Here, \(x_{t}\) represents the input vector at the current time, and \(h_{t-1}\) is the hidden state at the previous time. \(\overset{\sim}{h}\) represents the candidate hidden state, and \(h_{t}\) represents the final hidden state. The working process of this network is as follows. First, the reset gate \(r_{t}\) determines how much information from the previous hidden state \(h_{t-1}\) is ignored. The associated calculation formula is as follows:  
\[r_{t}=\sigma(w_{r}[h_{t-1},x_{z}]+b_{r}) \tag{2}\]  
Here, \(w_{r}\) is the weight matrix of the reset gate, \(b_{r}\) is the bias of the reset gate, and \(\sigma\) is the sigmoid activation function. The candidate hidden state \(\overset{\sim}{h}\) is subsequently calculated by combining the reset hidden state from the previous moment and the current input, and the calculation formula is as follows:  
\[\overset{\sim}{h}=tanh(w_{h}\cdot[r_{t}\odot h_{t-1},x_{t}]+b_{h}) \tag{3}\]  
Figure 5: Schematic diagram of the GRU structure. Here, \(w_{h}\) is the weight matrix of the candidate hidden state, \(b_{h}\) is the bias of the candidate hidden state, \(\odot\) represents the elementwise multiplication operation, and \(\tanh\) is the hyperbolic tangent activation function. When \(r_{t}\approx 0\), \(h_{t-1}\) is ignored, the candidate state \(\widetilde{h}\) is solely determined by the current input \(x_{t}\). When \(r_{t}\approx 1\), \(h_{t-1}\) is retained, \(\widetilde{h}\) is jointly determined with \(x_{t}\). Then, gate \(z_{t}\), whose function is to determine how much information acquired from the hidden state \(h_{t-1}\) of the previous time step is retained in the current hidden state \(h_{t}\), is updated. The corresponding calculation formula is as follows:  
\[z_{t}=\sigma(w_{z}\cdot[h_{t-1},x_{t}]+b_{z}) \tag{4}\]  
Here, \(w_{z}\) represents the weight matrix of the update gate, and \(b_{z}\) represents the bias of the update gate. Finally, by fusing the hidden state \(h_{t-1}\) from the previous time step and the candidate hidden state \(\widetilde{h}\) of the current time step, the final hidden state \(h_{t}\) is calculated. The associated calculation formula is as follows:  
\[h_{t}=(1-z_{t})\odot h_{t-1}+z_{t}\odot\widetilde{h} \tag{5}\]  
When \(z_{t}\) is approximately 0, \(h_{t}\) is approximately equal to \(h_{t-1}\), meaning that the old state is retained. When \(z_{t}\) is approximately 1, \(h_{t}\) is approximately equal to \(\widetilde{h}\), indicating complete replacement by the new state. The BP neural network was inspired by the human nervous system. Numerous artificial neurons (nodes) form a multilayer network through weighted connections that enable communication and interactions between neurons [21]. This neural network can be employed for training tasks such as classification, regression, and clustering. The BP network can learn and store extensive input-output pattern mappings without requiring prior knowledge about the mathematical equations describing these relationships.