# A Deep Multi-Task Learning Model for OD Traffic Flow Prediction Between Highway Stations
## 4 Model Construction
### Inflow Trend Learner  
The tasks of the entrance inflow learning module include learning the time-varying trend of the total amount of entrance inflow (including time, day, and week), learning the spatial interaction patterns of destination stations (spatiotemporal fusion), and learning changes influenced by external environment. The internal structure of the learning module is shown in Figure 8.  
Firstly, construct a traffic map matrix \(\mathrm{G}_{in}^{t}\)\(=(\mathrm{V,E,A,w})\). Where \(\mathrm{w}\) is representing the destination weight matrix \(W_{i,j}^{t}=\frac{x_{i,j}^{t}}{x_{i}^{t}}\). Then, using node2 vec encoding, the constructed graph structure data are random_walk to obtain spatial information encoding, and the spatial expression of historical inflow traffic data are obtained (Algorithms 1 and 2). \[x_{i:}^{s}=node2 vec(G) \tag{3}\]  
\[Node\_sequence=Random\_walk(G) \tag{4}\]  
\[x_{i:}^{s}=SkipGram(Node\_sequence) \tag{5}\] \begin{table}
\begin{tabular}{c c} \hline \hline
**Symbol** & **Definition** \\ \hline \(x_{i}^{t}\) & The traffic flow of origin Station \(s_{i}\) during the time interval \(\mathrm{t}\) \\ \(x_{j}^{t}\) & The traffic flow of destination Station \(s_{i}\) during the time interval \(\mathrm{t}\) \\ \(x_{ij}^{t}\) & OD traffic flow between \(s_{i}\), \(s_{i}\) station within time interval \(\mathrm{t}\) \\ \(\mathrm{p}(i-j)\) & The attraction strength of the destination station \(s_{i}\) to the origin station \(s_{i}\) \\ \(\mathrm{h}_{i:}^{t}\mathrm{h}_{i:}^{t}\mathrm{h}_{j:}^{t}\mathrm{h}_{j:}^{t}\) & Hidden layer output \\ \(L_{min:}L_{in},L_{out}\) & Loss functions for each subtask \(s_{j}\) \\ \(\mathrm{\hat{X}}^{t}\) & Final model output data \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Summary of key symbols. Figure 7: OD contour map between stations in one time slice. ```
1. Firstly, generate parameters related to the random walk strategy \(\pi=(G,p,q)\)
2. \(G^{\prime}=(V,E,\pi)\), start node: u, Sequence length: \(l\), Generate an initialization walk sequence: \(N(u)\), Number of iterations for wandering: iter = r
3. for \(iter=1:r\)
4. for walk_iter = 1: \(l\)
5. curr = walk[\(-1\)];
6. Retrieve neighbor node information of the current node \(V_{curr}=GetNeighbors(curr,G^{\prime})\)
7. Sampling based on walk strategy \(s=AliasSample(V_{curr},\pi)\)
8. Find the next node, add \(s\) to \(walk(u)\)
9. Return \(walk(u)\)
10. \(f=SkipGram(k,d,walk)//\) Call SkipHram algorithm
11. Return \(f\)
```  
**Algorithm 1**_node2 vec_ algorithm  
Figure 8: Internal structure diagram of the entrance inflow learning module. ```
1. for each node \(v_{i}\) belonging to the current random walk sequence \(N_{R}(u)[j-w:j+w]\)
2. for traverse every node in the surrounding window \(\omega\) of the node \(\mathrm{u_{k}}\in N_{v_{i}}(u)[j-w:j+w]\)
3. Calculate loss function \(\mathrm{J}(\Phi)=-\log\mathrm{p}(\mathrm{u_{k}}|\Phi(v_{j}))\)  Gradient descent updates embedding matrix \(\Phi=\Phi-\alpha*\frac{\partial I}{\partial\Phi}\)
```
4. End for
5. End for ```
**Algorithm 2**\(SkipGram\) algorithm  
Based on the expression of historical traffic feature vectors, the GAT network was used to learn the trend of all traffic from origin station \(s^{o}=s_{i}\) entering the highway and the trend learning towards the destination station \(s^{d}=s_{j}\), and then can obtain dynamic spatial attention of entrance station \(\mathrm{a_{d}^{in}}\). There are unfinished trips in a time slot for any origin station, so \(x^{t}_{i:}\Rightarrow\mathrm{s_{i}}^{\mathrm{Inflow}}\) (Algorithm 3):  
\[\mathrm{S_{i}^{Inflow}}\geq\sum_{j=1}^{N}\mathrm{S_{ij}}\cdot x^{t}_{i:}\geq \sum_{j=1}^{N}x^{t}_{ij} \tag{6}\]  
In order to better fit the model, a specific threshold parameter \(\theta_{\mathrm{in}}\) needs to be set to control it. On the other hand, learning the trend of inflow traffic from adjacent station in the physical topology space will obtain static spatial attention \(\mathrm{a_{s}^{in}}\).