S IMULATING C ROWDS IN R EAL T IME WITH A GENT -B ASED M ODELLING AND A P ARTICLE F ILTER ∗

,


Introduction
. Agent-based modelling is a form of computer simulation that is well suited to modelling human systems (Bonabeau ; Farmer & Foley ). In recent years it has emerged as an important tool for decision makers who need to base their decisions on the behaviour of crowds of people (Henein & White ). Such models, that simulate the behaviour of synthetic individual people, have been proven to be useful as tools to experiment with strategies for humanitarian assistance (Crooks & Wise ), emergency evacuations (Ren et al. ; Schoenharl & Madey ), management of religious festivals (Zainuddin et al. ), reducing the risk of crowd stampedes (Helbing et al. ), etc. Although many agent-based crowd simulations have been developed, there is a fundamental methodological di iculty that modellers face: there are no established mechanisms for incorporating real-time data into simulations (Lloyd et al. ; Wang & Hu ; Ward et al. ). Models are typically calibrated once, using historical data, and then projected forward in time to make a prediction independently of any new data that might arise. Although this makes them e ective at analysing scenarios to create information that can be useful in the design of crowd management policies, it means that they cannot currently be used to simulate real crowd systems in real time. Without knowledge of the current state of a system it is di icult to decide on the most appropriate management plan for emerging situations. sources such as population counters, mobile phone cell tower usage statistics, etc., which means that considerable real-time analysis would be required before the data were appropriate for input into the data assimilation algorithm. Hence rather than presenting a proven solution, this paper lays important groundwork towards realtime pedestrian modelling, outlining the considerable challenges that remain.

Background
Agent-based crowd modelling . One of the core strengths of agent-based modelling is its ability to replicate heterogeneous individuals and their behaviours. These individuals can be readily placed within an accurate representation of their physical environment, thus creating a potentially powerful tool for managing complex environments such as urban spaces. Understanding how pedestrians are likely to move around di erent urban environments is an important policy area. Recent work using agent-based models have shown value in simulating applications from the design of railway stations (Klügl & Rindsfüser ; Chen et al. ), the organisations of queues (Kim et al. ), the dangers of crowding (Helbing et al. ) and the management of emergency evacuations (van der Wal et al. ). .
However, a drawback with all agent-based crowd simulations -aside from a handful of exceptions discussed below -is that they are essentially models of the past. Historical data are used to estimate suitable model parameters and models are evolved forward in time regardless of any new data that might arise. Whilst this approach has value for exploring the dynamics of crowd behaviour, or for general policy or infrastructure planning, it means that models cannot be used to simulate crowd dynamics in real time. The drivers of these systems are complex, hence the models are necessarily probabilistic. This means that a collection of models will rapidly diverge from each other and from the real world even under identical starting conditions. This issue has fostered an emerging interest in the means of better associating models with empirical data from the target system (see, e.g., Wang & Hu ; Ward et al. ; Long & Hu ).

