# CQFormer: Cyclic Quasi-Dynamic Transformers for Hourly Origin-Destination Estimation
## 4 Methodology
Then, the \(n_{f}\times n_{t}\) dimensional feature vectors are reshaped into \(n_{t}\) vectors with dimensions of \(n_{f}\), and both feature vectors from forward and backward networks are fed into the cyclic attention module. In the cyclic attention module, the forward embedded feature vector is mapped to query matrix \(Q\) and key matrix \(K\), and the backward embedded feature vector is mapped to value matrix \(V\), and the same operation is conducted through Equation (9). The training data for CQDFormer includes realistic traffic count data and paired simulation data configured from the prior demand matrices and real traffic states. The training process consists of two parts, where independent losses for forward and reverse processes are computed separately for the paired simulation data indicated by the yellow lines in \[F_{T}[\alpha_{i},\beta_{i}]=N(A_{i})=\sum_{r_{k}}N(r_{k})\delta_{A_{i}\in r_{ k}} \tag{5}\]1 Because the realistic OD matrix is difficult to be accessed in real-time, the training is constrained by cyclic consistency, represented by the blue line in \[F_{T}[\alpha_{i},\beta_{i}]=N(A_{i})=\sum_{r_{k}}N(r_{k})\delta_{A_{i}\in r_{ k}} \tag{5}\]2 The optimization objective for training can be represented as  
\[F_{T}[\alpha_{i},\beta_{i}]=N(A_{i})=\sum_{r_{k}}N(r_{k})\delta_{A_{i}\in r_{ k}} \tag{5}\]3  
\(D_{1},D_{2}\) are distance measure functions between variables, \(f_{\theta}\) is the forward network for OD estimation, and \(g_{\alpha}\) is the backward network for traffic assignment, where \(\theta\) and \(\alpha\) are learnable parameters. Because traffic count-OD paired data are often missing in real environments, the training data for neural networks need to be expanded by simulation, but uncalibrated simulation data tend to cause an obvious distribution shift between training and evaluation, thus the simulation needs to be calibrated first according to the data obtained in real environments. As illustrated in Figure 3, the prior OD matrices can be derived from historical data, roadside surveys and questionnaires, empirical models (e.g., gravity model), and license plate recognition. In the era of ITS, the prior matrices can also be derived through other estimation models based on multiple data sources. It is worth noting that since these data sources are not necessarily available in real time, these models may not be used for OD estimation at any time, but the historical data generated by these models can be used for simulation calibration. In this study, we do not model the process of obtaining the prior matrices, but select 20 data samples from the test set as the prior matrices. Between each OD pair, we avail depth-first search combined with spatial direction information to obtain 200 paths, and choose all paths whose lengths are less than 1.3 times that of the shortest path as candidate paths between the OD pair. \[F_{T}[\alpha_{i},\beta_{i}]=N(A_{i})=\sum_{r_{k}}N(r_{k})\delta_{A_{i}\in r_{ k}} \tag{5}\]4 **The flowchart of generating traffic count-OD paired data. ** \(\boxbox\) are variables obtained from the real traffic scenario, \(\boxbox\) are variables generated in the simulation process, and \(\boxbox\) refers to the processing operations. \[F_{T}[\alpha_{i},\beta_{i}]=N(A_{i})=\sum_{r_{k}}N(r_{k})\delta_{A_{i}\in r_{ k}} \tag{5}\]5 **The training process. ** The proposed CQDFormer consists of forward and backward transformers, the paired simulation data are used for training the forward and backward process, respectively, and the real traffic count data are for training in the cyclic process. In the simulated traffic assignment, we consider three types of path selection patterns:  
1. **Fixed Path Selection Pattern**. For some familiar travel situations, travelers will tend to choose fixed travel paths. In this path selection path, the probability that a traveler chooses each path is related to the road conditions the path passes, the urban functional areas along the road, etc., and is fixed in each round of simulation. 2. \(N\)**Shortest Path Selection Pattern**[47].