Individual one-week activity sequence generation method based on activity mode
Through the individual weekly activity sequence generation method based on the activity mode, the activity sequence is learned and generated using Transformer and LDA models, which solves the computational complexity and accuracy problems of individual weekly activity sequence generation in the prior art, and realizes efficient and accurate activity sequence generation and multi-day dynamic simulation.
Patent Information
- Application Number
- CN202411935620.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-04-08
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The prior art is difficult to generate an individual weekly activity sequence, especially when dealing with complex spatiotemporal and spatial big data and dynamic activity modes, the computational complexity and accuracy problems are more prominent.
The activity pattern is used to generate an individual weekly activity sequence based on the activity pattern. Through natural language processing technology, deep learning technology and clustering methods, the activity sequence is learned and generated by the Transformer algorithm and LDA model, the activity pattern is identified and dimensionality reduction and clustering is performed, and high-precision individual weekly activity sequence is generated.
It reduces computational complexity, improves generation efficiency, can better capture the sequential dependence between activities in a weekly activity sequence, supports multi-day dynamic simulation, is suitable for large-scale data processing scenarios, and provides high spatial and temporal resolution individual activity prediction.
Smart Images

Figure CN119782866A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of resident activity demand modeling, and in particular to a method for generating an individual weekly activity sequence based on activity patterns. Background Art
[0002] Individual activity sequence generation is a core technology in the field of urban transportation and planning, which is used to simulate the activity behavior of individuals within a certain time range. Traditional traffic demand models mostly rely on residents' travel survey data and establish individual activity and travel models through statistical analysis. However, these methods have significant limitations:
[0003] Limited data scope: Traditional models are usually based on single-day travel data, which makes it difficult to capture the changing patterns of individual multi-day activity patterns and ignores the continuity and dynamics of long-term behavior.
[0004] Modeling methods are lagging behind: Most traditional methods rely on statistical models. Although they are suitable for small-scale, structured data, they are difficult to handle the current rapidly growing complex spatiotemporal big data.
[0005] Simplistic assumptions about activity patterns: Some models treat activity generation as independent events and fail to fully consider the sequentiality and dependencies between activities in the activity chain, thus limiting the predictive power and reliability of the model.
[0006] In recent years, the increasingly complex urbanization process has put forward higher requirements for the generation of multi-day activity sequences. The generation of a weekly activity sequence is more challenging than that of a single day, because individual activities have significant temporal regularity and spatial heterogeneity within a week. For example, the activity arrangements on weekdays and weekends are quite different, and the influence of factors such as work-residence constraints, social behavior patterns and individual preferences on activity sequences is also more complex. Therefore, the development of a method that can generate individual weekly activity sequences can not only provide key support for urban traffic demand forecasting, resource allocation and planning decisions, but also meet the needs of multi-day dynamic simulation and refined management.
[0007] Although relevant research has made some progress, there are still problems of complexity and computational burden in the field of activity sequence generation. Traditional activity generation methods usually rely on multiple sub-models, including activity frequency models, activity sequence models, activity time allocation models, etc. These modules are highly applicable in single-day activity generation, but when directly applied to weekly activity generation, the computational complexity will increase dramatically as the time span increases. In addition, due to the dynamic changes of activity patterns in different time periods, the accuracy of the model will also face significant challenges.
[0008] The need for model simplification in the context of big data: Big data provides important support for the establishment of an individual weekly activity model, but it also brings a huge amount of computation. To this end, recent studies have introduced clustering technology to reduce the complexity of the algorithm learning the activity patterns of the entire population by classifying people with similar activity characteristics. This classification of people based on activity characteristics is called "activity pattern." However, how to further develop a simplified method based on activity patterns to adapt to the task of generating individual weekly activities with complex spatiotemporal characteristics is still an urgent problem to be solved.
[0009] In response to the above challenges, there is an urgent need for a method to generate an individual weekly activity sequence based on activity patterns, using natural language processing technology, deep learning technology and clustering methods to efficiently learn the rules of activity sequences, so as to generate more accurate individual weekly activity sequences. For example, the sequence generation algorithm in natural language processing (NLP) provides a new idea for activity sequence generation, treating a user activity sequence as a document and each activity purpose as a word in the document. By drawing on advanced methods in the field of natural language processing, such as the LDA topic model, activity sequence generation can more accurately capture the differences in activity purposes, the dependencies of activity sequences, and the overall structural characteristics of the sequence. In addition, the self-attention mechanism in the Transformer algorithm can capture global dependencies and solve the problem of long sequence modeling. It can achieve efficient parallel computing through position encoding, which is suitable for large-scale activity data processing, and the multi-head attention mechanism can fuse multi-dimensional information to improve the generation quality. At the same time, the Transformer algorithm performs well in similar natural language generation tasks, proving its superiority in complex sequence modeling and providing reliable support for generating sequences that are more in line with actual activity rules.
[0010] How to achieve accurate and rapid prediction of an individual's weekly activities under the background of big data has become a technical problem that needs to be solved. Summary of the invention
[0011] The purpose of the present invention is to overcome the defects of the above-mentioned prior art and provide a method for generating an individual weekly activity sequence based on activity patterns.
[0012] The purpose of the present invention can be achieved by the following technical solutions:
[0013] According to one aspect of the present invention, a method for generating an individual weekly activity sequence based on an activity pattern is provided, the method comprising the following steps:
[0014] Step 1: Based on the one-week spatiotemporal big data of individuals with activity labels, the one-week activity chain and population attribute characteristics of all individuals are obtained;
[0015] Step 2, inputting the one-week activity chains of all individuals into the one-week activity pattern recognition module to obtain the one-week activity pattern recognition result;
[0016] Step 3: After matching the weekly activity pattern recognition results with the population attribute characteristics, the results are input into the weekly activity sequence generation module, and the weekly activity sequences of all individuals are output based on the trained weekly activity sequence generation model.
[0017] Preferably, the weekly activity pattern recognition module comprises a weekly activity sequence reconstruction submodule, a weekly activity sequence dimension reduction submodule and a weekly activity sequence clustering submodule which are connected in sequence.
[0018] More preferably, the one-week activity sequence reconstruction submodule is used to reconstruct the one-week activity chain, and the reconstruction method is: assuming that the minimum stay time of an activity is 30 minutes, 24 hours are divided into 48 time periods, with a total of seven activity days per week. The activity time segments are coded 1-48, and the activity days are coded 1-7. The corresponding codes for the activity purposes in each time period are: activity day number_activity time segment number_activity purpose number, where the activity purposes include home, work, shopping and entertainment, and others, which are coded 1-4 respectively.
[0019] Preferably, the one-week activity sequence dimensionality reduction submodule is used to reduce the dimensionality of the reconstructed one-week activity sequence before clustering; wherein the dimensionality reduction is performed based on the LDA model, and the probability distribution of each activity sequence on different activity topics is output, and this is used as the vectorized representation of the activity sequence.
[0020] Preferably, the weekly activity sequence clustering submodule is used to cluster the activity sequence after dimensionality reduction to obtain the optimal cluster number and activity pattern recognition results.
[0021] More preferably, the clustering adopts a similarity matrix and a K-Means++ algorithm, and the optimal number of clusters is determined by analyzing the sum of squared errors within the cluster under different numbers of clusters through the elbow method.
[0022] Preferably, the one-week activity sequence generation module includes a one-week activity sequence learning submodule and a one-week activity sequence generation submodule;
[0023] The one-week activity sequence learning submodule performs feature processing on the training set data that has matched the demographic attribute characteristics in each activity mode, inputs it into the Transformer model, obtains the optimal model training result, and quantifies the model performance according to the evaluation index as the one-week activity sequence generation model;
[0024] The weekly activity sequence generation submodule first performs feature processing on the test set data that has matched the demographic attribute characteristics in each activity mode, and then inputs the first a feature sequences into the trained weekly activity sequence generation model to predict the next activity, and uses the previous prediction result as a feature to predict the next result, thereby performing rolling prediction and generating an individual weekly activity sequence, where a is greater than 1.
[0025] More preferably, the feature processing is specifically as follows: taking the first n activity sequence elements as n features, the n+1th activity sequence element as the element to be predicted, breaking a complete activity sequence into multiple subsequences, and adding m demographic attribute features to form a new data set, wherein n and m are both integers greater than 1.
[0026] More preferably, the evaluation index is the cosine similarity between the generated individual weekly activity sequence and the actual sequence.
[0027] Preferably, the one-week activity pattern recognition result, i.e., the recognized activity patterns, include regular work type, work with one day off type, work without a day off type, night shift without a day off type, shopping and entertainment activity-dominated type, other activity-dominated type, and complex activity-dominated type.
[0028] Compared with the prior art, the present invention has the following beneficial effects:
[0029] 1) Reduce computational complexity and improve model generation accuracy: The present invention simplifies the process of generating an individual's weekly activity sequence by introducing activity pattern recognition. Compared with the traditional complex method that requires multiple sub-models to independently process the number, sequence and time allocation of activities, the activity pattern-based activity sequence generation method of the present invention effectively reduces the computational complexity and significantly improves the generation efficiency, which is suitable for large-scale data processing scenarios; at the same time, the Transformer algorithm is used to learn the individual's weekly activity sequence information under different activity patterns, which can better capture the sequential dependencies between activities in the weekly activity sequence and can quickly predict the activity sequence results with higher accuracy.
[0030] 2) Support for multi-day dynamic simulation: Compared with the traditional single-day activity generation method, the present invention supports the generation of dynamic activity sequences for multiple days (especially a week). By capturing the changing patterns of activities over a long period of time, it can provide more timely and continuous individual activity predictions, and provide high spatiotemporal resolution support for urban planning and traffic management.
[0031] 3) Expanding application areas: The present invention is not only applicable to urban traffic demand forecasting, but can also provide technical support for multiple fields such as dynamic simulation of resident behavior, smart city management, and personalized service recommendation, and has strong versatility and expansibility. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 A basic flow chart of a method is provided in an embodiment of the present invention;
[0033] Figure 2 A schematic diagram of reconstructing a one-week activity sequence provided in an embodiment of the present invention;
[0034] Figure 3 The perplexity-topic number curve diagram of the LDA model provided in an embodiment of the present invention is shown;
[0035] Figure 4 A schematic diagram of using an elbow diagram to determine the number of activity pattern recognition categories for one week provided in an embodiment of the present invention;
[0036] Figure 5 A schematic diagram of a one-week activity pattern recognition result provided in an embodiment of the present invention;
[0037] Figure 6 A schematic diagram of a curve of the minimum cross entropy loss value-n value of the model under various activity modes in one week provided in an embodiment of the present invention;
[0038] Figure 7 Comparison between the activity sequence generation result under the one-week activity mode provided in the embodiment of the present invention and the actual value based on the activity mode;
[0039] Figure 8 The activity sequence generation result under the one-week activity pattern provided in the embodiment of the present invention is compared with the actual value not based on the activity pattern. DETAILED DESCRIPTION
[0040] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0041] This embodiment relates to a method for generating an individual weekly activity sequence based on activity patterns, which combines the LDA topic model and Transformer to learn and generate the individual weekly activity sequence, thereby providing a more accurate and scalable solution for individual weekly activity prediction and urban traffic planning under the background of big data.
[0042] like Figure 1 , the method comprises the following steps:
[0043] S1, based on the one-week spatiotemporal big data of individuals with activity labels, directly obtains the one-week activity chain and population attribute characteristics of all individuals;
[0044] S2, based on the one-week activity chains of all individuals, input them into the one-week activity pattern recognition module to obtain the one-week activity pattern recognition results;
[0045] S3, based on the activity pattern recognition results of one week, in each activity pattern, it is divided into the training set and test set required by the activity sequence generation module in a ratio of 8:2;
[0046] S4, matching the data of the training set and the test set with the demographic attribute characteristics, and inputting them into the weekly activity sequence generation module. After model training and performance testing, a model for generating a weekly activity sequence can be obtained.
[0047] S2 specifically includes:
[0048] S201, reconstruction of one-week activity sequence: Since the data structure of the original individual one-week activity chain cannot be directly input into the activity pattern recognition algorithm, the original activity chain needs to be reconstructed. The reconstruction method is as follows: Since the minimum stay time of an activity is 30 minutes, 24 hours is divided into 48 time periods, and it is defined as an activity day from 4 am of the current day to 4 am of the next day, with a total of 7 activity days. The activity time segment is coded as 1-48, and the activity day is coded as 1-7. For the purpose of the activity, the one-week activity chain comes from the individual spatiotemporal big data of the mobile platform. Its activity purposes include home (H), work (W), shopping and entertainment (S&E) and others (O), coded from 1 to 4. Considering that the solvability of long sequences with multiple elements is low, and the travel time is shorter than the activity duration, in order to obtain a better explanation of the activity pattern recognition results, the activity purpose in each grid is labeled according to the activity start time. The travel part between activities is not listed separately, so the activity purpose in each time period can be coded as: "activity day number_activity time segment number_activity purpose number".
[0049] S202, dimensionality reduction of one-week activity sequence: After obtaining the reconstructed one-week activity sequence, if it is directly input into the clustering algorithm, due to the large number of features, the algorithm is difficult to capture the rules, so dimensionality reduction is required before clustering. In natural language processing, topic modeling is an important technology used to extract potential topic patterns from large-scale text data. Latent Dirichlet Allocation (LDA) is a widely used topic modeling method. Its core idea is to represent a document as a mixture of several topics, and each topic is composed of a probability distribution of a set of words. Through the LDA model, the text can be reduced from a high-dimensional space to a topic distribution vector, which simplifies the data structure while retaining semantic information. Analogous to the study of activity pattern recognition, a user's one-week activity sequence can be regarded as a "document", and the activity purpose is similar to a "vocabulary". By applying the LDA model, the activity sequence can be decomposed into the probability distribution of several "activity topics", each topic reflecting a group of activity patterns with common characteristics. This method can not only achieve dimensionality reduction representation of activity sequences, but also effectively capture the potential semantic structure in activity sequences and reveal the topic differences of different user activity patterns. It is proposed to vectorize and reduce the dimension of activity sequences based on the LDA model. Specifically, after inputting each activity sequence into the LDA model, its probability distribution on different activity topics is obtained, and this is used as the numerical representation of the activity sequence. This method can simultaneously consider the differences in activity purposes and their distribution characteristics in the activity sequence, providing an efficient and intuitive representation method for activity pattern analysis and subsequent prediction.
[0050] S203, clustering of one-week activity sequences: obtain vector representation of activity sequences after dimensionality reduction, input it into a clustering algorithm, such as the K-Means++ algorithm adapted to big data, and obtain the optimal number of clusters according to the elbow method, thereby obtaining the activity pattern recognition result.
[0051] The Latent Dirichlet Allocation (LDA) model in the dimensionality reduction of the one-week activity sequence in S2 specifically includes: In activity pattern recognition, we can analogize it with text recognition in natural language processing, and regard a user's one-week activity sequence as a document, and each activity purpose as a word in the document. Based on this analogy, we can use the LDA model to vectorize the activity sequence to capture the differences and order of activity purposes.
[0052] LDA is a generative probabilistic model that is widely used in topic modeling. LDA assumes that each document is generated by a mixture of multiple topics, and each topic is represented by the probability distribution of words. The goal is to discover the potential activity topic distribution from the activity sequence, thereby providing better feature representation for subsequent clustering algorithms.
[0053] The LDA model is based on the following basic assumptions: 1) each document (activity sequence) can be represented as a mixture of multiple topics; 2) each topic is represented by a probability distribution of words (activity purpose).
[0054] Specifically, the LDA model assumes that each document d has a specific topic distribution θ d , which is generated by Dirichlet distribution; each topic k has a specific word distribution This distribution is also generated by the Dirichlet distribution.
[0055] For each word in the document, first a topic is selected from the topic distribution, and then a word is selected from the word distribution of that topic.
[0056] The mathematical representation of the LDA model is as follows:
[0057]
[0058] Among them, α and β are the hyperparameters of the Dirichlet distribution, θ d is the topic distribution of document d, is the word distribution of topic k, z dn is the topic of the nth word in document d, w dn is the nth word in document d, p(θ|α) is the Dirichlet prior distribution of the document topic distribution, is the Dirichlet prior distribution of the word distribution of topic k, p(z dn |θ d ) is the probability of selecting a topic in the topic distribution, is the conditional probability of word generation under a certain topic, D is the number of documents, K is the total number of topics, N d The number of words.
[0059] LDA model parameter adjustment:
[0060] The input parameters α and β of the LDA model generally take the default values α=1 / K, β=0.01, K is the total number of topics, which is the most critical parameter of the LDA model. Perplexity is usually used to determine the optimal number of topics. The perplexity-topic number curve is usually drawn to determine the optimal number of topics. Consistent with the elbow method, the topic where the perplexity decreases slowly is the optimal number of topics. The calculation formula of perplexity is as follows:
[0061]
[0062] Where |D| is the number of documents in the document collection, W dis the set of words in document d, N d is the number of words in document d, p(W d ) is the log probability of the set of terms in document d.
[0063] Specifically, for each word w in document d, its probability p(W d ) is calculated as follows:
[0064]
[0065] Where K is the number of topics, p(w dn |z du =k) is the word w in topic k du The probability, p(z dn =k|θ d ) is the probability of topic k in document d.
[0066] The K-Means++ and elbow method in the dimensionality reduction of the one-week activity sequence in S2 specifically include: K-Means++ is an improved version of the classic K-Means clustering algorithm. The main purpose is to improve the quality of the initial cluster center selection, thereby enhancing the convergence speed and clustering effect of the algorithm. The basic idea of K-Means++ is to select the initial cluster center through a probability distribution, so that each new cluster center is more likely to be located far away from the existing center, thereby avoiding the local optimal problem caused by improper initial center selection in traditional K-Means. The specific steps of the algorithm are as follows:
[0067] Suppose there is a data set where x i ∈R d , we hope to divide the data samples into k categories.
[0068] Step 2031: randomly select a data point x from the data set as the first cluster center c1;
[0069] Step 2032: Select the remaining cluster centers:
[0070] For j = 2, ..., k, perform the following steps in sequence:
[0071] For each point x in the dataset i , calculate its distance D(x i ):
[0072]
[0073] D(x i ) 2 As a weighted probability distribution, select the next cluster center c from the data setj , x i The probability of being selected as the next cluster center is:
[0074]
[0075] Step 2033: Use the selected k cluster centers as initial centers and run the standard K-Means algorithm until convergence.
[0076] Elbow method to determine the number of clusters:
[0077] In cluster analysis, determining the appropriate number of clusters k is a key issue. The Elbow Method is a commonly used method to select the optimal number of clusters. The Elbow Method determines the appropriate k value by analyzing the sum of squared errors (SSE) within clusters under different numbers of clusters.
[0078] Elbow method steps:
[0079] Step a): Calculate the intra-cluster error sum of squares for different k values:
[0080]
[0081] Among them, C i represents the i-th cluster, U i is the center of the i-th cluster, and x is the cluster C i The sample points in , k is the number of clusters.
[0082] Step b): draw a curve of SSE changing with k;
[0083] Step c): Determine the optimal number of clusters k: In the plotted curve, find the point where SSE decreases significantly with the increase of k, that is, the "elbow" point. The k value corresponding to the "elbow" point is usually considered to be the optimal number of clusters, because after this point, the improvement of SSE by increasing the k value becomes gradually slow, such as Figure 4 .
[0084] S4 specifically includes:
[0085] S401, one-week activity sequence learning: Considering that the self-attention mechanism in the Transformer algorithm can capture global dependencies and solve the problem of long sequence modeling, efficient parallel computing is achieved through position encoding, which is suitable for large-scale activity data processing, and the multi-head attention mechanism can integrate multi-dimensional information to improve the generation quality. In addition, the Transformer algorithm performs well in similar natural language generation tasks, proving its superiority in complex sequence modeling and providing reliable support for generating sequences that are more in line with the actual activity rules. Therefore, Transformer is selected as the core algorithm for one-week activity sequence learning. The training set data that has matched the demographic attribute characteristics under each activity mode is feature processed and input into the Transformer algorithm to obtain the optimal model training results, and the model performance is quantified according to the evaluation indicators as a one-week activity sequence generation model.
[0086] S402, one-week activity sequence generation: perform feature processing similar to the training set on the test set data that has matched the demographic attribute characteristics in each activity mode, input the first few feature sequences, use the trained one-week activity sequence generation model to predict the next activity, and use the previous prediction result as a feature to predict the next result. In this way, rolling prediction is performed to generate an individual one-week activity sequence.
[0087] The Transformer algorithm in the learning of one-week activity sequence in S4 specifically includes: The Transformer model was originally proposed by Vaswani et al. for processing natural language processing (NLP) tasks. Due to its outstanding performance in processing sequence data (such as text, time series data, etc.), Transformer has become the mainstream model in the field of NLP. The Transformer model is mainly composed of an encoder and a decoder, each of which is composed of multiple identical layers stacked together. Each layer contains two main sublayers: a multi-head self-attention mechanism and a feed forward neural network. In addition, each sublayer contains a residual connection and layer normalization. Unlike traditional recurrent neural networks (such as LSTM), Transformer does not rely on sequence order for processing, so it can be calculated in parallel, greatly improving training efficiency.
[0088] Each layer of the encoder consists of the following parts:
[0089] Multi-Head Self-Attention:
[0090] The self-attention mechanism can calculate the correlation between each position in the sequence and other positions, capturing global dependencies. Multi-head attention processes multiple attention heads in parallel, allowing the model to focus on different feature subspaces.
[0091] For the input sequence X = [x1, x2, ..., x n ], the self-attention is calculated as follows:
[0092]
[0093] Where Q, K and V represent query, key and value matrices respectively. k is the dimension of the key vector.
[0094] Calculation of multi-head attention mechanism:
[0095] Multihead(Q,K,V)=Concat(head1,head2,…,head h )W O
[0096] Among them, head i =Attention(QW i Q ,KW i K ,VW i V ), W i Q , W i K , W i V and W O are all trainable weight matrices.
[0097] Feed Forward Neural Network:
[0098] Each encoder layer also includes a feed-forward neural network that acts on the representation vector of each position. The feed-forward network usually consists of two linear transformations and an activation function:
[0099] FFN(x)=max(0,xW1+b1)W2+b2
[0100] Among them, W1 and W2 are trainable weights, and b1 and b2 are trainable biases.
[0101] Residual Connection and Layer Normalization: Residual connection adds the input directly to the output of the sublayer to alleviate the gradient vanishing and gradient exploding problems. Layer normalization normalizes the output of each layer to stabilize the training process.
[0102] The structure of the decoder is similar to that of the encoder, but with an additional sublayer that performs attention on the encoder output (Encoder-Decoder Attention):
[0103] Masked Multi-Head Self-Attention:
[0104] It is similar to the multi-head self-attention mechanism in the encoder, but uses masking technology to ensure that each position only pays attention to the previous position to prevent information leakage.
[0105] Encoder-Decoder Attention:
[0106] When performing multi-head attention calculations, the query matrix comes from the decoder input, while the key and value matrices come from the encoder output, enabling the decoder to focus on the encoder's contextual information.
[0107] The feedforward neural network and residual connections are the same as those of the encoder.
[0108] Positional Encoding: Since Transformer does not depend on sequence order, positional encoding is used to provide sequence position information. Positional encoding can be generated by sine and cosine functions:
[0109]
[0110] Among them, pos represents the position, i represents the dimension index, and d model is the dimension of the embedding vector.
[0111] Model training: Use the first n activity sequences plus personal attribute features for embedding and positional encoding as input to train the Transformer model to predict the next activity. Define the loss function (such as cross entropy) and optimization algorithm (such as Adam) during the training process.
[0112] The feature processing of the training set data that has matched the demographic attribute characteristics in each activity mode in the one-week activity sequence learning in S4 specifically includes:
[0113] The first n activity sequence elements are regarded as n features, and the n+1th activity sequence element is regarded as the element to be predicted. A complete activity sequence is broken into multiple subsequences. At the same time, m population attribute features are added to form a new data set for model training.
[0114] The evaluation indicators for learning one-week activity sequences in S4 specifically include:
[0115] In the activity sequence generation task, the generated sequence can be regarded as a vector, and the actual sequence can also be represented as another vector. By calculating the cosine similarity between the generated sequence and the actual sequence, we can evaluate the extent to which the generated sequence is similar to the actual sequence. Cosine similarity is an indicator that measures the degree of directional similarity between two vectors in space. The calculation is relatively simple and applicable to high-dimensional data, which is especially important for processing large-scale activity sequence data. The calculation method is the inner product of two vectors divided by the product of their norms. Its value is between -1 and 1, where 1 means that the two vectors are exactly the same in direction, 0 means completely unrelated, and -1 means the directions are completely opposite. The formula is:
[0116]
[0117] Among them, A and B are two vectors.
[0118] This embodiment also involves an application of a method for generating an individual weekly activity sequence based on an activity pattern. The research data of this embodiment is the individual spatiotemporal big data of a mobile platform with activity purpose labels in a certain city in 2023. First, based on the data, the individual weekly activity chain and demographic attribute characteristics are extracted. The demographic attribute characteristics include gender, age, car ownership, income and occupation, a total of 5 types of characteristic attributes.
[0119] The activity pattern recognition module is used to perform the following processing:
[0120] Reconstruction of one-week activity sequence: Reconstruct the activity sequence based on the individual one-week activity chain data. Label the activity purpose in each grid according to the activity start time. The activities and the travel parts between activities are not listed separately. The activity purpose in each time period is coded as: "Activity day number_Activity time segment number_Activity purpose number", such as Figure 2 As shown, Figure 2 1_8_1 means that the activity purpose during the period of 7:30-8:00 on Monday is "staying at home"; 1_17_2 means that the activity purpose during the period of 11:00-12:00 on Monday is "working"; 7_28_4 means that the activity purpose during the period of 17:00-17:30 on Sunday is "others".
[0121] Dimensionality reduction of one-week activity sequence: Based on the reconstructed activity sequence, it is input into the LDA model to perform vector representation dimensionality reduction. Figure 3 It is the perplexity curve in the LDA model. It can be found that when the number of topics is 8, the curve begins to decrease slowly. Then 8 is selected as the best number of topics under this data, and the similarity matrix is calculated with this number of topics.
[0122] Clustering of weekly activity sequences: Based on the similarity matrix, KMeans++ algorithm is superimposed, and the elbow method ( Figure 4 ), we can determine that the optimal number of clusters is 7. Figure 5 This is the clustering result under this method. It can be found that the recognition effect is good. In various activity modes, the dominant activity purpose in each activity mode can be clearly obtained, and the modes such as night shift work and six-day work a week are all recognized. Specifically, the activity characteristics of each activity mode are shown in Table 1, with a total of 7 types of activity modes, including regular work type, work with one day off type, work without a day off type, night shift without a day off type, shopping and entertainment activity dominant type, other activity dominant type, and complex activity dominant type.
[0123] Table 1
[0124]
[0125] Based on the 7 types of activity modes identified, the data set under each type of activity mode is divided into training set and test set in a ratio of 8:2.
[0126] Activity sequence generation module:
[0127] One-week activity sequence learning: Based on the above training set, individual demographic attribute characteristics are matched and feature processing is performed. The processing example is shown in Table 2.
[0128] Table 2
[0129]
[0130] The feature-processed data is input into the Transformer algorithm for activity sequence learning. Generally speaking, the Transformer structure is set as follows:
[0131] Construct a Transformer network, including embedding layers, positional encodings, encoder layers, and decoder layers.
[0132] Embedding layer: used to convert discrete input (such as words or characters) into continuous high-dimensional vector representation. Parameters include: input_dim: input vocabulary size (number of words in the vocabulary), here is the number of element types of each activity sequence in the activity sequence; embed_dim: the dimension of the embedding vector, usually 256, 512, 1024, etc. Considering the long activity sequence, set the dimension to 1024.
[0133] Position encoding layer: Position encoding is added to provide position information.
[0134] The encoder layer is the core component of Transformer, which includes a multi-head self-attention mechanism and a feedforward neural network. The parameters include: embed_dim: the dimension of the embedding vector, which is consistent with the embedding layer; num_heads: the number of heads of the multi-head self-attention, usually 8 or 16, set to 8 here; ffn_dim: the hidden layer dimension of the feedforward neural network, a higher dimension can enhance the nonlinear ability of the model, usually 2048, set to 2048 here; dropout_rate: to prevent overfitting, the common value is between 0.1 and 0.5, set to 0.1 here.
[0135] Decoder layer: The decoder layer is similar to the encoder layer, but in addition to the multi-head self-attention mechanism, it also includes the encoder-decoder attention mechanism. Parameters include: embed_dim: the dimension of the embedding vector, which is consistent with the encoding layer; num_heads: the number of heads of the multi-head self-attention, which is consistent with the encoding layer; ffn_dim: the hidden layer dimension of the feedforward neural network, which is consistent with the encoding layer; dropout_rate: the dropout rate, which is consistent with the encoding layer.
[0136] Transformer model: Combine the encoder layer and the decoder layer to form a complete Transformer model. Parameters include: num_encoder_layers: the number of encoder layers, which is set to 4 here; num_decoder_layers: the number of decoder layers, which is set to 4 here.
[0137] Model training: Use the previous n activity sequences plus personal attribute features for embedding, and positional encoding as input to train the Transformer model to predict the next activity. During the training process, define the loss function (such as the cross entropy loss function) and the optimization algorithm (such as Adam).
[0138] Finally, if Figure 6 As shown in Figure 1, after selecting the optimal number of features n in each activity mode, the final Transformer model is obtained.
[0139] One-week activity sequence generation: Based on the above test set, match the individual demographic attributes, perform feature processing similar to the training set, input the first few feature sequences, use the trained one-week activity sequence generation model to predict the next activity, and use the previous prediction result as a feature to predict the next result. In this way, rolling prediction is performed to generate an individual one-week activity sequence. The generation results under each activity mode are as follows: Figure 7 As shown in , it can be found that the generated effect is better than the true value. In addition, in order to prove the effectiveness of activity sequence generation based on activity patterns, a control group was set up. In the control group, activity pattern recognition was not performed, and activity sequence learning and generation were performed directly. The comparison results are shown in Figure 7 , Figure 8 As shown in the cosine similarity in Table 3, it can be found that before the activity sequence generation model is built, performing activity pattern recognition (compared with not performing activity pattern recognition) can better improve the accuracy of the activity sequence generation results. This phenomenon is mainly due to the fact that before the activity sequence is generated, the activity regularity of the data can be further improved by identifying the activity pattern, which enables the algorithm to better capture the regularity.
[0140] Table 3
[0141] Activity sequence generation based on activity patterns Activity sequence generation not based on activity patterns Activity Mode 1 0.84 0.78 Activity Mode 2 0.89 0.80 Activity Mode 3 0.86 0.79 Activity Mode 4 0.92 0.80 Activity Mode 5 0.80 0.75 Activity Mode 6 0.77 0.72 Activity Mode 7 0.74 0.69
[0142] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A method for generating an individual weekly activity sequence based on activity patterns, characterized in that: The method comprises the following steps: Step 1: Based on the one-week spatiotemporal big data of individuals with activity labels, the one-week activity chain and population attribute characteristics of all individuals are obtained; Step 2, inputting the one-week activity chains of all individuals into the one-week activity pattern recognition module to obtain the one-week activity pattern recognition result; Step 3: After matching the weekly activity pattern recognition results with the population attribute characteristics, the results are input into the weekly activity sequence generation module, and the weekly activity sequences of all individuals are output based on the trained weekly activity sequence generation model.
2. The method for generating an individual weekly activity sequence based on activity patterns according to claim 1, characterized in that: The weekly activity pattern recognition module comprises a weekly activity sequence reconstruction submodule, a weekly activity sequence dimension reduction submodule and a weekly activity sequence clustering submodule which are connected in sequence.
3. The method for generating an individual weekly activity sequence based on activity patterns according to claim 2, characterized in that: The one-week activity sequence reconstruction submodule is used to reconstruct the one-week activity chain. The reconstruction method is: assuming that the minimum stay time of an activity is 30 minutes, 24 hours are divided into 48 time periods, with a total of seven activity days per week. The activity time segments are coded 1-48, and the activity days are coded 1-7. The corresponding codes for the activity purposes in each time period are: activity day number_activity time segment number_activity purpose number, where the activity purposes include home, work, shopping and entertainment, and others, which are coded 1-4 respectively.
4. The method for generating an individual weekly activity sequence based on activity patterns according to claim 1, characterized in that: The one-week activity sequence dimensionality reduction submodule is used to reduce the dimensionality of the reconstructed one-week activity sequence before clustering; the dimensionality reduction is performed based on the LDA model, and the probability distribution of each activity sequence on different activity topics is output, and this is used as the vectorized representation of the activity sequence.
5. The method for generating an individual weekly activity sequence based on activity patterns according to claim 1, characterized in that: The one-week activity sequence clustering submodule is used to cluster the activity sequence after dimensionality reduction to obtain the optimal cluster number and activity pattern recognition results.
6. The method for generating an individual weekly activity sequence based on activity patterns according to claim 5, characterized in that: The clustering adopts a similarity matrix and a K-Means++ algorithm, and the optimal number of clusters is determined by analyzing the sum of squares of intra-cluster errors under different numbers of clusters through the elbow method.
7. The method for generating an individual weekly activity sequence based on activity patterns according to claim 1, characterized in that: The one-week activity sequence generation module includes a one-week activity sequence learning submodule and a one-week activity sequence generation submodule; The one-week activity sequence learning submodule performs feature processing on the training set data that has matched the demographic attribute characteristics in each activity mode, inputs it into the Transformer model, obtains the optimal model training result, and quantifies the model performance according to the evaluation index as the one-week activity sequence generation model; The weekly activity sequence generation submodule first performs feature processing on the test set data that has matched the demographic attribute characteristics in each activity mode, and then inputs the first a feature sequences into the trained weekly activity sequence generation model to predict the next activity, and uses the previous prediction result as a feature to predict the next result, thereby performing rolling prediction and generating an individual weekly activity sequence, where a is greater than 1.
8. The method for generating an individual weekly activity sequence based on activity patterns according to claim 7, characterized in that: The feature processing is specifically as follows: the first n activity sequence elements are regarded as n features, the n+1th activity sequence element is regarded as the element to be predicted, a complete activity sequence is broken into multiple subsequences, and m population attribute features are added to form a new data set, where n and m are both integers greater than 1.
9. The method for generating an individual weekly activity sequence based on activity patterns according to claim 7, characterized in that: The evaluation index is the cosine similarity between the generated individual weekly activity sequence and the actual sequence.
10. The method for generating an individual weekly activity sequence based on activity patterns according to claim 1, characterized in that: The one-week activity pattern recognition result is the recognized activity pattern, including regular work type, work with one day off type, work without a day off type, night shift without a day off type, shopping and entertainment activity-dominated type, other activity-dominated type, and complex activity-dominated type.
Citation Information
Patent Citations
User activity mode dividing and attribute speculating method
CN107527313A
Resident representative activity pattern recognition method and system based on LDA topic modeling
CN116186621A