## 2 Methods
### EG-DGATN Model Framework
#### 2.3.2 Dynamic Graph ST-Attention Layer  
The dynamic graph ST-attention layer is the core component of the EG-DGATN. It dynamically learns the potential relationships in the sensor network by generating dynamic graphs, thus enhancing the effectiveness of aggregating information [21]. While aggregating information, this layer utilizes the multi-head attention mechanism from Transformer to optimize the message-passing mechanism in GCNs to update sensor node information. This layer mainly comprises the sensor network's first-order neighborhood dynamic graph generation and message-passing processes.  
The dynamic graph \(A_{d}\) generation process can be illustrated in Equation (11):  
\[\left\{\begin{aligned} M^{k}=tanh\Big{(}\beta E^{k}\Gamma_{g^{c}}^{k} \Big{)},k\in 1,2\\ A_{d}(i,j)=b\cdot ReLU\Big{(}tanh\Big{(}\beta(M_{ij}^{1}M_{ij}^{2} \Gamma^{T}-M_{ij}^{2}M_{ij}^{1})\Big{)}\Big{)}\end{aligned}\right. \tag{11}\]  
where \(M_{1},M_{2}\in R^{N\times D}\) is described by two neural networks with randomly initialized embedding matrices \(E_{1},E_{2}\in\mathbb{R}^{N\times D}\) and trainable parameters \(\Gamma_{g^{c}}^{1},\Gamma_{g^{c}}^{2}\in\mathbb{R}^{N\times D}\) computed via the Tanh activation function. \(\beta\) is a hyper-parameter that adjusts the saturation rate of activation. To reduce the overhead required for computation, a mask b is generated based on \(A_{d}\in\mathbb{R}^{N\times N}\) and computed via the Gumbel-sigmoid trick [22] to sparsify the learned adjacency matrix and to ensure the unidirectionality of the graph edge structure.  
While updating the dynamic graph through training, this layer incorporates the multi-head attention in Transformer, allocating \(Q,K,V\) for each edge generated in \(A_{d}\) and computing the attention weights for each edge to obtain the attention score matrix \(A_{apt}\). Multiplying the value vectors of each sensor node by the corresponding attention matrix and summing the results of all neighboring nodes along the direction of the dynamic graph edges achieve message passing and updating of the hidden layer states of each sensor node. This process can be described by Equations (12)-(14):  
\[Q=H_{l-1}W_{Q},\;K=H_{l-1}W_{K},V=H_{l-1}W_{V} \tag{12}\]  
\[A_{apt}(i,j)=\frac{exp\big{(}K_{i},Q_{j}\big{)}}{\sum_{n\in N(i)}exp\big{(}K_{i },Q_{n}\big{)}} \tag{13}\]  
\[DGSA\Big{(}H_{l-1}^{i},A_{apt}\Big{)}=\sum_{n\in N(i)}A_{apt}(i,n)\cdot H_{l-1} ^{n} \tag{14}\]  
where \(H_{l-1}\) represents the hidden layer output of the \(l\)-th layer. \(H_{l-1}\) is first projected to three matrices, \(W_{Q},W_{K}\in\mathbb{R}^{D\times D_{QK}}\), and \(W_{V}\in\mathbb{R}^{D\times D_{V}}\) are the weight matrices for calculating the \(Q,K,V\), respectively. In practice, it is expected to set \(D_{QK}=D_{V}\). \(i\) is a sensor node, and \(N(i)\) is the set of first-order neighboring nodes of \(i\) in \(A_{d}\).  
Expanding from a single self-attention mechanism to a multi-head attention mechanism enriches the information richness. Ultimately, the sensor information will be aggregated across all attention heads. The update process of node information can be described by Equation (15):  
\[H_{l}^{i}=FC(concat\big{(}DGSA\big{(}H_{l-1},A_{apt}\big{)}_{1},\dots,DGSA \big{(}H_{l-1},A_{apt}\big{)}_{h}\big{)}\,W_{O})\in\mathbb{R}^{N\times T \times D} \tag{15}\]  
where \(H_{0}=Concat\big{(}InputLayer(X),STE\big{)}\), \(W_{O}\) is a learnable parameter, and \(h\) is the number of heads using the multi-head attention mechanism.  
Relative to global ST-attention and local ST-attention mechanisms, the first-order Neighbor Dynamic Graph ST-Attention can effectively regulate the flow of information in the sensor network and adjust the aggregation scope of organized information, thereby reducing the complexity of the model [23]. The process is shown in Figure 3.