This paper targets the estimation of route-level bus arrival time. Based on the physical mechanisms of bus operation, the prediction task is decoupled into two processes, namely inter-station travel and station dwell, and a customized prediction model is constructed for each according to their differing spatio-temporal characteristics. This chapter presents, in turn, the problem formulation and method overview, the data and features, the model inputs, and the network architectures of the two prediction models.
3.1. Problem Formulation and Method Overview
The bus arrival time is jointly determined by the inter-station travel time and the station dwell time, whose underlying physical generation mechanisms differ fundamentally. Inter-station travel time varies relatively smoothly and exhibits strong regularity, being governed mainly by the traffic conditions of adjacent segments and, in particular, by the propagation of upstream-downstream congestion. Station dwell time, by contrast, is shaped by the combined effects of passenger-flow fluctuations, extreme weather, and concentrated transfers; it varies drastically, frequently produces sudden prolonged stops, and follows a value distribution with a pronounced long tail. To accommodate the differentiated spatio-temporal characteristics of these two processes, this paper decouples whole-route arrival time prediction into two spatio-temporal sequence prediction sub-tasks and models each separately.
The bus network is modeled as a directed graph
, where the node set
contains
N spatial nodes, and the edge set
E together with the adjacency matrix
characterizes the connectivity among nodes. At time step
t, the feature vectors of all nodes are stacked into a graph signal matrix
at the current moment, where
F is the feature dimension of a single node. Taking a historical observation window of length
, the historical input tensor is constructed as
. The prediction problem is then defined as follows: given the historical tensor
X and the graph structure
G, a spatio-temporal mapping network
predicts the target state tensor
over the next
time steps, as expressed in Equation (
1).
where
denotes the set of learnable parameters of the network model.
On this basis, the proposed method comprises three stages. First, the multi-source heterogeneous data are normalized and preprocessed, and a spatio-temporal feature matrix at the event granularity is extracted. Next, the input features are split by attribute into two streams: a continuous physical stream (numerical features such as historical operation time series and their periodic encodings) and a discrete semantic stream (categorical features such as weather, road conditions, and congestion level). The two streams are processed separately to prevent the discrete semantic information from being diluted by the continuous features. Finally, according to the characteristics of each task, the features are fed into two customized models: a Dual-Branch Spatio-Temporal Graph Convolutional Network for inter-station travel and a Spatio-Temporal Graph Convolutional Network with Transformer for station dwell. Both models share graph convolution, spatial self-attention, and heterogeneous feature fusion as a common modeling backbone, while adopting different structures in the temporal modeling stage tailored to the characteristics of their respective processes; each ultimately outputs its own predictions, which are combined into the whole-route arrival time. The overall framework of the method is illustrated in
Figure 1.
3.2. Data and Features
This paper takes Bus Route No. 3 in Hohhot as the case study. The route comprises two independent travel directions: the inbound direction contains 36 stops and 35 segments, and the outbound direction contains 37 stops and 36 segments. The dataset comprises four types of data: vehicle-mounted GPS, route nodes, weather, and segment-level traffic conditions, obtained from the Hohhot Public Transport Corporation, the Amap (Gaode) API, and the Baidu API. Among them, the GPS data record the operating status of the vehicles themselves, while the weather and traffic data characterize the external environment affecting bus operation. The composition of each data source is summarized in
Table 2.
The raw data were first normalized in coordinates and along the time axis, corrected through trajectory-to-road-network topology matching, and cleaned by outlier removal. Operational metrics were then extracted at the granularity of station-stop and inter-station travel events, and aggregated at 1 min and 5 min resolutions, respectively. External data, such as weather and traffic conditions, were matched strictly backward using only observations preceding the event time, so as to prevent future-information leakage. On this basis, features including temporal lags, congestion residuals, and environmental interactions were constructed, ultimately yielding a 36-dimensional spatio-temporal feature matrix. According to their physical properties, the matrix features fall into two categories (a continuous physical stream and a discrete semantic stream) whose specific composition and tensorization are detailed in
Section 3.3 in conjunction with each prediction task.
3.3. Model Inputs
3.3.1. Inter-Station Travel Inputs
In terms of feature processing, the input features are split into two categories, namely a continuous physical stream and a discrete semantic stream, and differentiated processing strategies are applied according to their respective attributes to avoid the loss of semantic information.
Continuous physical stream: The extracted features include the logarithmic series of historical travel times, sine-cosine periodic encodings of the hour and the day of the week, and morning/evening peak indicators. These features are normalized to the
interval via min-max scaling, providing the model with numerically stable, scale-free physical-state inputs. The min-max scaling is defined in Equation (
2).
where
x denotes the raw value of the continuous feature to be normalized, and
and
are the minimum and maximum values of that feature, respectively. Through this mapping, all continuous features are projected onto the
interval, eliminating the dimensional discrepancies among features and ensuring that each contributes with equal weight during model training.
Discrete semantic stream: Weather condition codes, traffic density codes, road status codes, and congestion levels are extracted and converted into discrete integers via label encoding, so as to meet the input requirements of the model’s embedding layer.
Temporal alignment and aggregation are performed at a 5 min granularity, and missing spatio-temporal entries are filled by interpolation together with forward and backward filling, so as to preserve the integrity of the temporal structure.
A sliding window of length 6 is used to construct time-series samples, where the input consists of historical multi-step features and the output is the future single-step travel time. The model finally outputs a continuous feature tensor, a discrete feature tensor, a graph-structure tensor, and a label tensor, with dimensions , , , .
For spatial graph construction, a weighted directed graph is built upon the physical topological relationships among bus segments, with nodes corresponding to travel segments. Based on the travel distance between segments, a Gaussian kernel is used to compute the edge weights, capturing the decay of spatial proximity, as defined in Equation (
3).
where
denotes the edge weight between segment
i and segment
j,
is the physical travel distance between the two segments, and
is the bandwidth of the Gaussian kernel, which controls the decay rate of spatial correlation. A shorter distance yields a larger edge weight, thereby reflecting spatial proximity.
In addition, a self-loop is added to each segment to preserve the propagation of its own features and to improve the stability of the graph convolution.
3.3.2. Station Dwell Inputs
In terms of feature processing, the input features are split into two categories: continuous features and discrete features. To capture the fluctuating nature of dwell time, enhanced features such as rolling statistics are extracted to characterize short-term fluctuations, while time-series data leakage is strictly avoided.
Continuous features: the logarithmic series of dwell time, periodic encodings of the hour and the day of the week, and the 3 min rolling mean, 3 min rolling standard deviation, 3 min rolling maximum, and 10 min rolling mean are extracted. All rolling statistics are computed from shifted historical data, without introducing any future information. The continuous features are then normalized to the [0, 1] interval via min-max scaling.
Discrete features: these include morning/evening peak, afternoon peak, weekend indicators, weather condition codes, traffic density codes, and road condition codes, which are converted into integer sequences through label encoding for subsequent categorical embedding learning.
Temporal alignment is performed at a 1 min granularity to construct an equally spaced spatio-temporal sequence, and missing values are handled by interpolation and filling.
A sliding window of length 6 is used to construct time-series samples, where the input consists of historical multi-step features and the output is the future single-step travel time. The model finally outputs a continuous feature tensor, a discrete feature tensor, a graph-structure tensor, and a label tensor, with dimensions , , , .
For target-distribution correction and spatial graph construction, a logarithmic transformation is applied to the target variable to address the skewness and long-tailed nature of dwell time, mapping it to an approximately normal distribution and reducing the influence of extreme values. The transformation is defined in Equation (
4). After the transformation, the target is normalized so that it remains consistent with the numerical range of the inputs.
where
y denotes the raw target value of station dwell time, and
is the target value after the logarithmic transformation. The
transformation alleviates the right-skewed distribution and long tail of dwell time, thereby mitigating the impact of extreme values on model training.
A linearly structured directed graph is constructed according to the sequential order of stops, where the nodes correspond to bus stops and adjacent stops are linked by bidirectional connections to reflect the travel association between them; a self-loop is added to each node to preserve the propagation of its own features. Considering that the travel association between adjacent stops is relatively uniform, and in order to simplify computation and improve training stability, all edge weights are set to 1. This setting meets the feature-interaction needs of the subsequent spatial modeling and is consistent with the spatial-correlation characteristics of station dwell time.
3.4. Bus Inter-Station Travel Time Prediction Model
Inter-station travel time evolves smoothly and exhibits strong temporal regularity, and its spatial dependence arises both from congestion propagation between adjacent segments and from implicit associations among non-adjacent yet similar segments. To address this characteristic, and building on the separated inputs of the continuous physical stream and the discrete semantic stream, this section proposes a Dual-Branch Spatio-Temporal Graph Convolutional Network. DSTGCN is an end-to-end spatio-temporal prediction architecture comprising five modules: a multi-source input layer, a dual-branch spatial feature extraction layer, a heterogeneous feature fusion layer, a temporal evolution feature extraction layer, and a regression output layer. The overall architecture is illustrated in
Figure 2.
3.4.1. Dual-Branch Spatial Feature Extraction Layer
The dual-branch spatial feature extraction layer captures the spatial dependence of the road network. It consists of three steps: feature projection, dual-branch parallel extraction, and residual fusion. Together, these steps handle the physical-connectivity constraints of the road network and the global implicit spatial associations, providing a basis for the subsequent feature fusion. Because traffic-flow diffusion in urban road networks is heterogeneous, a conventional single-graph network is prone to the limitation of a predefined local receptive field. This layer therefore adopts a dual-branch architecture that balances physical-connectivity constraints with the flexibility of global associations. A linear projection is first applied to map the input features into a high-dimensional latent space, as defined in Equation (
5).
where
is the continuous physical-stream input tensor,
and
are the weight and bias of the linear projection layer, respectively, and
is the high-dimensional feature tensor after the initial projection.
The first branch performs local physical-dependency modeling based on spectral graph convolution. Taking the static adjacency matrix of the road network and physical-distance decay weights as priors, this branch models the linear spatial diffusion of traffic flow and the spatial coupling between adjacent segments.This computation is given in Equation (
6).
where
is the weighted adjacency matrix with self-loops added,
is the corresponding degree matrix, and
is the weight of the graph-convolution layer.
The second branch performs global implicit-association modeling based on multi-head spatial self-attention. This branch does not rely on the physical connectivity of the road network; by computing dynamic similarities among all nodes, it identifies functional regions with similar traffic patterns (e.g., transportation hubs that are spatially distant yet share tidal morning/evening peak patterns). This computation is given in Equations (7) and (8).
where
Q,
K, and
V are the query, key, and value matrices, respectively;
is the feature dimension of the key matrix in the attention mechanism;
is the spatial-attention output feature; and
is the spatial fusion feature after the residual connection and layer normalization.
Finally, the model adopts a residual aggregation strategy that adds the physical-connectivity features and the global semantic features element-wise, i.e., . This dual-branch architecture retains the constraints of the road network’s physical connectivity while providing the flexibility of global perception, thereby overcoming the limitation of a single-graph structure in capturing long-range spatial dependence.
3.4.2. Deep Heterogeneous Feature Fusion Layer
The heterogeneous feature fusion layer enables the interaction between continuous traffic-flow features and discrete environmental features, addressing the environmental-semantic dilution caused by conventional feature concatenation. Traditional spatio-temporal prediction models often concatenate high-dimensional, sparse, discrete environmental variables, such as weather and road conditions, with continuous traffic flow and normalize them jointly, which tends to dilute and even lose the environmental semantics. This layer therefore fuses the two types of heterogeneous features through discrete-feature embedding.
This architecture designs a dedicated categorical embedding space for the discrete semantic stream, mapping discrete categorical tokens into dense continuous vectors
to strengthen the model’s contextual awareness. During feature interaction, a spatial-first order is followed: the spatio-temporal feature
extracted by the two branches is obtained first, then concatenated with the external embedding features along the feature dimension and fed into a fully connected projection layer to complete the interaction, as defined in Equation (
9).
where
denotes the concatenation of the spatial features and the environmental embedding features along the feature dimension;
and
are the weight and bias of the fusion projection layer, respectively; and
is the fused spatio-temporal feature tensor.
This fusion mechanism nonlinearly modulates the spatial state of traffic flow through discrete environmental factors, enabling the model to adjust the baseline for computing travel efficiency of the corresponding segment under different weather conditions.
3.4.3. Temporal Evolution Modeling Layer
The temporal evolution feature extraction layer tracks the macroscopic diffusion trend of traffic flow and addresses the local feature attenuation and response lag that traditional recurrent neural networks suffer from when handling long sequences. This layer embeds a lightweight temporal attention module in front of the LSTM to form a two-layer temporal processing structure, which reweights the features across different time frames and improves the model’s ability to capture the non-stationary evolution of traffic flow.
The temporal attention module adaptively allocates weights to the historical time steps. Let the fused spatio-temporal sequence be
; a feedforward neural network computes a weight score for each historical time step, which is then normalized by the Softmax function, as defined in Equations (10) and (11).
where
,
, and
are learnable weight parameters;
S is the intermediate weight matrix; and
is the normalized temporal attention weight.
This mechanism performs feature weighting through the Hadamard product, as defined in Equation (
12), reweighting the feature responses at different time points. The weighted time-series features are then fed into the LSTM unit, which processes the temporal information through its internal gating mechanism and tracks the macroscopic diffusion trend of traffic flow, as defined in Equation (
13). Finally, the hidden state
at the end of the sequence is extracted, and the prediction is produced through a regression mapping, as defined in Equation (
14); this alleviates the prediction lag caused by an end-to-end sequence model’s undifferentiated treatment of time steps.
where ⊙ denotes the Hadamard product, i.e., element-wise matrix multiplication;
and
are the hidden state and cell state of the LSTM unit at time step
t, respectively;
and
are the weight and bias of the output layer, respectively; and
is the predicted inter-station travel time.
The regression output layer maps the high-dimensional features from the temporal evolution feature extraction layer to the final inter-station travel time prediction, and the model parameters are optimized via a loss function. The model adopts the MSE as the loss function, as defined in Equation (
15), driving the parameters to converge by minimizing the squared error between the predicted and ground-truth values.
where
y is the ground-truth inter-station travel time,
is the predicted inter-station travel time, and
n is the number of samples.
3.5. Bus Station Dwell Time Prediction Model
The bus arrival time is jointly determined by the inter-station travel time and the station dwell time. Compared with the smooth running state along segments, station dwell time is affected by the combined influence of passenger-flow fluctuations, extreme weather, concentrated transfers, and the use of accessibility facilities, exhibiting pronounced non-stationarity and an extreme-valued long tail. When handling such non-stationary time series, traditional recurrent neural networks suffer from long-range memory decay and gradient instability.
To this end, this section proposes STGCN-Trans (Spatio-Temporal Graph Convolutional Network with Transformer), an end-to-end spatio-temporal prediction architecture comprising five modules: a multi-source input layer, a spatial feature extraction layer, a heterogeneous feature fusion layer, a global temporal modeling layer, and a regression prediction layer. The framework extracts dependencies in spatio-temporal data through multi-source input fusion, feature extraction via graph convolution and spatial attention, and global temporal modeling with a Transformer, thereby completing station dwell time prediction. The overall architecture is illustrated in
Figure 3.
3.5.1. Multi-Source Input Layer
The multi-source input layer is the input module of STGCN-Trans. It receives two types of feature tensors (continuous features and discrete features) and applies a differentiated processing pipeline according to the properties of each, so as to preserve complete and effective feature representations. The input features comprise continuous features and discrete features , as detailed below.
Discrete features: the discrete categorical tokens are first transformed into dense continuous vectors through a categorical embedding layer, after which positional encoding (PE) is added to preserve the sequential order information, compensating for the self-attention mechanism’s limited sensitivity to absolute positions within the sequence.
Continuous features: these are fed directly into the subsequent layer, where a feedforward neural network performs the dimensional transformation and projects them into a high-dimensional latent space, meeting the input-dimension requirements of the subsequent spatial feature extraction.
Specifically, the continuous feature tensor is , where B is the batch size, T is the length of the time series, N is the number of station nodes, and is the dimension of the normalized continuous variables. After projection by the feedforward neural network, is obtained. The discrete feature tensor is , from which a dense continuous representation of the environmental variables, , is produced after the embedding layer, where is the embedding dimension of the discrete features.
3.5.2. Spatial Feature Extraction Layer
The spatial feature extraction layer primarily extracts the complex dependencies along the spatial dimension. Through the joint processing of spectral graph convolution and spatial self-attention, it accounts for both the spatial-connectivity constraints of the road network and the global implicit associations, providing input for the subsequent feature fusion. This layer consists of three main steps: spectral graph convolution (GCN), multi-head spatial self-attention, and residual fusion, described as follows.
Spectral graph convolution (GCN): the spatial structural information of the continuous features processed by the multi-source input layer is extracted. Taking the stop adjacency graph with uniform edge weights as a prior, this branch models the spatial diffusion of dwell-related patterns between adjacent stops and captures the dependence among neighboring nodes, as defined in Equation (
16).
where
is stop adjacency matrix with self-loops added, defined on adjacent stops with uniform edge weights of 1,
is the corresponding degree matrix, and
is a learnable weight parameter.
Spatial multi-head self-attention (Spatial MSA): after the GCN layer, a multi-head spatial self-attention mechanism is introduced in parallel to overcome the feature-extraction limitation of GCN, which is constrained by physical associations in Euclidean space. By linearly mapping the query matrix
Q, key matrix
K, and value matrix
V, it dynamically computes spatial similarities along the node dimension
N, further capturing interactions along the spatial dimension and identifying implicit associations among non-adjacent stops, as defined in Equation (
17).
Residual fusion: the outputs of the GCN and the spatial attention are combined through a residual connection and layer normalization to achieve late fusion, yielding a comprehensive spatial feature representation, as defined in Equation (
18). This retains the rigid constraints of physical edges while endowing the model with global perception; the feature tensor is finally reshaped to
.
3.5.3. Heterogeneous Feature Fusion Layer
The heterogeneous feature fusion layer enables the deep interaction between spatial features and discrete environmental features, avoiding the environmental-semantic dilution caused by conventional feature concatenation. External environmental factors, such as abrupt weather changes and weekends or holidays, exert a strong nonlinear modulation on bus dwell time. If high-dimensional, sparse, discrete features are forcibly concatenated with continuous traffic flow and normalized jointly, the environmental semantics are readily diluted.
To this end, this layer adopts a deep fusion strategy: the spatial state
output by the spatial feature extraction layer is concatenated along the feature dimension with the environmental embedding features
produced by the multi-source input layer, and fed into a fully connected projection layer to perform the cross-modal nonlinear mapping, as defined in Equation (
19). The underlying rationale is to use the environmental context to modulate the base spatio-temporal features, enabling the model to adaptively account for the effects of factors such as rainfall on boarding/alighting efficiency and vehicle delays.
where
denotes the concatenation of the spatial features and the environmental embedding features along the feature dimension;
and
are the weight and bias of the fusion projection layer, respectively; and
is the fused spatio-temporal feature tensor.
3.5.4. Global Temporal Modeling Layer
The global temporal modeling layer primarily captures the non-stationary impulse characteristics and the temporal dependencies across the input window of station dwell time, and alleviates the long-range memory decay of traditional recurrent neural networks. It mainly consists of three steps: tensor dimension reshaping, positional encoding, and temporal feature extraction by a Transformer encoder, described as follows.
First, to avoid the redundant interference of spatial-dimension computation and to focus on the temporal evolution of each individual stop, the fused tensor output by the heterogeneous feature fusion layer is permuted and reshaped: the time-step dimension T and the node dimension N are exchanged, and the batch dimension B and the node dimension N are merged, yielding a time-series-dominant independent evolution tensor . The rationale of this permutation is to let the Transformer encoder focus on the temporal evolution within the input window of a single stop, rather than the multi-stop spatial correlation within a single time step; this matches the dominant characteristic of station dwell time, in which the temporal variation within a single stop is the primary driver of dwell-time changes, while the spatial correlation across stops is a secondary factor.
To compensate for the self-attention mechanism’s limited sensitivity to absolute positions in the sequence, an alternating sine-cosine positional encoding (PE) is introduced, as defined in Equations (20)–(22).
where
is the position index within the sequence,
i is the feature-dimension index, and
D is the total feature dimension.
The tensor is then fed into a Transformer encoder module comprising a multi-layer perceptron and multi-head self-attention, as defined in Equation (
23). Through the parallel allocation of attention weights, this module alleviates the information decay caused by the step-by-step propagation of traditional RNNs along the time axis; when an abnormally long dwell event occurs in the historical sequence, the Transformer can capture this peak feature directly across time steps, more effectively modeling transient patterns and extreme-valued outliers.
Finally, the hidden state of the last time step of the Transformer encoder, , is extracted as the aggregated temporal feature, providing the primary feature support for the subsequent regression prediction.
3.5.5. Regression Prediction Layer
The regression prediction layer is the output module of STGCN-Trans. Its main function is to map the temporal features from the global temporal modeling layer to the final station dwell time predictions, and to optimize the model parameters through a robust loss function. It consists of two main components: a fully connected (FC) layer and a loss function.
Fully connected (FC) layer: the last-time-step hidden state extracted by the global temporal modeling layer is mapped through a linear layer and reshaped back, producing the prediction matrix , thereby completing the conversion from features to predictions.
Loss function: given the long-tailed distribution of bus dwell time, where extreme outliers caused by factors such as equipment failures persist even after the logarithmic transformation, the smooth mean absolute error (smooth L1) is adopted as the optimization objective, so as to mitigate the gradient explosion that may arise during backpropagation.
Given the long-tailed distribution of dwell time, the smooth mean absolute error (smooth ) is adopted as the optimization objective. When the prediction residual satisfies , the mean squared error (MSE) is used to ensure stable convergence in the neighborhood of extreme points; when the residual exceeds , the loss switches to the mean absolute error (MAE) branch, so that the per-sample gradient saturates at a constant magnitude instead of scaling with the error. This mitigates the gradient explosion induced by extreme samples and improves the stability of parameter updates. The threshold is fixed at as a preset hyperparameter rather than a value learned during training. This choice is consistent with the residual statistics of the training set: after the logarithmic transformation and feature scaling, the dwell-time residuals occupy a compact range, and lies close to their 95th percentile, which serves as the boundary between normal fluctuations and outliers.