## 2 Methods
### EG-DGATN Model Framework
#### 2.3.1 Causal Spatiotemporal Embedding  
To avoid the accumulation of errors and error propagation commonly observed in long-granularity forecasts in traditional models, the EG-DGATN utilizes the Transformer architecture. The prediction process of Transformer is temporally synchronized, which requires each sensor to be pre-position encoded at different time granularities. To accurately capture the correlation information in the sensor network, we optimize the common positional encoding with causal spatial embedding, achieving synchronous modeling of sensor nodes in both the causal spatial domain and temporal domain. Causal spatiotemporal embedding \(STE\) includes both causal spatial embedding \(SE\) and temporal embedding \(TE\).  
To fully embed the sensor space feature in the causal domain, Node2 Vec [20] is utilized to perceive the causal space and generate embedding vectors. Node2 Vec conducts random walks on the causal-directed matrix and the DTW similarity matrix across three time spans, producing a vector representation for each walk sequence. These vector representations are then aggregated to obtain a comprehensive embedding for each sensor. Furthermore, the embeddings of the causal structures between different sensor sequences learned by Node2 Vec on various graph structures are then aggregated. After passing through fully connected (FC) layers. In this way, we enable SE to obtain the causal relationships in the water demand sensor network under different time spans, enriching the information contained therein, as shown in Equation (8).  
\[SE=FC\big{(}concat(Node2 Vector Encoding(G_{s},G_{M},G_{L},G_{DTW}))\big{)}\in \mathbb{R}^{N\times(T+P)\times D} \tag{8}\]  
where \(TE\) represents the position of a variable in the entire time steps [12]. \(T\) represents the length of the training window, while \(P\) represents the size of the prediction window.  
Considering the daily, weekly, and seasonal periodicity of water usage, one-hot encoding is performed for the position of the current time step within a day, the position within a week, and the position within a month relative to the entire year, generating \(V_{time}\in\mathbb{R}^{1\times 288}\), \(V_{week}\in\mathbb{R}^{1\times 7}\), \(V_{month}\in\mathbb{R}^{1\times 12}\). The process of generating embedding is shown in Equations (9) and (10).  
\[TE=unsqueeze(FC(concat(V_{time},V_{week},\ V_{month}))\ \in\mathbb{R}^{N\times(T+P) \times D} \tag{9}\]  
\[STE=TE+SE\in\mathbb{R}^{N\times(T+P)\times D} \tag{10}\]  
where the unsqueeze function is used to expand the dimensions, aligning the dimensions of time encoding with those of causal space encoding.  
By combining \(SE\) and \(TE\), we enable the transformation of causal spatiotemporal features into more actionable causal spatiotemporal embeddings. This process distinctly identifies the unique position of specific time granularities within the causal spatiotemporal graph across various periods. The \(STE\) is divided into two parts in training: the length of the two parts is aligned with the training window \(T\) and the prediction window \(P\), respectively. The first part will be used as positional coding in the encoder, which is merged with the sequence and then passes through the input layer to the coding stage, ultimately generating the sequence representation. Subsequently, the latter segment is amalgamated with the sequence representation and directed into the Decoder. This step will enable the decoder to forecast the outcome associated with a specific location accurately.