Data-driven agent-based modelling .
The concept of Data-Driven Agent-Based Modelling (DDABM) emerged from broader work in data-driven application systems (Darema ) that aims to enhance or refine a model at runtime using new data. One of the most well developed models in this domain is the 'WIPER' system (Schoenharl & Madey ). This uses streaming data from mobile telephone towers to detect crisis events and model pedestrian behaviour. When an event is detected, an ensemble of agent-based models are instantiated from streaming data and then validated in order to estimate which ensemble member most closely captured the particular crisis scenario (Schoenharl & Madey ). Although innovative in its use of streaming data, the approach is otherwise consistent with traditional methods for model validation based on historical data (Oloo & Wallentin ). Similar attempts have been made to model solar panel adoption (Zhang et al. ), rail (Othman et al. ) and bus (Kieu et al.
) travel, crime (Lloyd et al. ), bird flocking (Oloo et al. ) and aggregate pedestrian behaviour (Ward et al. ), but whilst promising, these models have limitations. For example, they either assume that agent behaviours can be proxied by regression models (Zhang et al. ) (which will make it impossible to use more advanced behavioural frameworks to encapsulate the more interesting features of agent behaviour), are calibrated manually (Othman et al. ) (which is infeasible in most cases), optimise model parameters dynamically but not the underlying model state (Oloo et al. ) (which might have diverged substantially from reality), or use models whose dynamics can be approximated by an aggregate mathematical model (Lloyd et al. ; Ward et al. ) (neglecting the importance of using agent-based modelling in the first place).
. In addition to those outlined above, there are two further studies that are of direct relevance and warrant additional discussion. The first is that of Lueck et al. ( ), who developed an agent-based model of an evacuation coupled with a particle filter. Their aim is to develop a new data association scheme that is able to map from a 'simple' data domain, such as that produced by population counters that might exist in the real world, to a more complex domain, such as an agent-based model that aims to simulate the real system. This mapping is important because without such a method it is di icult to determine which observations from the real world should map onto individual agents in the simulation. As with this paper, Lueck et al. ( ) use simulated "ground-truth" data akin to the 'identical twin' approach. The main di erence between this paper and that one relates to the underlying system that is being simulated. Here the agents move across a continuous surface and crowding emerges as the agents collide. In theory the agents can reach any part of the environment, although in practice this is very unlikely because they attempt to move towards specific exits. In Lueck et al. ( ) the agents navigate across a vector road network so their movements are constrained to a set of discrete nodes and there are no collisions or 'crowding' as such. Ultimately although the two simulations are drawn from the same research domain, that of pedestrian movements, they are working on di erent problems. As will be addressed in the discussion, immediate future work for this paper will be to move towards a more realistic pedestrian system and it is expected that the mapping method proposed by Lueck et al. ( ) will be essential as a means of consolidating the aggregate observations that are drawn from the real world with state vector of an agent-based model that simulates individual agents. .
The second study is that of Wang & Hu ( ) who investigated the viability of simulating individual movements in an indoor environment using streams of real-time sensor data to perform dynamic state estimation. As with this paper and that of Lueck et al. ( ), the authors used an 'identical twin' experimental framework. An ensemble of models were developed to represent the target system with a particle filter used to constrain the models to the hypothetical reality. A new particle resampling method called 'component set resampling' was also proposed that is shown to mitigate the particle deprivation problem; see Section . for more details. The research presented within this paper builds on Wang & Hu ( ) by: (i) attempting to apply data assimilation to a system that exhibits emergence; and (ii) performing more extensive experiments to assess the conditions under which a particle filter is appropriate for assimilating data into agent-based crowd models.

Data Assimilation and the Particle Filter
.
'Data assimilation' refers to a suite of mathematical approaches that are capable of using up-to-date data to adjust the state of a running model, allowing it to more accurately represent the current state of the target system. They have been successfully used in fields such as meteorology, where in recent years -day weather forecasts have become more accurate than -day forecasts were in the s (Bauer et al. ); partly due to improvements in data assimilation techniques (Kalnay ). The need for data assimilation was initially born out of data scarcity; numerical weather prediction models typically have two orders of magnitude more degrees of freedom than they do observation data. Initially the problem was addressed using interpolation (e.g. Panofsky ; Charney ), but this soon proved insu icient (Kalnay ). The eventual solution was to use a combination of observational data and the predictions of short-range forecasts (i.e. a model) to create the full initial conditions (the 'first guess') for a model of the current system state that could then make forecasts. In e ect, the basic premise is that by combining a detailed but uncertain model of the system with sparse but less uncertain data, "all the available information" can be used to estimate the true state of the target system (Talagrand ).
. A particle filter is only one of many di erent methods that have been developed to perform data assimilation. Others include the Successive Corrections Method, Optimal Interpolation, D-Var, D-Var, and various variants of Kalman Filtering; see Carrassi et al. ( ) for a review. The particle filter method is chosen here because it is non-parametric; such methods and are better suited to performing data assimilation in systems that have nonlinear and non-Gaussian behaviour (Long & Hu ), such as agent-based models. In fact, agent-based models are typically formulated as computer programs rather than in the mathematical forms required of many data assimilation methods, such as the Kalman filter and its variants (Wang & Hu ). .
The particle filter is a brute force Bayesian state estimation method. The goal is to estimate a posterior distribution, i.e. the probability that the system is in a particular state conditioned on the observed data, using an ensemble of model instances, called particles. Each particle has an associated weight, normalised to sum to one, that are drawn from a prior distribution. In the data assimilation step, discussed shortly, each particle is confronted with observations from the pseudo-real system and weights are adjusted depending on the likelihood that a particle could have produced the observations. Unlike most other data assimilation methods, a particle filter does not actually update the internal states of its particles. Instead, the worst performing particles -those that are least likely to have generated the observations -are removed from subsequent iterations, whereas better performing particles are duplicated. This has the advantage that, when performing data assimilation on an agent-based model, it is not necessary to derive a means of updating unstructured variables. For example, it is not clear how data assimilation approaches that have been designed for mathematical models that consist of purely numerical values will update models that contain agents with categorical variables.
. Formally, a particle filter (PF) P k consists of an ensemble of simulation realisations and a corresponding set of weights, i.e. where N p is the number of particles, x (i) k is the state vector of the i-th particle at the k-th observation, w k is the corresponding weight associated with particle i at observation k, and the weights are subject to the condition Np i=1 w (i) k = 1 for all observations k. The general method of the particle filter is to use P k , the simulation model and new information in the form of observations to determine P k+1 .

