Dealing with uncertainty in agent-based models for short-term predictions

Agent-based models (ABMs) are gaining traction as one of the most powerful modelling tools within the social sciences. They are particularly suited to simulating complex systems. Despite many methodological advances within ABM, one of the major drawbacks is their inability to incorporate real-time data to make accurate short-term predictions. This paper presents an approach that allows ABMs to be dynamically optimized. Through a combination of parameter calibration and data assimilation (DA), the accuracy of model-based predictions using ABM in real time is increased. We use the exemplar of a bus route system to explore these methods. The bus route ABMs developed in this research are examples of ABMs that can be dynamically optimized by a combination of parameter calibration and DA. The proposed model and framework is a novel and transferable approach that can be used in any passenger information system, or in an intelligent transport systems to provide forecasts of bus locations and arrival times.


Introduction
Agent-based modelling (ABM) [1] is a field that excels in its ability to simulate complex systems. Instead of deriving aggregated equations of system dynamics, ABM encapsulates system-wide characteristics from the behaviours and interactions of individual agents, e.g. human, animals or vehicles. ABM has emerged as an important tool for many applications ranging from urban traffic simulation [2], humanitarian assistance [3] to emergency evacuations [4].
Despite the many advances and applications of ABM, the field suffers from a serious drawback: models are currently unable to incorporate up-to-date data to make accurate real-time predictions [5][6][7]. Models are typically calibrated once, using historical data, then projected forward in time to make a prediction. Here, calibration is ideal for one point in time, but as the simulation

