A spatiotemporal data prediction method based on spatial grid coding and large language model
Through the spatiotemporal data prediction method based on spatial grid coding and large language model, the problems of complex dependencies and lack of real-time performance in spatiotemporal data prediction are solved, and efficient and interpretable user location prediction is achieved, which adapts to new user behaviors and reduces computing resource consumption.
Patent Information
- Application Number
- CN202510525900.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-25
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2045-04-25
AI Technical Summary
Existing spatiotemporal data prediction methods are difficult to effectively capture complex spatiotemporal dependencies, lack real-time performance and computational efficiency, and lack interpretability, and cannot meet the needs of application scenarios such as real-time traffic prediction.
A spatiotemporal data prediction method based on spatial grid coding and a large language model is adopted. By dividing the geographical area into grid cells, sequential coding and two-dimensional coding are used to generate unique identifiers. The Transformer model with attention mechanism is combined to predict user locations, and a large language model is combined to generate highly interpretable prediction results.
Explicitly capturing geographic spatial proximity and regionalized semantics improves the model's generalization and interpretability, reduces dependence on labeled data, supports small sample learning and rapid adaptation to new user behaviors, and improves the accuracy and credibility of predictions.
Smart Images

Figure CN120045633B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of artificial intelligence and spatiotemporal data analysis, and specifically relates to a spatiotemporal data prediction method based on spatial grid coding and a large language model. Background Art
[0002] Spatiotemporal data prediction is a fundamental task in human mobility research. It aims to predict a user's next destination by analyzing their movement trajectory. With the widespread adoption of mobile devices and the rapid development of positioning technology, a vast amount of spatiotemporal data (such as GPS trajectories and check-in data) has been recorded, providing a rich foundation for studying human mobility behavior. This data not only contains users' geographic locations but also encompasses multidimensional features such as time, dwell time, and activity type, providing crucial support for understanding and predicting human mobility patterns. However, existing spatiotemporal data prediction methods still face several challenges: First, data complexity: Spatiotemporal data is high-dimensional, nonlinear, and dynamically changing, making it difficult for traditional prediction models to capture complex spatiotemporal dependencies. Second, spatiotemporal dependencies: Human mobility behavior is influenced not only by temporal factors (such as time of day, day of the week, and season) but also by spatial factors (such as geographic location and regional function), necessitating the simultaneous modeling of spatiotemporal dependencies. Third, real-time requirements: Many application scenarios (such as real-time traffic prediction) require models to rapidly process dynamically changing spatiotemporal data. Existing methods suffer from limitations in both real-time performance and computational efficiency. Fourth, lack of explainability: Most existing prediction models are "black box" models, which lack the explainability of prediction results and cannot meet the needs of transparency and credibility in practical applications. Summary of the Invention
[0003] In order to solve the above problems, the present invention provides a spatiotemporal data prediction method based on spatial grid coding and a large language model.
[0004] To achieve the above-mentioned purpose, the present invention is implemented through the following technical solutions:
[0005] The present invention provides a spatiotemporal data prediction method based on spatial grid coding and a large language model, comprising the following steps:
[0006] S1. Divide the geographic area into grid cells based on its spatial extent, calculate the number of rows and columns of the grid based on the height and width of the geographic area and the size of the cells, and process the grid cells using an encoding method, where each cell is identified by a unique identifier; the encoding method includes sequential encoding and two-dimensional encoding;
[0007] Furthermore, according to the height of the geographical area and width and the size of the unit , calculate the number of rows in the grid and number of columns , the formula is as follows:
[0008] ,
[0009] in, Indicates the height of the grid, Indicates the width of the grid.
[0010] Furthermore, the encoding method includes:
[0011] Sequential coding: Grid cells are numbered sequentially in a row-first manner, from left to right and from top to bottom. The formula for numbering the grid cell in row i and column j is:
[0012] ,
[0013] in, Indicates the cell number of the sequential encoding, C is the total number of columns in the grid; in the two-dimensional encoding method, each cell is represented by a row index and a column index;
[0014] The two-dimensional encoding is: the grid cell is represented as a two-dimensional coordinate (x, y), where x represents the column index and y represents the row index. The calculation formula for numbering the grid cell in the i-th row and j-th column is:
[0015] ,
[0016] in, Indicates the unit number of the two-dimensional code;
[0017] Each grid unit generates a unique location identifier through the above encoding method. The unique identifier is a sequential number or a two-dimensional coordinate, which is used to represent the location identifier in the tuple.
[0018] S2. Based on the user's stay history, a spatiotemporal dependency model is constructed, representing each stay as a tuple. By analyzing the historical and contextual stay sequences, the user's next location is predicted; the tuple includes the start time, day of the week, stay duration, location identifier, and position identifier.
[0019] Furthermore, the user's stay record is generated through the following steps:
[0020] S211 extracts the longitude and latitude coordinates with timestamps from the GPS trajectory data, and then identifies the stop points based on distance and time thresholds;
[0021] S212. Cluster the stay points using the DBSCAN clustering algorithm to generate a unique location ID for representing the location identifier in the tuple;
[0022] S213. Associate a time feature and a space feature with each stay point.
[0023] Furthermore, the spatiotemporal dependency model is a Transformer model based on the attention mechanism. The historical stay sequence and the context stay sequence are input into the spatiotemporal dependency model to predict the user's next location, including the following steps:
[0024] S221. Data preprocessing: Represent each stop as a tuple S = (st, dow, dur, pid, tid), where st represents the start time, dow represents the day of the week, and dur represents the duration of the stop; and pid represents the location identifier and tid represents the spatial identifier.
[0025] S222. Sequence generation and filling mechanism: Select all the user's stay points in the past T days ,common A stopover point Stops are sorted by time and then truncated or padded to a fixed length , get the historical stay sequence M; select the stay points in the last Δt hours ,common A stopover point Stops are sorted by time and then truncated or padded to a fixed length , get the context stay sequence N; merge the historical stay sequence M and the context stay sequence N to get the input sequence , , The feature representation dimension representing each stay point;
[0026] S223. Input sequence The tuples in are jointly encoded with spatiotemporal features:
[0027] The start time st is encoded by sinusoidal position coding to obtain the start time vector , , the formula is as follows:
[0028] ,
[0029] ,
[0030] in, Represents the dimension index, ; represents the dimension of time encoding, represents the cosine function, represents the sine function, Indicates the start time In even dimensions The encoded value of the dimension, Indicates the start time In odd dimensions The encoded value of the dimension; through the learnable embedding table , convert the day of the week dow into a week embedding vector , represents the original dimension of the embedding vector;
[0031] based on Mesh partitioning to construct embedding matrix , and then obtain the location identifier vector , Represents the dimension of the embedding matrix; the operation steps are: each grid cell generates a unique location identifier tid through sequential encoding or two-dimensional encoding, and the embedding matrix is initialized to a Gaussian distribution , in the training, the cosine similarity of the embedding vectors of adjacent grids is improved through back propagation optimization and clustered in the embedding space, and finally the embedding matrix is obtained through table lookup operation. Get the location identifier vector from ;
[0032] The start time vector , weekday embedding vector and a vector of location identifiers After splicing, linear mapping is performed to obtain the fused comprehensive feature vector, which is expressed as follows:
[0033] ,
[0034] in, represents the integrated feature vector after fusion, represents the weight matrix of the linear projection, represents the bias term of the linear projection, represents the concatenation vector, Represents matrix multiplication;
[0035] The input sequence The fused comprehensive feature vectors corresponding to the L stop points are stacked to form a comprehensive feature vector matrix: ,
[0036] ,
[0037] in, Indicates the The fused comprehensive feature vector, represents the comprehensive eigenvector matrix;
[0038] Furthermore, the learnable embedding table At the beginning of model training, the uniformly distributed random initialization is used to contain 7 row vectors from Monday to Sunday. The parameters are optimized through end-to-end training, so that the embedding vectors of Monday to Friday are clustered in the latent space, and Saturday and Sunday form independent semantic clusters. The embedding vector of the day of the week is obtained through linear transformation. .
[0039] Furthermore, the table lookup operation is specifically to input the unique location identifier tid of the grid unit, use tid as the row index, and locate the embedded matrix The corresponding row of , the output directly returns the row vector.
[0040] S224. Input the comprehensive feature vector matrix into the spatiotemporal dependency model to predict the probability distribution of the user's next location.
[0041] Furthermore, the spatiotemporal dependency model includes 6 encoder layers and prediction layers. Each encoder layer includes a multi-head attention sublayer, a residual connection and layer normalization layer, a feedforward network sublayer, and a quadratic residual and normalization layer. The operation process is as follows:
[0042] In the first encoder layer, the integrated feature vector matrix The input to the multi-head attention sublayer is split into 8 independent subspaces according to the number of heads; each head generates a query through a learnable weight matrix ,key Sum ; Calculate the scaled dot product attention for each head and get the output of each attention head ; Concatenate the outputs of the 8 attention heads and pass them through the weight matrix Perform linear transformation to obtain the output of the multi-head attention sub-layer , the formula is: ; The output of the multi-head attention sublayer After residual connection and layer normalization layer and comprehensive feature vector matrix Perform residual connection and normalization to obtain the output of residual connection and layer normalization layer , the formula is as follows:
[0043] ,
[0044] in, Represents the layer normalization processing operation; the residual connection is connected to the output of the layer normalization layer After being processed by the two-layer fully connected network of the feedforward network sublayer, the output of the feedforward network sublayer is obtained , the formula is as follows:
[0045] ,
[0046] in, represents a nonlinear activation function, and Represent the weight matrices of the first and second fully connected layers respectively; and Represents the bias vectors of the first and second fully connected layers respectively; the output of the feedforward network sublayer After the quadratic residual and normalization layer and the residual connection and layer normalization layer output Perform residual connection and normalization to finally get the output of the first layer encoder , the formula is: ;
[0047] The output of the first layer encoder As the input of the second layer encoder, repeat the above operation until the output of the sixth layer encoder is obtained ;
[0048] In the prediction layer, the end vector of the sequence is extracted from the output of the sixth layer encoder , through the weight matrix The end vector of the sequence Mapped to the candidate location set, the probability distribution of the user's next location is obtained, which is expressed as follows:
[0049] ,
[0050] in, represents the total number of candidate positions, Represents learning different positions and The association weight of Indicates the user's next location for The probability distribution of Represents the bias vector of the prediction layer.
[0051] S3. Combined with a large language model, a spatiotemporal instruction optimization prompt template is designed. By introducing grid coding and context-aware reasoning, the model is guided to analyze historical data and context data, generate the next position prediction, and provide explanations for each prediction.
[0052] Furthermore, the spatiotemporal instruction optimization prompt template includes a probability mapping module, an instruction generation module, an explanation generation module, and a result verification module;
[0053] The probability distribution of the user's next location The input is sent to the probability mapping module, and the probability distribution is sorted in descending order to select the top K positions with the highest probability values. Then, the positions with probabilities greater than the threshold are filtered and retained. If the number of candidates is less than K, all positions that meet the threshold are retained. Finally, a sorted list of candidate positions is obtained.
[0054] The historical stay sequence M, the context stay sequence N, and the sorted candidate location list are input into the instruction generation module. The structured template engine converts the original input data into standard JSON instructions. First, the structured data is converted into serialized text data. Then, the serialized text data is injected into the predefined JSON template to obtain a complete JSON instruction that can be parsed.
[0055] The complete JSON instruction is input into the explanation generation module to generate a structured explanation. The explanation generation module uses a large language model;
[0056] The structured interpretation is input into the result verification module for quality control and standardization.
[0057] The advantages of the present invention are:
[0058] Through grid-based encoding, the model explicitly captures geographic proximity and regional semantics, avoiding the prediction bias caused by isolated location IDs in traditional methods. A unified gridding rule ensures model consistency across different geographic regions (e.g., across cities), further enhancing generalization. Enhanced spatiotemporal dynamic modeling capabilities: The combination of the Transformer model and a hierarchical modeling strategy enables accurate prediction of user spatiotemporal behavior. This hierarchical modeling strategy employs a phased, multi-granular architecture. At the feature fusion level, a primary linear fusion of time encoding, week embedding, and grid embedding is performed, followed by cross-enhancement of long- and short-term features through the high-level Transformer layer. This layered approach enables the model to explicitly distinguish between long-term periodic patterns and short-term bursts, enabling the model to adaptively distinguish between these two. Zero-shot inference based on natural language instruction templates significantly reduces reliance on labeled data. For example, when deploying in a new city, only gridding parameters (e.g., grid size) need to be adjusted to generate predictions, without retraining the model. In contrast, traditional deep learning methods (e.g., Transformers) require retraining the embedding layer for each region, consuming significant computational resources. In addition, the reasoning process driven by the large language model supports small-sample learning and can adapt to new user behavior patterns with only a small number of examples, further expanding the scope of application. By directly outputting prediction reasons through the large language model, users can intuitively understand the model's decision logic and improve the credibility of decisions. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.
[0060] Figure 1 Flow chart of the steps of the method of the present invention. DETAILED DESCRIPTION
[0061] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments derived by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0062] Example 1
[0063] In this embodiment, Figure 1 As shown, the present invention provides a spatiotemporal data prediction method based on spatial grid coding and a large language model, the specific steps of which include:
[0064] S1. Divide the geographic area into grid cells based on its spatial extent, calculate the number of rows and columns of the grid based on the height and width of the geographic area and the size of the cells, and process the grid cells using an encoding method to ensure spatial continuity and adjacency. Each cell is identified by a unique identifier; the encoding method includes sequential encoding and two-dimensional encoding.
[0065] Specifically, according to the height of the geographical area and width and the size of the unit , calculate the number of rows in the grid and number of columns , the formula is as follows:
[0066]
[0067] in, Indicates the height of the grid, Indicates the width of the grid.
[0068] Specifically, the encoding method includes:
[0069] Sequential coding: Grid cells are numbered sequentially in a row-first manner, from left to right and from top to bottom. The formula for numbering the grid cell in row i and column j is:
[0070] ,
[0071] in, Indicates the cell number of the sequential encoding, C is the total number of columns in the grid; in the two-dimensional encoding method, each cell is represented by a row index and a column index;
[0072] The two-dimensional encoding is: the grid cell is represented as a two-dimensional coordinate (x, y), where x represents the column index and y represents the row index. The calculation formula for numbering the grid cell in the i-th row and j-th column is:
[0073] ,
[0074] in, Indicates the unit number of the two-dimensional code;
[0075] Each grid unit generates a unique location identifier through the above encoding method. The unique identifier is a sequential number or a two-dimensional coordinate, which is used to represent the location identifier in the tuple.
[0076] S2. Based on the user's stay history, a spatiotemporal dependency model is constructed, representing each stay as a tuple. By analyzing the historical and contextual stay sequences, the user's next location is predicted; the tuple includes the start time, day of the week, stay duration, location identifier, and position identifier.
[0077] Specifically, the user's stay record is generated through the following steps:
[0078] S211 extracts the longitude and latitude coordinates with timestamps from the GPS trajectory data, and then identifies the stay point based on the distance and time threshold; if the user stays within a 200-meter radius for more than 30 minutes, it is considered a stay point;
[0079] S212. Cluster the stay points using the DBSCAN clustering algorithm to generate a unique location ID, which is used to represent the location identifier in the tuple. This location ID is dynamically generated by DBSCAN clustering and depends on the actual distribution density of the user's stay points. Even if two stay points belong to the same grid cell (the same If the physical distance exceeds the clustering threshold, the points may be divided into different clusters (different location IDs); conversely, stay points across grids may be clustered into the same location ID. The DBSCAN parameters are set to a neighborhood radius of 200 meters, and the minimum number of samples is adjusted according to the data distribution. Isolated points that do not form valid clusters (such as short stays or GPS drift points) are filtered out, and only points with significant stay significance are retained.
[0080] S213. Associate a time feature and a space feature with each stay point.
[0081] Specifically, the spatiotemporal dependency model is a Transformer model based on the attention mechanism. The historical stay sequence and the context stay sequence are input into the spatiotemporal dependency model to predict the user's next location, including the following steps:
[0082] S221. Data preprocessing: Represent each stop as a tuple S = (st, dow, dur, pid, tid), where st represents the start time, dow represents the day of the week, and dur represents the duration of the stop; and pid represents the location identifier and tid represents the spatial identifier.
[0083] S222. Sequence generation and filling mechanism: Select all the user's stay points in the past T days ,common A stopover point Stops are sorted by time and then truncated or padded to a fixed length , get the historical stay sequence M; select the stay points in the last Δt hours ,common A stopover point Stops are sorted by time and then truncated or padded to a fixed length , get the context stay sequence N; merge the historical stay sequence M and the context stay sequence N to get the input sequence , , The feature representation dimension for each stay point; preferably, 1. Historical sequence M: Time range: stay points within the past T = 14 days, sorted by time and truncated / padded to length =100; after sorting by time from earliest to latest, if the number of stay points exceeds 100, only the most recent 100 will be retained (i.e., the older data will be truncated); if the number of stay points is less than 100, a zero vector will be added to the beginning of the sequence. 2. Context sequence N: Time range: the stay points within the last Δt=24 hours, sorted by time and truncated / padded to length =100 (the truncation / filling method is the same as the historical series).
[0084] S223. Input sequence The tuples in are jointly encoded with spatiotemporal features:
[0085] The start time st is encoded by sinusoidal position coding to obtain the start time vector , , the formula is as follows:
[0086] ,
[0087] ,
[0088] in, Represents the dimension index, , The dimension representing time coding determines the expressive power of time features. ; represents the cosine function, represents the sine function, Indicates the start time In even dimensions The encoded value of the dimension, Indicates the start time In odd dimensions The encoded value of the dimension; through the learnable embedding table , convert the day of the week dow into a week embedding vector , represents the original dimension of the embedding vector; preferably, the learnable embedding table At the beginning of model training, the model is randomly initialized by uniform distribution, including 7 row vectors from Monday to Sunday. The default is 64. Through end-to-end training and parameter optimization, the embedding vectors of Monday to Friday are clustered in the latent space, and Saturday and Sunday form independent semantic clusters. If the output dimension is 64, the embedding vector of the day of the week is obtained through linear transformation. , .
[0089] based on Mesh partitioning to construct embedding matrix , and then obtain the location identifier vector , represents the dimension of the embedding matrix, =256; the operation steps are: each grid cell generates a unique location identifier tid through sequential coding or two-dimensional coding, and the embedding matrix is initialized to a Gaussian distribution , in the training, the cosine similarity of the embedding vectors of adjacent grids is improved through back propagation optimization and clustered in the embedding space, and finally the embedding matrix is obtained through table lookup operation. Get the 256-dimensional position identifier vector from Preferably, the table lookup operation is specifically to input the unique location identifier tid of the grid unit, use tid as the row index, and locate the embedded matrix The corresponding row of , the output directly returns the 256-dimensional vector of the row.
[0090] The start time vector , weekday embedding vector and a vector of location identifiers After splicing, linear mapping is performed to obtain the fused comprehensive feature vector, which is expressed as follows:
[0091] ,
[0092] in, represents the integrated feature vector after fusion, ; represents the weight matrix of the linear projection, ; represents the bias term of the linear projection, represents the concatenation vector, Represents matrix multiplication;
[0093] The input sequence The fused comprehensive feature vectors corresponding to the L stop points are stacked to form a comprehensive feature vector matrix: ,
[0094] ,
[0095] in, Indicates the The fused comprehensive feature vector, represents the comprehensive eigenvector matrix;
[0096] S224. Input the comprehensive feature vector matrix into the spatiotemporal dependency model to predict the probability distribution of the user's next location.
[0097] Specifically, the spatiotemporal dependency model includes 6 encoder layers and prediction layers. Each encoder includes a multi-head attention sublayer, a residual connection and layer normalization layer, a feedforward network sublayer, and a quadratic residual and normalization layer. The operation process is as follows:
[0098] In the first encoder layer, the integrated feature vector matrix The input to the multi-head attention sublayer is split into 8 independent subspaces according to the number of heads; the dimension of each attention head is for , each head generates a query through a learnable weight matrix ,key Sum , the formula is as follows:
[0099] ,
[0100] ,
[0101] ,
[0102] ,
[0103] in, 、 、 Respectively represent queries ,key Sum The learnable weight matrix; calculate the scaled dot product attention for each head to get the output of each attention head , the formula is as follows:
[0104] ,
[0105] in, Represents the Softmax function; concatenate the outputs of the 8 attention heads into a 512-dimensional vector and pass it through the weight matrix Perform linear transformation to obtain the output of the multi-head attention sub-layer , the formula is: ; The output of the multi-head attention sublayer After residual connection and layer normalization layer and comprehensive feature vector matrix Perform residual connection and normalization to obtain the output of residual connection and layer normalization layer , the formula is as follows:
[0106] ,
[0107] in, Represents the layer normalization processing operation; the residual connection is connected to the output of the layer normalization layer After being processed by the two-layer fully connected network of the feedforward network sublayer, the output of the feedforward network sublayer is obtained , the formula is as follows:
[0108] ,
[0109] in, represents a nonlinear activation function, and Represent the weight matrices of the first and second fully connected layers respectively, ; and Represents the bias vectors of the first and second fully connected layers respectively; the output of the feedforward network sublayer After the quadratic residual and normalization layer and the residual connection and layer normalization layer output Perform residual connection and normalization to finally get the output of the first layer encoder , the formula is: ;
[0110] The output of the first layer encoder As the input of the second layer encoder, repeat the above operation until the output of the sixth layer encoder is obtained ;
[0111] In the prediction layer, the end vector of the sequence is extracted from the output of the sixth layer encoder , further, after the user stay sequence is processed by the six-layer encoder, the sixth layer outputs Contains high-order spatiotemporal feature representations for each time step. Since the input sequence is strictly arranged in ascending time order (the earliest behavior is at the beginning and the latest behavior is at the end), the system directly extracts the last row vector of the matrix As the spatiotemporal state encoding of the user at the latest moment, where L is the sequence length (L= ); through the weight matrix The end vector of the sequence Mapped to the candidate location set, the probability distribution of the user's next location is obtained, which is expressed as follows:
[0112] ,
[0113] in, Indicates the total number of candidate locations (i.e., the number of grids ), Represents learning different positions and The association weight of Indicates the user's next location for The probability distribution of Represents the bias vector of the prediction layer.
[0114] S3. Combined with a large language model, a spatiotemporal instruction optimization prompt template is designed. By introducing grid coding and context-aware reasoning, the model is guided to analyze historical data and context data, generate the next position prediction, and provide explanations for each prediction, thereby enhancing the interpretability and reliability of the model.
[0115] Specifically, the spatiotemporal instruction optimization prompt template includes a probability mapping module, an instruction generation module, an explanation generation module, and a result verification module;
[0116] The probability distribution of the user's next location Input to the probability mapping module, the probability distribution is sorted in descending order, and the top K positions with the highest probability values are selected. Then, they are filtered according to the probability threshold, and positions with probabilities greater than the threshold are retained. If the number of candidates is less than K, all positions that meet the threshold are retained. Finally, a sorted list of candidate positions is obtained. The steps are as follows: the longitude and latitude coordinates in the user trajectory data are mapped to a unified location identifier tid through geographic grid division, and then all coordinate points corresponding to each location identifier tid are subjected to DBSCAN spatial clustering analysis. By setting the neighborhood radius eps and the minimum number of points min_samples parameters, different semantic areas in the same grid are divided into independent clusters, and each cluster is assigned a semantic location with a hierarchical structure: the location identifier pid. Noise points that are not classified into any cluster during the clustering process will be directly eliminated. Finally, a mapping dictionary with the location identifier tid as the key and the location identifier pid as the value is constructed.
[0117] During the preprocessing phase, the system first maps the longitude and latitude coordinates in the user trajectory data to a unified grid cell identifier (TID) using a geographic grid. For example, using a 10×10 grid, each coordinate point is assigned a unique TID value based on its row and column position. Next, to enrich these grid locations with richer semantic information, the system performs DBSCAN spatial clustering analysis on all coordinate points corresponding to each TID. By setting parameters such as the neighborhood radius (eps) and the minimum number of points (min_samples), the system separates semantically distinct areas within the same grid (such as the main entrance of a shopping mall and the parking lot) into independent clusters. Each cluster is assigned a hierarchical semantic location ID (PID), typically in the form of a combination of "tid_clusterIndex" to ensure global uniqueness. Noise points that are not assigned to any cluster are directly eliminated during the clustering process. Ultimately, the system constructs a mapping dictionary with tid as the key and the corresponding pid list as the value. During the candidate location screening phase, each location is first calculated based on its coordinates to obtain its tid. The mapping table is then queried to obtain its semantic pid. If the tid does not exist in the mapping table or the corresponding pid list is empty, the location is marked as "unknown" and removed from the candidate list. This ensures that the location data processed by the model retains the spatial structure of the grid while incorporating the semantic hierarchical information brought by clustering, while effectively filtering out noise points in the data. This processing method enables subsequent spatiotemporal prediction models to be trained and inferred based on richer semantic location information.
[0118] The historical stay sequence M, the context stay sequence N, and the sorted list of candidate positions are input into the instruction generation module. The structured template engine converts the original input data into strictly standardized JSON instructions: First, the structured data is converted into serialized text data; then the serialized text data is injected into a predefined JSON template to obtain a complete and parsable JSON instruction;
[0119] The structured template engine first receives the historical stay sequence M ([{pid: "1230", tid: 35, st: "2023-10-01 09:00:00", dow: "Monday", dur: 60}]), the context stay sequence N (in the same format as M), and the filtered Top-K list of candidate positions. The list of candidate positions is as follows:
[0120] ([{pid: "7890", tid: 55, prob: 0.72}, {pid: "5671", tid: 46, prob: 0.15}]). These structured data are converted into serialized text data: The historical sequence is organized as "User's stay records in the past 14 days: Location 1230 (grid 35) stayed for 60 minutes at 09:00 on October 1st (Monday)..." The context sequence is converted into "Recent 24-hour activities: Location 5671 (grid 46) stayed for 30 minutes..." The candidate positions are sorted by probability as "1. Location 7890 (grid 55, probability 72%) 2. Location 5671 (grid 46, probability 15%)". These serialized text data are then injected into a predefined JSON template, which already has three key data blocks (history, context, candidates) and strict response requirements. For example, it is mandatory to include the predicted_pid field, and it is stipulated that the explanation must be presented in three dimensions: historical pattern (calculating the frequency of occurrence of the target location in the historical data), spatial relationship (calculating the Manhattan distance based on grid encoding), and time dependence (counting the proportion of accesses during the same time period). When processing the candidate position with pid = "7890" and prob = 0.72, the template engine will automatically emphasize in the instruction that it is necessary to focus on analyzing the historical access pattern of this location in the early morning on weekdays (such as the frequency of occurrence reaching 60%), the grid distance from the current location (such as 2 units apart), and the proportion of accesses during the 09:00 - 10:00 period (such as 42%). Finally, a complete JSON instruction that can be parsed by the machine is generated, and its structure fully follows the preset template, ensuring that the downstream large language model can accurately understand the task requirements.
[0121] The complete JSON instruction is input into the explanation generation module to generate a structured explanation. The explanation generation module uses a large language model. After receiving the JSON structured instruction, the GPT-3.5 model generates a structured explanation through the following process: First, the model receives serialized text input from the instruction generation module. This input contains the user's historical stay records, context location information, and a list of candidate locations. The model calculates word unit weights through the decoder's self-attention mechanism and uses beam search (beam width k=3) to generate coherent text. During the generation process, the model organizes content based on a predefined logical chain (historical regularity → spatial proximity → temporal dependency). The output is an itemized explanation content (historical pattern, spatial relationship, temporal dependency). Historical pattern: The access frequency is counted from the user's historical record (for example, pid1 appears 5 times every Monday), and the large language model summarizes it into natural language. Spatial relationship: The grid distance (such as Manhattan distance) between the predicted location and the context location is calculated: If ≤ 1, the location is marked as adjacent. Time dependency: The visit ratio of the location in the same time period (e.g., 17:00-18:00) in the entire data is calculated and converted into a peak period description by the model.
[0122] The structured explanations are fed into the result validation module for quality control and standardization. This module performs comprehensive quality control and standardization on prediction results generated by GPT-3.5. Upon receiving the natural language output of the model (e.g., JSON data containing the predicted location ID and three explanations), the validation engine first rigorously checks that the output structure conforms to pre-set specifications. This includes confirming that the predicted_pid field exists and is a valid location identifier, that the probability value is within the 0-1 range, and that the three explanation dimensions—historical patterns, spatial relationships, and temporal dependencies—are intact. The system then performs in-depth logical consistency verification: verifying the accuracy of spatial relationship descriptions by recalculating the Manhattan distance between grid coordinates; confirming that the access frequency is consistent with the original data by querying the historical database; and verifying that the temporal distribution statistics are reasonably calculated. For results that pass validation, the module performs standardization transformations and extracts key metrics to generate structured output. Missing fields, data inconsistencies, or calculation discrepancies are detected, resulting in a validation failure and triggering a result regeneration process. This ensures that the final prediction results maintain the readability of natural language while maintaining a rigorous structure that is machine-readable.
[0123] Example 2
[0124] This example describes the prediction process of the method of the present invention in detail based on actual application scenarios, combined with data and processes. This example takes the user location prediction in urban areas as an example, covering the complete process from geographical area division to final location prediction. In an urban area, the geographical range is highly = 10 km and width = 15 km, and the goal is to predict the user's next location within that area. The following are the specific steps:
[0125] Step S1: Divide the geographic area into grid cells according to its spatial extent. Calculate the number of rows and columns of the grid based on the height and width of the geographic area and the size of the cells. Then, process the spatial data using sequential coding or two-dimensional coding to ensure that spatial continuity and adjacency are preserved. Finally, identify each cell with a unique identifier.
[0126] Step S2: Based on the user's stay history, a spatiotemporal dependency model is constructed, each stay is represented as a tuple (start time, day of the week, stay duration, place identifier, location identifier), and the user's next location is predicted by analyzing the historical stay sequence and the context stay sequence;
[0127] Step S3: Combined with the large language model, a spatiotemporal instruction optimization prompt template is designed. By introducing grid coding and context-aware reasoning, the model is guided to analyze historical data and context data, generate the next position prediction, and provide explanations for each prediction, thereby enhancing the interpretability and reliability of the model.
[0128] Furthermore, in step S1, the grid division and encoding steps include:
[0129] Meshing: The size of the grid cells is set to the height = 1 km and width = 1 km. Calculate the number of rows and columns of the grid:
[0130] ,
[0131] ,
[0132] Therefore, the geographical area is divided into 10×15 grid cells.
[0133] Encode the grid:
[0134] Sequential encoding: Each grid cell is encoded in a row-first manner. For example, the grid cell in row i and column j is encoded as: For example, the grid cell at row 3 and column 5 is encoded as: 3 15 5=50;
[0135] Two-dimensional encoding: Each grid cell is represented by a two-dimensional encoding (x, y), where x represents the column index and y represents the row index. For example, the grid cell at row 3 and column 5 is represented as (5-1, 3-1) = (4, 2).
[0136] Each grid cell generates a unique identifier (sequential encoding or two-dimensional encoding) through the above encoding method, which is used as the input of the spatiotemporal dependency model.
[0137] Furthermore, in step S2, the step of constructing the spatiotemporal dependency model includes:
[0138] Data preparation: The user's stay record is represented as a tuple S = (st, dow, dur, pid, tid), where
[0139] st: start time, the starting time of the stay (such as "2023-10-01 09:00:00");
[0140] dow: day of the week, the day of the week to stay on (such as "Monday");
[0141] dur: duration of stay, length of stay (e.g. “60” minutes);
[0142] pid: location identifier, a unique identifier of the place you stayed (such as "1234");
[0143] tid: location identifier, which is the unique identifier of the grid cell where the stop is located (the result of encoding the grid, such as "50" or "(4, 2)");
[0144] Example data:
[0145] = (2023-10-01 09:00:00, Monday, 60, 1234, 35);
[0146] = (2023-10-01 10:00:00, Monday, 30, 5678, 46);
[0147] = (2023-10-01 12:00:00, Monday, 90, 9012, 55);
[0148] Historical stay sequence and contextual stay sequence: Assume that the user's stay sequence is , where Q is the sequence length 3. The historical stay sequence M includes the user's stay records in the past month and is used to capture long-term mobility patterns. The contextual stay sequence N includes the user's stay records in the past 24 hours and is used to capture recent mobility patterns.
[0149] Constructing a spatiotemporal dependency model: The model input is the historical stay sequence M and the context stay sequence N, expressed as: The model uses a Transformer model based on the attention mechanism to fuse temporal and spatial features. The temporal features st and dow are encoded as a time vector. The spatial feature tid is encoded as a grid embedding vector (based on the grid division of R and C). The model output is the predicted probability distribution of the user's next location, for example:
[0150]
[0151]
[0152]
[0153] Output description: tid: target grid location identifier (sequential encoding or two-dimensional encoding); prob: the probability that the user's next location belongs to this grid cell; the output is sorted in descending order of probability, and the top 3 results are retained to enhance interpretability.
[0154] Furthermore, in step S3, the design method of the spatiotemporal instruction optimization prompt template includes:
[0155] Probability Mapping Module:
[0156] Input: Probability distribution of spatiotemporal dependency model output:
[0157] ;
[0158] Construction method and processing flow
[0159] 1. Candidate location screening: Top-K selection (K=3): select the top three items with the highest probability; probability threshold filtering (threshold = 0.05): eliminate items with a probability < 0.05 (for example, retain all in the example);
[0160] 2. tid→pid mapping: Convert semantic location IDs based on the pre-processed mapping table (e.g., {55:1234,46:5678,35:9012}). If a tid is not in the mapping table (e.g., a new grid cell), it is marked as "unknown" and removed.
[0161] Output: sorted list of candidate locations:
[0162] [{"pid":1234,"tid":55,"prob":0.72},
[0163] {"pid":5678,"tid":46,"prob":0.15},
[0164] {"pid":9012,"tid":35,"prob":0.08}].
[0165] Instruction generation module:
[0166] After receiving structured input data, this module converts it into JSON instructions that can be parsed by the large language model through the template engine;
[0167] The input consists of a historical dwell sequence M: [{"pid":1234,"st":"2023-09-01 08:30:00","tid":35,"dur":45}, ...] (representing the user's behavior patterns over the past month), a contextual dwell sequence N: [{"pid":1234,"st":"2023-10-01 09:00:00","tid":35,"dur":60}, ...] (reflecting recent activity), and a list of candidate locations (sorted by probability). First, the historical data is converted into a natural language description, such as "The user's dwell history over the past 14 days shows frequent visits to grid 35 (location 1234) every Monday morning." The contextual data is converted into "Spent 60 minutes in grid 35 in the last 24 hours." The candidate locations are formatted as "1. Grid 55 (72% probability) 2. Grid 46 (15%)." This information is injected into a strictly defined JSON template to generate structured instructions containing three major data blocks (history, recent activities, and candidate locations) and clear response requirements. It is specifically stipulated that predicted_pid must be output and an explanation including three dimensions: historical patterns (such as periodic access statistics), spatial relationships (grid distance calculation), and time dependencies (time period proportion analysis).
[0168] Explanation of the generated module:
[0169] In the explanation generation module, after GPT-3.5 receives the instruction from the instruction generation module, the system processes it into the final output: the predicted location pid=1234, with a detailed explanation, including historical patterns (8 visits every Monday at 9:00 am in the past month, with significant periodicity), spatial relationships (although the predicted grid 55 is actually 9 units away from the current grid 46, it is located along the subway line, which is in line with commuting habits), and time dependency (the location accounts for 78% of visits between 9:00 and 10:00, and the current Monday at 09:30 perfectly matches the user behavior pattern).
[0170] Result verification module
[0171] Input: Model generated text (example): {predicted_pid:1234, explanation:{...}};
[0172] Output: format verification results (pass / fail) and standardized final output;
[0173] Example output: {status: passed, predicted_pid: 1234, explanation: ,...}.
[0174] Example 3
[0175] In this embodiment, the experimental data of the method of the present invention and the existing method are compared:
[0176] 1. Experimental Setup and Dataset
[0177] The experiment was based on the Geolife dataset from Microsoft Research Asia, which contains GPS trajectory data from 182 users, covering over three years of movement history, totaling 17,621 tracks. Data preprocessing involved identifying stop points (stay duration ≥ 30 minutes, radius ≤ 200 meters) and clustering them using the DBSCAN algorithm to generate unique place identifiers. The data was divided into a training set (70%), a validation set (15%), and a test set (15%). Evaluation metrics included accuracy (Acc@k), weighted F1 score, and normalized discounted cumulative gain (nDCG@k).
[0178] 2. Comparison method
[0179] LSTM: A prediction method based on long short-term memory networks;
[0180] LSTM-SA: LSTM model combined with hierarchical self-attention mechanism;
[0181] DeepMove: Multimodal embedding recurrent neural networks.
[0182] MobTcast - Transformer-based mobile feature extractor.
[0183] MHSA: Multi-Head Self-Attention Network;
[0184] LLM-Mob: LLMs-based mobility prediction method;
[0185] LLM-ZS: LLMs method for zero-shot learning;
[0186] T-LENs (this invention): A prediction framework combining trellis coding and LLMs.
[0187] 3. Comparison of experimental results
[0188] 3.1 Prediction result data
[0189] Table 1 Performance comparison of different models using various metrics on the Geolife dataset
[0190]
[0191] The results presented in the table compare the performance of different models using various metrics on the Geolife dataset. "No time information" indicates that the prediction model does not use target time information, measuring the model's performance when time is ignored. "With time information" indicates that the prediction model uses target time information, such as time point and day of the week, to help the model better align its predictions with user mobility behavior. The proposed T-LENs framework, which combines two different encoding schemes (bold for sequential encoding and underlined for two-dimensional encoding), significantly outperforms existing baseline models in terms of accuracy and ranking-based metrics.
[0192] 3.1.1 Accuracy Improvement
[0193] The most significant improvement was observed in the Acc@1 metric, with both sequential encoding (without temporal information: 49.6%, with temporal information: 55.6%) and two-dimensional encoding (without temporal information: 49.6%, with temporal information: 53.7%) showing significant gains compared to the best learned baseline (MHSA, 31.4%). This improvement can be attributed to the fact that spatial encodings more effectively capture spatial relationships than traditional location ID-based methods. Specifically, by encoding locations based on their spatial relationships, the model can better understand and predict frequently visited or adjacent locations, especially for top-ranked predictions.
[0194] 3.1.2 Enhancement of Weighted F1 and nDCG@10
[0195] The T-LENs framework also performs well on weighted F1 and nDCG@10 ranking-based metrics, which consider not only the correctness of predictions but also the order of their relevance. Sequential encoding, which uses target temporal information in the prediction model, achieves a weighted F1 score of 0.473 and nDCG@10 of 0.659, while two-dimensional encoding achieves 0.458 and 0.656, respectively. These improvements reflect the model's ability to capture both long-term and short-term spatiotemporal dependencies. The inclusion of a tiling scheme helps preserve geographic proximity and contextual patterns, enabling a more reasonable ranking of possible next positions.
[0196] 3.1.3 Influence of target time information
[0197] Another factor contributing to the performance improvement is the integration of target temporal information. For both encoding methods, adding temporal information leads to consistent improvements across all metrics. This suggests that incorporating temporal patterns, such as time of day or day of the week, helps the model better align its predictions with user mobility behavior.
[0198] 3.2 Case Study
[0199] Table 2 Case study results
[0200]
[0201] The following is a concise analysis of the case study results presented in Table 2, where the ground-truth next location is location code 13; the target time information (15:13, Friday) is a key input to the model's prediction, helping it determine which historical data is most relevant and infer the user's most likely location at that particular time. Different models handle time differently, resulting in varying predictions. We compare the predictions of LLM-Mob (k = 10) with two T-LENs variants—one using sequential encoding and the other using two-dimensional encoding. LLM-Mob places location 13 third in its prediction list, while both T-LENs (sequential encoding) and T-LENs (two-dimensional encoding) identify location 13 as the top candidate. This ranking difference is particularly important for metrics such as Acc@1 (accuracy at the top of the list) and nDCG@10, which reward higher correct prediction rankings. In LLM-Mob's (k = 10) prediction, it emphasized the user's weekend activity at location codes 54 and 55, noting that location code 13 was also frequently visited. However, the model only ranked 13 third, meaning that while LLM-Mob recognized 13's relevance, it considered 54 and 55 slightly more likely based on recency or temporal patterns. In our sequential code prediction, it attributed 13's higher ranking to the frequent weekend and Monday visits, as well as the recent context pointing to 13's continued activity. By utilizing a sequential coding scheme, T-LENs (sequential coding) more accurately captured the user's preference for 13 and its surrounding locations, leading it to elevate 13 to the top of the list. T-LENs (two-dimensional coding) emphasized spatial proximity, citing the codes near (16, 13) and (13, 18), which surround location code 13. The QR code retains the geographic coordinates, enabling the model to identify the strong association of 13 with these closely adjacent points, further confirming that 13 is the most likely next location. As a result, T-LENs demonstrates stronger prediction accuracy and better consistency with users’ actual movement patterns.
[0202] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art will be able to modify the technical solutions described in the aforementioned embodiments or substitute equivalents for some of the technical features. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention shall be included within the scope of protection of the present invention.
Claims
1. A spatiotemporal data prediction method based on spatial grid coding and large language model, characterized in that: The following steps are involved: S1. Divide the geographic area into grid cells based on its spatial extent. Calculate the number of rows and columns of the grid based on the height and width of the geographic area and the size of the cells. Use an encoding method to process the grid cells, identifying each cell with a unique identifier. The encoding method comprises: Sequential coding: Grid cells are numbered sequentially in a row-first manner, from left to right and from top to bottom. The formula for numbering the grid cell in row i and column j is: , in, Indicates the cell number of the sequential encoding, C is the total number of columns in the grid; in the two-dimensional encoding method, each cell is represented by a row index and a column index; Two-dimensional encoding: Grid cells are represented as two-dimensional coordinates (x, y), where x represents the column index and y represents the row index. The formula for numbering the grid cell in row i and column j is: , in, Indicates the unit number of the two-dimensional code; Each grid cell generates a unique location identifier through the above encoding method, wherein the unique identifier is a sequential number or a two-dimensional coordinate, which is used to represent the location identifier in the tuple; S2. Based on the user's stay history, a spatiotemporal dependency model is constructed, representing each stay as a tuple. By analyzing the historical and contextual stay sequences, the user's next location is predicted; the tuple includes the start time, day of the week, stay duration, location identifier, and position identifier. S3. Combined with a large language model, a spatiotemporal instruction optimization prompt template is designed. By introducing grid coding and context-aware reasoning, the model is guided to analyze historical data and context data, generate the next position prediction, and provide explanations for each prediction.
2. The spatiotemporal data prediction method based on spatial grid coding and large language model according to claim 1, characterized in that: In step S1, according to the height of the geographical area and width and the size of the unit , calculate the number of rows in the grid and number of columns , the formula is as follows: , in, Indicates the height of the grid, Indicates the width of the grid.
3. The spatiotemporal data prediction method based on spatial grid coding and large language model according to claim 2, characterized in that: The user's stay record in step S2 is generated by the following steps: S211 extracts the longitude and latitude coordinates with timestamps from the GPS trajectory data, and then identifies the stop points based on distance and time thresholds; S212. Cluster the stay points using the DBSCAN clustering algorithm to generate a unique location ID for representing the location identifier in the tuple; S213. Associate a time feature and a space feature with each stay point.
4. The spatiotemporal data prediction method based on spatial grid coding and large language model according to claim 3, characterized in that: In step S2, the spatiotemporal dependency model is a Transformer model based on the attention mechanism. The historical stay sequence and the context stay sequence are input into the spatiotemporal dependency model to predict the user's next location, including the following steps: S221. Data preprocessing: Represent each stop as a tuple S = (st, dow, dur, pid, tid), where st represents the start time, dow represents the day of the week, and dur represents the duration of the stop; and pid represents the location identifier and tid represents the spatial identifier. S222. Sequence generation and filling mechanism: Select all the user's stay points in the past T days ,common A stopover point Stops are sorted by time and then truncated or padded to a fixed length , get the historical stay sequence M; select the stay points in the last Δt hours ,common A stopover point Stops are sorted by time and then truncated or padded to a fixed length , get the context stay sequence N; merge the historical stay sequence M and the context stay sequence N to get the input sequence , , The feature representation dimension representing each stay point; S223. Input sequence The tuples in are jointly encoded with spatiotemporal features: The start time st is encoded by sinusoidal position coding to obtain the start time vector , , the formula is as follows: , , in, Represents the dimension index, ; represents the dimension of time encoding, represents the cosine function, represents the sine function, Indicates the start time In even dimensions The encoded value of the dimension, Indicates the start time In odd dimensions The encoded value of the dimension; through the learnable embedding table , convert the day of the week dow into a week embedding vector , represents the original dimension of the embedding vector; based on Mesh partitioning to construct embedding matrix , and then obtain the location identifier vector , Represents the dimension of the embedding matrix; the operation steps are: each grid cell generates a unique location identifier tid through sequential encoding or two-dimensional encoding, and the embedding matrix is initialized to a Gaussian distribution , in the training, the cosine similarity of the embedding vectors of adjacent grids is improved through back propagation optimization and clustered in the embedding space, and finally the embedding matrix is obtained through table lookup operation. Get the location identifier vector from ; The start time vector , weekday embedding vector and a vector of location identifiers After splicing, linear mapping is performed to obtain the fused comprehensive feature vector, which is expressed as follows: , in, represents the integrated feature vector after fusion, represents the weight matrix of the linear projection, represents the bias term of the linear projection, represents the concatenation vector, Represents matrix multiplication; The input sequence The fused comprehensive feature vectors corresponding to the L stop points are stacked to form a comprehensive feature vector matrix: , , in, Indicates the The fused comprehensive feature vector, represents the comprehensive eigenvector matrix; S224. Input the comprehensive feature vector matrix into the spatiotemporal dependency model to predict the probability distribution of the user's next location.
5. The spatiotemporal data prediction method based on spatial grid coding and large language model according to claim 4, characterized in that: The learnable embedding table in step S223 At the beginning of model training, the uniformly distributed random initialization is used to contain 7 row vectors from Monday to Sunday. The parameters are optimized through end-to-end training, so that the embedding vectors of Monday to Friday are clustered in the latent space, and Saturday and Sunday form independent semantic clusters. The embedding vector of the day of the week is obtained through linear transformation. .
6. The spatiotemporal data prediction method based on spatial grid coding and large language model according to claim 5, characterized in that: The table lookup operation in step S223 is specifically to input the unique location identifier tid of the grid unit, use tid as the row index, and locate the embedded matrix The corresponding row of , the output directly returns the row vector.
7. The spatiotemporal data prediction method based on spatial grid coding and large language model according to claim 6, characterized in that: In step S224, the spatiotemporal dependency model includes 6 layers of encoders and prediction layers. Each encoder includes a multi-head attention sublayer, a residual connection and layer normalization layer, a feedforward network sublayer, and a quadratic residual and normalization layer. The operation process is as follows: In the first encoder layer, the integrated feature vector matrix The input to the multi-head attention sublayer is split into 8 independent subspaces according to the number of heads; each head generates a query through a learnable weight matrix ,key Sum ; Calculate the scaled dot product attention for each head and get the output of each attention head ; Concatenate the outputs of the 8 attention heads and pass them through the weight matrix Perform linear transformation to obtain the output of the multi-head attention sub-layer , the formula is: ; The output of the multi-head attention sublayer After residual connection and layer normalization layer and comprehensive feature vector matrix Perform residual connection and normalization to obtain the output of residual connection and layer normalization layer , the formula is as follows: , in, Represents the layer normalization processing operation; the residual connection is connected to the output of the layer normalization layer After being processed by the two-layer fully connected network of the feedforward network sublayer, the output of the feedforward network sublayer is obtained , the formula is as follows: , in, represents a nonlinear activation function, and Represent the weight matrices of the first and second fully connected layers respectively; and Represents the bias vectors of the first and second fully connected layers respectively; the output of the feedforward network sublayer After the quadratic residual and normalization layer and the residual connection and layer normalization layer output Perform residual connection and normalization to finally get the output of the first layer encoder , the formula is: ; The output of the first layer encoder As the input of the second layer encoder, repeat the above operation until the output of the sixth layer encoder is obtained ; In the prediction layer, the end vector of the sequence is extracted from the output of the sixth layer encoder , through the weight matrix The end vector of the sequence Mapped to the candidate location set, the probability distribution of the user's next location is obtained, which is expressed as follows: , in, represents the total number of candidate positions, Represents learning different positions and The association weight of Indicates the user's next location for The probability distribution of Represents the bias vector of the prediction layer.
8. The spatiotemporal data prediction method based on spatial grid coding and large language model according to claim 7, characterized in that: Step S3 specifically includes: The spatiotemporal instruction optimization prompt template includes a probability mapping module, an instruction generation module, an explanation generation module and a result verification module; The probability distribution of the user's next location The input is sent to the probability mapping module, and the probability distribution is sorted in descending order. The top K positions with the highest probability values are selected, and then filtered according to the probability threshold. Positions with probabilities greater than the threshold are retained. If the number of candidates is less than K, all positions that meet the threshold are retained. Finally, a sorted list of candidate positions is obtained. The historical stay sequence M, the context stay sequence N, and the sorted candidate location list are input into the instruction generation module. The structured template engine converts the original input data into standard JSON instructions. First, the structured data is converted into serialized text data. Then, the serialized text data is injected into the predefined JSON template to obtain a complete JSON instruction that can be parsed. The complete JSON instruction is input into the explanation generation module to generate a structured explanation. The explanation generation module uses a large language model; The structured interpretation is input into the result verification module for quality control and standardization.
Citation Information
Patent Citations
Method and system for comparative data analysis
WO2015164910A1
Natural intelligence for natural language processing
WO2024077002A2