.
There are many di erent PF methods. The standard form is the sequential importance sampling (SIS) PF which selects the weights using importance sampling (Bergman ; Doucet et al. ). The particles are sampled from an importance density (Uosaki et al.
). One pitfall of the SIS PF is particle degeneracy. This occurs when the weights of all the particles tend to zero except for one particle which has a weight very close to one. This results in the population of particles being a very poor estimate for the posterior distribution. One method to prevent particle degeneracy is to resample the particles, duplicating particles with a high weight and discarding particles with a low weight. The probability of a particle being resampled is proportional to its weight; known as the sequential importance resampling (SIR) PF. The particles can be resampled in a variety of di erent ways, including multinomial, stratified, residual, systematic, and component set resampling (Liu & Chen ; Douc et al. ; Wang & Hu ). Although resampling helps to increase the spread of particle weights, it is o en not su icient (Carrassi et al. ). In a similar manner to particle degeneration in the SIS PF, particle collapse can occur in the SIR PF. This occurs when only one particle is resampled so every particle has the same state. .
One of the main drawbacks with PF methods, as many studies have found (e.g. Snyder et al.
; Carrassi et al. ), is that the number of particles required to prevent particle degeneracy or collapse grows exponentially with the dimensionality of the model. This is an ongoing problem that will be revisited throughout this paper. Hence the work here o ers a useful starting point for particle filtering and agent-based crowd modelling, but there are considerable challenges that must be overcome before it can be proven to be useful in a real setting. Fortunately there are numerous innovations to the particle filter method, which we revisit in Section . , that will help. These include the auxiliary SIR PF and the regularised PF (Arulampalam et al. ), the merging PF (Nakano et al. ), and the resample-move PF (Gilks & Berzuini ), as well as many othera (van Leeuwen ).

Method
The agent-based model: StationSim . StationSim is an abstract agent-based model that has been designed to very loosely represent the behaviour of a crowd of people moving from an entrance on one side of a rectangular environment to an exit on the other side. This is analogous to a train arriving at a train station and passengers moving across the concourse to leave. A number of agents, N a , are created when the model starts. They are able to enter the environment, i.e. leave their train, at a uniform rate through one of three entrances. They move across the 'concourse' and then leave by one of the two exits. The entrances and exits have a set size, such that only a limited number of agents can pass through them in any given iteration. Once all agents have entered the environment and passed through the concourse then the simulation ends. The model environment is illustrated in Figure , with the trajectories of two interacting agents for illustration. All model parameters are specified in Table . . van der Wal et al.

The
). The reason for this simplicity is so that: ( ) the model can execute relatively quickly; ( ) the probabilistic elements in the model are limited as we know precisely from where probabilistic behaviour arises; and ( ) the model can be described fully using a state vector, as discussed in Section . . Importantly, the model is able to capture the emergence of crowding. This occurs because each agent has a di erent maximum speed that they can travel at. Therefore, when a fast agent approaches a slower one, they attempt to get past by making a random binary choice to move le or right around them. Depending on the agents in the vicinity, this behaviour can start to lead to the formation of crowds. To illustrate this, Figure shows the paths of the agents ( ) and the total agent density ( ) during an example simulation. The degree and location of crowding depends on the random allocation of maximum speeds to agents and their random choice of direction taken to avoid slower agents; these cannot be estimated a priori. Unlike in previous work where the models did not necessarily meet the common criteria that define agent-based models (Lloyd et al. ; Ward et al. , e.g.) this model respects three of the most important characteristics: • individual heterogeneity -agents have di erent maximum travel speeds; • agent interactions -agents are not allowed to occupy the same space so try to move around slower agents who are blocking their path; • emergence -crowding is an emergent property of the system that arises as a result of the choice of exit that each agent is heading to and their maximum speed.
. The model code is relatively short and easy to understand. It is written in Python, and is available in its entirety at in the project repository (DUST ). For the interested reader, additional model diagnostics have also been produced to illustrate the locations of collisions, a video of typical model evolution, the total evacuation time, the expected evacuation time were there no collisions, etc .

