Grid water depth prediction method and device based on lsh attention mechanism
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA INST OF WATER RESOURCES & HYDROPOWER RES
- Filing Date
- 2026-05-28
- Publication Date
- 2026-08-07
AI Technical Summary
[0004]本申请实施例提供了基于LSH注意力机制的网格水深预测方法及装置,可以解决现有技术中二维水动力模型无法实现跨时间段的预测的问题
[0028] This method collects multiple batches of boundary flow time-series data and grid depth time-series data from the output of a two-dimensional IFMS model. Through constructing and transposing feature tensors, and utilizing a series of processing steps including a Reformer model and a randomized rotating hash function, the predicted depth values for each grid cell at future time points are finally obtained using a pre-trained iTransformer. This process overcomes the limitation of existing two-dimensional IFMS models where the input boundary flow time-series data and output grid depth data must have the same time range, successfully achieving cross-time-period prediction and effectively improving the model's practicality in flood warning and long-term trend analysis.
Smart Images

Figure CN122527832A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of hydrological monitoring, and in particular to a grid-based water depth prediction method and device based on the LSH attention mechanism. Background Technology
[0002] Two-dimensional hydrodynamic models play a crucial role and have been widely used to accurately predict the inundation extent and water depth changes of watersheds, providing important scientific basis for flood control, disaster reduction, and rational water resource planning. Among them, the IFMS (Integrated Flood Modeling System) in two-dimensional mode, as a widely used hydrodynamic model, exhibits excellent performance in simulating water depth in irregular grids. It can accurately simulate water depth conditions in different regions, providing strong data support for relevant decision-making. However, the current simulation method of this model has significant limitations. Specifically, during the simulation process, the input boundary flow time series data and the output grid water depth data must be strictly consistent in time range. This prevents the model from achieving cross-time period predictions or extrapolations, making it difficult to meet the diverse needs of practical applications.
[0003] In practical flood warning work, it is often necessary to predict water conditions over a relatively long period in advance in order to take timely preventive measures. Long-term trend analysis also requires comprehensive analysis and extrapolation of water condition data from different time periods. This limitation of the model significantly affects its practicality in flood warning and long-term trend analysis. Summary of the Invention
[0004] This application provides a grid-based water depth prediction method and apparatus based on the LSH attention mechanism, which can solve the problem that existing two-dimensional hydrodynamic models cannot achieve cross-time period prediction. The technical solution is as follows:
[0005] In a first aspect, embodiments of this application provide a grid-based water depth prediction method based on the LSH attention mechanism, the method comprising:
[0006] B batches of boundary flow time-series data and B batches of grid water depth time-series data of the target watershed are collected from the output of the two-dimensional IFMS model. The watershed is divided into N grids and has M boundaries. Each batch of boundary flow time-series data includes T time points and the flow values of the M boundaries associated with each time point. Each batch of grid water depth time-series data includes the T time points and the water depth values of the N grids associated with each time point. B is an integer greater than 0, and M and N are integers greater than 1.
[0007] The collected data is standardized.
[0008] The first feature tensor is constructed based on the standardized data; the dimension of the first feature tensor is B×T×(N+M).
[0009] The first feature tensor is transposed in terms of time and feature dimensions to obtain the second feature tensor; the dimension of the second feature tensor is B×(N+M)×T.
[0010] Using the Reformer model, based on the projection of the second feature tensor and the weight matrix, query vector, key vector, and value vector are generated;
[0011] Each feature vector is bucketed using a random rotation hash function;
[0012] For each subset of feature vectors within a hash bucket, compute the attention matrix;
[0013] Merge the outputs of all hash buckets, restore the original feature vector order, and obtain the final weighted feature tensor;
[0014] The weighted feature tensor is decoded using a pre-trained iTransformer to obtain the water depth prediction values for each grid at future time points.
[0015] Secondly, embodiments of this application provide a grid-based water depth prediction device based on the LSH attention mechanism, the device comprising:
[0016] The acquisition unit is used to acquire B batches of boundary flow time-series data and B batches of grid water depth time-series data of the target watershed output by the two-dimensional IFMS model. The watershed is divided into N grids, and the watershed has M boundaries. Each batch of boundary flow time-series data includes T time points and the flow values of the M boundaries associated with each time point. Each batch of grid water depth time-series data includes the T time points and the water depth values of the N grids associated with each time point. B is an integer greater than 0, and M and N are integers greater than 1.
[0017] The processing unit is used to standardize the collected data;
[0018] The construction unit is used to construct a first feature tensor based on the standardized data; the dimension of the first feature tensor is B×T×(N+M).
[0019] The transpose unit is used to transpose the first feature tensor in terms of time and feature dimension to obtain a second feature tensor; the dimension of the second feature tensor is B×(N+M)×T.
[0020] The generation unit is used to generate query vectors, key vectors, and value vectors based on the projection of the second feature tensor and weight matrix using the Reformer model;
[0021] Bucketing units are used to bucket each feature vector using a random rotating hash function;
[0022] The computation unit is used to compute the attention matrix for a subset of feature vectors within each hash bucket;
[0023] The synthesis unit is used to merge the outputs of all hash buckets, restore the original feature vector order, and obtain the final weighted feature tensor.
[0024] The prediction unit is used to decode the weighted feature tensor using a pre-trained iTransformer to obtain the water depth prediction values for each grid at future time points.
[0025] Thirdly, embodiments of this application provide a computer storage medium storing a plurality of instructions adapted for loading by a processor and executing the above-described method steps.
[0026] Fourthly, embodiments of this application provide a server that may include a processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and to execute the above-described method steps.
[0027] The beneficial effects of the technical solutions provided in some embodiments of this application include at least the following:
[0028] This method collects multiple batches of boundary flow time-series data and grid depth time-series data from the output of a two-dimensional IFMS model. Through constructing and transposing feature tensors, and utilizing a series of processing steps including a Reformer model and a randomized rotating hash function, the predicted depth values for each grid cell at future time points are finally obtained using a pre-trained iTransformer. This process overcomes the limitation of existing two-dimensional IFMS models where the input boundary flow time-series data and output grid depth data must have the same time range, successfully achieving cross-time-period prediction and effectively improving the model's practicality in flood warning and long-term trend analysis.
[0029] Standardizing the collected data eliminates differences in units and scales between different data sets, making the data comparable and consistent. Constructing the first feature tensor based on the standardized data provides a standardized and unified data foundation for subsequent model processing, helping to improve the model's prediction accuracy and stability.
[0030] This paper employs a Reformer model combined with a randomized rotating hash function for feature processing. By bucketing the attention matrix and merging the outputs, it avoids the high computational complexity of traditional attention mechanisms when handling long sequence data. This innovative approach significantly improves computational efficiency while maintaining prediction accuracy, enabling the model to generate prediction results more quickly and meeting the real-time requirements of practical applications.
[0031] By decoding the weighted feature tensor using a pre-trained iTransformer, we can fully extract the potential information in the data and accurately predict the water depth values of each grid at future time points. These accurate predictions can provide reliable scientific basis for flood warnings, flood control and disaster reduction decisions, and long-term water resource planning, helping to reduce the losses caused by flood disasters. Attached Figure Description
[0032] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0033] Figure 1 This is a schematic diagram of the network architecture provided in the embodiments of this application;
[0034] Figure 2 This is a flowchart illustrating the grid-based water depth prediction method based on the LSH attention mechanism provided in this application embodiment;
[0035] Figure 3 This is a schematic diagram of the structure of a grid-based water depth prediction device based on the LSH attention mechanism provided in this application;
[0036] Figure 4 This is a schematic diagram of the structure of a server provided in this application. Detailed Implementation
[0037] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0038] It should be noted that the grid depth prediction method based on the LSH attention mechanism provided in this application is generally executed by the server, and correspondingly, the grid depth prediction device based on the LSH attention mechanism is generally set in the server.
[0039] Figure 1An exemplary network architecture is shown that can be applied to the grid depth prediction method or grid depth prediction device based on the LSH attention mechanism of this application.
[0040] like Figure 1 As shown, the network architecture may include: terminal device 101 and server 102. Terminal device 101 and server 102 can communicate with each other via the network, which serves as the medium for providing communication links between the various units. The network may include various types of wired or wireless communication links, such as: wired communication links including fiber optic cables, twisted-pair cables, or coaxial cables; and wireless communication links including Bluetooth communication links, Wi-Fi communication links, or microwave communication links.
[0041] The server 102 is equipped with a Reformer model and an iTransformer model. The server 102 uses the collected boundary flow time series data and grid water depth time series data to make predictions, obtain the grid water depth values for future time periods, and display the prediction results on the terminal device 101.
[0042] It should be noted that the terminal device 101 and the server 102 can be either hardware or software. When the terminal device 101 and the server 102 are hardware, they can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When the terminal device 101 and the server 102 are software, they can be implemented as multiple software programs or software modules (for example, to provide distributed services), or as a single software program or software module; no specific limitations are made here.
[0043] The terminal device of this application can be equipped with various communication client applications, such as video recording applications, video playback applications, voice interaction applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0044] A terminal device can be either hardware or software. When the terminal device is hardware, it can be various terminal devices with a display screen, including but not limited to smartphones, tablets, laptops, and desktop computers. When the terminal device is software, it can be installed on the terminal devices listed above. It can be implemented as multiple software programs or software modules (e.g., used to provide distributed services) or as a single software program or software module; no specific limitation is made here.
[0045] When the terminal device is hardware, it can also be equipped with a display device and a camera. The display device can be any device capable of displaying information, and the camera is used to capture video streams. For example, the display device can be a cathode ray tube display (CR), a light-emitting diode display (LED), an e-ink screen, a liquid crystal display (LCD), a plasma display panel (PDP), etc. Users can use the display device on the terminal device to view displayed text, images, videos, and other information.
[0046] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is for illustrative purposes only. Depending on implementation needs, there can be any number of terminal devices, networks, and servers.
[0047] The following will be combined with the appendix Figure 2 This paper provides a detailed description of the grid-based water depth prediction method based on the LSH attention mechanism provided in the embodiments of this application. The grid-based water depth prediction device based on the LSH attention mechanism in the embodiments of this application can be... Figure 1 The server shown.
[0048] Please see Figure 2 This document provides a flowchart illustrating a grid-based water depth prediction method based on the LSH attention mechanism, as described in an embodiment of this application. Figure 2 As shown, the method described in this application embodiment may include the following steps:
[0049] S201. Collect B batches of boundary flow time series data and B batches of grid water depth time series data of the target watershed from the output of the two-dimensional IFMS model.
[0050] The watershed is divided into N grids, and the watershed has M boundaries. The boundary flow time series data of each batch includes T time points and the flow values of the M boundaries associated with each time point. The grid water depth time series data of each batch includes the T time points and the water depth values of the N grids associated with each time point.
[0051] The server first connects to the 2D IFMS model interface to initiate the data acquisition process. This model simulates the hydrological dynamics of the target watershed, outputting B independent batches of boundary flow time-series data and B batches of grid-based water depth time-series data. The watershed is divided into N grid cells, each representing an independent geographical area, and M boundary points are set around the watershed to monitor water flow in and out of the watershed. Each batch of boundary flow time-series data contains records of T consecutive time points, each time point associated with M boundary flow values, in cubic meters per second. Similarly, each batch of grid-based water depth time-series data contains T records of the same time points, each time point associated with N grid water depth values, in meters. The server stores this data in a memory buffer to ensure data integrity and provide raw input for subsequent processing steps. The data acquisition process includes verifying time point alignment and batch consistency to prevent time series misalignment or missing values.
[0052] For example:
[0053] For example, a server collects simulated data for a city's watershed, setting the batch size B to 5, representing 5 independent simulation runs. The watershed is divided into 50 grid cells (N=50), with 4 boundary points M, representing 4 main inlets. Each batch contains 48 time points (T=48), recorded once per hour. Boundary flow data records the flow values of the 4 boundaries at each time point (e.g., boundary 1 flow is 120 cubic meters per second), and grid depth data records the depth values of all 50 grids at each time point (e.g., grid 1 depth is 1.2 meters). The server ensures that the time series of all batches are synchronized to avoid data deviation.
[0054] In some possible embodiments of this application, the method for watershed grid division includes:
[0055] The watershed is divided into N grids, including:
[0056] Determine the scope of the watershed;
[0057] The watershed is randomly divided into a small number of initial grids;
[0058] Traverse each grid and calculate its slope, elevation standard deviation, and location information;
[0059] If the calculated slope is greater than the slope threshold, the elevation standard deviation is greater than the elevation threshold, and the grid is connected to the watershed boundary, the grid is identified as a high-complexity grid, and then the high-complexity grid is divided into 4 smaller grids.
[0060] Otherwise, the grid is identified as a low-complexity grid;
[0061] Merge two adjacent low-complexity grids.
[0062] The process involves the server loading vector boundary data of the target watershed and resolving the polygon vertex coordinates using a geographic information system engine. A convex hull algorithm is then used to eliminate concave points on the boundaries, generating a minimum bounding rectangle as the computational domain. Simultaneously, a high-precision digital elevation model is imported, and the watershed area is rasterized into a 0.5-meter resolution basic grid matrix.
[0063] The first-level grid is created using a quadtree splitting method: based on the circumscribed rectangle of the watershed, it is equally divided into K×K initial grids along the latitude and longitude directions (K=√N / 10, where N is the total number of target grids). The area of each initial grid is 1 / K² of the total area of the watershed, ensuring that the initial division covers the entire watershed without overlap.
[0064] Execute the following steps for each initial grid:
[0065] Slope calculation: Based on all elevation points within the grid, the gradient is calculated using the Sobel operator, and the maximum slope value is taken as the slope of the grid.
[0066] Elevation standard deviation: The standard deviation of the set of elevation points within a statistical grid.
[0067] Location marking: If the grid has ≥2 intersection points with the watershed boundary polygon, it is marked as "boundary associated grid".
[0068] For each grid, the following decision logic is applied: if the slope is greater than 8% (slope threshold) and the elevation standard deviation is greater than 1.2 meters (elevation threshold), and it is marked as a boundary-related grid, then the grid is divided into 4 equal-area subgrids along the diagonal. The subgrids inherit the terrain parameters of the parent grid and the above steps are recursively executed until the subdivision conditions are no longer met.
[0069] For non-high complexity grids: construct a grid adjacency graph, mark grids with slope <3% and elevation standard deviation <0.5 meters as low complexity, traverse the adjacency graph, and merge adjacent low complexity grids to form new polygons; merging rules: the area of the new grid does not exceed 0.5% of the total watershed area, and the aspect ratio is <2:1; recalculate the terrain parameters for the merged grids.
[0070] Perform global validation: Check grid area dispersion (maximum grid area / minimum grid area ≤ 20). Force secondary subdivision for grids with excessively large areas. Generate the final grid topology matrix, recording the vertex coordinates, adjacency relationships, and terrain attributes of each grid.
[0071] This embodiment targets high-slope, highly undulating boundary regions (such as steep riverbanks and tributary confluences), using recursive subdivision to improve grid resolution and accurately capture abrupt topographic changes. Compared to traditional uniform grids, it significantly improves the simulation accuracy of key hydrological parameters such as water level gradients and velocity fields, especially reducing physical distortions during flood front evolution.
[0072] For low-complexity regions (such as flat plains and gentle slopes), an intelligent merging mechanism significantly reduces the number of invalid grids while maintaining the rationality of hydrological response. This strategy effectively compresses the scale of numerical computation, shortens model solution time, and provides a feasible basis for large-scale watershed real-time simulation.
[0073] Prioritize subdividing the grid at the intersection with the watershed boundary to ensure the spatial accuracy of hydrological boundary conditions (such as inflow / outflow points and levee structures). This strengthens the physical consistency between the internal grid and the boundary conditions, avoids flow transmission errors caused by coarse grids, and improves the closure of the overall water balance.
[0074] S202. Standardize the collected data.
[0075] The server performs standardization on the collected raw data to eliminate differences across different feature scales and improve model training stability. This process includes calculating the statistical parameters for each feature dimension, such as the mean and standard deviation of boundary flow and grid depth. The server independently processes all batches, time points, and features: first, it calculates the global mean and standard deviation of the entire dataset; then, it applies a transformation to each data point, subtracting the mean and dividing by the standard deviation to standardize the data distribution to a normal distribution with a mean of zero and a standard deviation of one. This process involves traversing all data points, performing batch calculations to optimize efficiency, and storing the results as the standardized dataset. Standardization ensures that subsequent model inputs are unaffected by dimensions, reducing the risk of numerical instability.
[0076] For example:
[0077] For example, when processing boundary flow data, the server calculates the average flow rate across all batches and time points as 100 cubic meters per second, with a standard deviation of 25. Then, each flow rate value is subtracted by 100 and divided by 25 (e.g., the original value of 125 is standardized to 1.0). For gridded water depth data, the average depth is 0.8 meters, with a standard deviation of 0.15. Each depth value is subtracted by 0.8 and divided by 0.15 (e.g., the original value of 0.95 is standardized to 1.0). After standardization, all feature values have a consistent range, facilitating model processing.
[0078] In some possible embodiments of this application, the server initiates a full data scan, traversing all B batches, T time points, and M boundary locations. For the traffic value at each boundary location, streaming accumulation is performed: Average calculation: The sum of all traffic values is accumulated in real time, and the final value is divided by the total number of data points (B×T×M) to generate the global average traffic value. Standard deviation calculation: The squared difference between each traffic value and the current accumulated average is calculated synchronously, and the arithmetic mean of the sum of squared differences is taken, followed by the square root to generate the global standard deviation of the traffic. This process employs a batch parallel computing strategy, where each computing node independently processes local data and then merges the global results, ensuring memory efficiency under massive data volumes.
[0079] The same mechanism is used to traverse B batches, T time points, and N grid cells: Average value calculation: Sum of all water depth values divided by the total number of data points (B×T×N). Standard deviation calculation: Based on real-time mean, the squared difference accumulator is dynamically updated; the final value processing is the same as the flow rate standard deviation.
[0080] To avoid repeated traversal, the server opens a dual-channel memory buffer to synchronously load raw traffic and water depth data, and the statistical process shares the time dimension index to reduce I / O overhead.
[0081] Based on the previously generated global statistics, perform a linear transformation on the original traffic dataset:
[0082] Centralization: Subtract the global average traffic value from the raw traffic value at each boundary location, each time point, and each batch. Scaling: Divide the centralized result by the global standard deviation of the traffic.
[0083] The transformation process employs a vectorized computation engine, processing data in batches by dimension slices. Within each slice, a broadcast mechanism is used to perform batch calculations of statistics and the original data matrix. The transformation results are written to a new memory space, while a backup of the original data is retained.
[0084] Perform the same operation on the water depth data: Centering: Subtract the global average water depth value from the water depth value of each grid cell at each time point and in each batch. Scaling: Divide the centering result by the global standard deviation of the water depth.
[0085] To address the spatial continuity characteristics of grid data, a local smoothing check is performed after transformation: detect abrupt changes in the standardized values of adjacent grids (such as a difference greater than 3 times the local standard deviation), trigger an outlier review mechanism to eliminate data processing errors.
[0086] Furthermore, the server allocates two independent and structurally symmetrical data buffers in memory:
[0087] Traffic Channel: Create a three-dimensional array storage structure with a dimensional layout of [batch B × time point T × boundary M], and load the original boundary traffic time series data into a contiguous memory block according to the row priority principle.
[0088] Depth channel: Construct a three-dimensional array structure [batch B × time point T × grid N] and store the grid depth time-series data in the same memory alignment manner.
[0089] Establish a unified time dimension mapping table for the two channels. Each time point t (0 ≤ t < T) corresponds to the same memory offset address base in the dual channels. Use a non-blocking I / O pipeline to synchronously read the flow rate and depth data batches, and ensure time-series alignment through timestamp verification to generate a shared time index handle, enabling any channel to directly locate the data block of the corresponding moment in the other channel when accessing the data at time t.
[0090] Traverse the shared time index, synchronously read the flow rate value and depth value at time t, and accumulate them into the global statistical register respectively. Based on the unified time index slice, perform normalization operations on the flow rate and depth data at the same moment t in parallel. The converted normalized data is written back to the dual channels according to the original structure, maintaining the consistency of the time dimension.
[0091] This embodiment achieves triple optimizations through a spatio-temporal coupling memory management architecture:
[0092] Ensuring time-series consistency: Force the flow rate and depth data to be processed at the same time section, eliminating the risk of time misalignment caused by traditional asynchronous loading.
[0093] Intensifying computing resources: The shared time index reduces the address calculation overhead by 50%, and the improvement of memory access locality enables the data loading speed to break through the storage bandwidth bottleneck.
[0094] Synchronizing physical processes: Maintain the coupling relationship of hydrological elements (boundary flow rate and internal depth) at the same moment, retaining the physical authenticity basis for subsequent spatio-temporal joint feature extraction.
[0095] Enhancing system scalability: The dual-channel structure supports dynamically adding and deleting data sources, and new observation elements only need to expand the channels without changing the core processing logic.
[0096] S203. Construct the first feature tensor according to the data after normalization processing.
[0097] The first feature tensor has a dimension of B×T×(N+M). The server constructs a three-dimensional tensor, called the first feature tensor, based on the standardized dataset. This tensor has a dimension of B×T×(N+M), where B is the number of batches, T is the number of time points, N is the number of grids, and M is the number of boundaries. The construction process involves feature dimension concatenation: the server merges the N grid depth values and M boundary flow values for each batch and time point into a single feature vector with a length equal to N+M. Specifically, the server iterates through all batches and time points, extracts the corresponding depth and flow values, and combines them sequentially into a feature vector (e.g., the first N elements are depth, and the last M elements are flow), ultimately forming a complete three-dimensional tensor. This tensor represents a global view of batches, time, and features, facilitating subsequent sequence modeling.
[0098] For example:
[0099] For example, after standardizing the data, the server constructs a tensor with B representing 10 batches, T representing 100 time points, N representing 50 grids, and M representing 5 boundaries. The first feature tensor has dimensions of 10×100×55. For batch 1 and time point 1, the feature vector contains water depth values for 50 grids (e.g., positions 1 to 50) and flow rates for 5 boundaries (e.g., positions 51 to 55), totaling 55 elements. This tensor integrates all data, providing a unified input structure.
[0100] In some embodiments of this application, the transpose operation is performed according to the following formula:
[0101] transposed=X.permute(0,2,1); X represents the first feature tensor, and Xtransposed represents the transposed second feature tensor.
[0102] The dimensions of the three-dimensional tensor are numbered sequentially:
[0103] Index 0: First dimension (e.g., batch dimension B). Index 1: Second dimension (e.g., time dimension T). Index 2: Third dimension (e.g., feature dimension F=N+M).
[0104] The permute rule permute(0,2,1) means:
[0105] Output tensor first dimension ← Input tensor first dimension (index 0: batch B remains unchanged).
[0106] Output tensor second dimension ← input tensor third dimension (index 2: feature F moves to the second position).
[0107] Output tensor 3rd dimension ← Input tensor 2nd dimension (index 1: time T moves to the 3rd position).
[0108] This embodiment transforms "time slice data" into "feature time series", making the complete evolution process of each hydrological element (such as water depth of a certain grid or flow rate of a certain boundary) a continuous and analyzable object.
[0109] S204. Transpose the first feature tensor in time and feature dimensions to obtain the second feature tensor.
[0110] The second feature tensor has a dimension of B×(N+M)×T. The server performs a dimension transpose operation on the first feature tensor, swapping the order of time and feature dimensions. The original tensor dimension is B×T×(N+M), and after transpose it becomes B×(N+M)×T. The transpose process involves rearranging the tensor elements: in each batch, the feature dimension (i.e., N+M grids and boundaries) becomes the primary dimension, and the time dimension T becomes the secondary dimension. The server implements this operation through memory remapping to ensure data continuity. After transpose, each feature (such as a specific grid or boundary) is represented as a complete time series, making it easier for the model to focus on the temporal dependencies between features.
[0111] For example:
[0112] For example, the first feature tensor has a dimension of 10×100×55 (B=10, T=100, N+M=55), and after transpose, the second feature tensor becomes 10×55×100. This means that for batch 1, feature 1 (e.g., water depth in grid 1) is now a time series of length 100 (containing water depth values at all time points), and feature 55 (e.g., flow rate in boundary 5) is also an independent series, which is beneficial for subsequent time series analysis.
[0113] S205. Using the Reformer model, based on the projection of the second feature tensor and weight matrix, generate the query vector, key vector, and value vector.
[0114] The server processes the second feature tensor using a pre-configured Reformer model. First, the input features are mapped to a query vector Q, a key vector K, and a value vector V through a weight matrix projection operation. The server applies three independent linear transformation layers, each corresponding to a trainable weight matrix. The projection process compresses the time series of each feature (dimension T) into a low-dimensional space (e.g., dimension D), generating Q, K, and V vectors. Specifically, the server applies matrix multiplication to each feature vector (dimension T) of the second feature tensor, using the projection weights to transform it into fixed-dimensional Q, K, and V representations. These vectors provide the underlying input for the attention mechanism, capturing the relationships between features.
[0115] For example:
[0116] For example, given an input second feature tensor with dimensions of 10×55×100, the server uses a projection matrix to map the time series of each feature (length 100) to a dimension of 64. For feature 1 (water depth in grid 1), the projection generates a query vector Q1 (dimension 64), a key vector K1 (dimension 64), and a value vector V1 (dimension 64). Similarly, all 55 features are processed independently to generate complete sets of Q, K, and V.
[0117] S206. Use a random rotation hash function to bucket each feature vector.
[0118] The server implements a random rotation hash function to distribute feature vectors into hash buckets, reducing computational complexity. The process involves generating a random rotation matrix and applying it to each feature vector (represented by Q, K, and V). The server calculates the hash value of the rotated vector and distributes it into a predetermined number of buckets based on this value. Each bucket contains a subset of features, and the bucket size is controlled by the hash function to ensure an approximately uniform distribution. This step optimizes memory and computational resource usage through localized attention computation while maintaining approximate global relationships.
[0119] For example:
[0120] For example, the server sets up 10 hash buckets and generates a random rotation matrix. For 55 feature vectors (64 in each dimension), the rotation is applied and the hash value is calculated; assuming feature 1 has a hash value of 3, it is assigned to bucket 3, and feature 2 has a hash value of 8, it is assigned to bucket 8. Ultimately, bucket 3 may contain 5-6 feature vectors, and bucket 8 may contain a similar number, thus achieving feature grouping.
[0121] In some possible embodiments of this application, the method of bucketing each feature vector using a random rotation hash function includes:
[0122] The second feature tensor is hashed using the formula h(x) = argmax([xR; -xR]), which assigns similar features to the same hash bucket; R represents a random rotation matrix with shape [dk, b / 2]. This represents the number of hash buckets.
[0123] The server pre-generates a reproducible random rotation matrix (R):
[0124] Dimension Configuration: The shape is ([dk, b / 2]), where (dk) is the feature vector dimension (i.e., the query / key vector length), and (b) is the total number of target hash buckets. Element Generation: All elements are independently sampled from a standard normal distribution, ensuring uniform coverage of the high-dimensional space by rotation direction. Orthogonalization: Gram-Schmidt orthogonalization is performed on (R) to eliminate inter-dimensional correlation and improve hash stability.
[0125] For each feature vector (x) (dimension dk) of the second feature tensor (X) (dimension (B*F*T), where F is the total number of features), perform the following operations: Forward projection: compute (xR) to obtain a (b / 2) dimensional vector. Negative projection: compute (-xR) to obtain a vector of the same dimension. Concatenation operation: merge into a (b) dimensional vector of ([xR;-xR]), constructing a sign-sensitive bidirectional representation.
[0126] Apply the hash function (h(x)=argmax([xR;-xR])):
[0127] Maximum value index location: Select the dimension index with the largest value among the (b) elements of the concatenated vector.
[0128] Hash bucket allocation: The index value is directly used as the bucket number (h(x)\in{0,1,…,b-1}).
[0129] Dynamic bucket balancing: Real-time monitoring of the number of vectors in each bucket. If the number of vectors in a bucket exceeds the load threshold, a sub-bucket splitting mechanism is triggered.
[0130] Hash bucket physical storage: Create (b) independent memory pools, each pool storing memory pointers to the feature vectors within the bucket, recording the batch (B) and feature position (F) to which each feature vector belongs, maintaining traceability. When the model processes the current bucket, the background preloads the data from the next bucket into the GPU memory.
[0131] This embodiment uses random rotation projection to map the original vectors to a hyperspherical space, maximizing the use of vector angle information. This ensures that physically related features (such as water levels in adjacent grids and upstream / downstream flows) are grouped into the same bucket due to directional similarity, providing semantic consistency for local attention. It reduces the computational complexity of global attention, allowing for fully parallelized in-bucket computation, overcoming the memory bottleneck of traditional Transformers and supporting ultra-large-scale watershed grid modeling. Bidirectional construction simultaneously captures positive and negative correlation features, ensuring that opposing physical phenomena such as sudden water level changes and reverse flow fluctuations are still grouped into the same bucket, avoiding the fragmentation of hydrological process correlations due to sign differences. Based on a real-time statistical bucket splitting mechanism, the bucket granularity of high-density feature regions is adaptively adjusted to prevent local computational overload caused by uneven feature distribution, ensuring efficient utilization of hardware resources.
[0132] S207. For each feature subset within a hash bucket, calculate the attention matrix.
[0133] The server independently computes the attention matrix for each subset of feature vectors within each hash bucket. The process includes: first, extracting all query vectors Q and key vectors K within the bucket; second, calculating the dot product of Q and K to obtain a similarity score; next, applying the softmax function to normalize the score into attention weights; and finally, using these weights to perform a weighted summation of the value vector V to generate a new feature representation. This step performs a local attention mechanism within the bucket, capturing the relationships between feature subsets while reducing the overall computational burden. The server processes all buckets in parallel to improve efficiency.
[0134] For example:
[0135] For example, bucket 3 contains 5 feature vectors (such as the water depth features of grids 1-5). The server computes their Q and K dot product matrices (5×5), applies softmax to obtain attention weights (e.g., the weight of grid 1 for grid 3 is 0.7), and then sums them with V. The output is a new vector (64 dimensions) for each feature, representing the updated temporal feature.
[0136] Furthermore, this application employs a parallel approach to compute the attention matrix, and this parallel architecture achieves four breakthroughs through multi-level computational collaboration:
[0137] The inter-bucket and intra-bucket dual-level parallelism maximizes the utilization of computing resources to the hardware limit, making the attention computation time only related to the maximum bucket size, thus breaking free from the O(F²) complexity constraint of the traditional Transformer.
[0138] Features within hash buckets naturally cluster due to high similarity, and local attention accurately captures hydrological couplings within the grid group (such as water level conduction along the river and slope confluence interaction), avoiding noise interference introduced by global computation.
[0139] The bucketing mechanism breaks down a massive matrix into micro-blocks that can be loaded into the high-speed cache (L1 / L2), reducing memory usage compared to traditional solutions and supporting single-card processing of tens of thousands of watershed grid features.
[0140] The characteristics of different hydrological regions (such as mountainous areas, plains, and riverine areas) are separated into independent buckets, allowing for differentiated configuration of calculation accuracy to meet the numerical sensitivity requirements of actual hydrological processes.
[0141] S208. Merge the outputs of all hash buckets, restore the original feature order, and obtain the final weighted feature tensor.
[0142] The server collects the output vectors of all hash buckets and merges them into a complete feature set. Since the bucketing operation may scramble the original feature order, the server restores the position of each feature vector based on the initial index. The merging process involves concatenating the bucket outputs into a three-dimensional tensor with the same dimensions as the second feature tensor (B×(N+M)×T). Finally, a weighted feature tensor is generated, where the time series of each feature has been updated through an attention mechanism, containing global and local relational information. This tensor serves as the input for subsequent decoding.
[0143] For example:
[0144] For example, after merging the outputs of 10 buckets, the server restores the original order of the 55 features (e.g., feature 1 at position 1, feature 55 at position 55). The weighted feature tensor has a dimension of 10×55×100 (B=10, N+M=55, T=100), where the time series of feature 1 has been adjusted according to the attention weights to represent the optimized water depth or flow sequence.
[0145] S209. Decode the weighted feature tensor using a pre-trained iTransformer to obtain the water depth prediction values of the N grids at future time points.
[0146] The server inputs a weighted feature tensor into a pre-trained iTransformer model for decoding, predicting grid depth values for future time points. iTransformer, based on the Transformer architecture, is specifically designed for sequence prediction. The decoding process includes: the model processes the input tensor through a multi-layer self-attention mechanism to capture temporal dependencies; then, a decoder layer progressively generates the output sequence for future time points. The server is configured with a model output dimension of B×T_future×N, where T_future is the number of predicted time points and N is the number of grids. Finally, the model outputs the predicted depth value in meters for each batch, each future time point, and each grid. The prediction results are stored in a database or file for hydrological analysis and decision support.
[0147] For example:
[0148] For example, with an input weighted feature tensor of dimension 10×55×100, the server uses iTransformer to predict the water depth value for the next 24 hours (T_future=24). The output tensor has a dimension of 10×24×50 (assuming N=50), representing the predicted water depth for all 50 grids in the next hour across 10 batches (e.g., the predicted water depth for batch 1, time point 1, and grid 1 is 1.1 meters). The model utilizes trained parameters to ensure accurate predictions.
[0149] The beneficial effects of this application are:
[0150] This method collects multiple batches of boundary flow time-series data and grid depth time-series data from the output of a two-dimensional IFMS model. Through constructing and transposing feature tensors, and utilizing a series of processing steps including a Reformer model and a randomized rotating hash function, the predicted depth values for each grid cell at future time points are finally obtained using a pre-trained iTransformer. This process overcomes the limitation of existing two-dimensional IFMS models where the input boundary flow time-series data and output grid depth data must have the same time range, successfully achieving cross-time-period prediction and effectively improving the model's practicality in flood warning and long-term trend analysis.
[0151] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0152] Please see Figure 3 This document illustrates a schematic diagram of a grid-based water depth prediction device based on the LSH attention mechanism, provided in an exemplary embodiment of this application, hereinafter referred to as device 3. Device 3 can be implemented as all or part of a server through software, hardware, or a combination of both. Device 3 includes: an acquisition unit 301, a processing unit 302, a construction unit 303, a transpose unit 304, a generation unit 305, a bucketing unit 306, a calculation unit 307, a synthesis unit 308, and a prediction unit 309.
[0153] The acquisition unit 301 is used to acquire B batches of boundary flow time series data and B batches of grid water depth time series data of the target watershed output by the two-dimensional IFMS model; the watershed is divided into N grids, the watershed is set with M boundaries, each batch of boundary flow time series data includes T time points and the flow values of the M boundaries associated with each time point, and each batch of grid water depth time series data includes the T time points and the water depth values of the N grids associated with each time point, where B is an integer greater than 0, and M and N are integers greater than 1;
[0154] Processing unit 302 is used to standardize the collected data;
[0155] Construction unit 303 is used to construct a first feature tensor based on the standardized data; the dimension of the first feature tensor is B×T×(N+M).
[0156] Transpose unit 304 is used to transpose the first feature tensor in terms of time and feature dimension to obtain a second feature tensor; the dimension of the second feature tensor is B×(N+M)×T.
[0157] The generation unit 305 is used to generate a query vector, a key vector, and a value vector by using the Reformer model and projecting the second feature tensor and the weight matrix.
[0158] Bucketing unit 306 is used to bucket each feature vector using a random rotation hash function;
[0159] Computation unit 307 is used to compute the attention matrix for a subset of feature vectors within each hash bucket;
[0160] Synthesis unit 308 is used to merge the outputs of all hash buckets, restore the original feature vector order, and obtain the final weighted feature tensor;
[0161] Prediction unit 309 is used to decode the weighted feature tensor using a pre-trained iTransformer to obtain the water depth prediction values of each grid at future time points.
[0162] In one or more possible embodiments, the standardization process for the collected data includes:
[0163] Iterate through all batches, all time points, and all boundary locations to calculate the global average and global standard deviation of traffic.
[0164] Iterate through all batches, all time points, and all grid cells to calculate the global mean and global standard deviation of water depth;
[0165] The standardized flow value is obtained by subtracting the global average flow value from each flow value and then dividing by the global standard deviation of the flow.
[0166] The standardized water depth value is obtained by subtracting the global average water depth value from each water depth value and then dividing by the global standard deviation of the water depth value.
[0167] In one or more possible embodiments, a dual-channel memory buffer is created to simultaneously load B batches of boundary flow time-series data and B batches of grid depth time-series data, with the two data sharing the time dimension during the standardization process.
[0168] In one or more possible embodiments, the watershed is divided into N grids, including:
[0169] Determine the scope of the watershed;
[0170] The watershed is randomly divided into a small number of initial grids;
[0171] Traverse each grid and calculate its slope, elevation standard deviation, and location information;
[0172] If the calculated slope is greater than the slope threshold, the elevation standard deviation is greater than the elevation threshold, and the grid is connected to the watershed boundary, the grid is identified as a high-complexity grid, and then the high-complexity grid is divided into 4 smaller grids.
[0173] Otherwise, the grid is identified as a low-complexity grid;
[0174] Merge two adjacent low-complexity grids.
[0175] In one or more possible embodiments, the transpose operation is performed according to the following formula:
[0176] Xtransposed = X.permute(0,2,1); X represents the first feature tensor, and Xtransposed represents the transposed second feature tensor.
[0177] In one or more possible embodiments, the bucketing of each feature vector using a random rotation hash function includes:
[0178] Perform a hash mapping on the second feature tensor: h(x)=argmax([xR;-xR]), which assigns similar features to the same hash bucket; R represents a random rotation matrix with shape [dk,b / 2], which is the number of hash buckets.
[0179] In one or more possible embodiments, the attention matrix is computed in parallel for a subset of feature vectors within each hash bucket.
[0180] It should be noted that the device 3 provided in the above embodiments, when executing the grid depth prediction method based on the LSH attention mechanism, is only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the above functions. In addition, the grid depth prediction device based on the LSH attention mechanism provided in the above embodiments and the grid depth prediction method embodiment based on the LSH attention mechanism belong to the same concept, and the implementation process is detailed in the method embodiment, which will not be repeated here.
[0181] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0182] This application also provides a computer storage medium that can store multiple instructions, which are adapted to be loaded and executed by a processor as described above. Figure 2 The method steps of the illustrated embodiment can be found in the following documentation for detailed execution. Figure 2 The specific details of the illustrated embodiments will not be elaborated here.
[0183] This application also provides a computer program product that stores at least one instruction, which is loaded and executed by the processor to implement the grid-based water depth prediction method based on the LSH attention mechanism as described in the above embodiments.
[0184] Please see Figure 4 This provides a schematic diagram of a server structure for an embodiment of this application. For example... Figure 4 As shown, the server 400 may include: at least one processor 401, at least one network interface 404, a user interface 403, a memory 405, and at least one communication bus 402.
[0185] The communication bus 402 is used to enable communication between these components.
[0186] The user interface 403 may include a display screen and a camera. Optionally, the user interface 403 may also include a standard wired interface and a wireless interface.
[0187] The network interface 404 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).
[0188] The processor 401 may include one or more processing cores. The processor 401 connects to various parts of the server 400 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 405, and by calling data stored in the memory 405. Optionally, the processor 401 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 401 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content to be displayed on the screen; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 401 and may be implemented as a separate chip.
[0189] The memory 405 may include random access memory (RAM) or read-only memory. Optionally, the memory 405 may include a non-transitory computer-readable storage medium. The memory 405 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 405 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 405 may also be at least one storage device located remotely from the aforementioned processor 401. Figure 4 As shown, the memory 405, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and application programs.
[0190] exist Figure 4 In the server 400 shown, the user interface 403 is mainly used to provide an input interface for the user and obtain the user input data; while the processor 401 can be used to call the application program stored in the memory 405 and specifically execute, such as Figure 2 The method shown can be referred to for details. Figure 2 As shown, it will not be elaborated further here.
[0191] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory, or random access memory, etc.
[0192] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. A grid-based water depth prediction method based on the LSH attention mechanism, characterized in that, include: Collect B batches of boundary flow time series data and B batches of grid water depth time series data of the target watershed from the output of the two-dimensional IFMS model; The watershed is divided into N grids, and the watershed has M boundaries. The boundary flow time series data of each batch includes T time points and the flow values of the M boundaries associated with each time point. The grid water depth time series data of each batch includes the T time points and the water depth values of the N grids associated with each time point. B is an integer greater than 0, and M and N are integers greater than 1. The collected data is standardized. The first feature tensor is constructed based on the standardized data; the dimension of the first feature tensor is B×T×(N+M). The first feature tensor is transposed in terms of time and feature dimensions to obtain the second feature tensor; the dimension of the second feature tensor is B×(N+M)×T. Using the Reformer model, based on the projection of the second feature tensor and the weight matrix, query vector, key vector, and value vector are generated; Each feature vector is bucketed using a random rotation hash function; For each subset of feature vectors within a hash bucket, compute the attention matrix; Merge the outputs of all hash buckets, restore the original feature vector order, and obtain the final weighted feature tensor; The weighted feature tensor is decoded using a pre-trained iTransformer to obtain the water depth prediction values for each grid at future time points.
2. The method according to claim 1, characterized in that, The standardization process for the collected data includes: Iterate through all batches, all time points, and all boundary locations to calculate the global average and global standard deviation of traffic. Iterate through all batches, all time points, and all grid cells to calculate the global mean and global standard deviation of water depth; The standardized flow value is obtained by subtracting the global average flow value from each flow value and then dividing by the global standard deviation of the flow. The standardized water depth value is obtained by subtracting the global average water depth value from each water depth value and then dividing by the global standard deviation of the water depth value.
3. The method according to claim 2, characterized in that, A dual-channel memory buffer is established to simultaneously load B batches of boundary flow time-series data and B batches of grid depth time-series data. During the standardization process, the two data sets share the time dimension.
4. The method according to claim 1, 2, or 3, characterized in that, The watershed is divided into N grids, including: Determine the scope of the watershed; The watershed is randomly divided into a small number of initial grids; Traverse each grid and calculate its slope, elevation standard deviation, and location information; If the calculated slope is greater than the slope threshold, the elevation standard deviation is greater than the elevation threshold, and the grid is connected to the watershed boundary, the grid is identified as a high-complexity grid, and then the high-complexity grid is divided into 4 smaller grids. Otherwise, the grid is identified as a low-complexity grid; Merge two adjacent low-complexity grids.
5. The method according to claim 4, characterized in that, Perform the transpose operation according to the following formula: Xtransposed = X.permute(0,2,1); X represents the first feature tensor, and Xtransposed represents the transposed second feature tensor.
6. The method according to claim 1, 2, 3, or 5, characterized in that, The step of using a random rotation hash function to bucket each feature vector includes: The second feature tensor is hashed using the formula h(x) = argmax([xR; -xR]), which assigns similar features to the same hash bucket; R represents a random rotation matrix with shape [dk, b / 2]. This represents the number of hash buckets.
7. The method according to claim 6, characterized in that, The attention matrix is calculated in parallel for the subset of feature vectors within each hash bucket.
8. A grid-based water depth prediction device based on the LSH attention mechanism, characterized in that, include: The acquisition unit is used to acquire B batches of boundary flow time-series data and B batches of grid water depth time-series data of the target watershed output by the two-dimensional IFMS model. The watershed is divided into N grids, and the watershed has M boundaries. Each batch of boundary flow time-series data includes T time points and the flow values of the M boundaries associated with each time point. Each batch of grid water depth time-series data includes the T time points and the water depth values of the N grids associated with each time point. B is an integer greater than 0, and M and N are integers greater than 1. The processing unit is used to standardize the collected data; The construction unit is used to construct a first feature tensor based on the standardized data; the dimension of the first feature tensor is B×T×(N+M). The transpose unit is used to transpose the first feature tensor in terms of time and feature dimension to obtain a second feature tensor; the dimension of the second feature tensor is B×(N+M)×T. The generation unit is used to generate query vectors, key vectors, and value vectors based on the projection of the second feature tensor and weight matrix using the Reformer model; Bucketing units are used to bucket each feature vector using a random rotating hash function; The computation unit is used to compute the attention matrix for a subset of feature vectors within each hash bucket; The synthesis unit is used to merge the outputs of all hash buckets, restore the original feature vector order, and obtain the final weighted feature tensor. The prediction unit is used to decode the weighted feature tensor using a pre-trained iTransformer to obtain the water depth prediction values for each grid at future time points.
9. A computer storage medium, characterized in that, The computer storage medium stores a plurality of instructions, which are adapted to be loaded by a processor and executed as method steps as claimed in any one of claims 1 to 7.
10. A server, characterized in that, include: A processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and executed the method steps as claimed in any one of claims 1 to 7.