Data processing method and apparatus, and electronic device
By converting the absolute coordinates of trajectory data into relative coordinates and generating multi-channel images, and using the ViT encoder for feature encoding, the problems of privacy leakage and poor generalization ability in existing technologies are solved, achieving efficient and highly generalizable trajectory learning and analysis.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- WISDOM FOOTPRINT DATA TECH CO LTD
- Filing Date
- 2026-04-02
- Publication Date
- 2026-07-10
Smart Images

Figure CN122364567A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of big data technology, and more specifically, to a data processing method, apparatus, and electronic device. Background Technology
[0002] With the widespread adoption of mobile positioning technology, user trajectory data has become a key data resource in fields such as urban computing and intelligent transportation. By analyzing and modeling massive amounts of trajectory data, it is possible to uncover user movement patterns, predict future locations, and identify areas of interest, thereby providing decision support for applications such as route planning, business site selection, and public safety.
[0003] Currently, there are two main approaches to using trajectory data for model training and data analysis: One approach is trajectory sequence modeling based on absolute coordinates. This method represents a user's movement trajectory as a series of time-ordered absolute latitude and longitude coordinates and encodes this sequence using recurrent neural networks (such as LSTM and GRU) to capture the temporal dependencies in the trajectory. The final output is an embedded representation of the user's trajectory, which can be used for downstream tasks such as next location prediction. However, this approach directly processes the user's absolute latitude and longitude coordinates, exposing sensitive locations such as home address and workplace, posing a risk of privacy leakage. Furthermore, the features learned by the model are strongly coupled with specific geographical regions; a model trained in city A cannot be directly applied to city B and requires retraining, resulting in poor generalization ability. Finally, one-dimensional sequence modeling loses the neighborhood relationships in two-dimensional space, making it difficult to capture spatial patterns such as "a residential area 5 kilometers northeast of the workplace at a 40-degree angle."
[0004] The second approach is trajectory protection based on differential privacy, exemplified by DP-Traj. Its core principle is to add random noise that satisfies the definition of differential privacy to the original absolute coordinate data, and then perturb the trajectory points using a Laplace or exponential mechanism. This allows for statistical analysis or data publication while maintaining mathematically defined privacy. However, this added random noise for privacy protection disrupts the spatiotemporal continuity of the trajectory, leading to a significant drop in the performance of downstream tasks (such as clustering and prediction) and a substantial loss of utility. Furthermore, the noise mechanism for differential privacy requires noise injection at various stages of model training and data processing, increasing complexity and computational overhead. Finally, attackers can still infer some sensitive locations by combining publicly available information (such as city maps and landmark distribution), making it difficult to defend against background knowledge attacks.
[0005] Therefore, existing technologies struggle to achieve efficient and generalizable trajectory learning and analysis while ensuring user trajectory privacy and security. Summary of the Invention
[0006] The purpose of this application is to provide a data processing method, apparatus, and electronic device to improve the above-mentioned problems.
[0007] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows: In a first aspect, embodiments of this application provide a data processing method, the data processing method comprising: Acquire the user's historical spatiotemporal data, which includes multiple trajectory points, and the trajectory points include geographical location coordinates; Based on the historical spatiotemporal data, the geographical coordinates of each trajectory point are converted into relative coordinates; Based on the relative coordinates of each trajectory point, a preset standard image, and multiple pre-divided time intervals, a multi-channel image corresponding to each time interval is generated. Each pixel of the multi-channel image corresponds to at least one trajectory point, and each pixel includes multiple feature channels that characterize user behavior semantics. Each of the multi-channel images is divided into multiple image blocks, and an input sequence is generated based on all the image blocks, wherein the input sequence includes the embedding vector of each image block, the position of the image block in the multi-channel image, and the time interval to which the image block belongs; The input sequence is input into the ViT encoder for feature encoding to obtain a general feature representation that characterizes user behavior patterns. The general feature representation is used at least for supervised learning, user clustering, risk prediction, or urban computing tasks.
[0008] Optionally, the trajectory points further include dwell time, and the step of converting the geographic coordinates of each trajectory point into relative coordinates based on the historical spatiotemporal data includes: Based on the geographical coordinates and dwell time of each trajectory point, the activity weighted centroid of the user is calculated, and the activity weighted centroid represents the location of the user's behavior center; Using the active weighted centroid as the origin, the geographical coordinates of each trajectory point are converted into relative coordinates, which include the geographical distance from the trajectory point to the active weighted centroid and the orientation angle of the trajectory point relative to the active weighted centroid.
[0009] Optionally, the relative coordinates include the geographical distance from the trajectory point to the active weighted centroid and the orientation angle of the trajectory point relative to the active weighted centroid; The step of generating a multi-channel image corresponding to each time interval based on the relative coordinates of each trajectory point, a preset standard image, and multiple pre-divided time intervals includes: For each trajectory point, a piecewise nonlinear mapping function is used to convert the geographic distance into pixel distance. The piecewise nonlinear mapping function indicates that when the geographic distance is less than a set local activity radius threshold, a linear mapping is used, and when the geographic distance is greater than or equal to the local activity radius threshold, a logarithmic compression mapping is used. Based on the image size of the standard image and the pixel distance, the orientation angle is linearly mapped to obtain the pixel coordinates of the trajectory point in the standard image; For each time interval, the multi-channel features of all trajectory points with the same pixel coordinates are aggregated to obtain the multi-channel image corresponding to each time interval.
[0010] Optionally, the piecewise nonlinear mapping function satisfies the following formula:
[0011] in, Indicates the pixel distance, Indicates the geographical distance. This represents the local activity radius threshold, used to distinguish between local and long-distance activities; This represents the pixel radius corresponding to the local activity radius threshold. This represents the logarithmic compression parameter, used to control the degree of mapping compression for the long-distance activity; The linear mapping of the direction angle satisfies the following formula:
[0012]
[0013] in, Represents the pixel coordinates, Indicates the direction angle, This indicates the image size of the standard image.
[0014] Optionally, the step of aggregating multi-channel features of all trajectory points having the same pixel coordinates includes: According to the formula Aggregate multi-channel features of all trajectory points with the same pixel coordinates; where t represents the time interval. This represents the pixel coordinates, and k represents the channel. This represents the set of all trajectory points that share the same pixel coordinate. The weight represents the trajectory point p, which is obtained based on the dwell time or access frequency of the trajectory point p; This represents the feature value of trajectory point p in the k-th channel; The multi-channel features include at least normalized access frequency, dwell time features, temporal distribution features, and region of interest category probabilities, and satisfy the following formula:
[0015]
[0016]
[0017]
[0018] in, This indicates the normalized access frequency. This indicates the dwell time characteristic. This indicates the duration of stay at trajectory point p; This indicates the time distribution characteristics. The timestamp of the trajectory point p that falls within the time interval t; This represents the probability of the category of the region of interest. This represents a predefined set of geographic semantic categories.
[0019] Optionally, the step of generating the input sequence based on all the image patches includes: Each image patch is flattened and linearly projected to obtain the embedding vector of each image patch; All the embedded vectors, the learnable tag vectors used to aggregate overall user behavior information, and the user static profile tag vectors used to encode user static attribute information are concatenated to obtain a reference sequence. A spatial location encoding vector and a temporal location encoding vector are superimposed on each of the embedding vectors in the reference sequence to obtain an input sequence, wherein the spatial location encoding vector represents the position of the corresponding image patch in the multi-channel image, and the temporal location encoding vector represents the time interval to which the image patch belongs.
[0020] Optionally, the spatial location encoding vector satisfies the following formula:
[0021]
[0022] Where i represents the position index of the image patch; j represents the dimension index, starting from 0, corresponding to each dimension of the spatial position encoding vector; d represents the total dimension of the spatial position encoding vector, which is the same as the embedding dimension of the ViT encoder; 10000 represents the normalization factor, used to control the wavelength variation in different dimensions; This represents the exponential term, which determines the wavelength frequency in different dimensions.
[0023] Optionally, the step of inputting the input sequence into a ViT encoder for feature encoding to obtain a general feature representation characterizing the user behavior pattern includes: The input sequence is input into the ViT encoder for feature encoding. The ViT encoder includes a multi-layer Transformer module, and each layer of the Transformer module includes a multi-head self-attention network, a layer normalization network, and a feedforward network. The output vector corresponding to the first position is extracted from the output sequence of the last layer Transformer module of the ViT encoder, and the output vector is layer normalized to obtain the general feature representation.
[0024] Secondly, embodiments of this application provide a data processing apparatus, the data processing apparatus comprising: The acquisition module is used to acquire the user's historical spatiotemporal data, which includes multiple trajectory points, and the trajectory points include geographical location coordinates. The conversion module is used to convert the geographical coordinates of each trajectory point into relative coordinates based on the historical spatiotemporal data; The image generation module is used to generate a multi-channel image corresponding to each time interval based on the relative coordinates of each trajectory point, a preset standard image and multiple pre-divided time intervals, wherein one pixel of the multi-channel image corresponds to at least one trajectory point, and each pixel includes multiple feature channels representing user behavior semantics. A sequence generation module is used to divide each of the multi-channel images into multiple image blocks and generate an input sequence based on all the image blocks, wherein the input sequence includes the embedding vector of each image block, the position of the image block in the multi-channel image, and the time interval to which the image block belongs; The encoding module is used to input the input sequence into the ViT encoder for feature encoding to obtain a general feature representation that characterizes the user behavior pattern. The general feature representation is used at least for supervised learning, user clustering, risk prediction, or urban computing tasks.
[0025] Thirdly, embodiments of this application provide an electronic device, including a processor and a memory, wherein the memory is used to store a program, and the processor is used to implement the data processing method in the first aspect above when executing the program.
[0026] Compared to existing technologies, the data processing method, apparatus, and electronic device provided in this application first convert the geographical coordinates of each trajectory point in historical trajectory data into relative coordinates, protecting user privacy at the data source and effectively preventing the leakage of sensitive information such as home address and workplace. Then, multi-channel images are generated based on relative coordinates, preset standard images, and multiple time intervals, so that the trajectories of users in different regions are uniformly mapped to the standard images, eliminating the coupling dependency on specific geographical areas and improving the generalization ability in cross-city scenarios. Furthermore, the multi-channel images aggregate trajectory semantics at the pixel level, preserving spatial neighborhood relationships. After image block segmentation and ViT encoder processing, it can more accurately represent behavioral patterns that require global spatial reasoning, such as the spatial relationship between residential areas and workplaces. Finally, it outputs a general feature representation that can be directly adapted to various downstream tasks such as supervised learning, user clustering, risk prediction, and urban computing. Thus, while ensuring the privacy and security of user trajectory, it achieves efficient and highly generalizable trajectory learning and analysis. Attached Figure Description
[0027] Figure 1 This application provides a schematic flowchart of a data processing method according to an embodiment. Figure 1 .
[0028] Figure 2 This application provides a schematic flowchart of a data processing method according to an embodiment. Figure 2 .
[0029] Figure 3 A block diagram of a data processing apparatus provided in an embodiment of this application is shown.
[0030] Figure 4 A block diagram of an electronic device provided in an embodiment of this application is shown.
[0031] Icons: 100-Data processing device; 101-Acquisition module; 102-Conversion module; 103-Image generation module; 104-Sequence generation module; 105-Encoding module; 10-Electronic device; 11-Processor; 12-Memory; 13-Bus. Detailed Implementation
[0032] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.
[0033] The data processing method provided in this application is applied to electronic devices. The electronic device can be a computing device with big data processing and analysis capabilities, and can be deployed in a cloud data center or a regional edge server node. Optionally, the electronic device can be implemented using a standalone server or a server cluster composed of multiple servers.
[0034] Please refer to Figure 1 , Figure 1 The diagram shows a flowchart of a data processing method provided in an embodiment of this application, which may include the following steps: S101, Obtain the user's historical spatiotemporal data, which includes multiple trajectory points, and the trajectory points include geographical location coordinates; S102, based on historical spatiotemporal data, converts the geographical coordinates of each trajectory point into relative coordinates; S103, based on the relative coordinates of each trajectory point, a preset standard image and multiple pre-divided time intervals, generate a multi-channel image corresponding to each time interval, wherein one pixel of the multi-channel image corresponds to at least one trajectory point, and each pixel includes multiple feature channels representing the semantics of user behavior. S104, divide each multi-channel image into multiple image blocks, and generate an input sequence based on all image blocks, wherein the input sequence includes the embedding vector of each image block, the position of the image block in the multi-channel image, and the time interval to which the image block belongs; S105, input the input sequence into the ViT encoder for feature encoding to obtain a general feature representation that characterizes user behavior patterns, wherein the general feature representation is used at least for supervised learning, user clustering, risk prediction or urban computing tasks.
[0035] In step S101, taking user u as an example, the historical spatiotemporal data includes multiple trajectory points of user u. Each trajectory point includes a timestamp t, geographic location coordinates (lat, lon), and dwell time, forming an original observation sequence with spatiotemporal continuity. The geographic location coordinates are latitude and longitude pairs based on a global coordinate system.
[0036] In step S102, taking any trajectory point as an example, the geographical coordinates of the trajectory point are converted into relative coordinates. This can be done by first calculating the user's activity weighted centroid based on the geographical coordinates and dwell time of each trajectory point. The activity weighted centroid represents the location of the user's behavioral center. Then, taking the activity weighted centroid as the origin, the geographical coordinates of each trajectory point are converted into relative coordinates. The relative coordinates include the geographical distance from the trajectory point to the activity weighted centroid and the direction angle of the trajectory point relative to the activity weighted centroid.
[0037] In this way, the historical spatiotemporal data of user u is converted into a set of relative coordinates in polar coordinate form without any absolute geographic reference information. The relative coordinates only reflect the spatial distribution structure of the user's internal activities, completely stripping away external geographic semantics such as cities, administrative divisions or landmarks.
[0038] Optionally, taking user u as an example, its activity-weighted centroid satisfies the following formula:
[0039] in, This represents the activity-weighted centroid of user u. This represents the duration of stay at trajectory point i. The coordinates of trajectory point i represent the geographical location of the trajectory point, and N represents the number of trajectory points in the historical spatiotemporal data.
[0040] Optionally, Establish a relative polar coordinate system with the origin of user u's personal relative coordinate system, and assign each trajectory point to a polar coordinate system. Convert to relative coordinates The formula is as follows:
[0041]
[0042] in, Represents the trajectory point i, , The geographic coordinates of the weighted centroid of the activity. Indicates the trajectory point i to Geographical distance, Represents the trajectory point i relative to Direction angle (in radians) The function `atan2()` calculates the geographical distance between two points, while `atan2()` calculates the azimuth angle.
[0043] In step S103, after obtaining the relative coordinates of each trajectory point in the previous step, for each trajectory point, the geographical distance in the relative coordinates can be compressed to the pixel plane coordinates of the standard image through a piecewise nonlinear mapping function, and the orientation angle is linearly mapped to the pixel horizontal and vertical coordinate components. Then, all trajectory points at the same pixel position and belonging to the same time interval are weighted and fused according to a preset aggregation rule to form a four-dimensional tensor containing dimensions such as access frequency, dwell time, time distribution, and AOI (Area of Interest) category probability, i.e., a multi-channel image, thereby transforming the spatial behavior structure at the user's individual scale into an image-based data structure with unified geometric constraints and semantic interpretability.
[0044] In one possible implementation, Figure 1 Based on this, please refer to Figure 2 Step S103, which generates a multi-channel image for each time interval based on the relative coordinates of each trajectory point, a preset standard image, and multiple pre-divided time intervals, may include: S1031, for each trajectory point, a piecewise nonlinear mapping function is used to convert the geographic distance into pixel distance. The piecewise nonlinear mapping function indicates that when the geographic distance is less than the set local activity radius threshold, linear mapping is used, and when the geographic distance is greater than or equal to the local activity radius threshold, logarithmic compression mapping is used. S1032, Based on the image size and pixel distance of the standard image, the direction angle is linearly mapped to obtain the pixel coordinates of the trajectory point in the standard image; S1033, for each time interval, aggregate the multi-channel features of all trajectory points with the same pixel coordinates to obtain the multi-channel image corresponding to each time interval.
[0045] In sub-step S1031, geographic distance refers to the spherical distance from the trajectory point to the weighted centroid of user activity. The local activity radius threshold is a pre-set geographic range parameter used to distinguish between two types of behavioral patterns: high-frequency short-distance activity and low-frequency long-distance activity. Within the linear mapping interval, geographic distance is directly proportional to pixel distance, ensuring spatial resolution for localized behaviors such as living, working, and commuting. Within the logarithmic compression mapping interval, geographic distance growth is progressively compressed, ensuring that sparse events such as long-distance travel and intercity travel remain within the effective pixel range of the standard image, avoiding the loss of image edge information or invalid filling due to excessive distance.
[0046] In sub-step S1032, the orientation angle refers to the azimuth angle of the trajectory point relative to the weighted centroid of user activity, expressed in radians, with a value ranging from 0 to 2π. Linear mapping refers to proportionally mapping the orientation angle to the horizontal and vertical coordinate axes of the standard image, and combining this with the aforementioned pixel distance to determine the two-dimensional pixel position of the trajectory point in the standard image plane. This pixel position does not correspond to any real geographic entity; it serves only as a topological placeholder for the distribution of user behavior.
[0047] In sub-step S1033, the multi-channel features of all trajectory points with the same pixel coordinates are aggregated. This can be done by using the pixel coordinates as an index, traversing all trajectory points belonging to that pixel coordinate in each time interval, and calculating the normalized access frequency, dwell time weighted average, time distribution entropy value, and AOI category probability distribution according to the preset channel definition, forming a channel tensor containing at least two semantic dimensions.
[0048] In other words, for each trajectory point, firstly, a piecewise nonlinear function is used to map the geographic distance to image pixel coordinates. The piecewise nonlinear mapping function satisfies the following formula:
[0049] in, Indicates pixel distance. Indicates geographical distance. This indicates a local activity radius threshold (e.g., 5km), used to distinguish between local and long-distance activities. This represents the pixel radius corresponding to the local activity radius threshold. This represents the logarithmic compression parameter, used to control the degree of mapping compression for long-distance activities.
[0050] Then, the orientation angle maintains a linear mapping, satisfying the following formula:
[0051]
[0052] in, Represents pixel coordinates, Indicates the direction angle. This indicates the image size of a standard image.
[0053] In this way, the above process achieves the unification and standardization of the position in any scene, with absolute generalization, the inability to restore coordinate information, and absolute privacy protection, making it suitable for modeling environments such as federated learning.
[0054] Next, the H×W pixel grid is divided into T time intervals (e.g., T=4, including: weekday daytime, weekday nighttime, weekend daytime, and weekend nighttime), and for each pixel (x,y) and time interval t, K feature channels are aggregated to generate a four-dimensional tensor. That is, the multi-channel features of each pixel. .
[0055] Optionally, each pixel Satisfy the following formula:
[0056] Where t represents the time interval. This represents the pixel coordinates, and k represents the channel. This represents the set of all trajectory points that share the same pixel coordinate. This represents the weight of trajectory point p, which is based on the dwell time or visit frequency of trajectory point p. This represents the feature value of trajectory point p in the k-th channel.
[0057] The multi-channel features include at least normalized access frequency, dwell time features, time distribution features, and AOI category probability, and satisfy the following formula:
[0058]
[0059]
[0060]
[0061] in, This indicates the normalized access frequency. Indicates the duration of stay. This indicates the duration of stay at trajectory point p; Indicates the characteristics of time distribution. The timestamp of the trajectory point p that falls within the time interval t; This represents the probability of the category of the region of interest. This represents a predefined set of geographic semantic categories.
[0062] In step S104, the multi-channel image corresponding to each time interval is divided into multiple image blocks, and an input sequence is generated based on all image blocks. Specifically, each image block can be flattened and mapped to a fixed-dimensional embedding vector through a linear projection layer. At the same time, a two-dimensional spatial position code is injected to characterize the geometric layout of the image block in the grid, and a learnable temporal position code is superimposed to distinguish the image block sets corresponding to different time intervals. Finally, all image block embedding vectors, spatial position codes and temporal position codes are concatenated to form an ordered sequence, which serves as the structured input of the ViT encoder.
[0063] In one possible implementation, the process of generating the input sequence based on all image patches in step S104 may include: S1041, flatten and linearly project each image block to obtain the embedding vector of each image block; S1042, concatenate all embedded vectors, learnable labeled vectors used to aggregate overall user behavior information, and user static profile labeled vectors used to encode user static attribute information to obtain a reference sequence; S1043 is to superimpose a spatial location encoding vector and a temporal location encoding vector on each embedding vector in the reference sequence to obtain the input sequence. The spatial location encoding vector represents the position of the corresponding image patch in the multi-channel image, and the temporal location encoding vector represents the time interval to which the image patch belongs.
[0064] In sub-step S1041, the image patch is a fixed-size sub-region uniformly divided from the multi-channel image corresponding to each time interval. For example, the image of each time slice H×W×K is divided into P×P image patches. The flattening operation compresses the original four-dimensional tensor structure into a one-dimensional vector. The vector dimension is equal to the product of the number of channels and the number of pixels. The linear projection transformation performs an affine transformation on this one-dimensional vector through a learnable weight matrix and a bias vector, and the output is an embedding vector of fixed dimension.
[0065] Optionally, the process of flattening each image patch and converting it into an embedding vector through a linear projection layer satisfies the following formula:
[0066] in, Represents the features of the i-th image patch. Represents the projection weight matrix. d represents the bias vector, and d represents the dimension of the embedding vector.
[0067] In substep S1042, after obtaining the sequence containing all embedding vectors in the previous step, a learnable label vector is added to the beginning of the sequence. and user static profile tag vector , Used to aggregate global information. Used to encode user static attributes to obtain a reference sequence.
[0068] in, Located at the beginning of the sequence, its parameters are independently optimized during model training and are used to guide the self-attention mechanism to summarize and refine global behavioral patterns. Generated from static attributes such as the user's age, gender, and occupation through an embedding layer, these vectors reside in the same vector space as the image patch embedding vectors, collectively forming a structured prior representation of the user's individual background. The concatenation operation sequentially connects these three types of vectors into a single ordered sequence, forming a reference sequence with a clear semantic role division.
[0069] In sub-step S1043, the spatial location encoding vector uses a sine-cosine function to generate a location code based on the row and column indices of the image patch in a two-dimensional grid, enabling the model to distinguish behavioral patterns under different spatial layouts. The temporal location encoding vector is a learnable parameter, set individually for each pre-divided time interval, ensuring that the model can recognize the differences in behavioral distribution under different temporal semantics, such as weekday daytime, weekday nighttime, weekend daytime, and weekend nighttime. The superposition operation is an element-wise addition, which does not change the dimensional structure of the embedded vector, but only embeds the dual prior constraints of location and time in its numerical space.
[0070] Optionally, the spatial location encoding vector satisfies the following formula:
[0071]
[0072] Where i represents the position index of the image patch; j represents the dimension index, starting from 0, corresponding to each dimension of the spatial location encoding vector; d represents the total dimension of the spatial location encoding vector, which is the same as the embedding dimension of the ViT encoder; 10000 represents the normalization factor, used to control the wavelength variation in different dimensions. This represents the exponential term, which determines the wavelength frequency in different dimensions.
[0073] Optionally, the final input sequence satisfies the following formula:
[0074] in, , This represents the spatial location encoding vector corresponding to image patch i. Indicates time interval The corresponding time position encoding vector, Represents the embedding vector of image patches 1 to N.
[0075] In step S105, the ViT encoder is composed of multiple layers of Transformer modules stacked together. Each layer sequentially executes a multi-head self-attention mechanism, layer normalization, and feedforward neural network operations. By dynamically modeling the spatial association and temporal context dependency between any two image blocks through self-attention weights, it achieves joint capture of the semantic relationships of user activities at multiple scales, such as local neighborhood, cross-region, and cross-time period.
[0076] Optionally, the general feature representation is obtained by extracting the vector corresponding to the category label from the final output sequence of the ViT encoder and then performing layer normalization. The general feature representation is a fixed-dimensional, dense, continuous floating-point vector that does not carry any reversible geographic reconstruction information and is not bound to a specific city or geographic coordinate system. Furthermore, the general feature representation can be used for at least supervised learning, user clustering, risk prediction, or city computation tasks. Due to its cross-scenario consistency and semantic completeness, it can be directly reused across different downstream tasks without requiring redesign of feature engineering logic or adjustment of input format for different task types.
[0077] In one possible implementation, step S105, which involves inputting the input sequence into the ViT encoder for feature encoding to obtain a general feature representation characterizing user behavior patterns, may include: S1051, The input sequence is input into the ViT encoder for feature encoding. The ViT encoder includes a multi-layer Transformer module, and each layer of the Transformer module includes a multi-head self-attention network, a layer normalization network, and a feedforward network. S1052, extract the output vector corresponding to the first position from the output sequence of the last layer Transformer module of the ViT encoder, and perform layer normalization on the output vector to obtain a general feature representation.
[0078] In sub-step S1051, the multi-head self-attention network satisfies the formula:
[0079] Where Q represents the query matrix. where n is the sequence length. Let K be the dimension of each self-attention head; K represents the key matrix. V represents the value matrix. , For the dimension of values, usually ; This represents the dimension of the key vector; it is a scalar used for scaling to prevent the softmax input from being too large. Represents the attention score matrix. This represents the degree of attention each location pays to other locations; represents the scaling factor, used to stabilize the gradient and prevent softmax saturation; softmax represents the normalization function, used to convert attention scores into probability scores.
[0080] Layer normalized networks satisfy the formula:
[0081] in, Represents the input vector. or B represents the batch size; This represents the mean, calculated along the feature dimension. ; Indicates standard deviation, , It should be a small constant to prevent division by zero; This represents the scaling parameter. , which is a learnable parameter vector; Indicates the offset parameter. , which is a learnable parameter vector.
[0082] Feedforward networks satisfy the formula:
[0083] Optionally, Indicates the weights of the first layer. , It is usually 4d; For the first layer bias, ; Represents the ReLU activation function, used for nonlinear transformations; This indicates the weights of the second layer. , It is usually 4d; For the second layer bias, .
[0084] The general feature representation satisfies the formula:
[0085] Where L represents the number of layers in the Transformer module, This represents the output sequence of the Lth layer. n is the number of image patches. Represents the category label vector, It is used to aggregate global information; Represents the user profile tag vector. , used to encode user static attributes; This represents the vector of the i-th image patch. i=1,…,N; N represents the number of image patches. P represents the batch size.
[0086] In sub-step S1052, output from the last layer. Extract the vector corresponding to the first position. Then, perform layer normalization on the vector, that is, , This is the general characteristic representation of user u.
[0087] Compared with the prior art, the embodiments of this application have the following beneficial effects: First, existing technologies directly process users' absolute latitude and longitude coordinates, which poses a risk of privacy leakage. This embodiment constructs a polar coordinate system with the user's activity weighted centroid as the origin, converts absolute coordinates into personal relative coordinates, and nonlinearly maps them to a standard image, so that subsequent trajectory analysis does not reveal the user's real geographical location and protects user privacy.
[0088] Second, existing models are difficult to apply directly to new regions due to their strong coupling between learning and absolute geographical location. The personalized relative coordinate system used in this embodiment decouples the model input from the specific geographical region, and learns the general, location-independent behavioral patterns themselves. Therefore, a model trained in one region can be directly transferred to other cities without retraining or with very little data adaptation, which greatly improves the universality and deployment efficiency of the model.
[0089] Third, existing sequence models (such as RNN / LSTM) are difficult to effectively capture global neighborhood relationships and long-range dependencies between behaviors in two-dimensional space. This embodiment converts the trajectory into a multi-channel image and introduces the ViT encoder. By utilizing its global self-attention mechanism, it can model the complex relationships between different user activity locations (such as residence, work, and entertainment), thereby extracting behavioral features that contain higher-level semantics.
[0090] Fourth, existing methods rely on manually designed, rule-driven statistical features, which have limited completeness and expressive power. This embodiment can automatically generate a general feature representation and use it for various downstream tasks such as supervised learning, user clustering, risk prediction, and urban computing.
[0091] In order to perform the corresponding steps in the above method embodiments and various possible implementations, an implementation of a data processing apparatus is given below.
[0092] Please refer to Figure 3 , Figure 3 A block diagram of a data processing apparatus 100 provided in an embodiment of this application is shown. The data processing apparatus 100 is applied to an electronic device and includes: an acquisition module 101, a conversion module 102, an image generation module 103, a sequence generation module 104, and an encoding module 105.
[0093] The acquisition module 101 is used to acquire the user's historical spatiotemporal data, which includes multiple trajectory points, and the trajectory points include geographical coordinates.
[0094] The conversion module 102 is used to convert the geographical coordinates of each trajectory point into relative coordinates based on historical spatiotemporal data.
[0095] The image generation module 103 is used to generate a multi-channel image corresponding to each time interval based on the relative coordinates of each trajectory point, a preset standard image, and multiple pre-divided time intervals. Each pixel in the multi-channel image corresponds to at least one trajectory point, and each pixel includes multiple feature channels that represent the semantics of user behavior.
[0096] The sequence generation module 104 is used to divide each multi-channel image into multiple image blocks and generate an input sequence based on all image blocks. The input sequence includes the embedding vector of each image block, the position of the image block in the multi-channel image, and the time interval to which the image block belongs.
[0097] The encoding module 105 is used to input the input sequence into the ViT encoder for feature encoding to obtain a general feature representation that characterizes the user behavior pattern. The general feature representation is used at least for supervised learning, user clustering, risk prediction or urban computing tasks.
[0098] Optionally, the trajectory points also include dwell time. The conversion module 102 is specifically used to: calculate the user's activity weighted centroid based on the geographic coordinates and dwell time of each trajectory point. The activity weighted centroid represents the location of the user's behavior center. Using the activity weighted centroid as the origin, the geographic coordinates of each trajectory point are converted into relative coordinates. The relative coordinates include the geographic distance from the trajectory point to the activity weighted centroid and the direction angle of the trajectory point relative to the activity weighted centroid.
[0099] Optionally, the image generation module 103 is specifically used to: for each trajectory point, use a piecewise nonlinear mapping function to convert the geographic distance into pixel distance, wherein the piecewise nonlinear mapping function represents that when the geographic distance is less than a set local activity radius threshold, linear mapping is used, and when the geographic distance is greater than or equal to the local activity radius threshold, logarithmic compression mapping is used; according to the image size and pixel distance of the standard image, linear mapping is performed on the orientation angle to obtain the pixel coordinates of the trajectory point in the standard image; for each time interval, the multi-channel features of all trajectory points with the same pixel coordinates are aggregated to obtain the multi-channel image corresponding to each time interval.
[0100] Optionally, the sequence generation module 104 performs an input sequence generation method based on all image patches, including: flattening and linearly projecting each image patch to obtain an embedding vector for each image patch; concatenating all embedding vectors, a learnable tag vector for aggregating overall user behavior information, and a user static profile tag vector for encoding user static attribute information to obtain a reference sequence; and superimposing a spatial location encoding vector and a temporal location encoding vector on each embedding vector in the reference sequence to obtain an input sequence, wherein the spatial location encoding represents the position of the corresponding image patch in the multi-channel image, and the temporal location encoding represents the time interval to which the image patch belongs.
[0101] Optionally, the encoding module 105 is specifically used to: input the input sequence into the ViT encoder for feature encoding, wherein the ViT encoder includes a multi-layer Transformer module, each of which includes a multi-head self-attention network, a layer normalization network, and a feedforward network; extract the output vector corresponding to the first position from the output sequence of the last layer Transformer module of the ViT encoder, and perform layer normalization on the output vector to obtain a general feature representation.
[0102] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the data processing device 100 described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0103] Please refer to Figure 4 , Figure 4A block diagram of an electronic device 10 provided in an embodiment of this application is shown. The electronic device 10 includes a processor 11, a memory 12, and a bus 13. The processor 11 is connected to the memory 12 via the bus 13.
[0104] The memory 12 is used to store programs. After receiving an execution instruction, the processor 11 executes the programs to implement the data processing method disclosed in the above embodiments.
[0105] The memory 12 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0106] Processor 11 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed through integrated logic circuits in the hardware of processor 11 or through software instructions. Processor 11 can be a general-purpose processor, including a Central Processing Unit (CPU), a Microcontroller Unit (MCU), a Complex Programmable Logic Device (CPLD), a Field Programmable Gate Array (FPGA), embedded ARM chips, etc.
[0107] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by the processor 11, implements the data processing method disclosed in the above embodiments.
[0108] In summary, the data processing method, apparatus, and electronic device provided in this application first convert the geographical coordinates of each trajectory point in historical trajectory data into relative coordinates, protecting user privacy at the data source and effectively preventing the leakage of sensitive information such as home address and workplace. Then, multi-channel images are generated based on relative coordinates, a preset standard image, and multiple time intervals, allowing the trajectories of users from different regions to be uniformly mapped onto the standard image, eliminating coupling dependence on specific geographical areas and improving generalization ability in cross-city scenarios. Furthermore, the multi-channel images aggregate trajectory semantics at the pixel level, preserving spatial neighborhood relationships. After image block segmentation and ViT encoder processing, it can more accurately represent behavioral patterns requiring global spatial reasoning, such as the spatial relationship between residential areas and workplaces. Finally, it outputs a general feature representation that can be directly adapted to various downstream tasks such as supervised learning, user clustering, risk prediction, and urban computing. Thus, while ensuring user trajectory privacy and security, it achieves efficient and highly generalizable trajectory learning and analysis.
[0109] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A data processing method, characterized in that, The data processing method includes: Acquire the user's historical spatiotemporal data, which includes multiple trajectory points, and the trajectory points include geographical location coordinates; Based on the historical spatiotemporal data, the geographical coordinates of each trajectory point are converted into relative coordinates; Based on the relative coordinates of each trajectory point, a preset standard image, and multiple pre-divided time intervals, a multi-channel image corresponding to each time interval is generated. Each pixel of the multi-channel image corresponds to at least one trajectory point, and each pixel includes multiple feature channels that characterize user behavior semantics. Each of the multi-channel images is divided into multiple image blocks, and an input sequence is generated based on all the image blocks, wherein the input sequence includes the embedding vector of each image block, the position of the image block in the multi-channel image, and the time interval to which the image block belongs; The input sequence is input into the ViT encoder for feature encoding to obtain a general feature representation that characterizes user behavior patterns. The general feature representation is used at least for supervised learning, user clustering, risk prediction, or urban computing tasks.
2. The data processing method as described in claim 1, characterized in that, The trajectory points also include the duration of stay. The step of converting the geographical coordinates of each trajectory point into relative coordinates based on the historical spatiotemporal data includes: Based on the geographical coordinates and dwell time of each trajectory point, the activity weighted centroid of the user is calculated, and the activity weighted centroid represents the location of the user's behavior center; Using the active weighted centroid as the origin, the geographical coordinates of each trajectory point are converted into relative coordinates, which include the geographical distance from the trajectory point to the active weighted centroid and the orientation angle of the trajectory point relative to the active weighted centroid.
3. The data processing method as described in claim 1, characterized in that, The relative coordinates include the geographical distance from the trajectory point to the active weighted centroid and the orientation angle of the trajectory point relative to the active weighted centroid; The step of generating a multi-channel image corresponding to each time interval based on the relative coordinates of each trajectory point, a preset standard image, and multiple pre-divided time intervals includes: For each trajectory point, a piecewise nonlinear mapping function is used to convert the geographic distance into pixel distance. The piecewise nonlinear mapping function indicates that when the geographic distance is less than a set local activity radius threshold, a linear mapping is used, and when the geographic distance is greater than or equal to the local activity radius threshold, a logarithmic compression mapping is used. Based on the image size of the standard image and the pixel distance, the orientation angle is linearly mapped to obtain the pixel coordinates of the trajectory point in the standard image; For each time interval, the multi-channel features of all trajectory points with the same pixel coordinates are aggregated to obtain the multi-channel image corresponding to each time interval.
4. The data processing method as described in claim 3, characterized in that, The piecewise nonlinear mapping function satisfies the following formula: in, Indicates the pixel distance, Indicates the geographical distance. This represents the local activity radius threshold, used to distinguish between local and long-distance activities; This represents the pixel radius corresponding to the local activity radius threshold. This represents the logarithmic compression parameter, used to control the degree of mapping compression for the long-distance activity; The linear mapping of the direction angle satisfies the following formula: in, Represents the pixel coordinates, Indicates the direction angle, This indicates the image size of the standard image.
5. The data processing method as described in claim 3, characterized in that, The step of aggregating multi-channel features of all trajectory points with the same pixel coordinates includes: According to the formula Aggregate multi-channel features of all trajectory points with the same pixel coordinates; where t represents the time interval. This represents the pixel coordinates, and k represents the channel. This represents the set of all trajectory points that share the same pixel coordinate. The weight represents the trajectory point p, which is obtained based on the dwell time or access frequency of the trajectory point p; This represents the feature value of trajectory point p in the k-th channel; The multi-channel features include at least normalized access frequency, dwell time features, temporal distribution features, and region of interest category probabilities, and satisfy the following formula: in, This indicates the normalized access frequency. This indicates the dwell time characteristic. This indicates the duration of stay at trajectory point p; This indicates the time distribution characteristics. The timestamp of the trajectory point p that falls within the time interval t; This represents the probability of the category of the region of interest. This represents a predefined set of geographic semantic categories.
6. The data processing method as described in claim 1, characterized in that, The step of generating the input sequence based on all the image patches includes: Each image patch is flattened and linearly projected to obtain the embedding vector of each image patch; All the embedded vectors, the learnable tag vectors used to aggregate overall user behavior information, and the user static profile tag vectors used to encode user static attribute information are concatenated to obtain a reference sequence. A spatial location encoding vector and a temporal location encoding vector are superimposed on each of the embedding vectors in the reference sequence to obtain an input sequence, wherein the spatial location encoding vector represents the position of the corresponding image patch in the multi-channel image, and the temporal location encoding vector represents the time interval to which the image patch belongs.
7. The data processing method as described in claim 6, characterized in that, The spatial location encoding vector satisfies the following formula: Where i represents the position index of the image patch; j represents the dimension index, starting from 0, corresponding to each dimension of the spatial position encoding vector; d represents the total dimension of the spatial position encoding vector, which is the same as the embedding dimension of the ViT encoder; 10000 represents the normalization factor, used to control the wavelength variation in different dimensions; This represents the exponential term, which determines the wavelength frequency in different dimensions.
8. The data processing method as described in claim 1, characterized in that, The step of inputting the input sequence into the ViT encoder for feature encoding to obtain a general feature representation characterizing the user behavior pattern includes: The input sequence is input into the ViT encoder for feature encoding. The ViT encoder includes a multi-layer Transformer module, and each layer of the Transformer module includes a multi-head self-attention network, a layer normalization network, and a feedforward network. The output vector corresponding to the first position is extracted from the output sequence of the last layer Transformer module of the ViT encoder, and the output vector is layer normalized to obtain the general feature representation.
9. A data processing apparatus, characterized in that, The data processing device includes: The acquisition module is used to acquire the user's historical spatiotemporal data, which includes multiple trajectory points, and the trajectory points include geographical location coordinates. The conversion module is used to convert the geographical coordinates of each trajectory point into relative coordinates based on the historical spatiotemporal data; The image generation module is used to generate a multi-channel image corresponding to each time interval based on the relative coordinates of each trajectory point, a preset standard image and multiple pre-divided time intervals, wherein one pixel of the multi-channel image corresponds to at least one trajectory point, and each pixel includes multiple feature channels representing user behavior semantics. A sequence generation module is used to divide each of the multi-channel images into multiple image blocks and generate an input sequence based on all the image blocks, wherein the input sequence includes the embedding vector of each image block, the position of the image block in the multi-channel image, and the time interval to which the image block belongs; The encoding module is used to input the input sequence into the ViT encoder for feature encoding to obtain a general feature representation that characterizes user behavior patterns. The general feature representation is used at least for supervised learning, user clustering, risk prediction, or urban computing tasks.
10. An electronic device, characterized in that, It includes a processor and a memory, the memory being used to store a program, and the processor being used to implement the data processing method of any one of claims 1-8 when executing the program.