3.1. Overall Model Architecture
The spatiotemporal prediction of the composite groundwater quality safety index is essentially a regional continuous-field prediction problem. Its objective is not merely to extrapolate the water quality status of individual monitoring sites, but to learn the coupled relationships among the overall spatial pattern, local anomalous regions, and temporal evolution trends from continuous regional groundwater safety state maps. To this end, this study organizes the composite groundwater quality safety index of Yiyang City as a continuous spatial sequence input, enabling the model to perform both regional-scale prediction and community-scale point prediction within a unified framework. Specifically, the input sequence consists of composite groundwater quality safety index maps from multiple historical time steps, where each frame corresponds to the spatial distribution of safety scores at different locations within the study area. The overall model structure is shown in
Figure 1. The model first receives the historical regional safety index sequence and extracts multi-scale features ranging from shallow spatial textures to deep regional semantics through a multi-stage encoder. Let the historical input length be
T, the prediction horizon be
K, and the regional grid size be
. The input sequence can be expressed as
where
C denotes the number of input channels. When the model directly takes the composite groundwater quality safety index as input,
; when multi-source environmental variables, historical water quality indicators, or spatial auxiliary factors are further introduced,
C can be extended to a multi-channel form. In the encoding stage, a progressive downsampling structure is adopted to compress the spatial resolution and enlarge the receptive field, allowing the model to capture cross-regional water quality correlations. In the decoding stage, spatial details are gradually restored through progressive upsampling, while shallow features are incorporated to preserve regional boundaries, local abrupt changes, and the continuity of spatial distributions.
After obtaining multi-scale spatial features, the model further introduces spatial attention and temporal attention structures to enhance the modeling of regional dependencies and temporal variation patterns. Spatial attention is used to characterize potential associations among different grid regions, while temporal attention is used to identify historical time steps that are more critical for future prediction, thereby improving the model response to pollutant diffusion, short-term temporal fluctuations, and local anomalous changes. This spatiotemporal encoding process can be summarized as
where
denotes the multi-stage spatial encoder,
denotes spatial attention modeling,
denotes temporal attention modeling, and
represents the high-level spatiotemporal representation after integrating spatial structures and temporal dynamics. Subsequently, the model integrates encoder and decoder information through a multi-scale feature fusion module, and explicitly models the magnitude and direction of changes in the composite groundwater quality safety index between adjacent time steps using the Temporal Difference Interaction Module. Meanwhile, the Region-Guided Feature Modulation module adaptively adjusts feature responses according to regional weight maps and error-sensitive areas, enabling the model to focus more on spatial units with higher water quality risks or more intense variations. Finally, the model outputs regional prediction maps of the composite groundwater quality safety index for multiple future time steps, and point prediction results for designated communities or monitoring regions can be extracted using a spatial sampling operator. The overall prediction process is formulated as
where
denotes the decoder,
denotes the Temporal Difference Interaction Module,
denotes the multi-scale fusion operation,
denotes Region-Guided Feature Modulation,
denotes the prediction head,
denotes the regional prediction results for the future
K time steps,
denotes the spatial sampling or regional aggregation operation corresponding to community location
p, and
denotes the point prediction sequence of the designated community. Through the above design, the model can simultaneously account for the overall evolution of regional groundwater quality, small-scale spatial heterogeneity, and dynamic changes in local risk areas, providing a unified modeling basis for groundwater quality prediction, water resource safety zoning, and pollution risk early warning.
3.2. Temporal Difference Interaction Module, TDIM
The composite groundwater quality safety index usually exhibits a dynamic process in the temporal dimension, where slow evolution and local abrupt changes coexist. On the one hand, regional water quality status is affected by short-term hydrological variations, groundwater runoff, and gradual changes in pollutant levels, showing continuous variation characteristics. On the other hand, local pollutant inputs, extreme rainfall disturbances, or changes in human activities may lead to abnormal fluctuations within a short period. If only conventional temporal attention or convolutional structures are used, the model may tend to learn the overall trend while showing insufficient response to fine-grained changes between adjacent time steps. To address this issue, this study designs the Temporal Difference Interaction Module (TDIM), which jointly models trend information, differential variations, and cross-temporal dependencies in groundwater quality sequences through the main feature stream, differential encoding stream, and motion-aware temporal aggregation stream. The architecture of the module is shown in
Figure 2.
Given the temporal feature sequence from the upstream spatiotemporal encoder,
, where
, TDIM first performs linear projection on the feature of each time step and introduces learnable temporal positional encoding to preserve temporal order information:
where
denotes the feature projection operation,
d is the hidden channel dimension, and
represents the temporal positional embedding at the
t-th time step. This main feature stream is used to preserve the original spatiotemporal semantics and provide a stable basic representation for subsequent differential interaction.
To explicitly characterize the changes in groundwater quality status between adjacent time steps and across multiple temporal intervals, TDIM constructs a differential encoding stream. First, feature differences between adjacent time steps are calculated to capture short-term change direction and change intensity. Then, the operation is further extended to a multi-lag differential form, enabling the model to perceive both short-term fluctuations and accumulated changes across multiple monthly intervals within the input sequence. This process is defined as
where
denotes the set of differential lags.
corresponds to the adjacent-time-step difference, while larger
k values correspond to change responses across wider intervals within the historical input sequence. Furthermore, TDIM organizes the differential features at different lag scales into a temporal difference pyramid and extracts change patterns through a scale-shared encoder:
where
denotes concatenation along the channel dimension, and
is the differential encoding function. Through this design, the model can not only identify instantaneous changes in the groundwater quality index, but also capture multi-interval temporal processes such as gradual pollutant variation, local diffusion, and short-term water quality recovery.
Based on the differential features, TDIM further introduces motion-aware temporal attention to model the different contributions of historical time steps to the current predicted state. Specifically, the module constructs a temporal correlation matrix according to the current main feature
and the historical differential feature
, and obtains cross-temporal attention weights through normalization:
where
L denotes the temporal look-back window,
and
denote the query mapping and key mapping, respectively, and
denotes the feature similarity measure. Subsequently, the module performs cross-temporal aggregation on historical change features to obtain the motion-aware representation:
where
denotes the value mapping. This aggregation process enables the model to automatically focus on historical change segments that are more informative for explaining the evolution of the current water quality status, thereby alleviating the limitation that a fixed temporal window cannot adapt to different regional change rhythms.
Finally, TDIM performs adaptive fusion between the main feature stream and the differential change stream through channel calibration, scale alignment, and temporal gating mechanisms. Channel calibration is used to enhance feature channels related to water quality changes, scale alignment ensures consistency between main features and differential features in spatial resolution and channel dimension, and temporal gating dynamically controls the fusion ratio between trend information and change information according to the current state. The overall output is expressed as
where
denotes the scale alignment operation,
denotes the gating mapping function,
is the Sigmoid activation function, ⊙ denotes element-wise multiplication, and
represents the temporal gating weight. Through the above structure, TDIM can preserve the stable spatial pattern of regional groundwater quality while explicitly enhancing adjacent temporal differences, multi-lag variations, and cross-temporal dynamic propagation information, thereby improving the model ability to characterize the spatiotemporal evolution process of the composite groundwater quality safety index.
3.3. Region-Guided Feature Modulation, RGFM
After TDIM enhances temporal differential changes, the model can obtain spatiotemporal features with dynamic-change awareness. However, the spatial distribution of the composite groundwater quality safety index does not change uniformly. Different regions are jointly affected by topographic structures, pollutant inputs, groundwater runoff connectivity, land-use types, and the sparsity of monitoring sites, thus showing evident regional heterogeneity. If the output features of TDIM are directly fed into the prediction head, the model may tend to learn globally smoothed trends while weakening its attention to high-risk regions, spatial boundary regions, and locally significant changing areas. To address this issue, this study designs the Region-Guided Feature Modulation (RGFM) module. Based on spatiotemporal features, RGFM introduces regional priors, saliency responses, and boundary cues, and generates adaptive modulation parameters through regional affinity modeling, thereby enhancing the model ability to represent spatial differences in groundwater quality. The architecture of this module is shown in
Figure 3.
Given the features from different scales at the
t-th time step,
, RGFM first performs scale alignment and feature fusion:
where
denotes the spatial alignment operation at the
s-th scale,
denotes the fusion mapping function, and
represents the fused regional spatiotemporal feature. Subsequently,
is flattened and projected into regional feature tokens:
Here,
denotes the feature token of the
i-th spatial unit,
N is the number of spatial tokens, and
d is the token dimension.
To ensure that the regional modulation process relies not only on data-driven features but also on spatial prior knowledge in groundwater quality prediction, RGFM constructs a regional encoding branch. This branch contains three types of inputs: the regional prior map
, the saliency map
, and the boundary cue map
. Specifically,
describes relatively stable spatial risk differences within the study area,
represents salient response regions in the prediction features at the current time step, and
is used to characterize administrative boundaries, spatial transition zones, or high-gradient changing regions. These three types of regional cues are encoded by convolution and compressed by pooling to obtain the corresponding regional embeddings:
On this basis, RGFM performs adaptive normalized fusion on the three types of regional embeddings to obtain a unified region-guided vector:
where
,
,
denotes the adaptive weight of different regional cues, and
is a learnable parameter. This design enables the model to dynamically select more important regional constraint information according to the groundwater quality status at the current time step.
After obtaining the regional feature tokens and the region-guided vector, RGFM further constructs a regional affinity matrix to describe the potential relationships among different spatial units. Unlike a fixed adjacency matrix, this affinity matrix simultaneously considers feature similarity, regional prior modulation, and spatial positional relationships, and therefore can more flexibly reflect the non-uniform propagation characteristics of the composite groundwater quality safety index within the region:
where
and
denote the query mapping and key mapping, respectively,
and
denote the positional embeddings of the
i-th and
j-th spatial units,
denotes the regional relation encoding function, and
is a learnable vector. Then, Softmax normalization is applied to the regional affinity matrix to obtain the region-guided weight matrix:
Here,
represents the regional dependency strength from the
i-th spatial unit to the
j-th spatial unit, which can be used to selectively aggregate contextual information with similar water quality variation patterns or potential spatial associations.
Based on the region-guided weight matrix, RGFM performs weighted aggregation over all spatial tokens to obtain region-enhanced feature representations. This process enables high-risk regions to obtain supplementary information from regions with similar pollution responses, and allows boundary regions to acquire more stable spatial context from adjacent transition areas, thereby alleviating local prediction discontinuity and blurred regional boundary problems:
Here,
denotes the value mapping matrix, and
is the token sequence enhanced by regional context. Different from directly concatenating regional priors, this aggregation strategy establishes soft connections among spatial units through affinity relationships, enabling the model to automatically learn the propagation and collaborative variation relationships of groundwater quality status within the region.
Finally, RGFM restores the enhanced token sequence into a spatial feature map and generates the scaling parameter
and shifting parameter
to perform region-guided affine modulation on the original fused feature
. This modulation mechanism can finely adjust the feature response intensity at different spatial locations without disrupting the backbone spatiotemporal semantics:
Here, denotes the modulation parameter generation function, denotes splitting the output into the scaling term and shifting term, ⊙ denotes element-wise multiplication, and is the region-modulated feature output by RGFM. Through the above design, RGFM integrates multi-scale spatiotemporal features, regional priors, saliency responses, boundary cues, and regional affinity relationships into a unified modulation framework, enabling the model to focus more sufficiently on key spatial units in groundwater quality prediction and thereby improving the spatial representation ability of both regional-scale prediction and community-scale point prediction.
3.4. Training Objective and Loss Function
The training objective of this study is to enable the model to simultaneously achieve regional reconstruction accuracy, temporal variation consistency, regional risk sensitivity, and spatiotemporal boundary preservation. Given the historical input sequence , the model predicts the composite groundwater quality safety index map for the next month, denoted as , with the corresponding ground truth denoted as . In this study, the prediction horizon is fixed to one month, i.e., , throughout model training and evaluation. The overall training process is shown in Algorithm 1. In each training batch, the model sequentially performs spatiotemporal feature encoding, TDIM-based temporal difference enhancement, RGFM-based region-guided modulation, and joint optimization with multiple training objectives.
Specifically, the reconstruction fidelity term is used to constrain the overall numerical consistency between the prediction results and the ground truth composite groundwater quality safety index, which is defined as
| Algorithm 1 Training process of the proposed groundwater quality prediction model |
Require: Historical groundwater quality sequence , ground truth map Ensure: Optimized model parameters
- 1:
Initialize model parameters - 2:
for each training epoch do - 3:
for each mini-batch do - 4:
Extract multiscale spatiotemporal features from - 5:
Enhance temporal variation features using TDIM - 6:
Generate region-guided modulated features using RGFM - 7:
Predict the next-month groundwater quality map - 8:
Compute reconstruction, temporal, region-guided, and STB losses - 9:
Update by back-propagation - 10:
end for - 11:
end for
|
To enhance the model ability to characterize the temporal variation from the last observed month to the predicted month, this study introduces a one-step temporal variation consistency constraint. Specifically, the predicted and ground-truth temporal changes are first defined as
where
denotes the integrated groundwater quality risk map of the last observed month in the historical input sequence. The temporal consistency loss jointly constrains the magnitude and direction of the month-to-month variation:
The first term constrains the magnitude of groundwater quality variation between two consecutive months, while the second term encourages consistency in the overall direction of temporal change. The inner product and the corresponding norms are computed over the spatial domain.
In addition, the regional weight map
output by RGFM is used to construct a region-guided weighted error, enabling the model to pay more attention to high-risk regions, significantly changing regions, and boundary transition regions:
To further preserve the spatial boundaries of groundwater quality and their temporal variation boundaries, this study designs a spatiotemporal boundary-aware loss, namely STB Loss, which jointly constrains the prediction results through spatial gradients and temporal difference gradients:
Here, the first term preserves the spatial boundary structure of the predicted groundwater quality risk map, while the second term constrains the spatial distribution and boundary structure of the month-to-month variation magnitude. where
denotes the spatial gradient operator, and
is a constant used to prevent division by zero. Finally, the total training objective is formulated as
where
,
, and
denote the weighting coefficients of different loss terms, respectively. Through the above joint optimization, the model can better preserve the temporal continuity, regional risk sensitivity, and spatial boundary structure of the composite groundwater quality safety index while maintaining overall prediction accuracy.