Research problem and related works
Historical and real-time bus GPS data are often used by operators to locate buses and predict their locations and arrival times. The prediction of bus locations and arrival times in real time is a challenging problem [15]. Ideally, perfect knowledge of the current state of the system and any underlying processes is required. However, obtaining this level of knowledge is impossible owing to sources of uncertainty and the complex interactions in bus operations. The majority of research within this area has focused on machine learning methods to find a direct mapping between input data and bus arrival time. Examples of these methods include artificial neural networks [15], support vector machines [14] and Bayesian techniques [12]. While machine learning methods can provide very accurate and efficient predictions in real time, they are solely reliant on the quality and quantity of the available data. Even with high-resolution datasets that record accurate spatio-temporal bus locations, there is an array of additional features that are not recorded in the observed data (such as the downstream population waiting for a bus) so the full complexity of the system will never be captured.
Instead, analytical and simulation models of bus routes have been proposed that aim to reproduce the underlying processes in bus operations, rather than attempting to identify direct mappings between inputs and outputs. One of the earliest successes in simulating a simple bus systems was from cellular automata modelling [16][17][18][19]. While the dynamical foundations of these models are well understood, they are outperformed by more sophisticated models such as bus-following models [20][21][22][23][24]; traffic-following models [25][26][27], schedule-following models [28] and ABMs [29,30]. Bus-following models aim to model the fundamental dynamics of a bus route by modelling individual buses that follow each other (for example, speeding up if the bus ahead is far away). Traffic-following models, on the other hand, aim to model buses as a component of a transport system with private and public transport, where their speeds are affected by the traffic flow, traffic signals [26] or traffic density [27]. Schedulefollowing models assume that buses try to adhere to their schedules and adapt their speeds as they are ahead or behind the schedule [28]. There are also several recent ABMs of public transport, where buses are interacting with other buses and the traffic [29,30]. Compared to other approaches, ABM is able to replicate more complex phenomena in bus' operations, such as crowding, bus bunching and leap-frog bunching [29]. ABMs of buses are also often implemented in advanced ABM systems, such as MatSim [29] and AnyLogic [30], where multiple interactions and heterogeneous behaviour can be modelled.
One way for these models to fit better to the observed data is to adjust the model parameters until the model satisfies some predetermined criteria. This parameter adjustment process is often referred to as parameter calibration. Popular optimization techniques include simulated annealing [31], genetic algorithms, [32,33] and approximate Bayesian computation [34]. Parameter calibration, especially with ABMs, is often only implemented once, and therefore cannot account for any changes that may take place within the system during run time. In fact, the real bus operation is certainly dynamic, where the system states are changing over time in response to traffic conditions or passenger demand. In real time, there is also uncertainty about the bus operations that comes from the lack of information regarding the current system states. Examples of such unobservable system states include the number of passengers who are waiting at downstream stops or the number who plan to get off the bus, and the surrounding traffic conditions. The lack of information about these factors means that any model of bus operation in real time will have to make assumptions thereby introducing errors in their predictions. Therefore, this research will develop a framework that allows complex simulation models of buses to deal with uncertainty in real time and make short-term predictions. We will explore a combination of parameter calibration and a DA technique to deal with both the two types of uncertainties about the bus operation that have been discussed: the changing system states and the unobservable information. The idea is to calibrate an ABM bus route simulator using historical data which is then dynamically optimized on-the-fly using real-time data. This, in itself, is a novel and important contribution. Previous efforts have attempted to incorporate DA with ABMs directly (for example, see [6,7]) and indirectly (e.g. through a 'self-evolving simulation framework' [35]) but it is unclear how DA methods, that have typically been created for linear models [11], can be adapted for nonlinear ABMs.
DA methods assume that observational data are sparse and only describe the target system in limited detail. Therefore, a model is essential as a means of filling in the gaps in space and time left by the observations through the generation of additional data. In effect, the model propagates data from observed to unobserved areas [36]. Although techniques can be used to perform parameter estimation, they are most often framed as a state estimation problem. The aim is to calculate a posterior royalsocietypublishing.org/journal/rsos R. Soc. open sci. 7: 191074 probability for the state vector X t , given prior distributions from a model (in this case, a bus route operation model) and data from observations. It is this marriage of a model and real-time observational data (and the associated uncertainties) that offers the means of allowing all the available information to be used to determine the true state of the system as accurately as possible [37]. Models where the system state at time t are only dependent on the state at time t − 1 are termed Markovian. We are particularly interested in ABMs that can be written in a Markovian nature because DA algorithms require knowledge to the full model state in the form of the state vector X t . While some ABMs in the literature track agent histories and use this information to decide future states, these can be recast as Markovian ABMs by expanding the state vector to include these histories. Implementing a bus route system as a Markovian model requires variables such as vehicle locations, speeds, occupancies etc. It is reasonable to assume that the system state at the next time step only depends on the value of these variables at the current time step. For simplicity, we assume that the state vector used here has a fixed size. The unused variables (i.e. those for buses that have yet to enter the system) can be set to zero, enabling the state vector to be treated as sparse and passed efficiently between iterations. If the state vector has a fixed size, then all possible states of the system belongs to a state-space X [ R n . The system state evolves in some fixed interval {0, … , K}. We denote the state of the bus route at time t by X t [ X.
In practice, one would develop simulation models of bus systems that aim to replicate the real bus operations by providing outputs that are as close as possible to some historical bus data. This paper, instead, follows a 'pseudo-truth' experiment framework, similar to [6]. The experiment data to be used will be 'synthetic', or generated from simulation instead of using real data. The reason is that real data often comes with noise that hides the true state of the bus route (e.g. noise from GPS data). A simulated synthetic data would enable us to control the level of noise in the data, and to evaluate the modelling results against the ground truth rather than noisy data. Figure 1 shows the workflow of this study.
Any simulation model, in practice, is essentially an imperfect replication of reality. For instance, the real bus operation is both dynamic (the system states are changing over time) and stochastic (there is inherent randomness in the system). Recall that the objective of this paper is to improve the accuracy of short-term forecasts using ABMs by performing dynamic state estimation of the current system state. This is essentially the final product at time t + 1 in figure 1. Improvements of the forecasts at time t + 1 is archived by improving the estimation of system state at time t, by using DA to transform a 'prior state vector' ( pure models' estimates) to a 'posterior state vector' (models' estimates combined with real-time data).
Taking this into consideration, we develop a framework (illustrated in figure 1) where the model that will be used to generate the synthetic 'pseudo-truth' data that is both dynamic and stochastic, to be as close as possible to the real system. We will refer to this model as BusSim-truth. The developed framework will then be evaluated on two simpler variations of this model. This is similar to the practice where no simulation model of bus operations would be able to completely replicate the dynamics of the real bus system. Both simpler models are static (i.e. they both have states that are unchanged over time) but one of them is deterministic and another one is stochastic: (i) BusSim-deterministic: this model evolves exactly the same way in each model run; and (ii) BusSim-stochastic: this model is stochastic, e.g. the numbers of people waiting at bus stops is drawn from a random distribution.
The study workflow generally consists of two major steps. It starts with the development of the BusSim-truth model. Two sets of pseudo-truth data will be generated. The first represents 'historical' GPS data, which are essentially the outputs of multiple runs of the same BusSim-truth model with the same predefined set of parameters. The GPS data will be slightly different each time the model is run because BusSim-truth is stochastic and dynamic. The second set of data represent a single run of BusSim-truth, also using the same set of parameters. These data will represent synthetic 'real-time' GPS data and will be used to conduct DA. This situation is similar to the reality, where transport companies collect data across multiple days to build up a 'history' of the behaviour of the bus system and subsequently use these data to calibrate models. The 'real-time' data represent the current state of the world. The BusSim-truth model is not a perfect replication of reality, but contains the dynamic and stochastic features similar to a real bus system. It also replicates frequent phenomenon in bus operations such as bus bunching (where two buses of the same line arrive at the same bus stop at the same time).
As would be necessary in reality, BusSim-deterministic and BusSim-stochastic will first be calibrated against the synthetic 'historical' GPS data. In the second step of the study workflow, DA will be used in an attempt to update the states of the models to the 'real-time' GPS observations in order to produce more accurate short-term forecasts of the system behaviour.

A hypothetical version of reality: BusSim-truth and its two simpler variations
The first step in the proposed workflow is to develop an agent-based bus route model that will be used to generate synthetic GPS data for each bus on the route (BusSim-truth). BusSim-truth is a stochastic and dynamic model with two classes of agents (bus and bus stop) and predefined parameters (table 1). It is stochastic because the number of boarding passengers is drawn from a random distribution, and dynamic because its parameters gradually change over time. The level of stochasticity and dynamicity in BusSim-truth can also be adjusted to represent bus route systems where conditions are largely stable or volatile over time. Figure 2 illustrates the workflow for BusSim-truth. Only a brief explanation of the model is included here, as more information on how the BusSim-truth model works can be found in appendix A. At each current time step, each bus agent checks whether the next time step would be larger than the vehicle's scheduled dispatch time. If it is, we then check whether the bus is on the road (status equals MOVING), or at a stop for passenger dwelling (status equals DWELLING), or has finished its service (status equals FINISHED), otherwise the bus remains IDLE.
If the status is MOVING, we first check whether the bus is at a bus stop, by comparing the GeoFence area of each bus stop agent with the bus location. If the bus is not approaching a bus stop, its current speed will be compared with the surrounding traffic speed. In the case it is slower, we assume that the bus will speed up. If the speed already matches the traffic speed, the bus will maintain the same speed. Currently, the traffic volume on the whole network is represented as a single dynamic parameter, although in practice it would be relatively simple to make the traffic volume heterogeneous across the network. The system will first check if the stop is at the last stop when the bus is approaching a bus stop, where the bus status will be changed to FINISHED and the bus speed changed to zero. If it is not the last stop, the system will change the status of agent bus to DWELLING and its speed to zero.
As described in §2, we use BusSim-truth to generate two sets of synthetic data: (i) 'historical' GPS data that simulate normal bus route operation over a number of days and are used for calibration; and (ii) 'real-time' GPS data that represents a single run of the model and are used to represent the royalsocietypublishing.org/journal/rsos R. Soc. open sci. 7: 191074 bus system today. These are visualized in the time-space diagram in figure 3. Each coloured line shows the trajectory of one bus in the 'historical' GPS data. The bold black lines are another instance of the bus trajectory that we consider as the 'real-time' GPS data.
The x-axis shows the time of simulation from 0 to 6000 s, where multiple bus services can be found. The y-axis shows the distance from the first bus stop (distance equals zero) to the last stop (distance equals 40 000 m). Assuming that all buses start their service on-time, figure 3 shows bunches of bus service (each with a different colour) and their associated synthetic real-time data (bold lines). As the BusSim-truth model is stochastic, there are a spread of trajectories within each service. This is similar to the reality where buses operate slightly differently on multiple days.   Each record in the synthetic data is called an observation vector. The vector contains all of the observations made from the 'real world' (in this case the BusSim-truth).

Optimizing the parameters of BusSim-deterministic and BusSim-stochastic
Most ABMs have a large number of parameters. For the BusSim models, the model parameter vector S t at time t contains the arrival rate Arr t m , departure rate Dep t m at each stop m, and the traffic speed V t : The two simpler models (BusSim-deterministic and BusSim-stochastic) first need to be calibrated to the observations (the historical data). Here, an automatic parameter calibration process, based on the cross-entropy method (CEM) [38] is used. CEM is a population-based Monte Carlo learning algorithm to combinatorial multi-extremal optimization and importance sampling. It originated from the field of rare event simulation, where even small probabilities need to be estimated [38]. In principle, CEM develops a probability distribution over possible solutions for the optimal parameters of the model. New solution candidates are drawn from this distribution and are evaluated. The best candidates are then selected to form a new improved probability distribution of the optimal parameters, until certain criteria are met. CEM is chosen over other popular optimization methods in parameter calibration of ABMs, such as genetic algorithm [32] and simulated annealing [31], because of its probabilistic nature that facilitates the calibration of stochastic models [39]. The interested reader may refer to [38], and various applications of CEM, such as [39], for a more detailed account. A pseudo-code of the CEM algorithm that we adopted for this paper has also been described in appendix B.
Formally, the parameter calibration is an optimization problem to minimize some performance index PI(π) over all p [ R k . Here, a solution π = (π 1 , π 2 , …, π k ) denotes a set of parameters of the model under consideration and k denotes the number of dimension in this set (see equation (3.1)). Let p Ã denote the optimal solution, or the best set of model parameters that we want to find, that is (3:2) The above objective function is equivalent to finding p Ã such that PI (p Ã ) PI (p) 8X [ P, where Π is a constrained parameter space such that P [ R k . The performance index PI(π) is generally the difference between model output and observed data. The complexity of this problem comes from the stochasticity of BusSim, where the same solution π may yield a different realization PI(π). To reduce this stochastic effect, it is necessary to run the (stochastic) model multiple times, and to evaluate the simulation outputs against a compilation of observed data from multiple days or instances. Let K I be the number of replications required for each model evaluation and K O be the number of instances in the observed data, we can derive a more detailed objective function of the parameter calibration problem: where N is the number of buses, T is the number of time steps, s SIM j,i,t is the location of simulated bus agent j at time t for the replication i, and similarly s OBS j,o,t is the synthetic observed location of bus j at time t for the instance o. The objective function in equation (3.3) can be seen as the sum of the difference in mean location and standard deviation of locations at each time step for each bus and each replication/instance between the simulated outputs and synthetic observed data. Owing to the stochasticity within the system, we need to evaluate the difference in the mean and standard deviation of bus locations (the spread of bus locations over multiple instances are important).

Data assimilation using a particle filter
We can formulate an ABM as a state-space model _ X t ¼ f(X t ) þ e t and use DA to dynamically optimize the model states and parameters with up-to-date data to reduce uncertainty. The state-space model is represented by a state-space vector X t at time t, which contains all information of the current state of each agent in the model, and the important parameters that we want to dynamically optimize as the model is running: The state-space vector X t must contain all of the information that identifies the current state of the modelled system, allowing it to be projected forward to the next time step. Thus vector X t usually contains both the observation vector O t and the model parameters vector S t (equation 3.1) at time t. Note that S t has been calibrated in the previous section, but is still included in the state-space vector X t to allow the model to be dynamically optimized with new data-this is essential in dynamic situations where parameter values change over time. This approach is often referred to as dynamic calibration [40].
DA is a suite of methods to adjust the state of a running model using new data to better represent the current state of the system under study [7]. DA was born out of data scarcity, where observation data are sparse and insufficient to describe the system. Notwithstanding the proliferation of new data sources, insufficient data is still a major problem in research. The prediction of bus locations is a clear example where the number of future boarding and alighting passengers are unknown in real time. DA algorithms fill in the spatio-temporal gaps in the observed data by running a model forward in time until new observed data are available. This is typically called the predict step in DA algorithms. After the predict step, DA has an estimate of the current system state and its uncertainty (which is often referred as the 'prior' in Bayesian literature). The next step is typically called the update step, where new observations and uncertainty are used to update the current state estimates. The result is referred to as the 'posterior' in Bayesian literature, and should be the best guess of the system state from both the observations and model.
There are several DA algorithms in the literature, ranging from the simple Kalman filter [41] to more advanced extensions, including extended, ensemble and unscented Kalman filter [7]. These algorithms generally aim to extend the original Kalman filter by relaxing the assumption of linearity and introducing methods to work with nonlinear models. However, they may not be the most suitable candidate to incorporate data into ABMs for two reasons. First, ABMs are driven by a large number of interacting agents with goals, history and behavioural rules. As a result, they lack an analytic structure, such as differential or difference equations, to facilitate the implementation of the Kalman filter and its extensions where often the model Jacobian and covariance matrices need to be formulated [6]. Second, although the assumption of linearity has been relaxed, these extensions assume that the noise in the model estimation is Gaussian.
There is a flexible Bayesian filtering method that has been designed to work with nonlinear, non-Gaussian models without analytical structure; this is the PF. The key idea is to approximate a royalsocietypublishing.org/journal/rsos R. Soc. open sci. 7: 191074 posterior distribution by a set of samples or particles, drawn from this distribution. Each particle is a concrete hypothesis of the true system state. The set of particles approximates the posterior distribution. PF is best described as a non-parametric Bayes filter because it develops the belief using a finite number of samples.
Hypotheses of the system state at time t is represented by a set P t of N P weighted random particles: where X bie t is the state vector of the i-th particle and w bie t is the corresponding weight. Weights are non-zero, and the sum over all weights is 1. The core idea of the PF is to update and maintain this set of particles given model outputs and observations. A PF recursively estimates the particle set P t based on the estimate P t−1 at the previous time step, and the observation. The PF algorithm can be briefly described in three steps: (i) predict: generate the next set of particlesP t from the previous set P t−1 . This represents the prior distribution to describe how the system state evolves; (ii) importance weighting: compute the importance weight w bie t for each particle in P t . This is equivalent to the 'Update' step in the Kalman filter, and will give us the posterior distribution; and (iii) resampling: this step has no analogous step in the Kalman filter and its extensions. The resampling step creates a new set of particles from the current set. The likelihood to draw a particle is proportional to its weight. We adopt sample importance resampling (SIR), a popular bootstrap systematic resampling in the PF literature [6,36]. SIR has been developed to deal with particle deprivation, which is the problem when particles converge to a single particle after several iterations owing to one particle outperforming all others [42]. This problem significantly reduces the area of state space covered by the particles in later iterations.
Because resampling will generate particles using the existing pool of particles, it will not be able to produce particles where the prediction accuracy is better than the existing particle pool. This means that in classical PF, the model parameter S t of both BusSim-deterministic and BusSim-stochastic will be unchanged over time. Because the parameters change over time, we need to dynamically optimize S t . This problem is solved in this paper by a simple and generic solution. We improve the quality of the particles by diversification similar to [43], in a process also known as roughening, jittering and diffusing [44]. This is achieved by adding a random Gaussian white noise σ with mean 0 and a predefined standard deviation, not to the whole state vector X t , but to the model parameter S t , to increase the probability of having particles that represent the current state of the underlying model. The PF is applied to BusSim-deterministic and BusSim-stochastic using up-to-date data from the synthetic 'real-time' GPS data. DA could take place after any number of prior model iterations (e.g. [45] use a DA window of 100 iterations) but here it takes place after every model iteration. This is a fair assumption for this application because in reality bus GPS data could be available in near real-time, or at least at a frequency that is similar to the real amount of time represented by a single model iteration.

Numerical experiment 4.1. Experiment set-up
To generate the synthetic 'historical' and 'real-time' GPS data used in BusSim-deterministic and BusSimstochastic, we predetermine a set of model parameters to generate realistic GPS data. Table 2 lists the fixed parameters being used in this experiment.  1)) are time-varying and therefore, randomly generated using fixed rules. We first generate an initial arrival rate Arr 0 m at stop m at time 0 by a random generation from an uniform distribution between the minimum and maximum passenger arrival rate [minDemand, maxDemand]: (4:1) The departure rate is also generated from an uniform distribution, but also ordered ascending to represent the fact that more passengers alight at the end of the route than at the beginning. The departure rate at the last stop (stop M) is set as 1 to allow remaining passengers to alight the bus at the last stop: Finally, the initial traffic speed is set at 14 m s −1 .

The stochastic and dynamic nature of BusSim-truth
This section aims to provide a simple verification that demonstrates BusSim-truth generates realistic synthetic GPS data under different sets of parameters. First, let us look at some real trajectories from observed GPS data, as illustrated in figure 4. The figure shows six months of real GPS trajectories from July to December 2015. The data are from Route 555 in Brisbane, Australia, a busy bus route connecting Logan City to Brisbane Central Business District via a segregated busway. Each GPS record includes information about each visit to a bus stop, including: route number, trip ID, vehicle ID, scheduled departure time, observed arrival time and observed departure time. Figure 4 shows similar trajectories to the simulated trajectories illustrated earlier in figure 3. As previously discussed, we will not attempt to calibrate and validate BusSim-truth against this observed data. This section rather aims to show that BusSim-truth is reasonably realistic, can replicate common phenomena in bus operations and has parameters that we can easily control for in subsequent experiments.
We aim to control the stochastic and dynamic level in BusSim-truth using only a single parameter for each. Equation (4.1) controls the level of stochasticity in BusSim-truth. For instance, a pair of values [minDemand, maxDemand] ¼ [0:5, 1] means 0.5 to 1 passenger arriving at the bus stop each minute. By fixing the minDemand to be a small number (e.g. equals 0.5), we can control the stochasticity of BusSimtruth by a single parameter maxDemand, with a larger maxDemand meaning more stochasticity and vice versa. We control the level of dynamicity in BusSim-truth by a dynamic change rate parameter ξ, which gradually changes the arrival rate and surrounding traffic speed over the simulation period.
To implement an inner verification of the BusSim-truth model and to investigate the impacts of the stochastic and dynamic natures of the system under study, we evaluate the outputs from BusSim-truth using different values of stochasticity and dynamicity. Figure 5 gives an insight into the differences in bus trajectories when maxDemand equals 0.5 and 2. Note that when maxDemand equals 0.5, BusSim-truth reduces to a deterministic model (similar to BusSim-deterministic). This is because maxDemand would be equal to minDemand.  Each line in figure 5 shows the GPS trajectory of the bus location, as generated by BusSim-truth. The solid lines show the trajectory of buses at high and stochastic demand (maxDemand equals 2), whereas the dashed lines are for low and deterministic demand (maxDemand equals minDemand and equals 0.5). The trajectories in figure 5 show that as the maxDemand increases, there are more delays for individual buses and it is less likely that buses are able to keep stable headway from each other. In times of high passenger demand, BusSim-truth can replicate common phenomena in bus operations, including bus bunching and leap-frog bus bunching.
The dynamic nature of BusSim-truth is illustrated in figure 6 when the dynamic change rate parameter ξ is equal to 1% and 10%. Because the arrival rate and traffic speed gradually change, there is little change in the bus trajectories of BusSim-truth with ξ equalling 1% and 10%. As time passes, there are more delays for BusSim-truth as ξ equals 10%. This is because there are more passengers (higher arrival rate) and the buses are travelling slower (lower traffic speed).

Scenario 1: no calibration (benchmark)
This scenario aims to evaluate the prediction results from BusSim-deterministic and BusSim-stochastic without calibrating their parameters, performing DA. This is done to allow evaluation of the predictive  Figure 7 shows one particular case where maxDemand equals 2, and ξ equals 7%, as an example of the prediction results. The dashed lines show the predicted trajectories of each bus (each line represents a single bus) from BusSim-deterministic and BusSim-stochastic, whereas the solid line shows the synthetic real-time data. The models are used to make predictions of bus locations at the next time step (next 10 s) without any model training and calibration.
Both models poorly predict the trajectories of the 'real' buses. The gaps between the predictions and the real trajectories widen as the buses operate (as the distance and time increase). This shows that the models are diverging from reality. This is expected because the models do not have the optimal parameters to capture the bus route operations. These models are therefore not useful for real-time prediction without parameter calibration or DA.

Scenario 2: parameter calibration
In this scenario, BusSim-deterministic and BusSim-stochastic are calibrated using the cross-entropy method, as described in §3.2. The two calibrated models are used to predict the bus locations at each time step t, which can be compiled to trajectories. Figure 8 shows an example of the comparison between the predictions from BusSim-deterministic and BusSim-stochastic versus the synthetic 'real-time' GPS data, where the maxDemand equals 2 and ξ equals 7%. Figure 8 shows that both models outperform the models in scenario 1 (no calibration ( figure 7). At the first quarter of the route (when Distance is less than 1000), there are few visible gaps between the predicted trajectories and the synthetic real-time data. However, the increasing divergence is still a major problem in this scenario. The gaps between the predicted trajectories and synthetic real-time trajectories widen by time. This is because BusSim-stochastic and BusSim-deterministic are both also static models, i.e. their model states do not change over time, whereas the synthetic data comes from a dynamic system. At ξ equals 7%, both the passenger demand and the traffic speed are changing rapidly. The two models have been well calibrated to the synthetic 'historical' data, but will provide a prediction result that is unchanged over time, and fail to take into consideration the dynamical changes in the system states.
Recall that there are differences between the 'historical' and 'real-time' data owing to the stochastic nature of the system under study ( figure 3). However, BusSim-stochastic, despite being able to produce stochastic outputs, shows no improvement in prediction performance in comparison to BusSim-determinstic (this is only capable of producing deterministic outputs). This shows that the changing system state is the main source of prediction error, not the deterministic or stochastic nature of the models. To remedy this, we need a procedure that would help the static models to deal with the uncertainty from the changes in a dynamic system and prevent the errors gradually increasing throughout the simulation.

Scenario 3: applying a particle filter
As discussed, DA is the chosen approach to enable the static BusSim-stochastic and BusSim-deterministic models to deal with the uncertainty from a system that is changing over time. PF is the specific DA algorithm being adopted in this paper. PF is able to deal with nonlinear, non-Gaussian models without an analytical structure. The well-known high computation cost concern of the PF [6,33] is not an issue in this study because of the limited number of agents used (bus and bus stop agents). This section applies a PF to the calibrated BusSim-deterministic and BusSim-stochastic, as described in §3.3. At each time step t, the two models are only provided with the observation vector O t , which uses O t to correct their prediction of future state vectors X t to X T , where T is the last time step. Figure 9 illustrates the results after the models have been calibrated and have 'real-time' data incorporated (assimilated) into them during runtime. Figure 9 shows a much better prediction performance, in comparison to the previous scenarios (figures 7 and 8). There are still observable gaps between the prediction and the synthetic 'real-time' GPS data. This is because the underlying models do not know the underlying stochasticity and dynamicity in the synthetic data, but the improvements (which will be quantified shortly) certainly appear to be substantial. Both the models are now capable of providing short-term predictions that are very close to the synthetic real-time data. Similar to the previous scenario, it is also noted that the two models show a similar predicting performance, albeit one is deterministic and the other is stochastic. The PF algorithm has effectively optimized the models as they operate and enabled them to provide good predictions of the bus locations in real time.

Sensitivity analysis
In this section, we perform a sensitivity analysis to compare the prediction error in each scenario. The same experiments, as described in scenarios 1-3, are repeated at different values of maxDemand and dynamic change rate ξ. To increase the robustness of the comparison, 10 replications have been made for each experiment, and the average root mean squared error (RMSE) values are reported. RMSE is calculated as the difference in prediction bus location and synthetic 'real-time' bus location: whereŷ k and y k are the bus location at time k from the model prediction and synthetic 'real-time' data, respectively. Table 3 compares the RMSE from each scenario. It is clear that scenario 3 (combination of parameter calibration and DA) outperforms the other two scenarios.

Implications and limitations
This paper presents an integrated framework to reduce uncertainty in ABMs when making predictions in real time, by combining parameter calibration and DA. As discussed in § §1 and 2, an 'identical twin' approach has been adopted instead of real noisy data to facilitate an effective evaluation of the proposed methods against the synthetic 'ground truth'. The numerical experiment shows that the framework yields more accurate predictions than (i) a benchmark scenario (without parameter calibration), and (ii) a scenario with parameter calibration but without DA. In its current form, the framework can provide real time bus locations and arrival times for passenger information systems. The forecasted bus location and arrival information provides key intelligence for waiting passengers [46]. This is beneficial for all public transport passengers, but can be of particular benefit in countries, for example, in the Global South [47], where there are frequent delays owing to transport systems being complex, heterogeneous or heavily congested. The prediction of bus arrival times is also critical for real-time trip planners. These planning systems propose optimal alternative routes for passengers, or update information on a connecting service that may be unreachable owing to delayed buses.
Many advanced intelligent transport system applications rely heavily on predictions of bus location and arrival times, for example bus control studies such as [48]. A model-based prediction of bus location and arrival time, such as the framework in this paper, would allow bus operators the ability to evaluate and update their transportation infrastructures in real time. Although the proposed BusSim-Truth simulation model is relatively simple (at least when compared with industry-leading models such as MatSim [2]) it is able to recreate some of the important features of the bus system such as leapfrogging, bus bunching, and responses to dynamic passenger demand. It is, therefore, adequate as a test bed for the PF; future work will test the PF on a more advanced and realistic simulation.
A notable limitation with the current framework is with regards to the treatment of traffic. Currently, the traffic volume on the network is represented with a single parameter (V t in equation (3.1)). Therefore, although the traffic volume can vary dynamically, it is homogeneous across the bus route. Although it is technically simple to implement homogeneous ( per link) traffic volumes, this would substantially increase the size and complexity of the model state space and would require a much larger number of particles to adequately capture the additional complexity. A further exciting opportunity for future development is to explore the implications of the buses affecting the surrounding traffic, rather than the impact of the traffic on the buses.
DA methods, similar to many other data-driven methods, require and rely on the quality of data. Another limitation of this work is with regard to the cases where the data have major discrepancy, that have not been addressed in this current framework. The current models, in principal, should still produce particles that are more reliable than data that are highly inaccurate. Future studies may look at developing a data quality check procedure into the framework in figure 1 to allow skipping the DA step if the data quality deteriorates to a certain value.

Conclusion
This paper proposes parameter calibration and DA frameworks to enhance the prediction accuracy in ABMs when the system under study has a stochastic and dynamic nature. Ultimately the methods will be applied to real data from real systems, but currently hypothetical 'pseudo-truth' data are generated to test the algorithms in an experimental environment as per the 'identical twin' approach. We first develop a stochastic and dynamic ABM of a bus route, referred to as BusSim-truth. This model is employed to generate synthetic 'historical' and 'real-time' GPS data of bus locations. The 'historical' data are used to train two simpler models of bus routes, referred to as BusSim-deterministic and BusSim-stochastic, and evaluated against the 'real-time' data.
Similar to real practice, when any simulation model is a simplification of the reality, BusSimdeterministic and BusSim-stochastic are simpler than BusSim-truth, and thus may not be able to produce a prediction similar to the synthetic 'real-time' GPS data under limited data. We propose a solution for this issue by parameter calibration using cross-entropy method (scenario 2), by a combination of parameter calibration and PF (scenario 3), and show that they outperform the no calibration scenario (scenario 1), at various levels of uncertainty. This paper shows the need for parameter calibration and DA, and particularly the combination of them, to improve the accuracy of model-based prediction using ABMs in real time. Future research directions includes fitting the proposed framework with real data instead of synthetic data. Appendix A. The BusSim model The following notation will be used to formalize each of the simulation models:  Figure 2 illustrates the workflow for BusSim-truth. At each current time step t, each Bus agent checks whether the next time step would be larger than the vehicle's scheduled dispatch time δ j . If t > δ j , we then check whether the bus is on the road (status equals MOVING), or at a stop for passenger dwelling (status equals DWELLING), or has finished its service (status equals FINISHED), otherwise the bus remains IDLE.
If the status is MOVING, we first check whether the bus is at a bus stop, by comparing the GeoFence area of each bus stop agent with the bus' location. If the bus is not approaching a bus stop, its current speed v j will be compared with the surrounding traffic speed V. If v j < V, we assume that the bus will speed up with an acceleration rate a j , thus we have Therefore, for the next time step, the bus will cover a distance of If the speed already matches the traffic speed V, the bus will maintain the same speed. Or else if the bus is approaching a bus stop, the system will first check if the stop is the last stop. If it is the last stop, then the bus' status will be changed to FINISHED and bus speed is changed to zero. If it is not the last stop, the system will change the status of agent bus j to DWELLING and its speed to zero. The number of boarding and alighting passengers from the bus j, and the time that it will leave the stop are estimated as follows.
royalsocietypublishing.org/journal/rsos R. Soc. open sci. 7: 191074 The number of boarding passenger is proportional to the time gap between the current time (when bus j approaches the bus stop m) and the last time any bus visits the bus stop m: B j,m ¼ bPo(Arr m Á (t a jþ1,m À t a j,m )e j B j,m [ N: Equation (A 3) shows that the number of boarding passengers is estimated using a stochastic Poisson process. A Poisson process is widely adopted in the literature to estimate the count of passengers waiting at a public transport stop [25,27]. Extensions of this stochastic process have been introduced, such as a nonhomogeneous Poisson process [49], where the arrival rate is time-dependent, but for simplicity we adopt a homogeneous Poisson process for this paper. Equation (A 3) makes the BusSim-truth model stochastic, because there is randomness in the way the Poisson process generates a number. For more details on the number generation process using stochastic Poisson process (e.g. thinning algorithm), interested readers may refer to [50]. The number of boarding passengers is also limited by the available capacity of the bus: The number of alighting passengers is proportional to the number of passenger on board (bus occupancy) and the departure rate at the stop m. For simplicity, we assume that A j,m is the product between the departure rate from bus stop m and the current bus occupancy (the number of passenger on board leaving the last stop): A j,m ¼ bDep m Á Occ j,mÀ1 e j A j,m [ N: (A 5) To estimate the amount of time that bus will have to stay at the bus stop m for passenger boarding and alighting, a.k.a. dwell time D j,m , we adopt the approach in [51] and the transit capacity and quality of service manual (TCQSM) [52]: The parameter set [θ 1 , θ 2 , θ 3 ] represents the time spent for passenger boarding, alighting, and a fixed value for vehicle stopping and starting, respectively. Equation (A 6) is the formulation for a singledoor bus system, where boarding and alighting occurs sequentially. In BusSim, the bus j is only allowed to leave the bus m at time t d j,m , so this is also called the Leave stop time, as can be seen in figure 2.
If the status of bus j is DWELLING, it is at a stop for passenger boarding and alighting. We then check if the next time step would be larger or equal to the leave stop time t d j,m . If it would, then the bus would start accelerating to leave the stop, otherwise it would stay for at least another time interval. Finally, if the status of the bus is FINISHED, then we would do nothing. The modelling process then moves to the next bus agent until the last bus, then the whole model moves to the next time step until the last time step.
BusSim-truth also assumes that parameters dynamically change over time by introducing an additional parameter ξ to represent the change in passenger demand or surrounding traffic speed. For simplicity, we assume that a single, deterministic parameter ξ can model these dynamic changes. In practice, it is possible, and more desirable, to use a time-dependent value of ξ such that dynamic change is better captured, and multiple ξ to model different changes. ξ > 0 represents an increase in passenger demand and traffic speed, and ξ < 0 represents otherwise. In this paper, the change in passenger demand or traffic speed is modelled as and Arr m ¼ Arr m Á 1 À t T Á 100 j : A positive value of ξ in equation (A 9) gradually reduces the surrounding traffic speed V and increases the arrival rate Arr m , which would lead to more bus delays and congestion.
m j am 0 j þ (1 À a)m j %Update with step size α 18 s j as 0 j þ (1 À a)s j %Update with step size α 19 end