Data assimilation -Introduction and definitions
.
DA methods are built on the following assumptions: . Although they may have low uncertainty, observational data are o en spatio-temporally sparse. Therefore there are typically insu icient amounts of data to to describe the system in detail and a data-driven approach would not work.
. Models are not sparse; they can represent the target system in great detail and hence fill in the spatiotemporal gaps in observational data by propagating data from observed to unobserved areas (Carrassi et al. ). For example, some parts of a building might be more heavily observed than others, so a model that assimilated data from the observed areas might be able to estimate the state of the unobserved areas. However, if the underlying systems are complex, a model will rapidly diverge from the real system in the absence of up to date data (Ward et al. ).
. The combination a model and up-to-date observational data allow "all the available information" to be used to determine the state of the system as accurately as possible (Talagrand ).  Figure : Flowchart of data assimilation process using a particle filter.
. DA algorithms work by running a model forward in time up to the point that some new observational data become available. This is typically called the predict step. At this point, the algorithm has an estimate of the current system state and its uncertainty; the prior. The next step, update, involves using the new observations, and their uncertainties, to update the current state estimate to create a posterior estimate of the state. As the posterior has combined the best guess of the state from the model and the best guess of the state from the observations, it should be a closer estimate of the true system state than that which could be estimated from the observations or the model in isolation.

The particle filter .
There are many di erent ways to perform data assimilation, as discussed in Section . . Here, a potentially appropriate solution to the data assimilation problem for agent-based models is the particle filter -also known as a Bayesian bootstrap filter or a sequential Monte Carlo method -which represents the posterior state using a collection of model samples, called particles ( ). Figure illustrates the process of running a particle filter. Note that the 'pseudo-truth model' is a single instance of the agent-based model that is used as a proxy for the real system as per the identical twin experimental framework that we have adopted. The Sequential Importance Resampling (SIR) filter with systematic resampling is used here because it ranks higher in resampling quality and computational simplicity compared to other resampling methods (Hol et al. ; Douc et al. ).
. The data assimilation 'window' determines how o en new observations are assimilated into the particle filter. The size of the window is an important factor -larger windows generally result in the particles deviating further from the real system state. Here we fix the window at iterations. We denote the observation times by t k , for integers k between and the number of observations N obs , so in the particular case considered here t 1 is the th iteration of the simulation, t 2 the th etc.

The state vector and transition Function
.
Here, the state vector x (i) k at time t k of the i-th particle contains all the information that a transition function, i.e. the simulation model, needs to iterate the state forward by one time step, including all agent and simulation environment variables. Here, the particle filter is only used to estimate the model state, but it is worth noting that combined state and parameter estimation is possible (Ward et al. ). The state vector for StationSim consists of just the coordinates of each agent, thus x (i) k ∈ R 2Na . It is not necessary to store agent velocities since StationSim determines this from each agent's position and the positions of other agents nearby. Agents' maximum speeds and exit choices are assumed to be known parameters. .
The observation vector y k contains all of the observations made from the 'real world' (in this case the pseudotruth model) at the k-th observation. Here we assume that the observation vector is a measurement of the true state x k at time t k , with the addition of noise, so where ξ k is uncorrelated Gaussian noise, i.e. ξ k ∼ N (0, σ 2 m I) with mean 0, variance σ 2 m and I is the 2N a by 2N a identity matrix. .
The fact that the state and observation vectors have the same size has the e ect of 'pairing' agents in each particle to those in the pseudo-truth data, similar to the case considered in Wang & Hu ( ). Consequently it is worth noting that, because the particle filter will not be tasked with parameter estimation, the data assimilation problem is somewhat less complicated than it would be in a real application where this pairing would not be possible. For example, the agent parameter used to store the location of the exit out of the environment that an agent is moving towards is assumed to be known, consequently the particle filter does not need to estimate where the agents are going, only where they currently are. This is analogous to tracking all individuals in a crowd and providing snapshots of their locations at discrete points in time to the particle filter. This 'synthetic observation' is more detailed than data typically available.

Particle weights .
Each particle i in the particle filter has a time varying weight w (i) k associated with it that quantifies how similar a particle is to the observations. The weights are calculated at the end of each data assimilation window, i.e. when observations have become available. At the start of the following window the particles then evolve independently from each other (Fearnhead & Künsch ). The weights a er the k-th observation are computed as follows. For each particle, the l 2 -norm of the di erence between the particle state vector x (i) k and the observation vector y k is computed, ε and the updated weight is then w , where η is a normalising constant. The mean PF error at the k-th observation is then Here, a Sequential Importance Resampling (SIR, discussed in Section . or bootstrap filter is implemented that uses systematic resampling, which is computationally straightforward and has good empirical performance (Doucet et ( ) Using the inversion method, we calculate the cumulative sum of the normalised particle weights w (i) k and define the inverse function D of this cumulative sum, that is: ( ) Finally, the new locations of the resampled particles are given by x D(U i ) . Particles with relatively large error, and hence small weight, are likely to be removed during the resampling procedure, whereas those with low error, and hence high weight, are likely to be duplicated. The weighted sum of the particle states, is used to estimate the 'true' system state. Other summary statistics can be computed from appropriate weighted sums. .
A well-studied issue that particle filters face is that of particle deprivation (Snyder et al. ), which refers to the problem of particles converging to a single point such that all particles, but one, vanish (Kong et al. ). Here, the problem is addressed in two ways. Firstly, by simply using increasingly larger numbers of particles and, secondly, by diversifying the particles (Vadakkepat & Jing ); also known as roughening, jittering, and di using (Li et al. ; Shephard & Flury ; Pantrigo et al. ). In each iteration of the model we add Gaussian white noise to the particles' state vector to increase their variance, which increases particle diversity. This encourages a greater variety of particles to be resampled and therefore makes the algorithm more likely to represent the state of the underlying system. This method is a special case of the resample-move method presented in Gilks & Berzuini ( ). The amount of noise to add is a key hyper-parameter -too little and it has no e ect, too much and the state of the particles moves far away from the true state -as discussed in the following section.

Experimental Results
Outline of the experiments . Recall that the aim of this paper is to experiment with the conditions under which a typical particle filter coupled with an agent-based model can estimate the 'true' state of an underlying pedestrian system through the combination of a modelled state estimate and observational data. By examining the error-i.e. the di erence between the particle filter estimate of the system state and the pseudo-truth data-under di erent conditions, this paper will present some preliminary estimates of the potential for the use of particle filtering in real-time crowd simulation. In particular, this paper will estimate the minimum number of particles that are needed to model a system that has a given number of agents. The dynamics of the model used here are less complicated than those of more advanced crowd models, and hence the particle filter is tasked with an easier problem than it would have to solve in a real-world scenario. In addition, the number of particles used and the characteristics of the observations provided to the particle filter are much less complicated than would be the case in reality. Therefore although these experiments provide valuable insight into the general potential of the method for crowd simulation, considerable further work would be required before the method can be used to simulate real crowds in earnest. Sections . and . reflect on these factors in detail. .
It is well known that one of the main drawbacks with a particle filter is that the number of particles required can explode as the complexity of the system increases (e.g. Snyder et al. ; Carrassi et al. ). In this system, the complexity of the model is determined by the number of agents. As outlined in Section . , randomness is introduced through agent interactions. Therefore the fewer the number of agents, the smaller the chance of interactions occurring and the lower the complexity. As the number of agents increases, we find that the number of interactions increases exponentially; Figure , discussed in the following section, will illustrate this. This paper will also experiment with the amount of particle noise (σ p ) that needs to be included to reduce the problem of particle deprivation, as discussed in Sections . and . , but this is not a focus of the experiments.

.
To quantify the 'success' of each parameter configuration -i.e. the number of particles N p and amount of particle noise σ p that allow the particle filter to reliably represent a system of N a agents -an estimate of the overall error associated with a particular particle filter configuration is required. There are a number of di erent ways that this error could be calculated. Here, a three-step approach is adopted. Firstly, the overall error of a single particle is calculated by taking its mean weight a er resampling in every data assimilation window. Secondly, to calculate the error associated with all particles in a single experimental result -e.g. a particular (N a , N p ) combination -the mean error of every particle is calculated. Finally, because the results from an individual experiment will vary slightly, each (N a , N p ) combination is executed a number of times, M , and the overall error is taken as the median error across all of those individual experiments. The median is chosen because some experiments are outliers, therefore it is a fairer estimate of the overall error across all experiments.
. Formally, let ν k (j) be the mean PF error in data assimilation window k of the j-th experiment, thus the median of M experiments of the time-averaged mean PF error is: where T is the total number of data assimilation windows. .

Results
Benchmarking . Before experimenting with the particle filter, a set of benchmarking experiments were conducted. In these experiments the particle filter was run as normal but without particle reweighting or resampling. This provides an illustration of the degree of uncertainty that can be attributed to the random interactions of agents in the model and also allows us to quantify the level of error that would be expected were there no data assimilation. The number of agents (N a ) was varied from to in steps of and for each N a ten individual experiments were conducted. The number of particles chosen does not influence the overall error, so N p = 1000 was used in all benchmarking experiments to balance the computational demands of running larger numbers of particles with the drop in consistency that would occur with fewer particles. Figure illustrates the results of the benchmarking experiments. It presents the mean error of the population of particles for each experiment.
. The error in Figure increases with the number of agents. This is entirely expected because as the number of agents increases so does the randomness in the model and, hence, the degree to which models will diverge from a pseudo-truth state. Importantly, the red dots illustrate the median error that would be generate with reweighting and resampling (i.e. full data assimilation, discussed in Section . under the same numbers of agents and particles. In all cases the error is lower with data assimilation, evidencing the importance of the   Broadly there is a reduction in error from the bottom-right corner (few particles, many agents) to the top le corner (many particles, few agents). The results illustrate that, as expected, there is a larger error with increasing numbers of agents but this can be mediated with larger numbers of particles. Note the logarithmic scale used on the vertical axis; an exponentially greater number of particles is required for each additional agent included in the simulation.

.
There are two reasons for this exponential increase in the number of particles required. Firstly, as the number of agents increases so does the dimensionality of the state space. Also, with additional agents the chances of collisions, and hence stochastic behaviour, increases exponentially. This is illustrated by Figure which presents the total number of collisions that occur across a number of simulations with a given number of agents.
. On its own, the overall particle filter error (Figure ) reveals little information about which configurations would be judged 'su iciently reliable' to be used in practice. Therefore it is illuminating to visualise some of the results Figure : The total number of collisions that occur given the number of agents. The blue line represents a polynomial regression model of order with % confidence intervals. State of a particle filter with agents and particles a er and iterations a er resampling at the end of the first and second data assimilation windows. Black squares illustrate the pseudo-real locations of the agents and red circles represent the locations of those agents as predicted by individual particles. In this case all particles predict the agents' locations accurately and hence the red circles overlap.
of individual particle filter runs to see how the estimates of the individual agents' locations vary, and what might be considered an 'acceptable' estimate of the true state. Figure illustrates the state of a particle filter with particles and agents at the end of its first data assimilation window (a er resampling). With only ten agents in the system there are few, if any, collisions and hence very little stochasticity; all particles are able to represent the locations of the agents accurately. .
As the number of agents increases, collisions become much more likely and the chance of a particle diverging from the pseudo-truth state increases considerably. It becomes more common that no single particle will correctly capture the behaviours of all agents. Therefore even a er resampling there are some agents whose locations the particle filter is not able to accurately represent. Figure illustrates a filter running with agents and still only particles. The long black lines show the locations of pseudo-real agents and the corresponding agents in the individual particles; it is clear that for some agents none of the particles have captured their pseudo-real locations. This problem can be mediated by increasing the number of particles. Figure showed that with approximately , particles the error for simulations with agents drops to levels that are comparable to the simulations of agents. Hence a rule of thumb is that any particle filter with an overall error that is comparable to a clearly successful filter, i.e. as per Figure , are reliably estimating the state of the system.

Impact of resampling .
Resampling is the process of weighting all particles according to how well they represent the pseudo-truth data; those with higher weights are more likely to be sampled and used in the following data assimilation window. This is important to analyse because it is the means by which the particle filter improves the overall quality of its estimates. Figure  State of a particle filter with agents and particles. Lines connecting black squares (the pseudoreal agent locations) to red circles (particle estimate of the agent location) show that some particle estimates are a long way from the true agent locations. Figure : Median of the mean errors before and a er resampling agents in the system resampling is unnecessary because all particles are able to successfully model the state of the system. With more than agents, however, it becomes clear that the population of particles will rapidly diverge from the pseudo-truth system state and resampling is essential for the filter to limit the overall error.

Particle variance .
As discussed in Section . , the variance of the population of particles can be a reliable measure for estimating whether particle deprivation is occurring. If there is very little variance in the particles, then it is likely that they have converged close to a single point in the space of possible states. This needs to be avoided because, in such situations, it is extremely unlikely that any particles will reliably represent the state of the real system. • With agents and particles there is very low error and low variance (so low that the box plots are di icult to make out on Figure ). This suggests that particle deprivation is occurring, but there are so few agents that the simulation is largely deterministic so the particles are likely to simulate the pseudotruth observations accurately regardless.
• When the number of agents is increased to agents and particles, the errors are much larger. The increased non-linearity introduced by the greater number of agents (and hence greater number of colli- sions) means that the population of particles, as a whole, is not able to simulate the pseudo-truth data. Although particle variance can be high, none of the particles are successfully simulating the target.
• Finally, with agents and , particles, the errors are relatively low in comparison, especially a er the first few data assimilation windows, and a reasonable level of variance is maintained.
The number of particles (N p ) is the most important hyper-parameter, but the amount of noise added to the particles (σ p ) is also important as this is the means by which particle deprivation is prevented. However, the addition of too much noise will push a particle a long way away from the true underlying state. Under these circumstances, although particle deprivation is unlikely none of the particles will be close to the true state.
To illustrate this, Figure presents the median error with a greater amount of noise (σ p = 0.5). The overall pattern is similar to the equivalent graph produced with σ p = 0.25 in Figure -as the number of agents in the simulation (N a ) increases so does the number of particles required to maintain low error (N p ) -but the overall error in each (N a , N p ) combination is substantially larger for the experiments with additional noise. Future work could explore the optimal amount of noise in more detail; σ p = 0.25 was found to be the most reliable through trial and error.

Discussion and Future Work
Summary . This paper has experimented with the use of a sequential importance resampling (SIR) particle filter (PF) as a means of dynamically incorporating data into an abstract agent-based model of a pedestrian system. The results demonstrate that it is possible to use a particle filter to perform dynamic adjustment of the model. However, they also show that, as expected (Rebeschini & van Handel ; Carrassi et al. ), as the dimensionality of the system increases, the number of particles required grows exponentially as it becomes less likely that an individual particle will have the 'correct combination' of values (Long & Hu ). In this work, the dimensionality is proportional to the number of agents. At most , particles were used, which was su icient for a Figure : Median of the mean errors a er resampling with additional noise (σ = 0.5).
simulation with -agents. However, for a more complex and realistic model containing hundreds or thousands of agents, the number of particles required would grow considerably. In addition, the particle filter used in this study was also provided with more information than would normally be available. For example, information was supplied as fixed parameters on when each agent entered the simulation, their maximum speeds, and their chosen destinations. Therefore the only information that the particle filter was lacking were the actual locations of the agents and whether they would chose to move le or right to prevent a collision with another agent. It is entirely possible to include the additional agent-level parameters in the state vector, but this would further increase the size of the state space and hence the number of particles required.
. These constraints, and the additional computational challenges that would be required to relax them, do not mean that real-time agent-based crowd simulation with a particle filter is not feasible. To begin with, there are many improvements that can be made to this bootstrap filter to reduce the number of particles required. For a thorough review of relevant methods, see van Leeuwen ( ). In addition, it is possible to execute this particle filter on high performance machines with the thousands or tens of thousands of cores to significantly scale up the number of particles. Implementations of particle filters on GPUs are becoming popular (Lopez et al. ) due to the huge numbers of GPU cores that can be leveraged to execute the individual particles. The StationSim model would be relatively easy to reimplement in a language that lends itself well to a GPU implementation; current work is exploring this aspect in particular. In addition, although agent-based models are complex, high-dimensional and non-linear, this does not preclude them from successful particle filtering. Geophysical systems, such as the atmosphere or the oceans, are also non-linear and can have state spaces considerably larger than million variables, but have proven amenable to particle filtering (van Leeuwen ). Overall, although the experiments here show promise, it is important to note that work is still needed before the aim of simulating a real crowd will be realised. .
One particularly encouraging feature of the particle filter is that, unlike other data assimilation approaches, it does not dynamically alter the state of the running model. This could be advantageous because, with agentbased modelling, it is not clear that the state of an agent should be manipulated by an external process. Agents typically have goals and a history, and behavioural rules that rely on those features, so artificially altering an agent's internal state might disrupt their behaviour making it, at worst, nonsensical. Experiments with alternative, potentially more e icient, algorithms such as DVar or a the Ensemble Kalman Filter should be conducted to test this.

Improvements to the particle filter .
There are a number of possible improvements that could be made to the basic SIR particle filter to reduce the number of particles required. One obvious example is that of Component Set Resampling (Wang & Hu ). With that approach, individual components of particles are sampled, rather than whole particles in their entirety. Alternatively, a more commonly used approach is to reduce the dimensionality of the problem in the first place. With spatial agent-based models, such as the one used here, spatial aggregation provides such an opportunity. In the data assimilation stage, the state vector could be converted to an aggregate form, such as a population density surface, and particle filtering could be conducted on the aggregate surface rather than on the individual locations of the agents. A er assimilation, the particles could be disaggregated and then run as normal. This will, of course, introduce error because the exact positions of agents in the particles will not be known when disaggregating, but that additional uncertainty might be outweighed by the benefits of a more successful particle filtering overall. In addition, the observations that could be presented to an aggregate particle filter might be much more in line with those that are available in practice; this is discussed in more detail below. If the aim of real-time model optimisation is to give decision makers a general idea about how the system is behaving, then this additional uncertainty might not be problematic. A similar approach, proposed by Rebeschini & van Handel ( ), could be to divide up the space into smaller regions and then apply the algorithm locally to these regions. Although it is not clear how well such a "divide-and-conquer" approach would work in an agent-based model -for example, Long & Hu ( ) developed the method for a discrete cellular automata model -it would be an interesting avenue to explore further.

Towards the incorporation of real-world observations .
One assumption made throughout this paper, which limits its direct real-world use, is that the locations of pseudo-real individuals are known, albeit with some uncertainty, and that these locations in the 'real world' map directly on to agents in the associated agent-based models that make up the individual particles in the filter. Not only is this mapping unrealistic, it is very unlikely that all individuals in a crowd will be tracked in the first place. Further, we would argue that the privacy implications of tracking individual people are not outweighed by the benefits o ered by a better understanding of the system. In reality, the data sources that capture information about pedestrian movements are diverse. They include Wi-Fi sensors that count the number of smart phones in their vicinity (Crols & Malleson ; Soundararaj et al. ), CCTV cameras that count passers-by (Soldatos & Roukounaki ), population density estimates produced using mobile cellular network data (Bogomolov et al. ; Grauwin et al. ) or social media (McArdle et al. ) and occasionally some movement traces of individuals generated from smart-phone applications (Malleson et al. ). However, none of the data generated from these sources are going to be directly compatible with the agent-based simulation used to represent reality. In e ect, there is a problem of data association; i.e. "determining which observation should be associated with which agent in the simulation" (Lueck et al. ). There will need to be processes of aggregation, disaggregation, smoothing, cleaning, noise reduction, etc., in real time in order to map the observation space to the model state space. Fortunately, attempts to create such a mapping are emerging. For example, Lueck et al. ( ) develop a new method that maps anonymous counts of people to individual agents. Similarly, approaches such as that of Georgievska et al. ( ), who estimate overall crowd density from noisy, messy locations of individual smart phones, could be used to combine data from multiple sources but produce a consistent population density surface to inform the data assimilation algorithm. On the whole, however, considerable further work is needed to understand the implications of attempting to assimilate such diverse data into a real-time pedestrian model.

Future work .
Ultimately the aim of this work is to develop methods that will allow simulations of human pedestrian systems to be optimised in real time. Not only will such methods provide decision makers with more accurate information about the present, but they could also allow for better predictions of the near future (c.f. Kieu et al. ). As discussed previously, there are computational challenges that must be experimented with further, i.e. by leveraging infrastructure that is capabale of running millions of particles, and fundamental challenges with regards to mapping real observations on to an agent-based model state space. Both of these areas will be explored by immediate future work. One problem that might arise, particularly with respect to the available data, is whether real observations will be su icient to identify a 'correct' agent-based model. Therefore experiments should explore the spatio-temporal resolution of the aggregate data required. Identifiability/equifinality analysis might help initially as a means of estimating whether the available data are su icient to identify a seemingly 'correct' model in the first place. In the end, such research might help to provide evidence to policy makers for the number, and characteristics, of the sensors that would need to be installed to accurately simulate the target system, and how these could be used to maintain the privacy of the people who they are recording.